Skip to content

Instantly share code, notes, and snippets.

@danwakefield
Created January 22, 2025 16:32
Show Gist options
  • Save danwakefield/b8f61c9942c437feccfd9b6267fc77a6 to your computer and use it in GitHub Desktop.
Save danwakefield/b8f61c9942c437feccfd9b6267fc77a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
files=$(git diff --staged --name-only --diff-filter=ACMRTUXB | grep '\.rb$' | tr '\\\n' ' ')
# Check we have files before trying to run the tests.
# Prevents getting stuck if we only update non .rb files.
if [[ -n $files ]];then
if [ $commands[gxargs] ]; then
git diff --staged --name-only --diff-filter=ACMRTUXB | grep '\.rb$' | tr '\\\n' ' ' | gxargs --no-run-if-empty bundle exec rubocop -A --force-exclusion --config "$(git rev-parse --show-toplevel)/.rubocop.yml"
else
git diff --staged --name-only --diff-filter=ACMRTUXB | grep '\.rb$' | tr '\\\n' ' ' | /usr/bin/xargs bundle exec rubocop -A --force-exclusion --config "$(git rev-parse --show-toplevel)/.rubocop.yml"
fi
fi
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "${protected_branch} is a protected branch, create PR to merge"
exit 1 # push will not execute
else
exit 0 # push will execute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment