Last active
December 18, 2023 06:27
-
-
Save murtaza-u/2975194eb48833846dfd9dc5e62de69c to your computer and use it in GitHub Desktop.
Pre-commit Git hook to prevent accidentally committing `go.mod` with replace directive in it.
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 | |
root="$(git rev-parse --show-toplevel)" | |
cd "$root" || exit 1 | |
if [[ ! -r go.mod ]]; then | |
exit 0 | |
fi | |
mod="$(grep -E "^replace\s+.+\s{1}=>\s{1}.+$" go.mod 2>/dev/null)" | |
if [[ -z "$mod" ]]; then | |
exit 0 | |
fi | |
echo "replace directive found in go.mod. Remove it before committing" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment