Last active
January 4, 2016 03:29
-
-
Save tigerclaw-az/8562547 to your computer and use it in GitHub Desktop.
Git pre-commit hook that will look for all 'pre-commit-*' hooks and execute them one at a time.
This file contains hidden or 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 | |
SCRIPTPATH=`git rev-parse --show-toplevel`"/.git/hooks" | |
HOOKS="${SCRIPTPATH}/pre-commit-*" | |
shopt -s nullglob | |
pass=true | |
for hook in $HOOKS | |
do | |
echo "Running hook: "`basename $hook` | |
# run hook if it exists | |
if [ -f "$hook" ]; then | |
"$hook" | |
# if it returns with nonzero exit with 1 and thus abort the commit | |
if [ $? != 0 ]; then | |
echo -e "\t\033[31mFAILED\033[0m" | |
pass=false | |
else | |
echo -e "\t\033[32mSUCCEEDED\033[0m" | |
fi | |
else | |
echo "Error: file $hook not found." | |
exit 1 | |
fi | |
done | |
if ! $pass ; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment