Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Last active December 23, 2015 00:49
Show Gist options
  • Save davidcornu/6556710 to your computer and use it in GitHub Desktop.
Save davidcornu/6556710 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
remote, *_ = ARGV
remote ||= 'heroku'
branches = `git branch --remote --list origin*`.lines.map(&:strip)
result = branches.each_with_object({}) do |branch, h|
h[branch] = {
:ahead => `git log --oneline #{remote}/master..#{branch}`.lines.length,
:behind => `git log --oneline #{branch}..#{remote}/master`.lines.length
}
end
rows = [['Branch', 'Ahead', 'Behind']]
result.each do |branch, state|
rows << [branch, state[:ahead].to_s, state[:behind].to_s]
end
widths = (0..2).map { |i| rows.map { |row| row[i].length }.max }
rows.each do |row|
row.each_with_index { |value, index| print value.ljust(widths[index] + 2) }
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment