[英]Git post-receive hook clone successful, but reporting 'not a git repository'?
I have a post-receive
hook inside a Git repository that clones the repository into another directory and then cd
s into that directory. 我在Git存储库中有一个post-receive
钩子,它将存储库克隆到另一个目录,然后将cd
克隆到该目录。
#!/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. 如果我在登录SSH时运行此脚本,则git status
可以正常工作。 However, when the script is executed as the post-receive
hook, git status
reports this: 但是,当脚本作为post-receive
挂钩执行时, git status
报告以下内容:
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: 如果您确实要确保git命令将正常运行,则可以添加:
--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命令将知道工作树和要考虑的git repo在哪里。
git --work-tree=... --git-dir=... clone ...
Or, since git 1.8.5, as detailed in this answer : 或者,从git 1.8.5开始, 如此答案中所述 :
git -C=$TMP_GIT_CLONE clone ...
我需要在脚本顶部unset GIT_DIR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.