Class: Rfix::Collector

Inherits:
Dry::Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rfix/collector.rb

Constant Summary collapse

OPTIONS =
{
  include_untracked_content: true,
  ignore_whitespace_change: false,
  recurse_untracked_dirs: true,
  ignore_whitespace_eol: false,
  disable_pathspec_match: true,
  include_unmodified: true,
  include_untracked: true,
  ignore_submodules: true,
  include_ignored: false,
  deltas_are_icase: true,
  ignore_filemode: true,
  force_text: true,
  context_lines: 0
}.freeze

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rfix/collector.rb', line 31

def each(&block)
  construct = lambda do |path, statuses|
    File.call(basename: path, status: statuses, repository: repository)
  end

  statuses = Hash.new(EMPTY_ARRAY).tap do |statuses|
    repository.status do |path, status|
      statuses[path] = status
    end
  end

  if repository.head_unborn?
    statuses.each do |path, status|
      (block << construct).call(path, status)
    end
  else
    origin.diff_workdir(**OPTIONS.dup).tap do |diff|
      diff.find_similar!(
        renames_from_rewrites: true,
        renames: true,
        copies: true
      )
    end.each_delta do |delta|
      delta.new_file.fetch(:path).then do |file_path|
        (block << construct).call(file_path, statuses[file_path] + [delta.status])
      end
    end
  end
end