Class: RJGit::Plumbing::ApplyPatchToIndex
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
-
.diffs_to_patch(diffs) ⇒ Object
Take the result of RJGit::Porcelain.diff with options = true and return a patch String.
Instance Method Summary collapse
- #build_map ⇒ Object
- #commit(message, author, parents = nil, force = false) ⇒ Object
-
#initialize(repository, patch, ref = Constants::HEAD) ⇒ ApplyPatchToIndex
constructor
A new instance of ApplyPatchToIndex.
-
#new_tree ⇒ Object
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.
Methods inherited from Index
#add, #delete, #do_commit, successful?
Constructor Details
#initialize(repository, patch, ref = Constants::HEAD) ⇒ ApplyPatchToIndex
Returns a new instance of ApplyPatchToIndex.
428 429 430 431 432 433 434 435 |
# File 'lib/rjgit.rb', line 428 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
424 425 426 |
# File 'lib/rjgit.rb', line 424 def self.diffs_to_patch(diffs) diffs.inject(""){|result, diff| result << diff[:patch]} end |
Instance Method Details
#build_map ⇒ Object
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/rjgit.rb', line 441 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
437 438 439 |
# File 'lib/rjgit.rb', line 437 def commit(, , parents = nil, force = false) super(, , parents, @ref, force) end |
#new_tree ⇒ Object
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
463 464 465 466 |
# File 'lib/rjgit.rb', line 463 def new_tree map = build_map return ObjectId.to_string(build_new_tree(map, @ref)), map.keys end |