Last active
October 11, 2019 02:55
-
-
Save zailleh/63e9b7aa9a41f68a1c34be8f958ce20f to your computer and use it in GitHub Desktop.
Git pre-commit for Rubocop
This file contains hidden or 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/sh | |
BRANCH=$(git branch | grep \* | cut -d ' ' -f2) | |
REF=$(git merge-base master $BRANCH) | |
DIFFS=$(git diff --diff-filter AM --name-only --relative $REF) | |
if [ "$DIFFS" != "" ] | |
then | |
echo "Checking for rubocop offenses..." | |
OFFENSES=$(rubocop $(echo "$DIFFS")) | |
if [ "$(echo $OFFENSES | grep 'no offenses')" == "" ] | |
then | |
echo "$OFFENSES" | |
exit 1 | |
else | |
echo "No offenses, proceeding with commit" | |
fi | |
fi | |
echo "DONE!\nYou're a good citizen... this time!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment