Last active
August 29, 2015 13:56
-
-
Save papaben/9282466 to your computer and use it in GitHub Desktop.
Git Hook pre-receive.d invoker
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 | |
# 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