How to properly use post-receive hook?
My directory structure is:
~/parent.git/.git/hooks/post-receive
The post-receive hook looks like:
#!/bin/sh
git checkout开发者_如何学JAVA -f
When I push into parent.git, the script does not run. I can't figure out the problem, as every bit of the internet says this should work.
I chmod'd post-receive, so I know that is not the problem. Any help is much appreciated.
As Chris mentioned you seem to have the same problem as reset hard on git push
Specifically hooks run with CWD
and GIT_DIR
set to the .git
directory. This results in the checkout command running in the .git
dir and the normal error about that being overridden.
If you do an ls in the remote .git
dir you should find a full checkout in there.
The easiest way around this is to specify GIT_WORK_TREE on the front of the checkout command:
GIT_WORK_TREE=/my/git/checkout git checkout -f
The script Chris linked (http://utsl.gen.nz/git/post-update) is supposed to take care of this and a few other potential issues.
If I had a guess, I'd say that the pushing user doesn't have permission to perform the checkout in that directory. What I'd suggest you do is to build the minimal working script and build from there. IE, instead of:
git checkout -f
Do:
echo "Got here" > /tmp/git_push_log
Then try:
echo "Got here" > pwd_test
To check your assumptions about what directory this is operating in and what permissions are required.
精彩评论