Last active
December 23, 2015 00:49
-
-
Save davidcornu/6556710 to your computer and use it in GitHub Desktop.
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 | |
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