still need to investigate how git commit hooks even work
As shown in this gist
create a hooks
directory in your .git
folder and just name the file "pre-commit
"
(make it executable too, if you are not on Windows)
But as mentioned in your linked question by sschuberth:
Adding long-running tasks in a pre-commit
hook generally is a bad idea as it blocks you from working.
Such checks should be done on a CI system that gates merges of commits that break tests
In other words, commit and push to an intermediate repo with a pre-receive hook, which will reject your push if the entire unit test suite fails at any point.
The OP Creos points out in the comments the following pre-commit hook gist example by Chad Maughan, as a good template:
#!/bin/sh
# this hook is in SCM so that it can be shared
# to install it, create a symbolic link in the projects .git/hooks folder
#
# i.e. - from the .git/hooks directory, run
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit
#
# to skip the tests, run with the --no-verify argument
# i.e. - $ 'git commit --no-verify'
# stash any unstaged changes
git stash -q --keep-index
# run the tests with the gradle wrapper
./gradlew test
# store the last exit code in a variable
RESULT=$?
# unstash the unstashed changes
git stash pop -q
# return the './gradlew test' exit code
exit $RESULT