Class: RubyGit::Status::UnmergedEntry

Inherits:
Entry
  • Object
show all
Defined in:
lib/ruby_git/status/unmerged_entry.rb

Overview

Represents an unmerged file in git status

Constant Summary collapse

CONFLICT_TYPES =

Maps the change code to a conflict type symbol

{
  'DD' => :both_deleted,
  'AU' => :added_by_us,
  'UD' => :deleted_by_them,
  'UA' => :added_by_them,
  'DU' => :deleted_by_us,
  'AA' => :both_added,
  'UU' => :both_modified
}.freeze

Constants inherited from Entry

Entry::RENAME_OPERATIONS, Entry::STATUS_CODES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entry

#fully_staged?, #ignored?, #index_status, rename_operation_to_symbol, #staged?, status_to_symbol, #unstaged?, #untracked?, #worktree_status

Constructor Details

#initialize(conflict_type:, submodule_status:, base_mode:, our_mode:, their_mode:, worktree_mode:, base_sha:, our_sha:, their_sha:, path:) ⇒ UnmergedEntry

Initialize a new unmerged entry

Examples:

UnmergedEntry.new(
  conflict_type: :both_deleted,
  submodule_status: nil,
  base_mode: 0o100644,
  our_mode: 0o100644,
  their_mode: 0o100644,
  worktree_mode: 0o100644,
  base_sha: 'd670460b4b4aece5915caf5c68d12f560a9fe3e4',
  our_sha: 'd670460b4b4aece5915caf5c68d12f560a9fe3e4',
  their_sha: 'd670460b4b4aece5915caf5c68d12f560a9fe3e4',
  path: 'lib/example.rb'
)

Parameters:

  • conflict_type (Symbol)

    type of merge conflict

  • submodule_status (SubmoduleStatus, nil)

    submodule status if applicable

  • base_mode (Integer)

    mode of the file in the base

  • our_mode (Integer)

    mode of the file in our branch

  • their_mode (Integer)

    mode of the file in their branch

  • worktree_mode (Integer)

    mode of the file in the worktree

  • base_sha (String)

    SHA of the file in the base

  • our_sha (String)

    SHA of the file in our branch

  • their_sha (String)

    SHA of the file in their branch

  • path (String)

    file path



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/ruby_git/status/unmerged_entry.rb', line 216

def initialize( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
  conflict_type:,
  submodule_status:,
  base_mode:, our_mode:, their_mode:, worktree_mode:,
  base_sha:, our_sha:, their_sha:,
  path:
)
  super(path)
  @conflict_type = conflict_type
  @submodule_status = submodule_status
  @base_mode = base_mode
  @our_mode = our_mode
  @their_mode = their_mode
  @worktree_mode = worktree_mode
  @base_sha = base_sha
  @our_sha = our_sha
  @their_sha = their_sha
  @path = path
end

Instance Attribute Details

#base_modeInteger (readonly)

The mode of the file in the base

Examples:

entry.base_mode #=> 0o100644

Returns:

  • (Integer)


47
48
49
# File 'lib/ruby_git/status/unmerged_entry.rb', line 47

def base_mode
  @base_mode
end

#base_shaString (readonly)

The SHA of the file in the base

Examples:

entry.base_sha #=> 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'

Returns:

  • (String)


95
96
97
# File 'lib/ruby_git/status/unmerged_entry.rb', line 95

def base_sha
  @base_sha
end

#conflict_typeSymbol (readonly)

The type of merge conflict

Examples:

entry.conflict_type #=> :both_deleted

Returns:

  • (Symbol)

See Also:



23
24
25
# File 'lib/ruby_git/status/unmerged_entry.rb', line 23

def conflict_type
  @conflict_type
end

#our_modeInteger (readonly)

The mode of the file in our branch

Examples:

entry.our_mode #=> 0o100644

Returns:

  • (Integer)


