summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorTomasz Zarna <tomasz.zarna@tasktop.com>2012-01-12 18:32:53 +0100
committerTomasz Zarna <tomasz.zarna@tasktop.com>2013-04-04 15:11:49 +0200
commit545358577376bec8fc140a76ce0f72bf81cc0a94 (patch)
tree410629280cc5f6a62a09334b0a28937214539928 /org.eclipse.jgit.test
parent81b601de53125bbcd30620b58168154d7541d8ad (diff)
downloadjgit-545358577376bec8fc140a76ce0f72bf81cc0a94.tar.gz
jgit-545358577376bec8fc140a76ce0f72bf81cc0a94.zip
Add the no-commit option to MergeCommand
Added also tests and the associated option for the command line Merge command. Bug: 335091 Change-Id: Ie321c572284a6f64765a81674089fc408a10d059 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java125
1 files changed, 125 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 cf9573e44c..ba0847bd8d 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
@@ -142,6 +142,28 @@ public class MergeCommandTest extends RepositoryTestCase {
}
@Test
+ public void testFastForwardNoCommit() throws Exception {
+ Git git = new Git(db);
+ RevCommit first = git.commit().setMessage("initial commit").call();
+ createBranch(first, "refs/heads/branch1");
+
+ RevCommit second = git.commit().setMessage("second commit").call();
+
+ checkoutBranch("refs/heads/branch1");
+
+ MergeResult result = git.merge().include(db.getRef(Constants.MASTER))
+ .setCommit(false).call();
+
+ assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
+ result.getMergeStatus());
+ assertEquals(second, result.getNewHead());
+ assertEquals("merge refs/heads/master: Fast-forward", db
+ .getReflogReader(Constants.HEAD).getLastEntry().getComment());
+ assertEquals("merge refs/heads/master: Fast-forward", db
+ .getReflogReader(db.getBranch()).getLastEntry().getComment());
+ }
+
+ @Test
public void testFastForwardWithFiles() throws Exception {
Git git = new Git(db);
@@ -234,6 +256,31 @@ public class MergeCommandTest extends RepositoryTestCase {
db.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
+ @Theory
+ public void testMergeSuccessAllStrategiesNoCommit(
+ MergeStrategy mergeStrategy) throws Exception {
+ Git git = new Git(db);
+
+ RevCommit first = git.commit().setMessage("first").call();
+ createBranch(first, "refs/heads/side");
+
+ writeTrashFile("a", "a");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("second").call();
+
+ checkoutBranch("refs/heads/side");
+ writeTrashFile("b", "b");
+ git.add().addFilepattern("b").call();
+ RevCommit thirdCommit = git.commit().setMessage("third").call();
+
+ MergeResult result = git.merge().setStrategy(mergeStrategy)
+ .setCommit(false)
+ .include(db.getRef(Constants.MASTER)).call();
+ assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus());
+ assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(),
+ thirdCommit.getId());
+ }
+
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
@@ -481,6 +528,56 @@ public class MergeCommandTest extends RepositoryTestCase {
}
@Test
+ public void testSuccessfulContentMergeNoCommit() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ writeTrashFile("b", "1\nb\n3\n");
+ writeTrashFile("c/c/c", "1\nc\n3\n");
+ git.add().addFilepattern("a").addFilepattern("b")
+ .addFilepattern("c/c/c").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("a", "1(side)\na\n3\n");
+ writeTrashFile("b", "1\nb(side)\n3\n");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b")));
+ checkoutBranch("refs/heads/master");
+ assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b")));
+
+ writeTrashFile("a", "1\na\n3(main)\n");
+ writeTrashFile("c/c/c", "1\nc(main)\n3\n");
+ git.add().addFilepattern("a").addFilepattern("c/c/c").call();
+ RevCommit thirdCommit = git.commit().setMessage("main").call();
+
+ MergeResult result = git.merge().include(secondCommit.getId())
+ .setCommit(false)
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus());
+ assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(),
+ thirdCommit.getId());
+
+ assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(),
+ "a")));
+ assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b")));
+ assertEquals("1\nc(main)\n3\n",
+ read(new File(db.getWorkTree(), "c/c/c")));
+
+ assertEquals(null, result.getConflicts());
+
+ assertEquals(2, result.getMergedCommits().length);
+ assertEquals(thirdCommit, result.getMergedCommits()[0]);
+ assertEquals(secondCommit, result.getMergedCommits()[1]);
+ assertNull(result.getNewHead());
+ assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
+ }
+
+ @Test
public void testSuccessfulContentMergeAndDirtyworkingTree()
throws Exception {
Git git = new Git(db);
@@ -1345,6 +1442,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
}
+
@Test
public void testNoFastForward() throws Exception {
Git git = new Git(db);
@@ -1363,6 +1461,33 @@ public class MergeCommandTest extends RepositoryTestCase {
}
@Test
+ public void testNoFastForwardNoCommit() throws Exception {
+ // given
+ Git git = new Git(db);
+ RevCommit initialCommit = git.commit().setMessage("initial commit")
+ .call();
+ createBranch(initialCommit, "refs/heads/branch1");
+ RevCommit secondCommit = git.commit().setMessage("second commit")
+ .call();
+ checkoutBranch("refs/heads/branch1");
+
+ // when
+ MergeCommand merge = git.merge();
+ merge.setFastForward(FastForwardMode.NO_FF);
+ merge.include(db.getRef(Constants.MASTER));
+ merge.setCommit(false);
+ MergeResult result = merge.call();
+
+ // then
+ assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus());
+ assertEquals(2, result.getMergedCommits().length);
+ assertEquals(initialCommit, result.getMergedCommits()[0]);
+ assertEquals(secondCommit, result.getMergedCommits()[1]);
+ assertNull(result.getNewHead());
+ assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
+ }
+
+ @Test
public void testFastForwardOnlyNotPossible() throws Exception {
Git git = new Git(db);
RevCommit initialCommit = git.commit().setMessage("initial commit")