Skip to content

Instantly share code, notes, and snippets.

@iiska
Created October 4, 2010 12:40
Show Gist options
  • Save iiska/609631 to your computer and use it in GitHub Desktop.
Save iiska/609631 to your computer and use it in GitHub Desktop.
Refuse commit when there are debug code present.
#!/bin/sh
#
# Aborts commit if grepping diff encounters JS or Ruby debug lines.
has_console_log=$(git diff --cached | grep '^\+\s*console\.log\(.*\)')
has_console_dir=$(git diff --cached | grep '^\+\s*console\.dir\(.*\)')
has_ruby_debug=$(git diff --cached | grep "^\+\s*\(require \['\"\]ruby-debug\['\"\];\?\)\?\s*debugger")
if [ "$has_console_log" != "" ]
then
echo "ERROR: You have console.log in your commit."
exit 1
fi
if [ "$has_console_dir" != "" ]
then
echo "ERROR: You have console.dir in your commit."
exit 1
fi
if [ "$has_ruby_debug" != "" ]
then
echo "ERROR: You have \"require 'ruby-debug'\" or \"debugger\" in your commit."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment