Created
August 5, 2011 12:40
-
-
Save grosser/1127451 to your computer and use it in GitHub Desktop.
Script to push and merge all branches
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 | |
require 'rubygems' | |
require 'rake' | |
sh "git status | grep 'nothing to commit'" # ensure we are not dirty | |
sh "git fetch origin" # get current branch info | |
current_branch = `git branch | grep '*'`.split.last | |
def sync(branch) | |
sh "git checkout #{branch}" | |
push_and_pull | |
end | |
def merge(branch, options) | |
sync options[:into] | |
sync branch | |
sh "git checkout #{options[:into]} && git merge #{branch}" | |
sync options[:into] | |
end | |
def push_and_pull | |
status= `git status 2> /dev/null` | |
remote_pattern = /# Your branch is (.*?) / | |
diverge_pattern = /# Your branch and (.*) have diverged/ | |
if status =~ remote_pattern | |
if $1 == 'ahead' | |
sh "git push" rescue sh("git pull && git push") # sometimes ahead is outdated <-> just try with pull&push | |
else | |
sh "git pull" | |
end | |
elsif status =~ diverge_pattern | |
sh "git pull && git push" | |
end | |
end | |
merge 'deploy', :into => 'master' | |
merge 'master', :into => 'staging' | |
merge_into_staging = %w[clean_emails] | |
merge_into_staging.each do |branch| | |
merge 'deploy', :into => branch | |
merge branch, :into => 'staging' | |
end | |
sh "bundle exec cap fix:#{ARGV[0]}" unless ARGV[0].to_s.strip.empty? | |
sh "git checkout #{current_branch}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment