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.
Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature - no need to download anything. Git hooks are run locally. These hook scripts are only limited by a developer's imagination.
Implementing Git Hooks Upon initializing a new project, Git populates the hooks folder with template files. To enable the hook scripts, simply remove the . sample extension from the file name. Git will automatically execute the scripts based on the naming.
No. Hooks are per-repository and are never pushed.
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With