]> source.dussan.org Git - jgit.git/commitdiff
Create a MergeResult for deleted/modified files 09/3409/3
authorBernard Leach <leachbj@bouncycastle.org>
Fri, 13 May 2011 05:59:57 +0000 (15:59 +1000)
committerChris Aniszczyk <caniszczyk@gmail.com>
Thu, 19 May 2011 14:22:25 +0000 (09:22 -0500)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

index 9e75882349343deef2bf87b136636b7cfef3f688..39526e229a1b8ad454a123902bf1dabd79719423 100644 (file)
@@ -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
index 8758427583947b26c00f083f3eb87f8ca92e0a27..d347b59a0b49e803aadf482d94c3baea64de6c14 100644 (file)
@@ -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;