#!/bin/sh
# git hook to ensure code style
# ln ../../scripts/pre-commit .git/hooks/

which >/dev/null autopep8 || { echo "please install autopep8"; exit 1; }
files=$(git diff --name-only --staged --diff-filter=ACMRTUXB | egrep "*.py$")

if test -n "$files"; then
  diff=$(autopep8 --max-line-length=100 --diff $files)
  if [[ -n "${diff}" ]]; then
    echo
    autopep8 --max-line-length=100 --diff $files
    echo
    echo "To fix run: autopep8 --max-line-length=100 -i $files"
    exit 1
  fi
fi
