Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2018-04-04 06:30:43 +0000
committerMatthias Sohn2018-09-03 23:02:49 +0000
commit942688d80b40440e9835110982be2c4fbacecff7 (patch)
tree67937f1f2744cf218467f2453c8367cac12f8227 /org.eclipse.egit.gitflow.test
parent3103dcd44d43bbb655a3be40ce70106c725a7e2e (diff)
downloadegit-942688d80b40440e9835110982be2c4fbacecff7.tar.gz
egit-942688d80b40440e9835110982be2c4fbacecff7.tar.xz
egit-942688d80b40440e9835110982be2c4fbacecff7.zip
Fixed: EGit allows starting features with diverging develop branches
In comparison, when the upstream develop branch is ahead of the local develop branch command line Gitflow (AVH) raises an error: $ git flow feature start "foo" Branches 'develop' and 'origin/develop' have diverged. Fatal: And branch 'develop' may be fast-forwarded. Adjusted JUnit tests to cover new code. Change-Id: I2629301539e96b3911987ad300a7ed538b1d0516
Diffstat (limited to 'org.eclipse.egit.gitflow.test')
-rw-r--r--org.eclipse.egit.gitflow.test/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/AbstractDualRepositoryTestCase.java2
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationDivergingTest.java104
3 files changed, 107 insertions, 1 deletions
diff --git a/org.eclipse.egit.gitflow.test/META-INF/MANIFEST.MF b/org.eclipse.egit.gitflow.test/META-INF/MANIFEST.MF
index e0bbb1d029..c68c944eca 100644
--- a/org.eclipse.egit.gitflow.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.egit.gitflow.test/META-INF/MANIFEST.MF
@@ -9,5 +9,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.eclipse.egit.core;version="[5.1.0,5.2.0)",
org.eclipse.egit.core.test;version="[5.1.0,5.2.0)",
org.eclipse.jgit.junit;version="[5.1.0,5.2.0)",
+ org.hamcrest;version="[1.1.0,1.2.0)",
+ org.junit.rules;version="[4.12.0,4.13.0)",
org.junit;version="[4.3.0,5.0.0)"
Require-Bundle: org.eclipse.core.resources
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/AbstractDualRepositoryTestCase.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/AbstractDualRepositoryTestCase.java
index 6dd6a1dc93..9ceeafc212 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/AbstractDualRepositoryTestCase.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/AbstractDualRepositoryTestCase.java
@@ -50,7 +50,7 @@ public class AbstractDualRepositoryTestCase extends DualRepositoryTestCase {
private File workdir2;
- String projectName = "FeaturePublishTest";
+ String projectName = "FeatureTest";
protected RevCommit initialCommit;
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationDivergingTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationDivergingTest.java
new file mode 100644
index 0000000000..ffb2d31554
--- /dev/null
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/FeatureStartOperationDivergingTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (C) 2018, Max Hohenegger <eclipse@hohenegger.eu>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.gitflow.op;
+
+import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.egit.core.op.FetchOperation;
+import org.eclipse.egit.core.op.PullOperation;
+import org.eclipse.egit.gitflow.GitFlowRepository;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class FeatureStartOperationDivergingTest extends AbstractDualRepositoryTestCase {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void testFeatureStart_localDevelopBehind() throws Exception {
+ GitFlowRepository gfRepo1 = new GitFlowRepository(
+ repository1.getRepository());
+ GitFlowRepository gfRepo2 = new GitFlowRepository(
+ repository2.getRepository());
+
+ fetch(gfRepo2);
+ init(gfRepo2);
+ setDevelopRemote(gfRepo1, gfRepo2);
+
+ repository1.commit("origin/develop is 1 commit ahead");
+
+ FeatureStartOperation featureStartOperation = new FeatureStartOperation(
+ gfRepo2, MY_FEATURE);
+
+ expectedException.expect(CoreException.class);
+ expectedException.expectMessage(
+ "Branches 'develop' and 'origin/develop' have diverged."
+ + "\nAnd branch 'develop' may be fast-forwarded.");
+ featureStartOperation.execute(null);
+ }
+
+ @Test
+ public void testFeatureStart_localDevelopAhead() throws Exception {
+ GitFlowRepository gfRepo1 = new GitFlowRepository(
+ repository1.getRepository());
+ GitFlowRepository gfRepo2 = new GitFlowRepository(
+ repository2.getRepository());
+
+ fetch(gfRepo2);
+ init(gfRepo2);
+ setDevelopRemote(gfRepo1, gfRepo2);
+
+ new PullOperation(Collections.singleton(repository2.getRepository()),
+ -1).execute(null);
+
+ repository2.commit("develop is 1 commit ahead");
+
+ FeatureStartOperation featureStartOperation = new FeatureStartOperation(
+ gfRepo2, MY_FEATURE);
+ featureStartOperation.execute(null);
+
+ assertEquals("feature branch successfully created and checked out",
+ gfRepo2.getConfig().getFullFeatureBranchName(MY_FEATURE),
+ repository2.getRepository().getFullBranch());
+ }
+
+ private void fetch(GitFlowRepository gfRepo2)
+ throws InvocationTargetException {
+ RemoteConfig config = gfRepo2.getConfig().getDefaultRemoteConfig();
+ FetchOperation fetchOperation = new FetchOperation(
+ gfRepo2.getRepository(), config,
+ -1, false);
+ fetchOperation.run(null);
+ }
+
+ private void setDevelopRemote(GitFlowRepository remote,
+ GitFlowRepository local) throws IOException {
+ String develop = local.getConfig().getDevelop();
+ String developFull = remote.getConfig().getDevelopFull();
+ local.setRemote(develop, DEFAULT_REMOTE_NAME);
+ local.setUpstreamBranchName(develop, developFull);
+ }
+
+ private void init(GitFlowRepository gfRepo2) throws CoreException {
+ InitOperation initOperation = new InitOperation(
+ gfRepo2.getRepository());
+ initOperation.execute(null);
+ }
+
+}

Back to the top