开发者

How to properly use post-receive hook?

开发者 https://www.devze.com 2023-01-27 10:02 出处:网络
My directory structure is: ~/parent.git/.git/hooks/post-receive The post-receive hook looks like: #!/bin/sh

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消