14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitra/cli.rb', line 14
def analyze(reference_branch, matching = :all)
reference_branch ||= @tracker.current_branch
$stdout.puts "---- Analyzing branches in relation to #{reference_branch.yellow} ----"
branches = ([reference_branch] + @tracker.branches).uniq!
$stdout.puts "-- Using branches matching #{matching.map {|m| m.source}.join(', ').yellow} --" unless matching == :all
branches = branches.select { |branch| matching == :all or matching.inject(false) { |acc, match| acc || branch =~ match } }
$stdout.print "Analysing #{branches.size} branches: "
branch_analysis = branches.map do |branch|
$stdout.print '.'
$stdout.flush
unmerged = @tracker.branch(branch).commits_since(reference_branch).collect { |c| c.sha }
behind = @tracker.branch(reference_branch).commits_since(branch).collect { |c| c.sha }
{:name => branch, :behind => behind.size, :unmerged => unmerged.size}
end
$stdout.puts
name_max_size = branch_analysis.map { |item| item[:name].size }.sort.last
branch_analysis.each do |item|
state = []
state << "#{item[:unmerged]} ahead (unmerged)".red if item[:unmerged] > 0
state << "(but #{item[:behind]} behind)" if item[:unmerged] > 0 and item[:behind] > 0
state << 'merged'.green if state.empty?
$stdout.puts "%#{name_max_size}s %s" % [item[:name], state.join(', ')]
end
end
|