Skip to content

Instantly share code, notes, and snippets.

@papaben
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papaben/9282466 to your computer and use it in GitHub Desktop.
Save papaben/9282466 to your computer and use it in GitHub Desktop.
Git Hook pre-receive.d invoker
#!/bin/bash
# This script will run every script it finds in pre-receive.d
# ...passing along STDIN
# This can accompany https://github.com/box/bart/wiki/Git-Hooks
HOOKNAME=$(basename $0)
if [ -d "$GIT_DIR/hooks" ]; then
HOOKDIR="${GIT_DIR}/hooks/${HOOKNAME}.d"
else
echo "Couldn't determine hook directory...bailing"
exit 1
fi
# Capture the contents of STDIN so we can pass it to all hooks
stdin=$(cat /dev/stdin)
for i in $HOOKDIR/*; do
echo "Running hook $i"
echo "$stdin" | $i "$@"
retval=$?
if [ $retval != 0 ]; then
echo "Hook exited with code ${retval}...bailing"
exit $retval
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment