Several commands do not work in git post-receive

I am using git with trac. After clicking, I want to do two things:

  • Sending email to a developer using diff
  • If there is a special phrase in the commit message (for example, “see No. 1”), I want the commit message to be placed on the trac ticket.

The first thing is solved with git-commit-notifier. It works fine after I created the post-receive hook:

  #! / bin / sh

 /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml

My second requirement can be resolved as described in http://trac-hacks.org/wiki/GitPlugin#post-receivehookscripts . It also works great with such a hook after taking it:

  #! / bin / sh

 / var / trac / testgit / commit-updater

Both things work when they are separate. But I need to combine them. So, I created a 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 it does not work. Commands work fine when the launch is done separately, but only the first one works when they are put into the hook after receiving.

If I have such a hook:

  #! / bin / sh

 / var / trac / testgit / commit-updater
 /var/lib/gems/1.8/bin/git-commit-notifier /etc/git-commit-notifier.yml

I get 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 go to the order of these two teams, I get no errors, but only the first command works.

I would be grateful for any help. I have been trying to solve this problem for a long time and I have no ideas.

+6
git shell hook git-post-receive trac
source share
4 answers

Assuming my comment is correct and commit-updater eats all 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 
+5
source share

I found the ngoozeff solution useful, but I had to make a few additions. First, the script should fail if one of the hooks fails. Secondly, some hooks can expect arguments. In my case, the gitsilla hook was like that.

For me, the following worked to combine the Gitzill 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 

Pay attention to the operators $ * and exit. You can also use the $ GIT_DIR variable. The update.gitzilla and update.gitolite files are symbolic links.

+1
source share

An alternative to using the 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/

+1
source share

Since the input is not so large, you can do without a temporary file and save the data in a 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 
0
source share

All Articles