多个命令在 git post-receive 中不起作用
我正在使用 git 和 trac。推送后我想要做两件事:
- 使用 diff 向开发团队发送电子邮件
- 如果提交消息中有一些特殊短语(例如“参见#1”),那么我希望将提交消息放置在 trac 票证中。
第一件事是通过 git-commit-notifier 解决的。在我创建 post-receive hook 后,它完美地工作:
#!/bin/sh /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
我的第二个要求可以按照 中的描述来解决http://trac-hacks.org/wiki/GitPlugin#post-receivehookscripts。它也可以与此类 post-receive 挂钩完美配合:
#!/bin/sh /var/trac/testgit/commit-updater
这两件事在分开时都可以工作。但我需要将它们结合起来。所以我创建了 post-receive 钩子:
#!/bin/sh /var/trac/testgit/commit-updater /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
这很有趣,但这不起作用。这些命令在单独运行时运行得很好,但只有第一个命令在放入 post-receive 挂钩时才有效。
如果我有这样的钩子:
#!/bin/sh /var/trac/testgit/commit-updater /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
我确实收到以下错误
/var/lib/gems/1.8/gems/git-commit-notifier-0.8.0/bin/git-commit-notifier:12: undefined method `strip' for nil:NilClass (NoMethodError) from /var/lib/gems/1.8/bin/git-commit-notifier:19:in `load' from /var/lib/gems/1.8/bin/git-commit-notifier:19
但是如果我更改这两个命令的顺序,我不会收到任何错误,但只有第一个命令有效。
我将不胜感激任何帮助。我想解决这个问题很长时间了,但没有任何想法。
I'm using git with trac. After push I want two thing to be done:
- Sending email to development team with diff
- If there is some special phrase in commit message (like "see #1"), then I want the commit message to be placed in trac ticket.
The first thing is solved by git-commit-notifier. It works perfectly after I have created post-receive hook:
#!/bin/sh /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
My second requirement can be solved as discribed at http://trac-hacks.org/wiki/GitPlugin#post-receivehookscripts. It also works perfectly with such post-receive hook:
#!/bin/sh /var/trac/testgit/commit-updater
Both 2 things works when they are separate. But I need to combine them. So I have created post-receive hook:
#!/bin/sh /var/trac/testgit/commit-updater /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
It is very funny, but this is not working. The commands run perfectly well when the run separately, but only first one works when they are placed into post-receive hook.
If I have such hook:
#!/bin/sh /var/trac/testgit/commit-updater /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
I do receive the following error
/var/lib/gems/1.8/gems/git-commit-notifier-0.8.0/bin/git-commit-notifier:12: undefined method `strip' for nil:NilClass (NoMethodError) from /var/lib/gems/1.8/bin/git-commit-notifier:19:in `load' from /var/lib/gems/1.8/bin/git-commit-notifier:19
But if I change to order of this 2 commands I do not receive any errors, but only the first command works.
I will appreciate any help. I'm trying to solve this problem for a long time and I have no ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设我的评论是正确的,并且 commit-updater 正在吃掉所有的 stdin,这应该可以解决问题:
Assuming my comment is correct, and
commit-updater
is eating all ofstdin
, this should do the trick:我发现 ngoozeff 的解决方案很有用,但我必须做一些补充。首先,如果其中一个钩子失败,脚本应该失败。其次,一些钩子可能需要参数。就我而言,gitzilla 钩子就是这样。
对我来说,以下工作用于组合 gitzilla 和 gitolite 钩子:
注意 $* 和 exit 语句。您还可以使用 $GIT_DIR 变量。
update.gitzilla 和 update.gitolite 文件是符号链接。
I found ngoozeff's solution useful, but I had to make a few additions. At first, the script should fail if one of the hook fails. At second, some hooks may expect arguments. In my case the gitzilla hook was like that.
For me the following worked for combining gitzilla and gitolite hooks:
Note the $* and the exit statements. You can also use the $GIT_DIR variable.
The update.gitzilla and update.gitolite files are symbolic links.
使用文件的替代方法是:
来源:http ://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/
An alternative to using a file would be:
Source: http://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/
由于输入数据并不是那么大,因此您可以不使用临时文件并将数据保留在 shell 中:
Since the input data is not all that huge, you can go without temporary file and keep the data in the shell: