Created
November 10, 2023 12:45
-
-
Save kolypto/59975df841e4c25dd9cf178180ce32d8 to your computer and use it in GitHub Desktop.
Git pre-commit hook: ban "nocommit" lines, do not allow to commit
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/bash | |
# .git/hooks/pre-commit | |
# Find "//nocommit" lines in the diff, do not allow them | |
# This line will output all "nocommit" lines, if any: you'll see this as git error. | |
git diff --no-ext-diff --cached | grep -iE '//\s*nocommit' | |
# If the retcode=0, then "nocommit" lines were found. Fail on them. | |
if [[ $? -eq 0 ]]; then | |
echo "WARNING: You are going to commit some 'nocommit' lines!" | |
echo | |
echo "You can ignore this warning by running the commit command with '--no-verify'" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment