Last active
April 24, 2018 15:58
-
-
Save timuruski/ed20354fae75b3abb0d1bf6b1353c842 to your computer and use it in GitHub Desktop.
Modular pre-commit hook, script.
This file contains 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/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 |
This file contains 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/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