Skip to content

Instantly share code, notes, and snippets.

@stoyanvi
Forked from tigerclaw-az/pre-commit.bash
Created July 25, 2014 15:14
Show Gist options
  • Save stoyanvi/7998c652d828330d61cc to your computer and use it in GitHub Desktop.
Save stoyanvi/7998c652d828330d61cc to your computer and use it in GitHub Desktop.
#!/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