Created
December 19, 2018 18:28
-
-
Save fhwang/df623e283eb8a45254909070a2213028 to your computer and use it in GitHub Desktop.
A script for finding local branches that have not changed in X days.
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
#!/usr/bin/env ruby | |
unless ARGV.size == 1 | |
puts "git-stale-branches [days ago]" | |
exit | |
end | |
require 'date' | |
days_ago = ARGV.first.to_i | |
branches = `git for-each-ref refs/heads --format='%(committerdate:raw) %(refname:short)'` | |
branches.each_line do |line| | |
line =~ /^(\d+) -\d+ (\S+)/ | |
committerdatetime = Time.at($1.to_i) | |
committerdate = Date.new( | |
committerdatetime.year, committerdatetime.month, committerdatetime.day | |
) | |
branch_name = $2 | |
puts branch_name if committerdate + days_ago <= Date.today | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment