Created
September 13, 2019 19:03
-
-
Save anderseknert/630af768b65c67af22bef1ebaa426cb9 to your computer and use it in GitHub Desktop.
My golang 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/sh | |
# Fail on whitespace errors | |
exec git diff-index --check --cached $against -- | |
exit_code=0 | |
STAGED_GO_FILES=$(git diff --cached --name-only -- '*.go') | |
for file in $STAGED_GO_FILES; do | |
go fmt $file | |
golint $file | |
if [ $? -eq 0 ]; then | |
exit_code=1 | |
else | |
git add $file | |
fi | |
done | |
exit exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment