#!/bin/bash

TOTAL_ERRORS=0
if [[ ! $(which pycodestyle) ]]; then
    pip install pycodestyle
fi
# diff files on local machine.
files=$(git diff --cached --name-status | awk '$1 != "D" {print $2}')
for file in $files; do
    if [ "${file##*.}" == "py" & -f "${file}"] ; then
        pycodestyle --show-source $file --config=setup.cfg;
        TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
    fi
done

exit $TOTAL_ERRORS
