#!/bin/bash
# hook is called before each commit to verify that there are no errors

if git rev-parse --verify HEAD >/dev/null 2>&1
then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=$(git hash-object -t tree /dev/null)
fi

# Redirect output to stderr.
exec 1>&2

# If the project does not compile, print error message and fail.
if ! tpr validate > /dev/null 2>&1
then
    cat <<\EOF
Error: Compilation failed or has warnings.
EOF
    exit 1
fi

# check for whitespace errors
exec git diff-index --check --cached $against --
