Created
September 4, 2013 20:26
-
-
Save paulsmith/6442399 to your computer and use it in GitHub Desktop.
gofmt git pre-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/bash | |
if git rev-parse HEAD >/dev/null 2>&1; then | |
FILES=$(git diff --staged --name-only | grep -e '\.go$') | |
else | |
FILES=$(git ls-files -c | grep -e '\.go$') | |
fi | |
for file in $FILES; do | |
if test -n "$(gofmt -l $file)"; then | |
echo "Error: git pre-commit failed, file needs gofmt: $file" | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save as .git/hooks/pre-commit and chmod +x