Skip to content

Instantly share code, notes, and snippets.

@albenik
Last active July 2, 2019 06:48
Show Gist options
  • Select an option

  • Save albenik/ce87362acebf28566696181ba30409f5 to your computer and use it in GitHub Desktop.

Select an option

Save albenik/ce87362acebf28566696181ba30409f5 to your computer and use it in GitHub Desktop.
git pre-commit hook for go.mod consistency check
#!/bin/sh
# Runs `go mod tidy` first.
# Then checks for modified but not staged `go.mod` & `go.sum` fileds.
exec 1>&2
go mod tidy
gm=`git status --porcelain -- go.mod`
gs=`git status --porcelain -- go.sum`
if [ "$gm" == "MM go.mod" ] || [ "$gm" == " M go.mod" ] || [ "$gs" == "MM go.sum" ] || [ "$gs" == " M go.sum" ]; then
echo "Please check your go.mod file!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment