Skip to content

Instantly share code, notes, and snippets.

@jonasvp
Created March 7, 2011 08:29
Show Gist options
  • Save jonasvp/858223 to your computer and use it in GitHub Desktop.
Save jonasvp/858223 to your computer and use it in GitHub Desktop.
My .git/hooks/pre-commit - save yourself from embarassment using pyflakes
#!/bin/bash
TMPDIR=`mktemp -d`
TMPFILE=`mktemp`
git diff --cached --name-only --diff-filter=ACMR | xargs git checkout-index --prefix=$TMPDIR/ --
pyflakes $TMPDIR >$TMPFILE 2>&1
grep -v "unable to detect undefined names" $TMPFILE >$TMPFILE.2
egrep -v "migrations.*'(datetime|models)' imported but unused" $TMPFILE.2 >$TMPFILE
grep -rn "pdb.set_trace" $TMPDIR >>$TMPFILE
sed "s/^${TMPDIR//\//.}.//" $TMPFILE >$TMPFILE.2
mv $TMPFILE.2 $TMPFILE
CODE=0
OUTPUT=`cat $TMPFILE`
if [ -n "$OUTPUT" ]; then
cat $TMPFILE;
CODE=1;
fi
rm -Rf $TMPDIR $TMPFILE
exit $CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment