Class: Git::Commands::Diff Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/diff.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-diff/2.53.0

Implements the git diff command

Compares commits, the index, and the working tree.

Examples:

Typical usage

diff = Git::Commands::Diff.new(execution_context)
diff.call(numstat: true, shortstat: true, src_prefix: 'a/', dst_prefix: 'b/')
diff.call(patch: true, no_index: true, path: ['/path/a', '/path/b'])
diff.call(patch: true, cached: true)
diff.call('abc123', 'def456', raw: true, numstat: true, shortstat: true)

See Also:

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(**options) ⇒ Git::CommandLineResult #call(no_index: true, path:, **options) ⇒ Git::CommandLineResult #call(commit = nil, cached:, **options) ⇒ Git::CommandLineResult #call(commit, **options) ⇒ Git::CommandLineResult #call(commit, *commits, **options) ⇒ Git::CommandLineResult

Overloads:

  • #call(**options) ⇒ Git::CommandLineResult

    Compare the index to the working tree

    Examples:

    Diff.new(ctx).call(numstat: true, src_prefix: 'a/', dst_prefix: 'b/')

    Parameters:

    • options (Hash)

      command options

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits outside the allowed range (exit code > 2)

  • #call(no_index: true, path:, **options) ⇒ Git::CommandLineResult

    Compare two paths on the filesystem (outside git)

    Always use the path: keyword for the two filesystem paths so that paths beginning with - are safely separated by -- and cannot be mistaken for flags by git.

    Examples:

    Diff.new(ctx).call(patch: true, no_index: true, path: ['/a', '/b'])

    Parameters:

    • path (Array<String>)

      two filesystem paths to compare (passed after --)

    • options (Hash)

      command options

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits outside the allowed range (exit code > 2)

  • #call(commit = nil, cached:, **options) ⇒ Git::CommandLineResult

    Compare the index to HEAD or the named commit

    Examples:

    Diff.new(ctx).call(patch: true, cached: true)
    Diff.new(ctx).call('HEAD~3', patch: true, cached: true)

    Parameters:

    • commit (String, nil) (defaults to: nil)

      commit to compare the index against (defaults to HEAD)

    • options (Hash)

      command options

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits outside the allowed range (exit code > 2)

  • #call(commit, **options) ⇒ Git::CommandLineResult

    Compare the working tree to the named commit

    Examples:

    Diff.new(ctx).call('HEAD~3', numstat: true, shortstat: true)

    Parameters:

    • commit (String)

      commit reference to compare the working tree against

    • options (Hash)

      command options

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits outside the allowed range (exit code > 2)

  • #call(commit, *commits, **options) ⇒ Git::CommandLineResult

    Compare two or more commits or show a combined diff

    Examples:

    Compare two commits

    Diff.new(ctx).call('abc123', 'def456', raw: true, numstat: true)

    Combined diff of a merge commit

    Diff.new(ctx).call('main', 'feature-a', 'feature-b',
      merge_base: true)

    Parameters:

    • commit (String)

      first commit reference

    • commits (Array<String>)

      additional commit references

    • options (Hash)

      command options

    Options Hash (**options):

    • :patch (Boolean, nil) — default: nil

      generate patch output

      Alias: :p, :u

    • :no_patch (Boolean, nil) — default: nil

      suppress all diff output

      Alias: :s

    • :unified (Integer, String) — default: nil

      generate diffs with this many lines of context

      Alias: :U

    • :output (String) — default: nil

      write output to a file instead of stdout

    • :output_indicator_new (String) — default: nil

      character to indicate new lines in the patch

    • :output_indicator_old (String) — default: nil

      character to indicate old lines in the patch

    • :output_indicator_context (String) — default: nil

      character to indicate context lines in the patch

    • :raw (Boolean, nil) — default: nil

      generate the diff in raw format

    • :patch_with_raw (Boolean, nil) — default: nil

      synonym for --patch --raw

    • :indent_heuristic (Boolean, nil) — default: nil

      enable the indent heuristic for patch readability (--indent-heuristic)

    • :no_indent_heuristic (Boolean, nil) — default: nil

      disable the indent heuristic (--no-indent-heuristic)

    • :minimal (Boolean, nil) — default: nil

      spend extra time to produce the smallest possible diff

    • :patience (Boolean, nil) — default: nil

      use the patience diff algorithm

    • :histogram (Boolean, nil) — default: nil

      use the histogram diff algorithm

    • :anchored (String, Array<String>) — default: nil

      generate a diff using the anchored diff algorithm

      Pass an array for multiple anchored texts. Maps to --anchored=<text>.

    • :diff_algorithm (String) — default: nil

      choose a diff algorithm (patience, minimal, histogram, or myers)

    • :stat (Boolean, String, nil) — default: nil

      generate a diffstat

      Pass true for --stat; pass a string like '100,40,10' for --stat=100,40,10.

    • :stat_width (Integer, String) — default: nil

      limit the width of --stat output

    • :stat_name_width (Integer, String) — default: nil

      limit the filename width of --stat output

    • :stat_count (Integer, String) — default: nil

      limit the number of lines in --stat output

    • :stat_graph_width (Integer, String) — default: nil

      limit the graph width of --stat output

    • :compact_summary (Boolean, nil) — default: nil

      output a condensed summary of extended header information

    • :numstat (Boolean, nil) — default: nil

      show per-file insertion/deletion counts in decimal notation

    • :shortstat (Boolean, nil) — default: nil

      output only the aggregate totals line from --stat

    • :dirstat (Boolean, String, nil) — default: nil

      output the distribution of relative amount of changes per sub-directory

      Pass true for --dirstat; pass a string like 'lines,cumulative' for --dirstat=lines,cumulative.

      Alias: :X

    • :cumulative (Boolean, nil) — default: nil

      synonym for --dirstat=cumulative

    • :dirstat_by_file (Boolean, String, nil) — default: nil

      synonym for --dirstat=files,...

    • :summary (Boolean, nil) — default: nil

      output a condensed summary of extended header information

    • :patch_with_stat (Boolean, nil) — default: nil

      synonym for --patch --stat

    • :z (Boolean, nil) — default: nil

      use NUL as output field terminators

    • :name_only (Boolean, nil) — default: nil

      show only the name of each changed file

    • :name_status (Boolean, nil) — default: nil

      show only the name and status of each changed file

    • :submodule (Boolean, String, nil) — default: nil

      specify how differences in submodules are shown

      Pass true for --submodule; pass a string like 'log' or 'diff' for --submodule=<format>.

    • :color (Boolean, String, nil) — default: nil

      show colored diff

      Pass true for --color or a string like 'always' for --color=always.

    • :no_color (Boolean, nil) — default: nil

      disable colored diff (--no-color)

    • :color_moved (Boolean, String, nil) — default: nil

      color moved lines differently

      Pass true for --color-moved or a string like 'zebra' for --color-moved=zebra.

    • :no_color_moved (Boolean, nil) — default: nil

      disable coloring moved lines (--no-color-moved)

    • :color_moved_ws (Boolean, String, nil) — default: nil

      configure how whitespace is handled for move detection

      Pass true for --color-moved-ws or a string like 'ignore-all-space' for --color-moved-ws=ignore-all-space.

    • :no_color_moved_ws (Boolean, nil) — default: nil

      disable whitespace handling for move detection (--no-color-moved-ws)

    • :word_diff (Boolean, String, nil) — default: nil

      show a word diff

      Pass true for --word-diff; pass a string like 'color' for --word-diff=color.

    • :word_diff_regex (String) — default: nil

      use this regex to decide what a word is

    • :color_words (Boolean, String, nil) — default: nil

      equivalent to --word-diff=color plus optional regex

    • :no_renames (Boolean, nil) — default: nil

      turn off rename detection

    • :rename_empty (Boolean, nil) — default: nil

      use empty blobs as rename source (--rename-empty)

    • :no_rename_empty (Boolean, nil) — default: nil

      do not use empty blobs as rename source (--no-rename-empty)

    • :check (Boolean, nil) — default: nil

      warn if changes introduce conflict markers or whitespace errors

    • :ws_error_highlight (String) — default: nil

      highlight whitespace errors in context, old, or new lines

    • :full_index (Boolean, nil) — default: nil

      show full pre- and post-image blob object names

    • :binary (Boolean, nil) — default: nil

      output a binary diff that can be applied with git apply

    • :abbrev (Boolean, String, nil) — default: nil

      show only a partial prefix of object names

      Pass true for --abbrev; pass a string for --abbrev=<n>.

    • :break_rewrites (Boolean, String, nil) — default: nil

      break complete rewrite changes into delete/create pairs

      Alias: :B

    • :find_renames (Boolean, String, nil) — default: nil

      detect renames, optionally specifying a similarity threshold

      Alias: :M

    • :find_copies (Boolean, String, nil) — default: nil

      detect copies as well as renames

      Alias: :C

    • :find_copies_harder (Boolean, nil) — default: nil

      inspect all files as candidates for the source of copy

    • :irreversible_delete (Boolean, nil) — default: nil

      omit the preimage for deletes

      Alias: :D

    • :l (Integer, String) — default: nil

      prevent rename/copy detection from running if the number of targets exceeds this

    • :diff_filter (String) — default: nil

      select only files matching the specified status letters

    • :S (String) — default: nil

      look for differences that change the number of occurrences of a string

    • :G (String) — default: nil

      look for differences whose patch text contains added/removed lines matching a regex

    • :find_object (String) — default: nil

      look for differences that change the number of occurrences of an object

    • :pickaxe_all (Boolean, nil) — default: nil

      when -S or -G finds a change, show all changes in that changeset

    • :pickaxe_regex (Boolean, nil) — default: nil

      treat the -S string as an extended POSIX regular expression

    • :O (String) — default: nil

      control the order in which files appear in the output

    • :skip_to (String) — default: nil

      discard files before the named file from the output

    • :rotate_to (String) — default: nil

      move files before the named file to the end of the output

    • :R (Boolean, nil) — default: nil

      swap two inputs (reverse diff)

    • :relative (Boolean, String, nil) — default: nil

      show pathnames relative to a subdirectory

      Pass true for --relative or a string for --relative=<path>.

    • :no_relative (Boolean, nil) — default: nil

      show pathnames relative to the working directory (--no-relative)

    • :text (Boolean, nil) — default: nil

      treat all files as text

      Alias: :a

    • :ignore_cr_at_eol (Boolean, nil) — default: nil

      ignore carriage-return at end of line

    • :ignore_space_at_eol (Boolean, nil) — default: nil

      ignore changes in whitespace at end of line

    • :ignore_space_change (Boolean, nil) — default: nil

      ignore changes in amount of whitespace

      Alias: :b

    • :ignore_all_space (Boolean, nil) — default: nil

      ignore whitespace when comparing lines

      Alias: :w

    • :ignore_blank_lines (Boolean, nil) — default: nil

      ignore changes whose lines are all blank

    • :ignore_matching_lines (String, Array<String>) — default: nil

      ignore changes whose all lines match the given regex

      Pass an array for multiple patterns. Maps to --ignore-matching-lines=<regex>.

      Alias: :I

    • :inter_hunk_context (Integer, String) — default: nil

      show the context between diff hunks, fusing nearby hunks

    • :function_context (Boolean, nil) — default: nil

      show whole function as context lines for each change

      Alias: :W

    • :exit_code (Boolean, nil) — default: nil

      make the program exit with codes similar to diff(1)

    • :quiet (Boolean, nil) — default: nil

      disable all output of the program

    • :ext_diff (Boolean, nil) — default: nil

      allow an external diff helper (--ext-diff)

    • :no_ext_diff (Boolean, nil) — default: nil

      disallow an external diff helper (--no-ext-diff)

    • :textconv (Boolean, nil) — default: nil

      allow external text conversion filters for binary files (--textconv)

    • :no_textconv (Boolean, nil) — default: nil

      disallow external text conversion filters for binary files (--no-textconv)

    • :ignore_submodules (Boolean, String, nil) — default: nil

      ignore changes to submodules in the diff

      Pass true for --ignore-submodules; pass a string like 'all' for --ignore-submodules=all.

    • :src_prefix (String) — default: nil

      source prefix for diff headers (e.g. 'a/')

    • :dst_prefix (String) — default: nil

      destination prefix for diff headers (e.g. 'b/')

    • :no_prefix (Boolean, nil) — default: nil

      do not show any source or destination prefix

    • :default_prefix (Boolean, nil) — default: nil

      use the default source and destination prefixes

    • :line_prefix (String) — default: nil

      prepend an additional prefix to every line of output

    • :ita_invisible_in_index (Boolean, nil) — default: nil

      make intent-to-add entries appear as new files in git diff

    • :ita_visible_in_index (Boolean, nil) — default: nil

      revert --ita-invisible-in-index

    • :max_depth (Integer, String) — default: nil

      descend at most this many levels of directories per pathspec

    • :cached (Boolean, nil) — default: nil

      compare the index to HEAD or a named commit

      Alias: :staged

    • :merge_base (Boolean, nil) — default: nil

      use merge base of commits

    • :no_index (Boolean, nil) — default: nil

      compare two filesystem paths outside a repo

    • :base (Boolean, nil) — default: nil

      compare working tree with the base version (stage #1)

      Alias: :"1"

    • :ours (Boolean, nil) — default: nil

      compare working tree with our branch (stage #2)

      Alias: :"2"

    • :theirs (Boolean, nil) — default: nil

      compare working tree with their branch (stage #3)

      Alias: :"3"

    • :"0" (Boolean, nil) — default: nil

      omit diff output for unmerged entries

    • :c (Boolean, nil) — default: nil

      produce a combined diff (useful when showing a merge)

    • :cc (Boolean, nil) — default: nil

      produce a dense combined diff (useful when showing a merge)

    • :combined_all_paths (Boolean, nil) — default: nil

      show paths from all parents of a combined diff

    • :path (Array<String>) — default: nil

      zero or more paths to limit diff to

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits outside the allowed range (exit code > 2)



# File 'lib/git/commands/diff.rb', line 158