Created
October 7, 2013 03:58
-
-
Save rdallman/6862350 to your computer and use it in GitHub Desktop.
pre-commit hook for golang projects that assures all tests pass and all files are gofmt'd
This file contains 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 |
a redirect should suffice
"$(go test 2>&1 | grep "FAIL:" | awk '{print $3}')"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you get go test to send its FAIL outputs to STDOUT? I'm only catching them on STDERR.