Git post-receive hook not working properly

时光总嘲笑我的痴心妄想 提交于 2019-12-23 02:36:30

问题


I have a server with a git repository. Each time I make a push to that server I would like to regenerate my gitstats documentation for that repository.

In that machine if I execute the following command, the gitstats documentation it's refreshed properly:

gitstats /home/<username>/<proyect-name>/htdocs/ /home/<username>/gitstats

And here it's my post-receive hook in the repository in that server:

#!/bin/sh
gitstats /home/<username>/<proyect-name>/htdocs/ /home/<username>/gitstats

So when I make a push to that machine, it tries to execute that command, but it doesn't work correctly, the output message after the push contains the following error message:

remote: fatal: Not a git repository: '.'

If I remove that command from the hook, I don't get any error messages.

I don't understand why the command works fine when executed directly on the server and it doesn't when it's executed after a push.

Any suggestions?


回答1:


The problem is that GIT_WORK_TREE and/or GIT_DIR might not been properly set when executing gitstat within that hook.

Try setting them just before the gitstat command:

GIT_DIR=/home/<username>/<proyect-name>/.git
GIT_WORK_TREE=/home/<username>/<proyect-name>
gitstats ... 

Why those variables wouldn't be properly set?
See for instance "Calling 'git pull' from a git post-update hook"

Eventually we got our linux guru over and he noticed that the environment under which the git user runs is totally different when inside a hook.

That is a case where your <username> won't be the one you think when the hook is executed...



来源:https://stackoverflow.com/questions/10531052/git-post-receive-hook-not-working-properly

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