Skip to content

Instantly share code, notes, and snippets.

@yvon
Created December 14, 2011 17:36
Show Gist options
  • Save yvon/1477595 to your computer and use it in GitHub Desktop.
Save yvon/1477595 to your computer and use it in GitHub Desktop.
Git post-checkout hook changing database.yml
#!/usr/bin/env ruby
require 'fileutils'
# Change working directory to repository
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
branch = `git branch | grep '*' | cut -c 3-`.chomp
new_db_config_file = File.join('config', "database.#{branch}.yml")
if File.exists?(new_db_config_file)
actual_db_config_file = File.join('config', 'database.yml')
FileUtils.cp(actual_db_config_file, File.join('config', 'database.yml.backup'))
FileUtils.cp(new_db_config_file, actual_db_config_file)
puts "#{__FILE__}: config/database.yml modified"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment