Class: Git::FileDiffInfo

Inherits:
Data
  • Object
show all
Defined in:
lib/git/diff_info.rb

Overview

Immutable value object representing a single file's diff information

FileDiffInfo encapsulates the parsed data from a unified diff for one file, including the file path, patch text, mode changes, object identifiers, and type.

This class is used by DiffInfo for the legacy diff API.

Examples:

Create a FileDiffInfo from parsed diff output

diff_info = Git::FileDiffInfo.new(
  path: 'lib/example.rb',
  patch: "diff --git a/lib/example.rb b/lib/example.rb\n...",
  mode: '100644',
  src: 'abc1234',
  dst: 'def5678',
  type: 'modified',
  binary: false
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binaryBoolean (readonly)

Returns whether this is a binary file.

Returns:

  • (Boolean)

    whether this is a binary file



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#dstString (readonly)

Returns the destination blob object identifier.

Returns:

  • (String)

    the destination blob object identifier



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#modeString (readonly)

Returns the file mode (e.g., '100644' for regular files).

Returns:

  • (String)

    the file mode (e.g., '100644' for regular files)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#patchString (readonly)

Returns the full unified diff patch text for this file.

Returns:

  • (String)

    the full unified diff patch text for this file



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#pathString (readonly)

Returns the file path relative to the repository root.

Returns:

  • (String)

    the file path relative to the repository root



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#srcString (readonly)

Returns the source blob object identifier.

Returns:

  • (String)

    the source blob object identifier



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

#typeString (readonly)

Returns the type of change: 'modified', 'new', 'deleted', 'renamed'.

Returns:

  • (String)

    the type of change: 'modified', 'new', 'deleted', 'renamed'



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git/diff_info.rb', line 45

FileDiffInfo = Data.define(
  :path,
  :patch,
  :mode,
  :src,
  :dst,
  :type,
  :binary
) do
  # Check if this is a binary file
  #
  # @return [Boolean] true if the file is binary
  #
  def binary?
    binary
  end
end

Instance Method Details

#binary?Boolean

Check if this is a binary file

Returns:

  • (Boolean)

    true if the file is binary



58
59
60
# File 'lib/git/diff_info.rb', line 58

def binary?
  binary
end