Created
September 24, 2014 14:33
-
-
Save meagar/efb61fbd91f0188be7ba to your computer and use it in GitHub Desktop.
show legacy branches in a git repo
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
require 'time' | |
DAY = 60 * 60 * 24 | |
def print_branches(branches) | |
by_author = Hash.new { |hash,key| hash[key] = {} } | |
branches.each do |branch| | |
lines = `git show -s --pretty=medium #{branch}`.lines | |
# commit d8f1e9d4c755d46192db635e964a9b04d6882f90 | |
# (Merge: ...) | |
# Author: Some Author <some_author@example.com> | |
# Date: Tue Aug 19 11:29:28 2014 +0800 | |
# | |
# Some kind of message goes here | |
commit = lines.shift.gsub(/commit\s/, '').strip | |
author = lines.shift | |
author = lines.shift if author[/Merge/] # Merge commit has an extra line | |
author = author.gsub(/Author:\s+/, '').strip | |
date = Time.parse(lines.shift.gsub(/Date:\s+/, '').strip) | |
if (Time.now - date) / DAY > 30 | |
by_author[author][branch] = { commit: commit, date: date, message: lines.join('') } | |
end | |
end | |
authors = by_author.keys.sort do |a, b| | |
by_author[b].length - by_author[a].length | |
end | |
authors.each do |author| | |
puts "(#{by_author[author].length}) #{author}" | |
branches = by_author[author].keys.sort do |a,b| | |
by_author[author][a][:date] - by_author[author][b][:date] | |
end | |
branches.each do |branch| | |
puts "\t#{branch}" | |
branch = by_author[author][branch] | |
puts "\t\t #{((Time.now - branch[:date]) / (60 * 60 * 24)).to_i} days old" | |
puts "\t\t #{branch[:commit]}" | |
end | |
puts "\n" | |
end | |
end | |
puts "Merged branches" | |
puts "===============" | |
print_branches(`git branch -r --merged`.lines.map(&:strip)) | |
puts "Unmerged branches" | |
puts "=================" | |
print_branches(`git branch -r --no-merged`.lines.map(&:strip)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment