Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.