【问题标题】:Git Hook `post-receive` with `git pull` runs well via command line but returns empty string on automatic hookGit Hook `post-receive` 和 `git pull` 通过命令行运行良好,但在自动钩子上返回空字符串
【发布时间】:2013-10-08 08:10:20
【问题描述】:

就像许多人一样,我正在尝试在服务器端远程 git 上创建一个 post-receive 挂钩。以下是我的代码:

cd [LIVE SITE DIR] && git pull origin master | wall

我已添加wall,以便可以广播并接收通知。我注意到的一件事是,当我运行 ./post-receive 时,一切正常。

Broadcast message from root (Tue Oct  8 14:58:13 2013):

Updating 7ebd925..1a25791
Fast-forward
 html/header.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

但是,当我尝试做 git push 时,./post-receive 似乎被调用了,但我收到了以下空广播:

Broadcast message from root (Tue Oct  8 14:53:32 2013):

我尝试将pwdls 命令包含在post-receive 中,并且在这两种情况下一切正常。除了git pull,它似乎返回了一个空输出。

已经阅读了 SO 中提供的所有建议,但无济于事:(。非常感谢任何帮助或建议。

谢谢!

【问题讨论】:

    标签: git githooks


    【解决方案1】:

    确保你的post-receive钩子未设置GIT_DIR,否则它仍然会引用钩子的git repo,而不是你刚刚cd in的实时站点的git repo。

    cd [LIVE SITE DIR]
    unset GIT_DIR
    git pull
    

    或者:

    cd [LIVE SITE DIR]
    env -i origin master
    

    或者:

    cd [LIVE SITE DIR]
    git --git-dir=[LIVE SITE DIR]/.git pull
    

    【讨论】:

    • 感谢您的尝试。尝试了上述所有方法,但自动调用时一切都返回空字符串。
    • @HeruS 好的。独立于广播问题,我仍然建议取消设置GIT_DIR。现在,墙是正确的工具吗?见serverfault.com/a/390417/783rwall 是更好的选择吗?
    • 独立于 wallrwall 不知何故 git pull 仍未执行。 :(
    【解决方案2】:

    问题似乎是因为.git 中的一个文件HEAD 具有root 作为文件所有者。上面的 shell 脚本是使用另一个用户执行的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-19
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      • 1970-01-01
      相关资源
      最近更新 更多