Last active
October 28, 2019 08:30
-
-
Save jerry-tao/97466be0a612c6b78bc4c690047378e1 to your computer and use it in GitHub Desktop.
go_git_commit_hook
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 | |
# Check for compile. | |
echo "pre commit build check" | |
go build -o pre_commit_check main.go || exit 1 | |
rm pre_commit_check | |
echo "pre commit build success" | |
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') | |
[ -z "$gofiles" ] && exit 0 | |
unformatted=$(gofmt -l $gofiles) | |
[ -z "$unformatted" ] && exit 0 | |
# Some files are not gofmt'd. Print message and fail. | |
echo >&2 "Go files must be formatted with gofmt. Please run:" | |
for fn in $unformatted; do | |
echo >&2 " gofmt -w $PWD/$fn" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment