Last active
November 5, 2022 12:55
-
-
Save Aldaviva/2c6c8c41b3fae66cac32 to your computer and use it in GitHub Desktop.
Prevent commits with FIXME
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 | |
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 | |
filenamePattern='\.(js|json|java|html|htm|php|xml|css|less|groovy|nsi|nsh|properties|cs|xaml|csproj|sh|bash|bat|cmd|ps1|svg|md)$' | |
disallowedTokenPattern='\bFIXME\b' | |
git diff-index --cached --name-only --diff-filter=ACMRTUXB $against | \ | |
grep -E $filenamePattern | \ | |
xargs grep -E --with-filename -n --after-context=0 $disallowedTokenPattern && \ | |
echo -e "\nFound FIXME. Get rid of the temporary hacks and use \`git add; git commit\` to proceed." && \ | |
exit 1 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install this for all repositories in your user account:
pre-commit
in some directory, such as~/.git-hooks/
.git config --global core.hookspath ~/.git-hooks/