Created
February 28, 2011 07:29
-
-
Save birkirb/847042 to your computer and use it in GitHub Desktop.
Git show branches into which the current branch has been merged into.
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 | |
# git-show-merged: a simple script to show you which topic branches the | |
# current branch has been merged into, and which it hasn't. | |
# | |
# git-show-merged Copyright 2010 Birkir A. Barkarson <birkirb@stoicviking.net>. | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or (at | |
# your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You can find the GNU General Public License at: | |
# http://www.gnu.org/licenses/ | |
heads = if ARGV.empty? | |
[`git symbolic-ref HEAD`.chomp] | |
else | |
ARGV | |
end.map { |r| r.gsub(/refs\/heads\//, "") } | |
head = heads.first | |
branches = `git show-ref --heads`.scan(/^\S+ refs\/heads\/(\S+)$/).map { |a| a.first } | |
branches -= heads | |
if branches.empty? | |
$stderr.puts "No branches!" | |
exit(-1) | |
end | |
merged = Array.new | |
branches.each do |b| | |
`git checkout #{b} 2>&1` | |
if "" == `git log #{b}..#{head}` | |
merged << b | |
end | |
end | |
`git checkout #{head} 2>&1` | |
not_merged = branches - merged | |
puts "#{head} is merged into:" | |
merged.each { |b| puts " #{b}" } | |
puts | |
puts "#{head} is not merged into:" | |
not_merged.each { |b| puts " #{b}" } | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment