Last active
August 29, 2015 13:57
-
-
Save joeljames/9901671 to your computer and use it in GitHub Desktop.
Pre commit hook that prevents code from being commited if tests fails or if code has break points
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/sh | |
#Pre commit hook that prevents code from being commited if tests fails or if code has break points. | |
# Stash the changes that has not been added | |
git stash -q --keep-index | |
echo "Testing....." | |
python manage.py test | |
TEST_RESULT=$? | |
if [ $TEST_RESULT == 1 ]; then | |
echo "$(tput setaf 1)COMMIT REJECTED Some tests failed. Please fix the tests before commiting.(tput sgr0)" | |
exit 1 | |
fi | |
echo "Checking for code break points....." | |
INCLUDE_PATTERN="*.py" | |
BASE_DIR="." | |
grep -n -r --include=$INCLUDE_PATTERN -E "import pdb|set_trace" $BASE_DIR | |
GREP_RESULT=$? | |
if [ $GREP_RESULT == 0 ]; then | |
echo "$(tput setaf 1)COMMIT REJECTED Found code break point references. Please remove them before commiting. (tput sgr0)" | |
exit 1 | |
fi | |
# Unstash changes to the working tree that we had stashed | |
git stash pop -q | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment