gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' | grep -v '^vendor\/')
[ -z "$gofiles" ] && exit 0

unformatted=$(gofmt -l $gofiles)
[ -z "$unformatted" ] && exit 0

echo >&2 "Go files formatted with gofmt:"
for fn in $unformatted; do
        gofmt -w $PWD/$fn
        echo >&2 "$PWD/$fn"
done

echo >&2 "Files have been changed - the git commit has been aborted."
exit 1
