Skip to content

Instantly share code, notes, and snippets.

@supermario
Last active April 21, 2024 20:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save supermario/dfccea80890886c9660e to your computer and use it in GitHub Desktop.
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
#!/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