Created
October 16, 2009 19:53
-
-
Save scashin133/212022 to your computer and use it in GitHub Desktop.
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
def run_cmd(cmd) | |
puts "\nRunning: #{cmd}" | |
raise "#{cmd} failed" unless system cmd | |
end | |
def current_branch | |
`git status`.gsub(/On branch (.+)/) do | |
return $1 | |
end | |
return nil | |
end | |
def reset_branch(branch) | |
run_cmd "git branch -D #{branch}" | |
run_cmd "git push origin :#{branch}" | |
run_cmd "git checkout master" | |
run_cmd "git checkout -b #{branch}" | |
run_cmd "grb publish #{branch}" | |
end | |
def each_branch(regex = //, &block) | |
branches = `git branch`.split("\n") | |
branches.each do |branch| | |
branch = branch.gsub(/\*/, '').strip | |
yield(branch) if regex.match(branch) | |
end | |
end | |
namespace :git do | |
desc 'update all branches to have most recent changes from master' | |
task :catch_up do | |
each_branch /devel-/ do |branch| | |
puts "Integrating latest changes from master into branch #{branch}" | |
run_cmd "git checkout #{branch}" | |
run_cmd "git pull origin #{branch}" | |
run_cmd "git pull origin master" | |
run_cmd "git push origin #{branch}" | |
end | |
end | |
desc 'merge latest changes from master into devel branches and regenerate the staging branch' | |
task :update_staging_branch => ['git:catch_up', 'git:generate_staging_branch'] do | |
end | |
desc 'merge devel- branches into the staging branch' | |
task :generate_staging_branch do | |
run_cmd "git remote prune origin" | |
run_cmd "git branch -D staging" | |
run_cmd "grb track staging" | |
run_cmd "git checkout staging" | |
run_cmd "git pull origin staging" | |
run_cmd "git pull origin master" | |
run_cmd %Q{for i in `git branch -r | grep devel-`; do echo 'merging: ' $i; echo $i | awk -F\/ '{print $1" "$2}' | xargs git pull ; done} | |
run_cmd %Q{for i in `git branch -r | grep client-`; do echo 'merging: ' $i; echo $i | awk -F\/ '{print $1" "$2}' | xargs git pull ; done} | |
run_cmd "git push origin staging" | |
end | |
desc 'reset the staging branch to remove old devel branches etc' | |
task :reset_staging_branch do | |
reset_branch('staging') | |
end | |
desc 'cleanup files from merge conflicts' | |
task :cleanup do | |
run_cmd 'find . -name *.orig -exec rm {} \;' | |
end | |
desc 'update the current feature branch to have latest changes from master' | |
task :update do | |
run_cmd "git pull origin #{current_branch}" | |
run_cmd 'git pull origin master' | |
run_cmd 'git push origin HEAD' | |
end | |
desc 'release the current feature branch to master' | |
task :release => ['git:update', 'test'] do | |
require 'readline' | |
exit unless Readline.readline('This will release this branch to production. Are you sure (y/n)? ') == 'y' | |
feature_branch = current_branch | |
run_cmd 'git checkout master' | |
run_cmd 'git pull origin master' | |
run_cmd "git pull . #{feature_branch}" | |
run_cmd 'git push origin HEAD' | |
run_cmd "grb rm #{feature_branch}" | |
end | |
desc 'integrate the current feature branch into staging' | |
task :integrate => 'git:update' do | |
feature_branch = current_branch | |
run_cmd "git remote prune origin" | |
raise "Only master and devel branches should be integrated into staging. rename your branch and try again." unless feature_branch == 'master' || feature_branch.starts_with?('devel-') | |
run_cmd "git branch -D staging" | |
run_cmd "grb track staging" | |
run_cmd 'git checkout staging' | |
run_cmd "git pull . #{feature_branch}" | |
run_cmd 'git push origin HEAD' | |
run_cmd 'cap staging deploy' | |
run_cmd "git checkout #{feature_branch}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment