Skip to content

Instantly share code, notes, and snippets.

@leepa
Created February 9, 2011 10:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save leepa/818307 to your computer and use it in GitHub Desktop.
This is git-show-merges
#!/usr/bin/env ruby
## git-show-merges: a simple script to show you which topic branches have
## been merged into the current branch, and which haven't. (Or, specify
## the set of merge branches you're interested in on the command line.)
##
## git-show-merges Copyright 2008 William Morgan <wmorgan-git-wt-add@masanjin.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\//, "") }
branches = `git show-ref --heads`.
scan(/^\S+ refs\/heads\/(\S+)$/).
map { |a| a.first }
unknown = heads - branches
unless unknown.empty?
$stderr.puts "Unknown branch: #{unknown.first}"
exit(-1)
end
branches -= heads
heads.each do |h|
merged = branches.select { |b| `git log #{h}..#{b}` == "" }
unmerged = branches - merged
puts "merged into #{h}:"
merged.each { |b| puts " #{b}" }
puts
puts "not merged into #{h}: "
unmerged.each { |b| puts " #{b}" }
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment