Skip to content

Instantly share code, notes, and snippets.

@RhetTbull
Forked from intjonathan/pre-commit.sh
Created September 22, 2021 03:14
Show Gist options
  • Save RhetTbull/27e343575596ec20ff07d5f0bda3d2b7 to your computer and use it in GitHub Desktop.
Save RhetTbull/27e343575596ec20ff07d5f0bda3d2b7 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 ZZZ present
# I frequently use ZZZ to mark a spot where I'm working on an issue so I can come back to it
#
NOCOMMIT="ZZZ"
files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
if [ "$files" != "" ]
then
for f in $files
do
if [[ "$f" =~ [.](py|md|applescript|json)$ ]]
then
if [ "$(grep $NOCOMMIT $f)" != '' ]
then
echo "NOCOMMIT message present in file $f, aborting!"
echo "$(grep -n -C 3 $NOCOMMIT $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