Skip to content

Instantly share code, notes, and snippets.

@intjonathan
Created September 7, 2012 16:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save intjonathan/3667579 to your computer and use it in GitHub Desktop.
Save intjonathan/3667579 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