Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Last active December 24, 2015 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdgaag/6865420 to your computer and use it in GitHub Desktop.
Save avdgaag/6865420 to your computer and use it in GitHub Desktop.
Run Rubocop using the project settings on modified files in your Git repository. Store this in `.git/hooks/pre-commit` to reject commits with style offsenses.
#!/bin/bash
git diff --cached --name-status --diff-filter=ACM | awk '/\.rb$/ { print $2 }' | xargs rubocop -f s
exit_code=$?
if [[ $exit_code != 0 ]] ; then
echo 'Your commit was rejected because Rubocop found style guide violations.'
echo 'Run `rake rubocop` to test your code and inspect the offenses Rubocop'
echo 'has found.'
echo
echo 'If you really, REALLY want to commit this code, skip your pre-commit'
echo 'hooks with `git commit --no-verify`.'
fi
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment