Skip to content

Instantly share code, notes, and snippets.

@mkllnk
mkllnk / pre-commit
Last active April 1, 2016 04:49
Git pre-commit hook for Rubocop offenses
#!/bin/sh
# This script only checks the total number of offenses in modified files.
# If you removed old offenses, it may not warn you about new ones.
# Other scripts check all modified files for offenses.
# They don't ignore old offenses.
NUMBER_BEFORE=`git diff --cached --diff-filter=CMRTUXB --name-only -- '*.rb' | sed 's/^\(.*\)$/HEAD:\1/' | xargs git show | rubocop -s head -f o | tail -n 2 | head -n 1 | cut -d ' ' -f 1`
NUMBER_NOW=`git diff --cached --diff-filter=ACMRTUXB --name-only -- '*.rb' | xargs cat | rubocop -s now -f o | tail -n 2 | head -n 1 | cut -d ' ' -f 1`