Skip to content

Instantly share code, notes, and snippets.

@anderseknert
Created September 13, 2019 19:03
Show Gist options
  • Save anderseknert/630af768b65c67af22bef1ebaa426cb9 to your computer and use it in GitHub Desktop.
Save anderseknert/630af768b65c67af22bef1ebaa426cb9 to your computer and use it in GitHub Desktop.
My golang pre-commit hook
#!/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