Class: RJGit::Plumbing::ApplyPatchToIndex

Inherits:
Index
  • Object
show all
Defined in:
lib/rjgit.rb

Constant Summary collapse

ADD =
org.eclipse.jgit.diff.DiffEntry::ChangeType::ADD
COPY =
org.eclipse.jgit.diff.DiffEntry::ChangeType::COPY
MODIFY =
org.eclipse.jgit.diff.DiffEntry::ChangeType::MODIFY
DELETE =
org.eclipse.jgit.diff.DiffEntry::ChangeType::DELETE
RENAME =
org.eclipse.jgit.diff.DiffEntry::ChangeType::RENAME

Instance Attribute Summary

Attributes inherited from Index

#current_tree, #jrepo, #treemap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Index

#add, #delete, #do_commit, successful?

Constructor Details

#initialize(repository, patch, ref = Constants::HEAD) ⇒ ApplyPatchToIndex

Returns a new instance of ApplyPatchToIndex.



451
452
453
454
455
456
457
458
# File 'lib/rjgit.rb', line 451

def initialize(repository, patch, ref = Constants::HEAD)
  super(repository)
  @ref   = ref
  @patch = Patch.new
  @patch.parse(ByteArrayInputStream.new(patch.to_java_bytes))
  raise_patch_apply_error unless @patch.getErrors.isEmpty()
  @current_tree = Commit.find_head(@jrepo, ref).tree
end

Class Method Details

.diffs_to_patch(diffs) ⇒ Object

Take the result of RJGit::Porcelain.diff with options = true and return a patch String



447
448
449
# File 'lib/rjgit.rb', line 447

def self.diffs_to_patch(diffs)
  diffs.inject(""){|result, diff| result << diff[:patch]}
end

Instance Method Details

#build_mapObject



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/rjgit.rb', line 464

def build_map
  raise_patch_apply_error if @patch.getFiles.isEmpty()
  @patch.getFiles.each do |file_header|
    case file_header.getChangeType
    when ADD
      add(file_header.getNewPath, apply('', file_header))
    when MODIFY
      add(file_header.getOldPath, apply(getData(file_header.getOldPath), file_header))
    when DELETE
      delete(file_header.getOldPath)
    when RENAME
      delete(file_header.getOldPath)
      add(file_header.getNewPath, getData(file_header.getOldPath))
    when COPY
      add(file_header.getNewPath, getData(file_header.getOldPath))
    end
  end
  @treemap
end

#commit(message, author, parents = nil, force = false) ⇒ Object



460
461
462
# File 'lib/rjgit.rb', line 460

def commit(message, author, parents = nil, force = false)
  super(message, author, parents, @ref, force)
end

#new_treeObject

Build the new tree based on the patch, but don’t commit it Return the String object id of the new tree, and an Array of affected paths



486
487
488
489
# File 'lib/rjgit.rb', line 486

def new_tree
  map = build_map
  return ObjectId.to_string(build_new_tree(map, @ref)), map.keys
end