What could cause my git pre- and post- commit hooks to not run?
(please note: this question is not a duplicate; the answer to each of the other questions is either chmod +x
or "don't have a file extension", and neither are the issue here)
They are executable:
$ ls -alh .git/hooks/*-commit
-rwxr-xr-x … .git/hooks/post-commit
-rwxr-xr-x … .git/hooks/pre-commit
And this is the content of each of them:
#!/bin/sh
echo "$0 IS RUNNING"
exit 1
Running them manually works:
$ .git/hooks/pre-commit
.git/hooks/pre-commit IS RUNNING
But they aren't run by git
on commit:
$ git commit -am "Test hooks"
[master d17c0f38] Test hooks
1 file changed, 1 insertion(+)
This is with git 2.16.2
I have seen for instance the config core.hooksPath
being set to another path than $GIT_DIR/hooks
, making your hooks in that folder ignored.
Check your git config core.hooksPath
output, and more generally git config -l
for any out of the ordinary settings.
Note that a git commit -n
would skip the pre-commit hook.
Edit by wolever:
I've added this to the scripts in my core.hooksPath
directory, which will run the repo's hooks if they exist:
#!/bin/sh
set -eu
hook_name="$(basename "$0")"
hook_script=".git/hooks/$hook_name"
[ -e "$hook_script" ] && "$hook_script"
exit 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With