Last active
May 13, 2019 13:38
-
-
Save TeTiRoss/9d86d9bbec1a0b1e5741d7f319ede31f to your computer and use it in GitHub Desktop.
pre commit git hook for Ruby on Rails projects (rubocop & reek required to be installed)
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/bash | |
failed=false | |
ruby_files_modified=`git diff --staged --name-only --diff-filter=ACRM | grep -E '(\.rb|\.ruby|\.rake)' | xargs` | |
if ! [ -z "$ruby_files_modified" ]; then | |
printf '\e[1m\e[34m========= reek ============\n\e[0m' | |
bundle exec reek $ruby_files_modified | |
if [ $? != 0 ]; then | |
failed=true | |
fi | |
printf '\n' | |
printf '\e[1m\e[34m========= rubocop =========\n\e[0m' | |
bundle exec rubocop --force-exclusion $ruby_files_modified | |
if [ $? != 0 ]; then | |
failed=true | |
fi | |
printf '\n' | |
fi | |
# | |
# If your test suite takes much time to run, consider removing the step below, as it | |
# will run on any file update ( like README.md update, for example ). | |
# | |
files_modified=`git diff --staged` | |
if ! [ -z "$files_modified" ]; then | |
printf '\e[1m\e[34m========= rspec ===========\n\e[0m' | |
bundle exec rspec | |
if [ $? != 0 ]; then | |
failed=true | |
fi | |
printf '\n' | |
fi | |
if $failed; then | |
printf "\e[31m [!] Commit rejected, see the errors above. If you want to continue anyway use flag '--no-verify'. \e[0m \n" | |
exit 1 | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment