Skip to content

Instantly share code, notes, and snippets.

@midu
Created November 8, 2011 21:05
Show Gist options
  • Save midu/1349223 to your computer and use it in GitHub Desktop.
Save midu/1349223 to your computer and use it in GitHub Desktop.
pre-commit git hook to prevent console.log in javascript files
FILES_PATTERN='\.(js|coffee)(\..+)?$'
FORBIDDEN='console.log'
git diff --cached --name-only | grep -E $FILES_PATTERN | GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && echo 'COMMIT REJECTED Found "console.log" references in your javascript. Please remove them before commiting';
# my zsh does annoying things with !
[ $? -ne 0 ]
@gium
Copy link

gium commented Nov 9, 2011

pourquoi pas un truc genre
PAGER= git diff --cached --name-only | grep '\.\(ext1\|ext2\)$' | xargs grep foo && echo failing && exit 1

Le git diff -Sfoo je m'en sert en local car c'est rapide à taper pour vérifier que je commit pas des messages de debug.

@midu
Copy link
Author

midu commented Nov 9, 2011

I like that :) updated

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