]> source.dussan.org Git - jgit.git/commitdiff
Fix Check for FF_ONLY merges again 88/9988/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 29 Jan 2013 07:05:00 +0000 (08:05 +0100)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 29 Jan 2013 07:05:00 +0000 (08:05 +0100)
Added more FF-mode tests

Change-Id: I33eed5737d9411cc1cf214da62ce719916a1b736

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java

index df3cf58424d6f421394f75dc6dbe788d38eeb835..f4e418def57cc497d4b1ff4d2fc2c488d723462a 100644 (file)
@@ -204,28 +204,6 @@ public class MergeCommandTest extends RepositoryTestCase {
                }
        }
 
-       @Test
-       public void testMergeCannotDoRequiredFastForward() 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();
-               git.commit().setMessage("third").call();
-
-               MergeResult result = git.merge().include(db.getRef(Constants.MASTER))
-                               .setFastForward(FastForwardMode.NO_FF)
-                               .call();
-               assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
-       }
-
        @Theory
        public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
                        throws Exception {
@@ -1367,6 +1345,41 @@ public class MergeCommandTest extends RepositoryTestCase {
 
                assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
        }
+       @Test
+       public void testNoFastForward() throws Exception {
+               Git git = new Git(db);
+               RevCommit initialCommit = git.commit().setMessage("initial commit")
+                               .call();
+               createBranch(initialCommit, "refs/heads/branch1");
+               git.commit().setMessage("second commit").call();
+               checkoutBranch("refs/heads/branch1");
+
+               MergeCommand merge = git.merge();
+               merge.setFastForward(FastForwardMode.NO_FF);
+               merge.include(db.getRef(Constants.MASTER));
+               MergeResult result = merge.call();
+
+               assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+       }
+
+       @Test
+       public void testFastForwardOnlyNotPossible() throws Exception {
+               Git git = new Git(db);
+               RevCommit initialCommit = git.commit().setMessage("initial commit")
+                               .call();
+               createBranch(initialCommit, "refs/heads/branch1");
+               git.commit().setMessage("second commit").call();
+               checkoutBranch("refs/heads/branch1");
+               writeTrashFile("file1", "branch1");
+               git.add().addFilepattern("file").call();
+               git.commit().setMessage("second commit on branch1").call();
+               MergeCommand merge = git.merge();
+               merge.setFastForward(FastForwardMode.FF_ONLY);
+               merge.include(db.getRef(Constants.MASTER));
+               MergeResult result = merge.call();
+
+               assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
+       }
        private static void setExecutable(Git git, String path, boolean executable) {
                FS.DETECTED.setExecute(
                                new File(git.getRepository().getWorkTree(), path), executable);
index aacc970e5ee18240264f6dac9f737ebbfcf8c4ba..6eba35e1d2ce08ee79832c1669756f4fb8051289 100644 (file)
@@ -300,7 +300,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
                                                headCommit, srcCommit }, mergeStatus, mergeStrategy,
                                                null, msg);
                        } else {
-                               if (fastForwardMode == FastForwardMode.NO_FF) {
+                               if (fastForwardMode == FastForwardMode.FF_ONLY) {
                                        return new MergeResult(headCommit, srcCommit,
                                                        new ObjectId[] { headCommit, srcCommit },
                                                        MergeStatus.ABORTED, mergeStrategy, null, null);