From edb6593ef00ae6e16f6cbbf7250bbfbf19d2a346 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Tue, 4 Apr 2017 17:23:14 -0400 Subject: [PATCH] ResolveMergerTest: Add tests for content merges Change-Id: I2b85cc239e9b3090426c956cbf9af3deb4106a41 --- .../eclipse/jgit/merge/ResolveMergerTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java index a08dbbcc8..255262255 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java @@ -586,6 +586,64 @@ public class ResolveMergerTest extends RepositoryTestCase { } } + @Theory + public void checkContentMergeNoConflict(MergeStrategy strategy) + throws Exception { + Git git = Git.wrap(db); + + writeTrashFile("file", "1\n2\n3"); + git.add().addFilepattern("file").call(); + RevCommit first = git.commit().setMessage("added file").call(); + + writeTrashFile("file", "1master\n2\n3"); + git.commit().setAll(true).setMessage("modified file on master").call(); + + git.checkout().setCreateBranch(true).setStartPoint(first) + .setName("side").call(); + writeTrashFile("file", "1\n2\n3side"); + RevCommit sideCommit = git.commit().setAll(true) + .setMessage("modified file on side").call(); + + git.checkout().setName("master").call(); + MergeResult result = + git.merge().setStrategy(strategy).include(sideCommit).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + String expected = "1master\n2\n3side"; + assertEquals(expected, read("file")); + } + + @Theory + public void checkContentMergeConflict(MergeStrategy strategy) + throws Exception { + Git git = Git.wrap(db); + + writeTrashFile("file", "1\n2\n3"); + git.add().addFilepattern("file").call(); + RevCommit first = git.commit().setMessage("added file").call(); + + writeTrashFile("file", "1master\n2\n3"); + git.commit().setAll(true).setMessage("modified file on master").call(); + + git.checkout().setCreateBranch(true).setStartPoint(first) + .setName("side").call(); + writeTrashFile("file", "1side\n2\n3"); + RevCommit sideCommit = git.commit().setAll(true) + .setMessage("modified file on side").call(); + + git.checkout().setName("master").call(); + MergeResult result = + git.merge().setStrategy(strategy).include(sideCommit).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + String expected = "<<<<<<< HEAD\n" + + "1master\n" + + "=======\n" + + "1side\n" + + ">>>>>>> " + sideCommit.name() + "\n" + + "2\n" + + "3"; + assertEquals(expected, read("file")); + } + /** * Merging after criss-cross merges. In this case we merge together two * commits which have two equally good common ancestors