gpt4 book ai didi

git - 从 git 更新后 Hook 调用 'git pull'

转载 作者:IT王子 更新时间:2023-10-29 01:26:52 28 4
gpt4 key购买 nike

我有一个使用 gitolite 设置的中央 git 仓库。

我想设置一个 Hook ,以便每当用户推送到存储库时,它都会在其他地方执行 pull ,然后进行一些自动化测试。

到目前为止,我只想让它执行 pull 。

在 hooks 目录中,我在更新后创建了以下脚本名称:

#!/bin/sh  
cd /home/git/www/epicac
git pull

当我使用 ./post-update 调用此脚本时,它完全按照我的要求执行。

但是,每当它在我 Hook 时自动调用时,我都会得到:fatal: Not a git repository: '.'

知道为什么会这样吗?

最佳答案

您可以按照此 SO answer 中的建议运行各种诊断程序.

特别是,check out the the value of GIT_DIR and GIT_WORK_TREE .

While the hook is running, GIT_DIR and (if the worktree can't be inferred from GIT_DIR) GIT_WORK_TREE are set.
That means your pull won't run with the repository in the directory you changed to.


另请参阅博文 Using Git Inside a Git Hook :

Eventually we got our linux guru over and he noticed that the environment under which the git user runs is totally different when inside a hook.
Gitolite does a bunch of things to the env, but the one that was screwing us up was the setting of the GIT_DIR.
After we figured that out, the solution was as easy as:

ENV.delete 'GIT_DIR'

in our ruby script that is triggered by the 'post-receive' hook.


同样的交易 Git Tip: Auto update working tree via post-receive hook ,但有一种优雅的方式:

The solution?
It turns out the post-receive hook starts out with the GIT_DIR environment variable set to the repo/.git folder, so no matter what path you 'cd' into it will always try to run any following git commands there.
Fixing this is simply a matter of unsetting the GIT_DIR
(thanks to Ulrich Petri for the elegant env -i solution):

#!/bin/sh
cd ..
env -i git reset --hard

关于git - 从 git 更新后 Hook 调用 'git pull',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542854/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com