Last active
April 21, 2024 20:33
-
-
Save supermario/dfccea80890886c9660e to your computer and use it in GitHub Desktop.
Pre-commit hook to run Rubocop on changed files since fork from master
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 | |
# Install with: | |
# curl http://git.io/vEN3k > .git/hooks/pre-commit | |
# Fail if any command is non-zero | |
set -e | |
# Redirect output to stderr. | |
exec 1>&2 | |
# Commit where we forked from master | |
alias gmbm='git merge-base HEAD origin/master' | |
# Git files new/modified only (since fork from master) | |
alias gfcnm="git diff --diff-filter=AM --name-only \`gmbm\`" | |
# Run rubocop for all new/modified files with autocorrect | |
alias rc="gfcnm | grep -e 'rb$' | grep -v 'schema' | xargs bundle exec rubocop --rails -aD" | |
rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment