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 c92962950..9b4b7146f 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 @@ -107,7 +107,7 @@ public class MergeAlgorithmTest extends TestCase { * @throws IOException */ public void testTwoComplicatedModifications() throws IOException { - assertEquals(t("aZY"), + assertEquals(t("a"), merge("abcdefghij", "aZZZZfZhZj", "abYdYYYYiY")); } @@ -153,6 +153,18 @@ public class MergeAlgorithmTest extends TestCase { merge("abcdefghij", "abdefghij", "abZdefghij")); } + public void testInsertVsModify() throws IOException { + assertEquals(t("a"), merge("ab", "abZ", "aXY")); + } + + public void testAdjacentModifications() throws IOException { + assertEquals(t("ad"), merge("abcd", "aZcd", "abYd")); + } + + public void testSeperateModifications() throws IOException { + assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe")); + } + private String merge(String commonBase, String ours, String theirs) throws IOException { MergeResult r = MergeAlgorithm.merge(RawTextComparator.DEFAULT, T(commonBase), T(ours), T(theirs)); 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 868248713..aee0ba940 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java @@ -103,7 +103,7 @@ public final class MergeAlgorithm { // leave the loop when there are no edits more for ours or for theirs // (or both) while (theirsEdit != END_EDIT || oursEdit != END_EDIT) { - if (oursEdit.getEndA() <= theirsEdit.getBeginA()) { + if (oursEdit.getEndA() < theirsEdit.getBeginA()) { // something was changed in ours not overlapping with any change // from theirs. First add the common part in front of the edit // then the edit. @@ -115,7 +115,7 @@ public final class MergeAlgorithm { ConflictState.NO_CONFLICT); current = oursEdit.getEndA(); oursEdit = nextEdit(baseToOurs); - } else if (theirsEdit.getEndA() <= oursEdit.getBeginA()) { + } else if (theirsEdit.getEndA() < oursEdit.getBeginA()) { // something was changed in theirs not overlapping with any // from ours. First add the common part in front of the edit // then the edit. @@ -179,10 +179,10 @@ public final class MergeAlgorithm { Edit nextOursEdit = nextEdit(baseToOurs); Edit nextTheirsEdit = nextEdit(baseToTheirs); for (;;) { - if (oursEdit.getEndA() > nextTheirsEdit.getBeginA()) { + if (oursEdit.getEndA() >= nextTheirsEdit.getBeginA()) { theirsEdit = nextTheirsEdit; nextTheirsEdit = nextEdit(baseToTheirs); - } else if (theirsEdit.getEndA() > nextOursEdit.getBeginA()) { + } else if (theirsEdit.getEndA() >= nextOursEdit.getBeginA()) { oursEdit = nextOursEdit; nextOursEdit = nextEdit(baseToOurs); } else {