How to properly use post-receive hook?

允我心安 提交于 2019-12-11 07:12:47

问题


My directory structure is:

~/parent.git/.git/hooks/post-receive

The post-receive hook looks like:

#!/bin/sh
git checkout -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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4293823/how-to-properly-use-post-receive-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!