59
60
61
# File 'lib/ruby_git/status/unmerged_entry.rb', line 59

def our_mode
  @our_mode
end

#our_shaString (readonly)

The SHA of the file in our branch

Examples:

entry.our_sha #=> 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'

Returns:

  • (String)


107
108
109
# File 'lib/ruby_git/status/unmerged_entry.rb', line 107

def our_sha
  @our_sha
end

#pathString (readonly)

The path of the file

Examples:

entry.path #=> 'lib/example.rb'

Returns:

  • (String)


131
132
133
# File 'lib/ruby_git/status/unmerged_entry.rb', line 131

def path
  @path
end

#submodule_statusSubmoduleStatus? (readonly)

The submodule status if the entry is a submodule or nil

Examples:

entry.submodule #=> 'N...'

Returns:



35
36
37
# File 'lib/ruby_git/status/unmerged_entry.rb', line 35

def submodule_status
  @submodule_status
end

#their_modeInteger (readonly)

The mode of the file in their branch

Examples:

entry.their_mode #=> 0o100644

Returns:

  • (Integer)


71
72
73
# File 'lib/ruby_git/status/unmerged_entry.rb', line 71

def their_mode
  @their_mode
end

#their_shaString (readonly)

The SHA of the file in their branch

Examples:

entry.their_sha #=> 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'

Returns:

  • (String)


119
120
121
# File 'lib/ruby_git/status/unmerged_entry.rb', line 119

def their_sha
  @their_sha
end

#worktree_modeInteger (readonly)

The mode of the file in the worktree

Examples:

entry.worktree_mode #=> 0o100644

Returns:

  • (Integer)


83
84
85
# File 'lib/ruby_git/status/unmerged_entry.rb', line 83

def worktree_mode
  @worktree_mode
end

Class Method Details

.conflict_code_to_type(code) ⇒ Symbol

Convert conflict code to a symbol

Examples:

UnmergedEntry.conflict_code_to_type('DD') #=> :both_deleted

Parameters:

  • code (String)

    conflict code

Returns:

  • (Symbol)

    conflict type as symbol



185
186
187
# File 'lib/ruby_git/status/unmerged_entry.rb', line 185

def self.conflict_code_to_type(code)
  CONFLICT_TYPES[code] || :unknown
end

.parse(line) ⇒ RubyGit::Status::UnmergedEntry

Parse an unmerged change line of git status output

The line is expected to be in porcelain v2 format with NUL terminators.

The format is as follows: u

Examples:

line = 'uU N... 100644 100644 100644 100644 d670460b4b4aece5915caf5c68d12f560a9fe3e4 ' \
  'd670460b4b4aece5915caf5c68d12f560a9fe3e4 d670460b4b4aece5915caf5c68d12f560a9fe3e4 lib/example.rb'
UnmergedEntry.parse(line) #=> #<RubyGit::Status::UnmergedEntry:0x00000001046bd488 ...>

Parameters:

  • line (String)

    line from git status

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/ruby_git/status/unmerged_entry.rb', line 149

def self.parse(line) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  tokens = line.split(' ', 11)

  new(
    conflict_type: conflict_code_to_type(tokens[1]),
    submodule_status: SubmoduleStatus.parse(tokens[2]),
    base_mode: Integer(tokens[3], 8),
    our_mode: Integer(tokens[4], 8),
    their_mode: Integer(tokens[5], 8),
    worktree_mode: Integer(tokens[6], 8),
    base_sha: tokens[7],
    our_sha: tokens[8],
    their_sha: tokens[9],
    path: tokens[10]
  )
end

Instance Method Details

#unmerged?Boolean

Does the entry represent a merge conflict?

  • Merge conflicts are not considered untracked, staged or unstaged

Examples:

entry.conflict? #=> false

Returns:

  • (Boolean)


245
# File 'lib/ruby_git/status/unmerged_entry.rb', line 245

def unmerged? = true