Created
May 5, 2014 16:26
-
-
Save dgiunta/cc2542e2a6dcc2aec2d7 to your computer and use it in GitHub Desktop.
This little script essentially spits out a nicely formatted report from running git branch --contains <branch> on your local repository. You might use this script if you wanted to see which branches have been merged into master already.
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 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: git-branch-report [options]" | |
opts.on("--porcelain", "Output machine-readable output") do |v| | |
options[:porcelain] = v | |
end | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts opts | |
exit | |
end | |
end.parse! | |
branches = `git branch | sed -e "s/[\* ]*//"`.split("\n") | |
containing_branches = branches.inject({}) do |ret, branch| | |
ret[branch] = `git branch --contains "#{branch}" | sed -e "s/[\* ]*//"`.split("\n") | |
ret | |
end | |
if options[:porcelain] | |
containing_branches.each do |branch, branches| | |
puts "#{branch}: #{branches.join(" ")}" | |
end | |
else | |
puts "Branch Report" | |
containing_branches.each do |branch, branches| | |
puts <<-EOM | |
#{branch}: | |
-- #{branches.join("\n -- ")} | |
EOM | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment