尝试这个:
mkdir /tmp/one
cd /tmp/one
git init
echo -e "#!/usr/bin/env python3\nimport os\nos.system('git -C /tmp/one show')" > /tmp/one/.git/hooks/post-receive
chmod +x /tmp/one/.git/hooks/post-receive
touch test.txt
git add test.txt
git commit -m 'Initial commit'
cd /tmp/
git clone one two
cd two
git checkout -b test
echo "Why doesn't this work?" >> test.txt
git add test.txt
git commit -m "testing"
git push -u origin test
并观察非常混乱的消息:
remote: fatal: Not a git repository: '.'
什么?
说真的,有什么实际的挫折感?这是为什么完全打破?我可以去字面文件夹不是一个Git仓库(cd / && git -C /tmp/one/show
),它工作正常。为什么没有这个命令?
它还如果我做os.chdir('/tmp/one')
不起作用。我不能让后收到钩实际上弄清楚到底是怎么回事。这比快乐运行其它一些命令,如git merge
多,但也不会明白git的表演,git的状态,或者更重要的是对我来说,git -C /tmp/one checkout master
。我也试着只用裸
#!/bin/sh
git -C /tmp/one status
它给了我同样的错误信息 - qazxsw POI
任何线索是什么在世界上是怎么回事?
这里的问题是,从一个Git挂钩运行命令与设置各种环境变量运行。即按击你的人是not a git repostiory: '.'
,但有可能是其他人(例如,$GIT_DIR
,$GIT_WORK_TREE
,等等)。
他们对付你在当时的挂钩会是仓库设置正确。但你不希望这个钩子来处理这个仓库。你想这个钩到别处$GIT_INDEX_FILE
和处理一些其他的资料库。在这一点上,你应该清理掉不需要的环境变量,或与该库正确的设置覆盖它们。
总之,添加:
chdir
(在sh / bash的/等),或在Python:
unset GIT_DIR
使用del os.environ['GIT_DIR']
等时,(请注意,它实际上是设置Python版本只适用),或使用env
参数