aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernard Leach2011-05-13 01:59:57 (EDT)
committerChris Aniszczyk2011-05-19 10:22:25 (EDT)
commit5ec4977bb514ec8eb01dd22c3e908fe3fe6da83f (patch)
tree1fe106eb4ec4f2742faa7822a265bc71e4742907
parent37fe0988b26b7893888a073a33ccf0865723ca8b (diff)
downloadjgit-5ec4977bb514ec8eb01dd22c3e908fe3fe6da83f.zip
jgit-5ec4977bb514ec8eb01dd22c3e908fe3fe6da83f.tar.gz
jgit-5ec4977bb514ec8eb01dd22c3e908fe3fe6da83f.tar.bz2
Create a MergeResult for deleted/modified filesrefs/changes/09/3409/3
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>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java42
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java12
2 files changed, 54 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 9e75882..39526e2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/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
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 8758427..d347b59 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/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;