class Git::Diff
object that holds the diff between two commits
Attributes
Public Class Methods
Source
# File lib/git/diff.rb, line 11 def initialize(base, from = nil, to = nil) @base = base @from = from&.to_s @to = to&.to_s @path = nil @full_diff_files = nil end
Public Instance Methods
Source
# File lib/git/diff.rb, line 61 def [](key) process_full @full_diff_files.assoc(key)[1] end
Source
# File lib/git/diff.rb, line 66 def each(&) process_full @full_diff_files.map { |file| file[1] }.each(&) end
Source
# File lib/git/diff.rb, line 79 def name_status path_status_provider.to_h end
DEPRECATED METHODS
Source
# File lib/git/diff.rb, line 56 def patch @base.lib.diff_full(@from, @to, { path_limiter: @path }) end
Also aliased as: to_s
Source
# File lib/git/diff.rb, line 40 def path(*paths) validate_paths_not_arrays(paths) cleaned_paths = paths.compact @path = if cleaned_paths.empty? nil elsif cleaned_paths.length == 1 cleaned_paths.first else cleaned_paths end self end
Limits the diff to the specified path(s)
When called with no arguments (or only nil arguments), removes any existing path filter, showing all files in the diff. Internally stores a single path as a String and multiple paths as an Array for efficiency.
@example Limit diff to a single path
git.diff('HEAD~3', 'HEAD').path('lib/')
@example Limit diff to multiple paths
git.diff('HEAD~3', 'HEAD').path('src/', 'docs/', 'README.md')
@example Remove path filtering (show all files)
diff.path # or diff.path(nil)
@param paths [String, Pathname] one or more paths to filter the diff. Pass no arguments to remove filtering. @return [self] returns self for method chaining @raise [ArgumentError] if any path is an Array (use splatted arguments instead)
Source
# File lib/git/diff.rb, line 95 def stats { files: stats_provider.files, total: stats_provider.total } end
Private Instance Methods
Source
# File lib/git/diff.rb, line 149 def path_status_provider @path_status_provider ||= Git::DiffPathStatus.new(@base, @from, @to, @path) end
Source
# File lib/git/diff.rb, line 143 def process_full return if @full_diff_files @full_diff_files = process_full_diff end
Source
# File lib/git/diff.rb, line 157 def process_full_diff FullDiffParser.new(@base, patch).parse end
Source
# File lib/git/diff.rb, line 153 def stats_provider @stats_provider ||= Git::DiffStats.new(@base, @from, @to, @path) end
Source
# File lib/git/diff.rb, line 135 def validate_paths_not_arrays(paths) return unless paths.any?(Array) raise ArgumentError, 'path expects individual arguments, not arrays. ' \ "Use path('lib/', 'docs/') not path(['lib/', 'docs/'])" end