Skip to content

Instantly share code, notes, and snippets.

@julien-duponchelle
Last active September 6, 2016 11:07
Show Gist options
  • Save julien-duponchelle/5786a7bf0e9e9a6a8b20 to your computer and use it in GitHub Desktop.
Save julien-duponchelle/5786a7bf0e9e9a6a8b20 to your computer and use it in GitHub Desktop.
Git PEP 8 pre commit hook
#!/bin/bash
echo "Pre-commit started"
echo "PEP 8"
git diff --cached --name-only | grep .py | grep -v old_ | xargs autopep8 --in-place -v --aggressive --aggressive
git diff --cached --name-only | grep .py | grep -v old_ | xargs git add
git diff --cached --name-only | grep .py | grep -v old_ | xargs pep8
if [ $? == 0 ]
then
exit 0
fi
# Allows us to read user input below, assigns stdin to keyboard
exec < /dev/tty
echo "Do you want to ignore warning?"
select yn in "Yes" "No"; do
case $yn in
Yes ) exit 0;;
No ) exit 1;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment