Last active
September 15, 2016 18:08
-
-
Save Boztown/e56a02a4df68d69a396b1127481ce67b to your computer and use it in GitHub Desktop.
Post-Checkout GIT hook to change database_yml to the name of my current branch.
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
#!/usr/bin/env ruby | |
gem 'psych' | |
require 'psych' | |
branch = `git branch | grep '*' | cut -c 3-`.chomp | |
branch.gsub! '/', '_' | |
branch.gsub! '-', '_' | |
f = Psych.load_file("config/database.yml") | |
f["development"]["database"] = "ms_" + branch.to_s | |
File.open('config/database.yml', 'w') do |file| | |
file.write(Psych.dump(f).gsub("---\n", '')) | |
end | |
puts "Local development has been switched to: " + branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chuck this bad boy in
.git/hooks/post-checkout
, crack a beer and enjoy.