Skip to content

Instantly share code, notes, and snippets.

@tigerclaw-az
Last active January 4, 2016 03:29
Show Gist options
  • Save tigerclaw-az/8562547 to your computer and use it in GitHub Desktop.
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.
#!/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