Created
July 17, 2020 16:20
-
-
Save shannonwells/81ea4be53f8f538ef060e5a522433eaa to your computer and use it in GitHub Desktop.
pre-commit for a go project
This file contains hidden or 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 | |
export GO_NAMES='\.(go)$' | |
export GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E $GO_NAMES) | |
function exit_err() { echo "β π" ; exit 1; } | |
if [[ ! -z $GO_FILES ]] | |
then | |
echo "Examining $GO_FILES" | |
echo $GO_FILES | xargs gofmt -s -w || exit_err | |
/usr/local/bin/golangci-lint run --color=always ./... || exit_err | |
echo $GO_FILES | xargs git add | |
else | |
echo "nothing to do π" | |
exit 0 | |
fi | |
echo "β π" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment