Method: RubyGit::Status::RenamedEntry.parse

Defined in:
lib/ruby_git/status/renamed_entry.rb

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

Parse a git status line to create a renamed entry

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

The format is as follows: 2

Examples:

line = '2 RM N... 100644 100644 100644 d670460b4b4aece5915caf5c68d12f560a9fe3e4 ' \
  \d670460b4b4aece5915caf5c68d12f560a9fe3e4 50 lib/new_name.rb\0lib/old_name.rb'
RenamedEntry.parse(line) #=> #<RubyGit::Status::RenamedEntry:0x00000001046bd488 ...>

Parameters:

  • line (String)

    line from git status

Returns:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ruby_git/status/renamed_entry.rb', line 159

def self.parse(line) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  tokens = line.split(' ', 10)
  path, original_path = tokens[9].split("\0")

  new(
    index_status: Entry.status_to_symbol(tokens[1][0]),
    worktree_status: Entry.status_to_symbol(tokens[1][1]),
    submodule_status: SubmoduleStatus.parse(tokens[2]),
    head_mode: Integer(tokens[3], 8),
    index_mode: Integer(tokens[4], 8),
    worktree_mode: Integer(tokens[5], 8),
    head_sha: tokens[6],
    index_sha: tokens[7],
    operation: Entry.rename_operation_to_symbol(tokens[8][0]),
    similarity_score: tokens[8][1..].to_i,
    path: path,
    original_path: original_path
  )
end