Last active
December 24, 2015 21:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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