summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java31
2 files changed, 50 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
index aa8f8281e4..8a33425b1d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
@@ -198,6 +198,25 @@ public class MergeAlgorithmTest {
}
+ /**
+ * Test situations where (at least) one input value is the empty text
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testEmptyTexts() throws IOException {
+ // test modification against deletion
+ assertEquals(t("<AB=>"), merge("A", "AB", ""));
+ assertEquals(t("<=AB>"), merge("A", "", "AB"));
+
+ // test unmodified against deletion
+ assertEquals(t(""), merge("AB", "AB", ""));
+ assertEquals(t(""), merge("AB", "", "AB"));
+
+ // test deletion against deletion
+ assertEquals(t(""), merge("AB", "", ""));
+ }
+
private String merge(String commonBase, String ours, String theirs) throws IOException {
MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
T(commonBase), T(ours), T(theirs));
@@ -231,5 +250,4 @@ public class MergeAlgorithmTest {
public static RawText T(String text) {
return new RawText(Constants.encode(t(text)));
}
-
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java
index e6688f5bc9..112550a1de 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java
@@ -103,6 +103,37 @@ public final class MergeAlgorithm {
sequences.add(ours);
sequences.add(theirs);
MergeResult<S> result = new MergeResult<S>(sequences);
+
+ if (ours.size() == 0) {
+ if (theirs.size() != 0) {
+ EditList theirsEdits = diffAlg.diff(cmp, base, theirs);
+ if (!theirsEdits.isEmpty()) {
+ // we deleted, they modified -> Let their complete content
+ // conflict with empty text
+ result.add(1, 0, 0, ConflictState.FIRST_CONFLICTING_RANGE);
+ result.add(2, 0, theirs.size(),
+ ConflictState.NEXT_CONFLICTING_RANGE);
+ } else
+ // we deleted, they didn't modify -> Let our deletion win
+ result.add(1, 0, 0, ConflictState.NO_CONFLICT);
+ } else
+ // we and they deleted -> return a single chunk of nothing
+ result.add(1, 0, 0, ConflictState.NO_CONFLICT);
+ return result;
+ } else if (theirs.size() == 0) {
+ EditList oursEdits = diffAlg.diff(cmp, base, ours);
+ if (!oursEdits.isEmpty()) {
+ // we modified, they deleted -> Let our complete content
+ // conflict with empty text
+ result.add(1, 0, ours.size(),
+ ConflictState.FIRST_CONFLICTING_RANGE);
+ result.add(2, 0, 0, ConflictState.NEXT_CONFLICTING_RANGE);
+ } else
+ // they deleted, we didn't modify -> Let their deletion win
+ result.add(2, 0, 0, ConflictState.NO_CONFLICT);
+ return result;
+ }
+
EditList oursEdits = diffAlg.diff(cmp, base, ours);
Iterator<Edit> baseToOurs = oursEdits.iterator();
EditList theirsEdits = diffAlg.diff(cmp, base, theirs);