Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to push and merge all branches
#!/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