Method: RubyGit::Status::OrdinaryEntry.parse

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

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

Parse an ordinary change line of git status output

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

The format is as follows: 1

Examples:

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

Parameters:

  • line (String)

    line from git status

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ruby_git/status/ordinary_entry.rb', line 124

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

  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],
    path: tokens[8]
  )
end