Browse Source

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>
stable-1.0
Bernard Leach 14 years ago committed by Chris Aniszczyk
parent
commit
5ec4977bb5
  1. 42
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  2. 12
      org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

42
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -648,6 +648,48 @@ public class MergeCommandTest extends RepositoryTestCase {
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

12
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

@ -474,6 +474,18 @@ public class ResolveMerger extends ThreeWayMerger {
}
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;

Loading…
Cancel
Save