Skip to content

Instantly share code, notes, and snippets.

@naan
Last active December 10, 2015 02:18
Show Gist options
  • Save naan/4366407 to your computer and use it in GitHub Desktop.
Save naan/4366407 to your computer and use it in GitHub Desktop.
git pre-commit.sh for avoiding commit `console.*log` and `binding.pry`
#!/bin/sh
function check_forbidden_code {
git diff --cached --name-only | grep -E $1 > /dev/null || return
git diff --cached --name-only | grep -E $1 |\
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -E -n $2 && echo "COMMIT REJECTED Found '$2' references. Please remove them before commiting" && exit 1
}
JS_FILES_PATTERN='\.(js|coffee)(\..+)?$'
JS_FORBIDDEN='(console\..*log|debugger)'
check_forbidden_code $JS_FILES_PATTERN $JS_FORBIDDEN
RB_FILES_PATTERN='\.rb$'
RB_FORBIDDEN='binding.pry'
check_forbidden_code $RB_FILES_PATTERN $RB_FORBIDDEN
@naan
Copy link
Author

naan commented Dec 24, 2012

updated. check debugger too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment