从git post-update钩子调用'git pull' [英] Calling 'git pull' from a git post-update hook
问题描述
我想设置一个钩子,当用户推到回购站时,它执行一次拉其他地方随后进行了一些自动化测试。
到目前为止,我只希望它能够执行拉取操作。
hooks目录我创建了更新后的脚本名称:
#!/ bin / sh
cd / home / git / www / epicac
git pull
当我使用./post然而,无论何时它被自动调用,因为我挂钩,我得到:致命的:不是一个混帐存储库:'。' p>
任何想法为什么会发生这种情况?
按照此 SO答案中的建议运行。
特别是,检查 GIT_DIR
和 GIT_WORK_TREE
。
当钩子运行时,
GIT_DIR
和(如果工作树不能从GIT_DIR
>GIT_WORK_TREE
已设置。
这意味着您的pull将不会与您更改目录中的存储库一起运行。
另见博客文章在Git Hook中使用Git :
最终我们得到了我们的linux专家,他注意到git用户运行的环境在钩子内部完全不同。
gitolite为env做了一堆事情,但是那个把我们搞砸的人就是这个设定GIT_DIR
。
我们发现后,解决方案非常简单:
ENV.delete'GIT_DIR'
。 在 解决方案? I have a central git repo set up using gitolite. I want to set up a hook such that whenever a user pushes to the repo, it performs a pull elsewhere followed by some automated testing. So far, I only want to it perform the pull. In the hooks directory I created the following script names post-update: When I invoke this script using ./post-update, it does exactly what I want. However, whenever it's invoked automatically as I hook, I get: fatal: Not a git repository: '.' Any idea why this might be happening? You have various diagnostics to run as suggested in this SO answer. In particular, check out the the value of While the hook is running,
See also blog post 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.
in our ruby script that is triggered by the '
Same deal in
Git Tip: Auto update working tree via post-receive hook, but with an elegant way out of this: The solution?
这篇关于从git post-update钩子调用'git pull'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $在$ post-receive
'钩子触发的ruby脚本中输入
< blockquote>
Git提示:通过post-receive hook自动更新工作树,但用这种优雅的方式:
结果是 post-receive
钩子从 GIT_DIR
环境变量设置为 repo / .git code>文件夹,所以无论你用什么路径cd进入它,都会尝试在那里运行任何后续的git命令
。
解决这个问题只是一个麻烦取消设置 GIT_DIR
(感谢Ulrich Petri为优雅 env -i $ c $
#!/ bin / sh
cd ..
env -i git reset --hard
#!/bin/sh
cd /home/git/www/epicac
git pull
GIT_DIR
and GIT_WORK_TREE
.
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.
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'
post-receive
' hook.
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