I have a post-receive hook inside a Git repository that clones the repository into another directory and then cds into that directory.
#!/bin/bash --login
GIT_REPO="$HOME/oliverjash.me.git"
source "$HOME/.bash_profile"
checkout () {
BRANCH="$1"
TMP_GIT_CLONE="$2"
git clone $GIT_REPO $TMP_GIT_CLONE
cd $TMP_GIT_CLONE
git status
}
checkout master "$HOME/tmp/oliverjash.me"
checkout project "$HOME/tmp/project.oliverjash.me"
exit
If I run this script whilst logged in to SSH, git status works fine. However, when the script is executed as the post-receive hook, git status reports this:
remote: fatal: Not a git repository: '.'
I can’t understand why this is!
If you really want to be sure the git command will run properly, you can add:
--work-tree=$TMP_GIT_CLONE--git-dir=$TMP_GIT_CLONE/.gitThat way, the git commands will know where is the working tree and the git repo to consider.
Or, since git 1.8.5, as detailed in this answer: