- Copy the pre-commit file without an extension to {your project}/.git/hooks/
- make the file is executable
chmod +x pre-commit
Last active
October 21, 2015 13:59
-
-
Save gcziprusz/e83b03869e7f1329bf6d to your computer and use it in GitHub Desktop.
pre commit hook to check go format and run go tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
status=0 | |
IFS=$'\n' | |
for file in $(git diff --cached --name-only | grep -e '\.go$'); do | |
badfile="$(git --no-pager show :"$file" | gofmt -l)" | |
if test -n "$badfile" ; then | |
echo "git pre-commit check failed: file needs gofmt: $file" | |
status=1 | |
fi | |
done | |
badtest="$(go test | grep "FAIL:" | awk '{print $3}')" | |
if test -n "$badtest" ; then | |
for bad in $badtest; do | |
echo "git pre-commit check failed: go test failed: $bad" | |
done | |
status=1 | |
fi | |
exit $status | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment