Skip to content

Instantly share code, notes, and snippets.

@abner
Last active May 26, 2016 08:19
Show Gist options
  • Save abner/cdddf155c919ff37bc9a to your computer and use it in GitHub Desktop.
Save abner/cdddf155c919ff37bc9a to your computer and use it in GitHub Desktop.
Git Hooks Chain

Instructions

  1. Add the hook-chain script to the repository hooks

  2. Create a link symbolic to hook-chain with the name of the hook which will be chained

  • Eg: post-receive -> hook-chain
  1. Add scripts prefixed with the [hookname].

Just that.

Have Fun!!!

#!/bin/bash
hookname=`basename $0`
# reads stdin and saveS IT
data=$(cat)
# array to save exit codes of each script
exitcodes=()
# loop through multiple hook scripts and call then
# scripts should be named like post-receive-push_to_mirror, post-receive-notify, etc
for hook in $GIT_DIR/hooks/$hookname-*
do
test -x "$hook" || continue
echo "$data" | "$hook"
exitcodes+=($?)
done
# If any exit code isn't 0, fail.
for i in "${exitcodes[@]}"; do
[ "$i" == 0 ] || exit $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment