-
-
Save Shrulik/42ff6ce4ed18e99cb8e2591a8e3d297f to your computer and use it in GitHub Desktop.
pre-commit hook (add to .git/hooks/pre-commit) to refuse to commit debugger strings. Note list of file extensions to see which files are conisdered.
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 | |
# 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" =~ [.](ts|java|conf|css|html|js|json|log|properties|txt|xml|yml)$ ]] | |
then | |
if [ "$(grep NOCOMMIT $f)" != '' ] | |
then | |
echo "NOCOMMIT 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