Skip to content

Instantly share code, notes, and snippets.

@shannonwells
Created July 17, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannonwells/81ea4be53f8f538ef060e5a522433eaa to your computer and use it in GitHub Desktop.
Save shannonwells/81ea4be53f8f538ef060e5a522433eaa to your computer and use it in GitHub Desktop.
pre-commit for a go project
#!/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