Skip to content

Instantly share code, notes, and snippets.

@reedobrien
Last active June 23, 2016 19:30
Show Gist options
  • Save reedobrien/1ba37bcd855e99b57b64 to your computer and use it in GitHub Desktop.
Save reedobrien/1ba37bcd855e99b57b64 to your computer and use it in GitHub Desktop.
git pre-push hook for go proj
#!/bin/bash
set -e
# find all un-gofmt'd go files
unformatted=$(goimports -l -e .)
# if there are un-gofmt'd go files
if [ -n "$unformatted" ]; then
# print warnings and fail
echo >&2 "Go files must be formatted with goimports. Please run:"
for filename in $unformatted; do
echo >&2 "goimports -w $PWD/$filename"
done
exit 1
fi
# run go vet w/ go tool to check that the code can be built, etc.
echo "running go vet..."
go vet ./...
echo "...OK"
# check this build w/ the go build race detector
#go build -race $SOMEDIR
# make sure deps are set
# TODO: choose how to manage dependencies
# run go tests
echo "running go test..."
go test ./...
echo "...OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment