Created — forked from andre/mergefrom.rb

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A dirt-simple script to merge a pull request from someone on github

View mergefrom.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#! /usr/bin/env ruby
 
require "open3" # for reading stderr
 
# A dirt-simple script to merge a pull request from someone on github.
# Andre Lewis, 2009
#
# Assumptions:
# 1. you're currently working on master
# 2. you've already reviewed the pull request and have decided to include it.
#
# usage:
# mergefrom git://github.com/foo/bar.git
#
# or, optionally, to merge a specific commit:
#
# mergefrom git://github.com/foo/bar.git 25fe7ea
#
#
# What it does:
# 1. adds the remote repo
# 2. checks out the remote repo as a local branch
# 3. pulls from the remote master or specific commit you provided
# 4. switches back to master
# 5. (with your confirmation) merges the just-checked out branch
# 6. (with your confirmation) deletes your just-checked out branch
 
 
url=ARGV[0] # Looks like: git://github.com/andre/geokit-gem.git
commit=ARGV[1] # Looks like: 25fe7ea
 
# quick method to execute a command and print the output
def exe(cmd)
puts "EXECUTING: #{cmd}"
failed=nil
Open3.popen3(cmd) do |stdin, stdout, stderr|
out=stdout.read
err=stderr.read
puts out if out !=''
puts err if err !=''
failed = err=~/^fatal|^error/i
end
# give an option to continue if something went wrong
if failed
puts "Continue? [y|N]"
s=STDIN.gets.chomp.downcase
if s!='y'
puts "STOPPING ..."
exit
end
end
end
 
# bail if the url is blank or not a git url
if url.nil? || !url =~/^git/
puts "USAGE: mergefrom git://github.com/foo/bar.git"
puts "optionally, include a specific commit as the second argument: mergefrom git://github.com/foo/bar.git 25fe7ea"
exit
end
 
# format the commit if the commit argument is non-blank
commit = (commit.nil? || commit == '') ? '' : ":#{commit}"
 
# extract the branchname, or create it from the url
url=~/^git:\/\/github.com\/(\w+)\//
branch=$1 || url.gsub('git:','').gsub(/\W/i,'')
 
puts "checking out #{url} as local branch #{branch}"
 
exe "git remote add -f #{branch} #{url}"
exe "git checkout -b #{branch}/master"
exe "git pull #{branch} master#{commit}"
exe "git checkout master"
 
merge_command = "git merge #{branch}/master"
delete_branch_command = "git merge #{branch}/master"
 
puts "Checked out the branch, and now switched back to master. Do you want to merge now? [Y|n]"
s=STDIN.gets.chomp.downcase
if s != 'n'
exe merge_command
puts "merged. delete branch? [Y|n]"
s=STDIN.gets.chomp.downcase
if s != 'n'
exe delete_branch_command
else
puts "to delete: #{delete_branch_command}"
end
else
puts "to merge: #{merge_command}"
puts "to delete_branch: #{delete_branch_command}"
end
puts "to push: git push"
puts "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.