Skip to content

Instantly share code, notes, and snippets.

@rkbodenner
Forked from intjonathan/pre-commit.sh
Created September 11, 2012 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkbodenner/3699738 to your computer and use it in GitHub Desktop.
Save rkbodenner/3699738 to your computer and use it in GitHub Desktop.
pre-commit hook (add to .git/hooks/pre-commit) to refuse to commit debugger strings
#!/bin/sh
# Refuse to commit files with the string NOCOMMIT, debugger, or merge markers present.
#
files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
if [ "$files" != "" ]
then
for f in $files
do
if [[ "$f" =~ [.](conf|css|erb|html|js|json|log|properties|rb|ru|txt|xml|yml)$ ]]
then
if [ "$(grep NOCOMMIT $f)" != '' ]
then
echo "COMMIT message present in file $f, aborting!"
echo "$(grep -n -C 3 NOCOMMIT $f)"
exit 1
fi
if [ "$(grep debugger $f)" != '' ]
then
echo "debugger present in file $f, aborting!"
echo "$(grep -n -C 3 debugger $f)"
exit 1
fi
if [ "$(grep '<<<<<<<' $f)" != '' ]
then
echo "merge markers present in file $f, aborting!"
echo "$(grep -n -C 3 '<<<<<<<' $f)"
exit 1
fi
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment