Last active
September 14, 2015 21:33
-
-
Save pestophagous/8783885e327042d047a0 to your computer and use it in GitHub Desktop.
rename this to .git/hooks/pre-commit inside your git repo to prevent accidental commits that you tagged as DNC (do-not-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/sh | |
# | |
# https://twitter.com/pestophagous/status/501460327515815936 | |
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 | |
# DNC stands for 'do not commit' | |
MARKER_STRING_TO_PREVENT_A_COMMIT="DNC DNC DNC" | |
COUNT_BAD_DISALLOWED_LINES=`git diff --cached $against | grep "${MARKER_STRING_TO_PREVENT_A_COMMIT}" | wc -l` | |
if [ "$COUNT_BAD_DISALLOWED_LINES" -eq "0" ] | |
then | |
# don't do anything. we are happy so far. | |
true | |
else | |
echo "custom pre-commit script is BLOCKING this commit! You have \"$MARKER_STRING_TO_PREVENT_A_COMMIT\" (do not commit) in your source file!" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment