Last active
December 14, 2015 08:49
-
-
Save dwf/5060608 to your computer and use it in GitHub Desktop.
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 | |
# Run pyflakes on all changed .py files before commit. | |
# | |
# By David Warde-Farley, Feb 28, 2013 -- released under the 3-clause BSD license. | |
# | |
# To use, run this file from the script .git/hooks/pre-commit | |
FILES=`git diff --staged --name-status |grep '\.py$' |grep '^[AM]' |sed -e's/^[AM]\s\+//'` | |
ROOT=`git rev-parse --show-toplevel` | |
NUM_BAD_FILES=0 | |
for fn in $FILES; do | |
pyflakes $ROOT/$fn | |
STATUS=$? | |
if [ $STATUS ]; then | |
NUM_BAD_FILES=`expr $NUM_BAD_FILES + 1` | |
fi | |
done | |
if [ $NUM_BAD_FILES -gt 0 ]; then | |
echo "! Aborting commit; pyflakes errors in $NUM_BAD_FILES staged file(s)." | |
exit $NUM_BAD_FILES | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment