Method: Git::Diff#path

Defined in:
lib/git/diff.rb

#path(*paths) ⇒ self

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.

Examples:

Limit diff to a single path

git.diff('HEAD~3', 'HEAD').path('lib/')

Limit diff to multiple paths

git.diff('HEAD~3', 'HEAD').path('src/', 'docs/', 'README.md')

Remove path filtering (show all files)

diff.path  # or diff.path(nil)

Raises:

  • (ArgumentError)

    if any path is an Array (use splatted arguments instead)



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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