Skip to content

Instantly share code, notes, and snippets.

@sgrankin
Created January 9, 2015 19:17
Show Gist options
  • Save sgrankin/371ae302d929a6e7d48e to your computer and use it in GitHub Desktop.
Save sgrankin/371ae302d929a6e7d48e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# find all branches which have been squash merged into master
require 'pp'
# all branches
branches = %x{git branch | sed s/^..//}.split.map(&:chomp)
# sort by branch age; generate pretty time stamp while we're at it
branch_times = branches.map{|branch|
%x{git log -1 --pretty=format:'%cI\\t%Cgreen%cr%Creset' #{branch}}.split('\t') + [branch]
}.sort.map{|_, t, b| [b, t]}
# display
branch_times.each{|b,t|
puts "#{t}\t#{b}"
}
# find merged ones
merged = branch_times.reverse.select{|branch, _|
next if branch == 'dev'
patch_id = %x{git diff master...#{branch} | git patch-id --stable}.split[0]
next if not patch_id
merge_base = %x{git merge-base master #{branch}}.chomp
merged_ids = %x{git rev-list #{merge_base}..master | xargs git show | git patch-id --stable}.split.map{|line| line.split[0]}
status = (merged_ids.include? patch_id) ? 'merged' : 'unmerged'
puts "#{status}\t#{branch}"
merged
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment