Skip to content

Instantly share code, notes, and snippets.

@johncarney
Last active July 29, 2024 18:04
Show Gist options
  • Save johncarney/d9ae641728ff3765a0ada0c5307ef009 to your computer and use it in GitHub Desktop.
Save johncarney/d9ae641728ff3765a0ada0c5307ef009 to your computer and use it in GitHub Desktop.
Git pre-push rubocop check
#!/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