Skip to content

Instantly share code, notes, and snippets.

@corylanou
Last active May 27, 2019 08:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corylanou/3639c901965922d5507ce4acf539de4a to your computer and use it in GitHub Desktop.
Save corylanou/3639c901965922d5507ce4acf539de4a to your computer and use it in GitHub Desktop.
pre-commit hook
#!/usr/bin/env bash
fmtcount=`git ls-files | grep '.go$' | xargs gofmt -l 2>&1 | wc -l`
if [ $fmtcount -gt 0 ]; then
echo "Some files aren't formatted, please run 'go fmt ./...' to format your source code before committing"
exit 1
fi
vetcount=`go vet ./... 2>&1 | wc -l`
if [ $vetcount -gt 0 ]; then
echo "Some files aren't passing vet heuristics, please run 'go vet ./...' to see the errors it flags and correct your source code before committing"
exit 1
fi
@jonhadfield
Copy link

Running go tool vet ./ results in:
vet: invoking "go tool vet" directly is unsupported; use "go vet"
Shouldn't this be go vet ./?

@corylanou
Copy link
Author

Ahh, yes, they changed it to go vet in a previous release. I'm old school yet. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment