Skip to content

Instantly share code, notes, and snippets.

@voldmar
Created September 30, 2011 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save voldmar/1253329 to your computer and use it in GitHub Desktop.
Save voldmar/1253329 to your computer and use it in GitHub Desktop.
git pre-commit hook that checks forgotten print’s and pyflakes errors
#!/bin/bash
cd ./$(git rev-parse --show-cdup)
result=$(mktemp /tmp/pre-commit.XXXXX)
STAGED=${STAGED:---staged}
changed_py=$(git diff --name-only --diff-filter=AM $STAGED | grep -E '\.py$')
changed_js=$(git diff --name-only --diff-filter=AM $STAGED | grep -E '\.js$')
[[ -z $changed ]] && exit 0
if pip freeze -r requirements.txt 2>&- >&-
then
status=1
[[ -z extra_new_line ]] || { echo; echo; }
echo You have errors in requirements.txt
echo
extra_new_line=yes
fi
if grep -HEn '^\s* print' $changed_py > $result
then
status=1
[[ -z extra_new_line ]] || { echo; echo; }
echo You have some print’s in your python files
echo
extra_new_line=yes
cat $result
fi
if grep -HEn '^\s*console.log' $changed_py > $result
then
status=1
[[ -z extra_new_line ]] || { echo; echo; }
echo You have some console.log in you JS files
echo
extra_new_line=yes
cat $result
fi
if grep -HEn $USER $changed_py > $result
then
status=1
[[ -z extra_new_line ]] || { echo; echo; }
echo You have some mentions about your username in files
echo
extra_new_line=yes
cat $result
fi
if ! pyflakes $changed_py > $result
then
status=1
[[ -z extra_new_line ]] || { echo; echo; }
echo pyflakes says you have some errors
echo
cat $result
fi
rm -f $result
exit $status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment