class Git::Status::Git::Status::StatusFileFactory
A factory class responsible for fetching git status data and building a hash of StatusFile objects.
@api private
Public Class Methods
Source
# File lib/git/status.rb, line 298 def initialize(base) @base = base end
Create a new factory backed by the given git object
@param base [Git::Repository] the git object used as the status data provider
Public Instance Methods
Source
# File lib/git/status.rb, line 307 def construct_files files_data = fetch_all_files_data files_data.transform_values do |data| StatusFile.new(@base, data) end end
Gather all status data and build a hash of file paths to StatusFile objects
@return [Hash{String => Git::Status::StatusFile}] file paths mapped to
their status objects
Private Instance Methods
Source
# File lib/git/status.rb, line 320 def fetch_all_files_data files = @base.ls_files # Start with files tracked in the index. merge_untracked_files(files) merge_modified_files(files) merge_head_diffs(files) files end
Fetch and merge status information from multiple git commands
@return [Hash{String => Hash}] raw per-file status data keyed by path
Source
# File lib/git/status.rb, line 359 def merge_head_diffs(files) is_empty = @base.no_commits? return if is_empty # Merge changes between HEAD and the index. @base.diff_index('HEAD').each do |path, data| (files[path] ||= {}).merge!(data) end end
Merge HEAD-versus-index diff data into ‘files`, if commits exist
@param files [Hash] the in-progress files hash to update in place
@return [void]
Source
# File lib/git/status.rb, line 346 def merge_modified_files(files) # Merge changes between the index and the working directory. @base.diff_files.each do |path, data| (files[path] ||= {}).merge!(data) end end
Merge index-versus-working-tree diff data into ‘files`
@param files [Hash] the in-progress files hash to update in place
@return [void]
Source
# File lib/git/status.rb, line 334 def merge_untracked_files(files) @base.untracked_files.each do |file| files[file] = { path: file, untracked: true } end end
Merge untracked working-tree files into ‘files`
@param files [Hash] the in-progress files hash to update in place
@return [void]