Skip to content

Instantly share code, notes, and snippets.

@jjbohn
Created January 17, 2012 23:15
Show Gist options
  • Save jjbohn/1629700 to your computer and use it in GitHub Desktop.
Save jjbohn/1629700 to your computer and use it in GitHub Desktop.
jjbohn pre-commit hook
#!/bin/bash
diff=`git diff-index --name-status HEAD -- | cut -c3-`
echo "Checking for stray debugging code..."
for FILE in $diff ; do
if [[ -f $FILE && `egrep "(console.log)|(var_dump)|(print_r)" $FILE` ]]; then
echo $FILE 'contains debugging code. Commit canceled.'
exit 1
fi
done
# Run unit tests
echo "Running all unit tests..."
phpunit -c opensky/ --exclude-group functional,integration,crashy
if [[ $? != 0 ]]; then
echo "Unit test(s) failed. Commit canceled."
exit 1
fi
echo "Running changed tests..."
for FILE in $diff ; do
if [[ -f $FILE && ${FILE: -8} == "Test.php" ]]; then
phpunit -c opensky/ $FILE
if [[ $? != 0 ]]; then
echo $FILE ' test(s) failed. Commit canceled.'
exit
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment