Created
March 10, 2016 10:30
-
-
Save andrewslotin/13dcdd40395c8ae3e244 to your computer and use it in GitHub Desktop.
Pre-commit git hook to avoid committing non-formatted Go code
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 | |
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') | |
[ -z "$gofiles" ] && exit 0 | |
unformatted=$(gofmt -l $gofiles) | |
if [ ! -z "$unformatted" ]; then | |
echo "Go files must be formatted with gofmt. Please run:" >&2 | |
for fn in $unformatted; do | |
echo " gofmt -w $PWD/$fn" >&2 | |
done | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place this into
.git/hooks/pre-commit
and make it executable.