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?
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