Skip to content

Instantly share code, notes, and snippets.

@timuruski
Last active April 24, 2018 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timuruski/ed20354fae75b3abb0d1bf6b1353c842 to your computer and use it in GitHub Desktop.
Save timuruski/ed20354fae75b3abb0d1bf6b1353c842 to your computer and use it in GitHub Desktop.
Modular pre-commit hook, script.
#!/bin/bash --login
# Select only staged Ruby files, this may be expanded to other file types if necessary.
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep -E "\.(erb|rake|rb)$" | tr '\n' ' ')"
# Check for ruby style errors
if [ -n "$FILES" ]; then
bundle exec rubocop --force-exclusion --format=simple ${FILES}
fi
#!/bin/bash --login
# What is this?
# =============
# This is a modular pre-commit script that will execute the scripts found in the pre-commit.d directory. It is
# inspired by this project: https://github.com/datagrok/modular-git-hooks
set -e
# Using Git to get the top-level because this file is symlinked making
# $0 => .git/hooks/pre-commit, which isn't very helpful.
pre_commit_hooks="$(git rev-parse --show-toplevel)/script/git_hooks/pre-commit.d"
for hook_script in $(find $pre_commit_hooks -type f); do
if [[ -x $hook_script ]] && (! $hook_script $@); then
echo 1>&2 "TIP: In an emergency you can use \`git commit --no-verify\` to skip commit hooks."
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment