Created
January 12, 2016 15:24
-
-
Save threewordphrase/fe07f62ebc32a3bea3d9 to your computer and use it in GitHub Desktop.
branch-diff
This file contains hidden or 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 | |
# | |
# List branches merged into integration but not master: branch-diff --yes integration --no master | |
# | |
# List commits present in integration but not master: branch-diff --commits --yes integration --no master | |
# | |
require 'optparse' | |
require 'ostruct' | |
class OptparseExample | |
def self.parse(args) | |
options = OpenStruct.new | |
options.yes = :integration | |
options.no = :master | |
options.type = :branches | |
opt_parser = OptionParser.new do |opts| | |
opts.on("--yes YES", String, "Branch YES has the branches") do |b| | |
options.yes = b.to_sym | |
end | |
opts.on("--no NO", String, "Branch NO does not have the branches") do |b| | |
options.no = b.to_sym | |
end | |
opts.on("--branches", String, "Branches mode") do |type| | |
options.type = :branches | |
end | |
opts.on("--commits", String, "Commits mode") do |type| | |
options.type = :commits | |
end | |
end | |
opt_parser.parse!(args) | |
options | |
end | |
end | |
options = OptparseExample.parse(ARGV) | |
`git fetch origin --prune` | |
if options.type === :commits | |
puts "Commits present in #{options.yes} but not #{options.no}:" | |
command = "git log #{options.yes} ^#{options.no} --no-merges" | |
else | |
puts "Branches merged into #{options.yes} but not #{options.no}:" | |
command = "comm -12 <(git branch --no-merged #{options.no}) <(git branch --merged #{options.yes})" | |
end | |
system "bash -c '#{command}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment