I\'m just starting to look into Git hooks, but I can\'t seem to get them to run.
I set up a local repository, so there is now a \'.git\' directory in my project folder.
in my case where i did npm install
& accidentally deleted .git folder, npm install pre-commit --save
worked
For me i none of the above solution worked. I moved the pre-commit file from hooks to some other location, effectively deleting the file from hooks.
That Worked for me :D
If it helps anyone: I was getting following error:
error: cannot spawn .git/hooks/pre-commit: No error
Turned out that in my pre-commit file I did not have 'newline' character after last exit command:
#!/bin/sh
# From gist at https://gist.github.com/chadmaughan/5889802
# stash any unstaged changes
git stash -q --keep-index
# run the tests with the gradle wrapper
./gradlew test --daemon
# 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
# << must have a newline after above command >>
I was running gradle project on windows and gradle commands in cmder shell and cmd
You probably don't have the permissions to run the pre-commit
file
Run in your terminal:
chmod +x .git/hooks/pre-commit
Thanks to @vaughan for giving the idea
For me, I tried to run a .bat
file.
I discovered that backslashes need to be escaped:
For example:
#!/bin/bash
C:\\somefolder\\somefile.bat
Maybe it'll help someone - in my case, I had set core.hooksPath
to wrong directory. Reseting it with git config --global core.hooksPath '~/.githooks'
solved the issue :)