Skip to content

Instantly share code, notes, and snippets.

@zailleh
Last active October 11, 2019 02:55
Show Gist options
  • Save zailleh/63e9b7aa9a41f68a1c34be8f958ce20f to your computer and use it in GitHub Desktop.
Save zailleh/63e9b7aa9a41f68a1c34be8f958ce20f to your computer and use it in GitHub Desktop.
Git pre-commit for Rubocop
#!/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