Skip to content

Instantly share code, notes, and snippets.

@roman-m-work
Created January 22, 2017 13:25
Show Gist options
  • Save roman-m-work/6e721a2fc0771a26974493ba09eab5bc to your computer and use it in GitHub Desktop.
Save roman-m-work/6e721a2fc0771a26974493ba09eab5bc to your computer and use it in GitHub Desktop.
Git pre-commit hook to prevent accidental mistakes
#!/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