Created
May 25, 2012 15:22
-
-
Save hacklschorsch/2788752 to your computer and use it in GitHub Desktop.
GIT Hook-Chaining script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Author: orefalo | |
# @see http://stackoverflow.com/questions/8730514/chaining-git-hooks#8734391 | |
# | |
# Changes: | |
# [email protected]: Add [0-9] to file glob to exclude .sample files | |
# | |
# Usage: | |
# | |
# create file .git/hooks/hook-chain as follows | |
# | |
# Now link any hook that requires chaining, for instance | |
# ln -s hook-chain update | |
# ln -s hook-chain post-receive | |
# | |
# Finally, create the chains by renaming them as hookname.action. | |
# For instance, in the sample above, the update hook will run update.1acl | |
# followed by update.2github. The post-receive hook will run | |
# post-receive.1email followed by post-receive.2github. | |
hookname=`basename $0` | |
FILE=`mktemp` | |
trap 'rm -f $FILE' EXIT | |
cat - > $FILE | |
for hook in $GIT_DIR/hooks/$hookname.[0-9]* | |
do | |
if test -x "$hook"; then | |
# echo $hook | |
cat $FILE | $hook "$@" | |
status=$? | |
if test $status -ne 0; then | |
echo Hook $hook failed with error code $status | |
exit $status | |
fi | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not clear on the purpose of the
mktemp
command? Can you explain that? Also I have modified this for my own purposes. It allows for all of the scripts to run, even if one of them fails. Here is the code: