Skip to content

Instantly share code, notes, and snippets.

@mcast
Forked from abner/GitHooksChain.md
Last active May 26, 2016 18:10
Show Gist options
  • Save mcast/77eb93ecda8aa4e6d410e8b6ea58a6a7 to your computer and use it in GitHub Desktop.
Save mcast/77eb93ecda8aa4e6d410e8b6ea58a6a7 to your computer and use it in GitHub Desktop.
Git Hooks Chain - moving to https://github.com/mcast/git-hookchains

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
@mcast
Copy link
Author

mcast commented May 26, 2016

Hi @abner,

I would like to build this into something installable please.

I know this is a small file, but would you care to give it your preferred copyleft? Or if it's not your work, tell me where it came from?

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment