Created
February 15, 2023 04:41
-
-
Save luckylittle/0948a82d5db1f058dc18d534a500a0fc to your computer and use it in GitHub Desktop.
Pre-commit Git hook (.git/hooks/pre-commit.sh) that checks certain keywords
This file contains 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 | |
matches=$(git diff-index --patch HEAD | grep '^+' | grep -Pi 'password|keyword2|keyword3') | |
if [ ! -z "$matches" ] | |
then | |
cat <<\EOT | |
Error: Words from the blocked list were present in the diff: | |
EOT | |
echo $matches | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scripts must be named to match the related events (Git 2.x):