PEP 8 Git pre commit hook

This pre commit hook will check the PEP8 syntax of your Python files and ask you if you want to continue the commit process.

In your project directory create a file: .git/hooks/pre-commit and add the execution permission on it.


echo "Pre-commit started"
echo "PEP 8 check"
git diff  --cached --name-only | grep .py | xargs pep8

if [ $? == 0 ]
    exit 0

# 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;;