Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'rubygems'
require 'grit'
require 'active_support'
include Grit
#
# USAGE: dead_branches <path_to_repo>
#
# AUTHOR: Ben Sandofsky
# find all branches that have been merged into master
merged_branches = `git branch -a --merged`.split("\n").collect(&:strip) - ["* master"]
repo = Repo.new(ARGV[0])
merged_branches.each do |branch|
begin
last_commit = repo.commits(branch).first
last_time = Time.parse last_commit.to_hash['committed_date']
committer = last_commit.to_hash['committer']
# if the branch hasn't changed in 30 days
if last_time < 30.days.ago
puts "#{branch.sub("remotes/origin/", "")}:\t#{last_time.strftime("%m/%d/%Y")}\t#{committer['name']} #{committer['email']}\t#{last_commit.to_hash['id']}"
end
rescue
puts "Failure on branch: #{branch}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment