Created
January 22, 2017 13:25
-
-
Save roman-m-work/6e721a2fc0771a26974493ba09eab5bc to your computer and use it in GitHub Desktop.
Git pre-commit hook to prevent accidental mistakes
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
#!/usr/bin/env ruby | |
# vim: set syntax=ruby | |
TESTS = [ | |
[ | |
:has_no_staged_migrations, | |
%x[ git status -s| egrep "^\?\?\sdb\/migrate/.+\.rb$" ].empty?, | |
"You probably forgot to add newly created migrations." | |
], | |
[ | |
:db_config_not_changed, | |
%x[ git status -s| egrep "^\sM\sconfig\/database\.yml$" ].empty?, | |
"DB config has changed accidentally?!" | |
] | |
] | |
def tests_passed?(checklist) | |
passed = true | |
checklist.each do |test_item| | |
unless test_item[1] | |
puts "\e[3m\33[1;31m \tSTOP! #{test_item[2]}\33[m\e[0m" | |
passed = false | |
end | |
end | |
passed | |
end | |
exit( tests_passed?(TESTS) ? 0 : 1 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment