【发布时间】:2015-12-18 00:52:07
【问题描述】:
我在 /var/repo/myrepo.git 中使用
创建了一个存储库git init --bare
还有一个带有内部的 post-receive 钩子:
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/myrepo.git checkout -f
然后:
chmod +x post-receive
现在,从本地推送到远程工作正常,我知道这是因为我可以看到我的本地分支
/var/repo/myrepo.git/refs/heads
但问题是钩子不起作用。
如果我从终端运行:
git --work-tree=/var/www/domain.com --git-dir=/var/repo/myrepo.git checkout -f
repo 中的所有文件都复制到 /var/www/domain.com
那么为什么钩子不起作用,但如果从 bash 执行,里面的命令却可以呢?
UPDATE_1
按照建议,在 /var/repo/myrepo.git/hooks/post-receive 我正在使用:
git --work-tree=/var/www/domain.com --git-dir=/var/repo/myrepo.git checkout -f >/tmp/mylogfile 2>/tmp/mylogfile
该文件是可执行的,因为我可以运行它:
./post-receive
这会按预期复制我的 warking 目录中的所有 repo 文件,但文件 "/tmp/mylogfile" 是空的。
【问题讨论】:
-
会不会是
git在您的终端中的$PATH中,但在挂钩运行时却不在? -
老实说我不知道...我该如何检查?我已经用“apt-get install”安装了 git
-
在你的
post-receive钩子里做一个echo $PATH > /tmp/mypath && type git >> /tmp/mypath。如果知道git命令,type git将打印出路径。如果命令未知,type git将打印错误。执行git push,然后检查/tmp/mypath的内容。如果文件丢失,则挂钩根本没有运行。试试type git在您的普通终端上打印的内容。 -
我已经按照你的建议做了,但是 "ls -l /tmp" 返回 0 个文件...终端上的 "type git" 返回 "/usr/bin/git"
-
你的钩子没有运行。这就是为什么没有文件。 stackoverflow.com/questions/8206023/… 可能会给你一些有用的提示