Created
May 13, 2021 14:52
-
-
Save Blackmist/9c9d90ee4439866022332323c3e8fc0f to your computer and use it in GitHub Desktop.
git pre-commit hook to block commits that have URLs containing 'en-us'
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 | |
# | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
for i in `git diff --cached --name-only` | |
do | |
# check only what is staged | |
if echo `git show :$i` | grep -qEi "(http|https)://\S+/en-us"; then | |
echo "Commit rejected:" | |
echo $i " contains URL(s) with 'en-us'." | |
echo "To bypass this commit check, add --no-verify to your git commit command." | |
exit 1 | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use:
pre-commit
in the .git/hooks directory in your local github repo.git commit
, and your commit includes a URL with the stringen-us
, the commit will be rejected and a message displayed.--no-verify
parameter with your git commit.