Skip to content

Instantly share code, notes, and snippets.

@mattkatz
Forked from yalestar/gist:1054190
Last active March 1, 2022 16:32
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 mattkatz/44ae325fd43b9d942fecdf34fd4aa6c5 to your computer and use it in GitHub Desktop.
Save mattkatz/44ae325fd43b9d942fecdf34fd4aa6c5 to your computer and use it in GitHub Desktop.
pre-commit hook to prevent me from accidentally checking in debug code
#!/bin/sh
#
# This hook prevents you from committing any file containing "debugger".
#
# To enable this hook, rename this file to ".git/hooks/pre-commit".
DIFF_FILES=`git diff-index HEAD --cached --name-only`
if [ $? -ne 0 ]
then
echo "Error getting list of changed files in pre-commit hook"
exit 4
fi
for FILE in ${DIFF_FILES}
do
grep -rin -C2 "debugger" "$FILE"
if [ $? -ne 0 ]
then
false
else
echo "---------------------------"
echo "debugger code in: $FILE"
exit 4
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment