Skip to content

Instantly share code, notes, and snippets.

@aerickson
Created June 4, 2010 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aerickson/425107 to your computer and use it in GitHub Desktop.
Save aerickson/425107 to your computer and use it in GitHub Desktop.
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