Skip to content

Instantly share code, notes, and snippets.

@brendanjerwin
Last active December 11, 2015 01:08
Show Gist options
  • Save brendanjerwin/4520929 to your computer and use it in GitHub Desktop.
Save brendanjerwin/4520929 to your computer and use it in GitHub Desktop.
#!/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
@brendanjerwin
Copy link
Author

This will prevent a commit if the file contains debugger

Tested to work on OS X.

@brendanjerwin
Copy link
Author

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