Skip to content

Instantly share code, notes, and snippets.

@uris77
Created February 29, 2020 22:42
Show Gist options
  • Save uris77/917219cb5c685445d61314ab6c9db7f9 to your computer and use it in GitHub Desktop.
Save uris77/917219cb5c685445d61314ab6c9db7f9 to your computer and use it in GitHub Desktop.
Git precommit hook for Go
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment