多个命令在 git post-receive 中不起作用

发布于 2024-09-13 20:28:09 字数 1351 浏览 5 评论 0原文

我正在使用 git 和 trac。推送后我想要做两件事:

  1. 使用 diff 向开发团队发送电子邮件
  2. 如果提交消息中有一些特殊短语(例如“参见#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:

  1. Sending email to development team with diff
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

逆夏时光 2024-09-20 20:28:09

假设我的评论是正确的,并且 commit-updater 正在吃掉所有的 stdin,这应该可以解决问题:

#!/bin/sh

FILE=`mktemp`
cat - > $FILE
cat $FILE | /var/trac/testgit/commit-updater
cat $FILE | /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
rm $FILE

Assuming my comment is correct, and commit-updater is eating all of stdin, this should do the trick:

#!/bin/sh

FILE=`mktemp`
cat - > $FILE
cat $FILE | /var/trac/testgit/commit-updater
cat $FILE | /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
rm $FILE
荒芜了季节 2024-09-20 20:28:09

我发现 ngoozeff 的解决方案很有用,但我必须做一些补充。首先,如果其中一个钩子失败,脚本应该失败。其次,一些钩子可能需要参数。就我而言,gitzilla 钩子就是这样。

对我来说,以下工作用于组合 gitzilla 和 gitolite 钩子:

#!/bin/sh

FILE=`mktemp`
cat - > $FILE
cat $FILE | $GIT_DIR/hooks/update.gitzilla $* || exit 1 
cat $FILE | $GIT_DIR/hooks/update.gitolite $* || exit 1
rm $FILE

注意 $* 和 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:

#!/bin/sh

FILE=`mktemp`
cat - > $FILE
cat $FILE | $GIT_DIR/hooks/update.gitzilla $* || exit 1 
cat $FILE | $GIT_DIR/hooks/update.gitolite $* || exit 1
rm $FILE

Note the $* and the exit statements. You can also use the $GIT_DIR variable.
The update.gitzilla and update.gitolite files are symbolic links.

电影里的梦 2024-09-20 20:28:09

使用文件的替代方法是:

#!/bin/sh

while read oldrev newrev refname
do
   echo $oldrev $newrev $refname | /var/trac/testgit/commit-updater
   echo $oldrev $newrev $refname | /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
done

来源:http ://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/

An alternative to using a file would be:

#!/bin/sh

while read oldrev newrev refname
do
   echo $oldrev $newrev $refname | /var/trac/testgit/commit-updater
   echo $oldrev $newrev $refname | /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml
done

Source: http://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/

一杆小烟枪 2024-09-20 20:28:09

由于输入数据并不是那么大,因此您可以不使用临时文件并将数据保留在 shell 中:

#!/bin/sh

refs=$(cat)
/var/trac/testgit/commit-updater <<END
$refs
END
/var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml <<END
$refs
END

Since the input data is not all that huge, you can go without temporary file and keep the data in the shell:

#!/bin/sh

refs=$(cat)
/var/trac/testgit/commit-updater <<END
$refs
END
/var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml <<END
$refs
END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文