Last active
July 29, 2024 18:04
-
-
Save johncarney/d9ae641728ff3765a0ada0c5307ef009 to your computer and use it in GitHub Desktop.
Git pre-push rubocop check
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/sh | |
# Passes all changed and added files on the current branch to RuboCop before pushing. Paste the below into your | |
# .bin/hooks/pre-push file, which should be made executable. | |
# Note that it assumes that your trunk branch is named "main." If this is not the case, make the appropriate adjustment. | |
TRUNK_BRANCH=main | |
CURRENT_BRANCH="$(git branch --show-current)" | |
if [ "$CURRENT_BRANCH" != "$TRUNK_BRANCH" ]; then | |
rubocop $(git diff --name-status "$TRUNK_BRANCH" "$CURRENT_BRANCH" | egrep '^[AM]' | cut -f 2 | egrep '(^Gemfile|.rb)$') | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment