Skip to content

Instantly share code, notes, and snippets.

@Blackmist
Created May 13, 2021 14:52
Show Gist options
  • Save Blackmist/9c9d90ee4439866022332323c3e8fc0f to your computer and use it in GitHub Desktop.
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'
#!/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
@Blackmist
Copy link
Author

To use:

  1. save it as a file named pre-commit in the .git/hooks directory in your local github repo.
  2. when you run git commit, and your commit includes a URL with the string en-us, the commit will be rejected and a message displayed.
  3. If you need to bypass the check (for example, the string is not in a file you modified,) use the --no-verify parameter with your git commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment