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.



371
372
373
374
375
376
377
378
# File 'lib/rjgit.rb', line 371

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



367
368
369
# File 'lib/rjgit.rb', line 367

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

Instance Method Details

#build_mapObject



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/rjgit.rb', line 384

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



380
381
382
# File 'lib/rjgit.rb', line 380

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



406
407
408
409
# File 'lib/rjgit.rb', line 406

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