Last active
July 2, 2019 06:48
-
-
Save albenik/ce87362acebf28566696181ba30409f5 to your computer and use it in GitHub Desktop.
git pre-commit hook for go.mod consistency check
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/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