Create a MergeResult for deleted/modified files

Change Ia2ab4f8dc95020f2914ff01c2bf3b1bc62a9d45d added merge
support for when OURS or THEIRS was simultaneously deleted
and modified.  That changeset however did not add create an
entry in the conflicts table so clients would see a CONFLICTING
result but getConflicts() would return null.

This change creates a MergeResult for the conflicting file.

Bug: 345684
Change-Id: I52acb81c1729b49c9fb3e7a477c6448d8e55c317
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
This commit is contained in:
Bernard Leach 2011-05-13 15:59:57 +10:00 committed by Chris Aniszczyk
parent 37fe0988b2
commit 5ec4977bb5
2 changed files with 54 additions and 0 deletions

View File

@ -648,6 +648,48 @@ public void testDeletionOnSideConflict() throws Exception {
assertTrue(new File(db.getWorkTree(), "a").exists());
assertEquals("1\na(main)\n3\n", read(new File(db.getWorkTree(), "a")));
assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b")));
assertEquals(1, result.getConflicts().size());
assertEquals(3, result.getConflicts().get("a")[0].length);
}
@Test
public void testModifiedAndRenamed() throws Exception {
// this test is essentially the same as testDeletionOnSideConflict,
// however if once rename support is added this test should result in a
// successful merge instead of a conflict
Git git = new Git(db);
writeTrashFile("x", "add x");
git.add().addFilepattern("x").call();
RevCommit initial = git.commit().setMessage("add x").call();
createBranch(initial, "refs/heads/d1");
createBranch(initial, "refs/heads/d2");
// rename x to y on d1
checkoutBranch("refs/heads/d1");
new File(db.getWorkTree(), "x")
.renameTo(new File(db.getWorkTree(), "y"));
git.rm().addFilepattern("x").call();
git.add().addFilepattern("y").call();
RevCommit d1Commit = git.commit().setMessage("d1 rename x -> y").call();
checkoutBranch("refs/heads/d2");
writeTrashFile("x", "d2 change");
git.add().addFilepattern("x").call();
RevCommit d2Commit = git.commit().setMessage("d2 change in x").call();
checkoutBranch("refs/heads/master");
MergeResult d1Merge = git.merge().include(d1Commit).call();
assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
d1Merge.getMergeStatus());
MergeResult d2Merge = git.merge().include(d2Commit).call();
assertEquals(MergeResult.MergeStatus.CONFLICTING,
d2Merge.getMergeStatus());
assertEquals(1, d2Merge.getConflicts().size());
assertEquals(3, d2Merge.getConflicts().get("x")[0].length);
}
@Test

View File

@ -474,6 +474,18 @@ private boolean processEntry(CanonicalTreeParser base,
}
unmergedPaths.add(tw.getPathString());
// generate a MergeResult for the deleted file
RawText baseText = base == null ? RawText.EMPTY_TEXT
: getRawText(base.getEntryObjectId(), db);
RawText ourText = ours == null ? RawText.EMPTY_TEXT
: getRawText(ours.getEntryObjectId(), db);
RawText theirsText = theirs == null ? RawText.EMPTY_TEXT
: getRawText(theirs.getEntryObjectId(), db);
MergeResult<RawText> result = mergeAlgorithm.merge(
RawTextComparator.DEFAULT, baseText, ourText,
theirsText);
mergeResults.put(tw.getPathString(), result);
}
}
return true;