Skip to content

Instantly share code, notes, and snippets.

@grok
Last active July 6, 2016 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grok/ff093f7cbccb604c20621246c922eb5e to your computer and use it in GitHub Desktop.
Save grok/ff093f7cbccb604c20621246c922eb5e to your computer and use it in GitHub Desktop.
git pre-commit hook for checking for debug code you don't want committed. Basically add a comment that says // @debug or @debug or @debug -- and this will not let you commit that line.
#!/bin/sh
disallowed="@debug"
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
git diff --cached --name-status | while read x file; do
if [ "$x" == 'D' ]; then continue; fi
for word in $disallowed
do
if grep -Ei $word $file > /dev/null; then
echo "BRO! You left ${RED}DEBUG CODE${NC} in your shit. I'm not letting you commit this. Go clean your room: Found references to debug code in file: ${YELLOW}${file}${NC}\n"
exit 1
fi
done
done || exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment