Class: Rfix::CLI::Command::Status

Inherits:
Base
  • Object
show all
Defined in:
lib/rfix/cli/command/status.rb

Instance Method Summary collapse

Methods included from Log

prompt, say, say!

Instance Method Details

#call(**_params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rfix/cli/command/status.rb', line 11

def call(**_params)
  walker = Rugged::Walker.new(Rugged::Repository.discover)
  walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
  walker.push("HEAD")

  unless oid = walker.each_oid(limit: 1).first
    raise Error, "Repository contains no commits"
  end

  ref = Rfix::Branch::Reference.new(name: oid)
  repo = Repository.new(repository: Rugged::Repository.discover, reference: ref)
  files = repo.permitted

  pp files.map(&:status).uniq

  result = files.map do |file|
    file.to_s.split("/").reverse.reduce({}) do |acc, part|
      next { "#{part} (#{file.class}:#{file.status.join(', ')})" => {} } if acc.empty?

      { part.to_s => acc }
    end
  end.reduce(EMPTY_HASH, :deep_merge)

  puts TTY::Tree.new({ root: result }).render
end