调用“git pull”;来自 git post-update hook
我有一个使用 gitolite 设置的中央 git 存储库。
我想设置一个钩子,以便每当用户推送到存储库时,它都会在其他地方执行拉取,然后进行一些自动化测试。
到目前为止,我只想让它执行拉动操作。
在 hooks 目录中,我在更新后创建了以下脚本名称:
#!/bin/sh
cd /home/git/www/epicac
git pull
当我使用 ./post-update 调用此脚本时,它完全按照我的要求执行。
然而,每当我挂接时自动调用它时,我都会得到: fatal: Not a git repository: '.'
知道为什么会发生这种情况吗?
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:
#!/bin/sh
cd /home/git/www/epicac
git pull
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以按照此 SO 答案 中的建议运行各种诊断。
特别是 检查
GIT_DIR
和GIT_WORK_TREE
的值。另请参阅博客文章 在 Git Hook 中使用 Git:
同样的交易
Git 提示:通过 post-receive hook 自动更新工作树,但有一个优雅的方法:
You have various diagnostics to run as suggested in this SO answer.
In particular, check out the the value of
GIT_DIR
andGIT_WORK_TREE
.See also blog post Using Git Inside a Git Hook:
Same deal in
Git Tip: Auto update working tree via post-receive hook, but with an elegant way out of this:
如何指定
--git-dir
。How about specifying the
--git-dir
.没关系...在这里找到它: https://serverfault.com/questions/107608/git-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory
Never mind... found it here: https://serverfault.com/questions/107608/git-post-receive-hook-with-git-pull-failed-to-find-a-valid-git-directory
只需一行即可完成此操作:
This should do the trick in just one line: