#!/bin/bash

#TODO convert to python script

# Only test the changed files
#git diff --cached --name-status | awk '$1 != "R" { print $2 }'
#git diff-index --cached HEAD | awk '$5 != "R" { print $6 }'

# TODO: Test pep8?

#TODO: To force the commit run: git commit --no-verify

echo "Running pre-commit tests"
if [ ! -e build ] ; then
mkdir build
fi

pyflakes arachnid > build/pyflakes.log 2>&1
if [ "$?" != "0" ] ; then
more build/pyflakes.log
exit 1
fi

if [ "1" == "1" ] ; then
echo "Running pre-commit tests - success"
exit 0
fi

python2.6 setup.py build_ext --inplace > build/build.log 2>&1

if [ "$?" != "0" ] ; then
more build/build.log
exit 1
fi

# TODO: get directory of commit file
# TODO: Run on that

nosetests arachnid > build/nosetests.log 2>&1

if [ "$?" != "0" ] ; then
more build/nosetests.log
exit 1
fi

# TODO: Remove generated version of the file

sphinx-build -E -n -b coverage . build > build/sphinx.log 2>&1
if [ "$?" != "0" ] ; then
more build/sphinx.log
exit 1
fi

grep "warning" build/sphinx.log

if [ "$?" == "0" ] ; then
more build/sphinx.log
exit 1
fi

n=(`wc -l build/python.txt`)

if [ "${n[0]}" -gt "2" ] ; then
echo $n $maxval
more build/python.txt
exit 1
fi
	
echo "Running pre-commit tests - success"

