Skip to content

Instantly share code, notes, and snippets.

@grok
Last active Jul 6, 2016
Embed
What would you like to do?
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