We're using git with a central repo (using Gitosis). I've created a post-receive hook to generate an email to the dev mailing list whenever changes are pushed to the central repo, and to generate documentation from the documentation folder in the git repo.
Therefore, in ~git/ I've got a directory, we'll call it 'a' that contains a clone of the git repo. The post-receive hook looks like:
#!/bin/bash
cd ~git/repositories/a.git
. ~git/post-receive-email &> /dev/null
( cd ~git/a && git pull &> ~git/pull_log.log && php ~git/a/scripts/generate_markdown_documentation.php &> ~git/doc_log.log )
The email script is working, but the documentation generation is not. The content of pull_log.log is:
fatal: Not a git repository: '.'
Which makes me think that it's not changing to the correct directory in line 5 of the above script. Am I wrong? How can I get this to work?
Edit: I've updated the post-receive hook as suggested in the responses. The script is now:
#!/bin/bash
function die {
echo "$*" >&2; exit 1
}
function checkgit {
[ -d "$1/.git" ] || die "$1 could not possibly be a git repo; $1/.git is not a dir"
}
cd ~git/repositories/a.git
. ~git/post-receive-email &> /dev/null
( set -x
checkgit ~git/a
cd ~git/a
checkgit .
pwd
git pull
php ~git/a/scripts/generate_markdown_documentation.php )
And I get the following output from git push:
+ checkgit /var/git/a
+ '[' -d /var/git/a/.git ']'
+ cd /var/git/a
+ checkgit .
+ '[' -d ./.git ']'
+ pwd
/var/git/a
+ git pull
fatal: Not a git repository: '.'
+ php /var/git/a/scripts/generate_markdown_documentation.php
Any more help?
Oh, and if I run the script myself, it works (I run it by saying hooks/post-receive)
Discovered the problem, thanks to serverfault -- basically, environment variables GIT_DIR
and GIT_WORK_TREE
are set when the hook runs, and these affect git pull adversely. Unsetting the variables fixes the problem.
git pull
topwd
and see what shows up in the log. – Kauslick