Last active
December 11, 2015 01:08
-
-
Save brendanjerwin/4520929 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
| fi | |
| function clean_up { | |
| git stash pop -q | |
| return | |
| } | |
| git stash -q --keep-index | |
| for FILE in `git diff-index --name-status $against -- | sed '/^D/ d' | cut -c3-` ; do | |
| # Check if the file contains 'debugger' | |
| if grep --quiet debugger "$FILE"; then | |
| echo '\033[31mCOMMIT ABORTED -' $FILE 'contains a debugger statement.' | |
| clean_up | |
| exit 1 | |
| fi | |
| if grep --quiet "^[><=]\{7\}" "$FILE"; then | |
| echo '\033[31mCOMMIT ABORTED -' $FILE 'appears to have an unresolved merge.' | |
| clean_up | |
| exit 1 | |
| fi | |
| if [[ $FILE =~ .*(BACKUP)|(BASE)|(LOCAL)|(REMOTE).* ]]; then | |
| echo '\033[31mCOMMIT ABORTED -' $FILE 'is a temporary merge file.' | |
| clean_up | |
| exit 1 | |
| fi | |
| done | |
| clean_up | |
| exit |
Added the sed bit to make it ignore deletes. Go ahead and delete a file with a debugger in it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will prevent a commit if the file contains
debuggerTested to work on OS X.