Skip to content

Instantly share code, notes, and snippets.

@midu
Created November 8, 2011 21:05
Show Gist options
  • Select an option

  • Save midu/1349223 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

gium commented Nov 9, 2011

C'est vrai que ça manque une commande simple pour faire ce genre de trucs. En général je me contente de git diff -Sfoo.

@midu
Copy link
Copy Markdown
Author

midu commented Nov 9, 2011

oh pas mal cette petite commande :) je vais voir si je peux faire un truc un peu plus sexy avec :)

merci giuminou

@midu
Copy link
Copy Markdown
Author

midu commented Nov 9, 2011

couldn't improve it a lot :(

could make it into a one/two liner if I could return to modified_matching_files only files were forbidden is added (+)

@gium
Copy link
Copy Markdown

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
Copy Markdown
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