I have a post-receive
hook inside a Git repository that clones the repository into another directory and then cd
s 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/.git
That way, the git commands will know where is the working tree and the git repo to consider.
git --work-tree=... --git-dir=... clone ...
Or, since git 1.8.5, as detailed in this answer :
git -C=$TMP_GIT_CLONE clone ...
我需要在脚本顶部unset GIT_DIR
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.