Reputation: 11871
I'm using git with trac. After push I want two thing to be done:
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.
Upvotes: 6
Views: 2055
Reputation: 931
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
Upvotes: 0
Reputation: 1851
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/
Upvotes: 1
Reputation: 119
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.
Upvotes: 1
Reputation: 4746
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
Upvotes: 5