[英]Running git commands from post-receive hook
解释为什么我要这样做很复杂,但是我想做的是为特定的git存储库配备一个执行以下操作的post-receive钩子:
接收后的代码如下所示(简化):令“ repo”为git存储库的名称,令“ testdir”为同级目录的名称,最初为空,而使“ dev”为分支的名称。
cd ../testdir
git clone --local ../repo .
git checkout dev
但是,当脚本中的代码进入“ git checkout”时,git会返回“致命:不是git存储库:'。”
我不知道为什么git认为“ testdir”不是git存储库。 如果我从命令行(而不是在接收后)运行该命令,那么它们将正常工作。 我不知道为什么这种行为与接收后的行为会有所不同。 有任何想法吗?
您需要在post-receive
挂钩中取消设置GIT_DIR
。 问题是在您的挂钩脚本运行时, GIT_DIR=.
,在进行cd和克隆操作之后,该功能将不再有用。
我设置了一个本地测试环境,当我post-receive
脚本如下所示:
#!/bin/sh
cd ../testdir
git clone --local ../upstream.git .
git checkout dev
我得到这个:
remote: fatal: Not a git repository: '.'
但是,如果我未设置GIT_DIR
变量:
#!/bin/sh
unset GIT_DIR
cd ../testdir
git clone --local ../upstream.git .
git checkout dev
一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.