Class: Avm::Git::Commit::DiffTreeLine

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/git/commit/diff_tree_line.rb

Constant Summary collapse

DIFF_TREE_PATTERN =
/\A:(\d{6}) (\d{6}) (\S+) (\S+) (\S+)\t(\S.*)\z/.freeze
FIELDS =
%w[src_mode dst_mode src_sha1 dst_sha1 status path].freeze
GIT_COMMAND_ARGS =
%w[-c core.quotepath=off diff-tree --no-commit-id -r --full-index].freeze

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ DiffTreeLine

line: a line of command “git [GIT_COMMAND_ARGS]”‘s output. Reference: git-scm.com/docs/git-diff-tree



15
16
17
18
19
20
# File 'lib/avm/git/commit/diff_tree_line.rb', line 15

def initialize(line)
  m = DIFF_TREE_PATTERN.match(line.strip)
  raise "\"#{line}\" did not match pattern" unless m

  FIELDS.count.times { |i| send("#{FIELDS[i]}=", m[i + 1]) }
end

Instance Method Details

#fieldsObject



22
23
24
# File 'lib/avm/git/commit/diff_tree_line.rb', line 22

def fields
  FIELDS.map { |field| [field, send(field)] }.to_h
end