class Avm::Git::Organize::Repository

def all_branches

def all_branches
  eac_git_local.execute!
end

def all_references

def all_references
  ::Pathname.glob("#{refs_root}/**/*").select(&:file?)
            .map { |p| p.relative_path_from(refs_root).to_path }
end

def collect_originals

def collect_originals
  collect_references_with_pattern(
    %r{\Aoriginal/},
    ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
  )
end

def collect_reference(reference, operation)

def collect_reference(reference, operation)
  new_ru = ::Avm::Git::Organize::ReferenceUpdate.new(self, reference, operation)
  reference_update_by_ref(new_ru.reference).if_present do |ru_found|
    raise "Reference #{new_ru} already added (#{ru_found})"
  end
  @collected_references ||= []
  @collected_references << new_ru
end

def collect_references_with_pattern(pattern, operation)

def collect_references_with_pattern(pattern, operation)
  references_with_pattern(pattern).each do |reference|
    collect_reference(reference, operation)
  end
end

def collect_subrepos

def collect_subrepos
  collect_references_with_pattern(
    %r{\Asubrepo/},
    ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
  )
  collect_references_with_pattern(
    %r{\Aheads/subrepo/},
    ::Avm::Git::Organize::ReferenceUpdate::OPERATION_REMOVE
  )
end

def collected_references

def collected_references
  @collected_references || []
end

def reference_update_by_ref(reference)

def reference_update_by_ref(reference)
  collected_references.find { |ru| ru.reference == reference }
end

def references_with_pattern(pattern)

def references_with_pattern(pattern)
  all_references.select { |reference| pattern.if_match(reference, false) }
end

def refs_root_uncached

def refs_root_uncached
  eac_git_local.root_path / '.git' / 'refs'
end