Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2015-08-28 17:44:57 -0400
committerMatthias Sohn2015-09-10 07:18:50 -0400
commit02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb (patch)
tree7bcf811d502a52fd272b35c5599f1dd5194eab1c
parent03f3f339162b5f2968ebba8e763a96a97d161728 (diff)
downloadegit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.tar.gz
egit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.tar.xz
egit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.zip
Fixed: Specifying non-existing master does not abort initialization
- abort init operation if master is missing - added validator for missing master branch - ask user to create master branch - ask user to create initial commit if repository is empty - added control decorations to hint at source of problem - adjusted tests Bug: 475788 Change-Id: Ief9b1a361a3dce83358e7b84034bb6a477ec92e4 Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu>
-rw-r--r--org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/InitOperationTest.java14
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/Activator.java8
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java18
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/InitHandler.java56
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/InitDialog.java124
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties6
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java3
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties1
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/InitOperation.java14
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java136
10 files changed, 337 insertions, 43 deletions
diff --git a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/InitOperationTest.java b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/InitOperationTest.java
index 0f0d8f012..6f16732c6 100644
--- a/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/InitOperationTest.java
+++ b/org.eclipse.egit.gitflow.test/src/org/eclipse/egit/gitflow/op/InitOperationTest.java
@@ -11,6 +11,8 @@ package org.eclipse.egit.gitflow.op;
import static org.junit.Assert.assertEquals;
import static org.eclipse.egit.gitflow.GitFlowDefaults.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.egit.core.op.RenameBranchOperation;
import org.eclipse.egit.gitflow.GitFlowRepository;
import static org.eclipse.egit.gitflow.GitFlowConfig.*;
@@ -58,4 +60,16 @@ public class InitOperationTest extends AbstractGitFlowOperationTest {
GitFlowRepository gfRepo = new GitFlowRepository(repository);
assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
}
+
+ @Test(expected = CoreException.class)
+ public void testInitLocalMasterMissing() throws Exception {
+ testRepository
+ .createInitialCommit("testInitLocalMasterMissing\n\nfirst commit\n");
+
+ Repository repository = testRepository.getRepository();
+ new RenameBranchOperation(repository, repository.getRef(repository
+ .getBranch()), "foobar").execute(null);
+
+ new InitOperation(repository).execute(null);
+ }
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/Activator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/Activator.java
index a83b9a3ce..e51f684a9 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/Activator.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/Activator.java
@@ -60,6 +60,14 @@ public class Activator extends AbstractUIPlugin {
}
/**
+ * @param message
+ * @return Warning status for given message.
+ */
+ public static IStatus warning(String message) {
+ return new Status(IStatus.WARNING, getPluginId(), message);
+ }
+
+ /**
* @return the id of the egit ui plugin
*/
public static String getPluginId() {
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
index ece5fdcbe..cfe46cad1 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
@@ -112,6 +112,9 @@ public class UIText extends NLS {
public static String HotfixStartHandler_startingNewHotfix;
/** */
+ public static String InitDialog_branchDoesNotExistYetAndWillBeCreated;
+
+ /** */
public static String InitDialog_chooseBranchNamesAndPrefixes;
/** */
@@ -136,12 +139,27 @@ public class UIText extends NLS {
public static String InitDialog_masterBranch;
/** */
+ public static String InitDialog_masterBranchIsMissing;
+
+ /** */
public static String InitDialog_releaseBranchPrefix;
/** */
+ public static String InitDialog_selectedMasterBranchDoesNotExistCreateNow;
+
+ /** */
public static String InitDialog_versionTagPrefix;
/** */
+ public static String InitHandler_doYouWantToInitNow;
+
+ /** */
+ public static String InitHandler_emptyRepository;
+
+ /** */
+ public static String InitHandler_initialCommit;
+
+ /** */
public static String InitHandler_initializing;
/** */
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/InitHandler.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/InitHandler.java
index 5dd408eb1..602658b75 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/InitHandler.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/InitHandler.java
@@ -8,16 +8,27 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.actions;
+import static org.eclipse.jface.dialogs.MessageDialog.openQuestion;
+
+import java.util.List;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.internal.job.JobUtil;
+import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.op.InitOperation;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
import org.eclipse.egit.gitflow.ui.internal.UIText;
import org.eclipse.egit.gitflow.ui.internal.dialogs.InitDialog;
+import org.eclipse.egit.ui.internal.commit.CommitHelper;
import org.eclipse.jface.window.Window;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -28,22 +39,61 @@ public class InitHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
+ Shell activeShell = HandlerUtil.getActiveShell(event);
final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
if (gfRepo == null) {
return null;
}
- Shell activeShell = HandlerUtil.getActiveShell(event);
- InitDialog dialog = new InitDialog(activeShell);
+
+ Repository repository = gfRepo.getRepository();
+ if (!gfRepo.hasBranches()) {
+ boolean createMaster = openQuestion(
+ activeShell,
+ UIText.InitHandler_emptyRepository,
+ UIText.InitHandler_doYouWantToInitNow);
+ if (!createMaster) {
+ return null;
+ }
+
+ createInitialCommit(repository);
+ }
+
+ InitDialog dialog = new InitDialog(activeShell, gfRepo, getBranches(repository));
if (dialog.open() != Window.OK) {
return null;
}
- InitOperation initOperation = new InitOperation(gfRepo.getRepository(),
+ InitOperation initOperation = new InitOperation(repository,
dialog.getResult());
JobUtil.scheduleUserWorkspaceJob(initOperation,
UIText.InitHandler_initializing, JobFamilies.GITFLOW_FAMILY);
return null;
}
+
+ private void createInitialCommit(Repository repository)
+ throws ExecutionException {
+ CommitHelper commitHelper = new CommitHelper(repository);
+
+ CommitOperation commitOperation;
+ try {
+ commitOperation = new CommitOperation(repository,
+ commitHelper.getAuthor(), commitHelper.getCommitter(),
+ UIText.InitHandler_initialCommit);
+ commitOperation.execute(null);
+ } catch (CoreException e) {
+ throw new ExecutionException(e.getMessage());
+ }
+ }
+
+ private List<Ref> getBranches(Repository repository) throws ExecutionException {
+ List<Ref> branchList;
+ try {
+ branchList = Git.wrap(repository).branchList().call();
+ } catch (GitAPIException e) {
+ throw new ExecutionException(e.getMessage());
+ }
+ return branchList;
+ }
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/InitDialog.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/InitDialog.java
index 0c5b804d1..984f60f2d 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/InitDialog.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/InitDialog.java
@@ -17,6 +17,8 @@ import static org.eclipse.egit.gitflow.InitParameters.MASTER_BRANCH_PROPERTY;
import static org.eclipse.egit.gitflow.InitParameters.RELEASE_BRANCH_PREFIX_PROPERTY;
import static org.eclipse.egit.gitflow.InitParameters.VERSION_TAG_PROPERTY;
import static org.eclipse.egit.gitflow.ui.Activator.error;
+import static org.eclipse.egit.gitflow.ui.Activator.warning;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_branchDoesNotExistYetAndWillBeCreated;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_chooseBranchNamesAndPrefixes;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_developBranch;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_featureBranchPrefix;
@@ -25,29 +27,44 @@ import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_initializeR
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_invalidBranchName;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_invalidPrefix;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_masterBranch;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_masterBranchIsMissing;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_releaseBranchPrefix;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_selectedMasterBranchDoesNotExistCreateNow;
import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_versionTagPrefix;
import static org.eclipse.jface.databinding.swt.WidgetProperties.text;
import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID;
import static org.eclipse.jface.dialogs.IMessageProvider.ERROR;
-import static org.eclipse.jface.dialogs.IMessageProvider.INFORMATION;
+import static org.eclipse.jface.dialogs.MessageDialog.openQuestion;
+import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.eclipse.jgit.lib.Repository.isValidRefName;
import static org.eclipse.swt.SWT.Modify;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.egit.core.op.CreateLocalBranchOperation;
+import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.InitParameters;
+import org.eclipse.egit.gitflow.WrongGitFlowStateException;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.databinding.dialog.TitleAreaDialogSupport;
import org.eclipse.jface.databinding.dialog.ValidationMessageProvider;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -62,6 +79,35 @@ import org.eclipse.swt.widgets.Text;
* Dialog to gather inputs for the git flow init operation.
*/
public class InitDialog extends TitleAreaDialog {
+ private final class BranchValidator implements IValidator {
+ @Override
+ public IStatus validate(Object value) {
+ if (value == null || !isValidRefName(R_HEADS + value)) {
+ return error(NLS.bind(InitDialog_invalidBranchName, value));
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ private final class BranchExistsValidator implements IValidator {
+ private List<String> list;
+
+ public BranchExistsValidator(List<Ref> branchList) {
+ list = new ArrayList<>();
+ for (Ref ref : branchList) {
+ list.add(ref.getName());
+ }
+ }
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value == null || !list.contains(R_HEADS + value)) {
+ return warning(NLS.bind(InitDialog_branchDoesNotExistYetAndWillBeCreated, value));
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
private Text developText;
private InitParameters gitflowInitConfig = new InitParameters();
@@ -82,11 +128,20 @@ public class InitDialog extends TitleAreaDialog {
private static final int TEXT_WIDTH = 100;
+ private GitFlowRepository gfRepo;
+
+ private List<Ref> branchList;
+
/**
* @param parentShell
+ * @param gfRepo
+ * @param branchList
*/
- public InitDialog(Shell parentShell) {
+ public InitDialog(Shell parentShell, GitFlowRepository gfRepo,
+ List<Ref> branchList) {
super(parentShell);
+ this.gfRepo = gfRepo;
+ this.branchList = branchList;
}
@Override
@@ -123,9 +178,7 @@ public class InitDialog extends TitleAreaDialog {
if(okButton != null) {
okButton.setEnabled(type != ERROR);
}
- if (ERROR != type) {
- return INFORMATION;
- }
+
return type;
}
});
@@ -154,24 +207,21 @@ public class InitDialog extends TitleAreaDialog {
UpdateValueStrategy noModelToTarget = new UpdateValueStrategy(false, POLICY_ON_REQUEST);
- UpdateValueStrategy targetToModel = new UpdateValueStrategy();
- targetToModel.setBeforeSetValidator(new IValidator() {
- @Override
- public IStatus validate(Object value) {
- if (value == null || !isValidRefName(Constants.R_HEADS + value)) {
- return error(NLS.bind(InitDialog_invalidBranchName, value));
- }
- return Status.OK_STATUS;
- }
- });
- bind(context, noModelToTarget, targetToModel, DEVELOP_BRANCH_PROPERTY, developText);
- bind(context, noModelToTarget, targetToModel, MASTER_BRANCH_PROPERTY, masterText);
+ UpdateValueStrategy developUpdateStrategy = new UpdateValueStrategy();
+ developUpdateStrategy.setBeforeSetValidator(new BranchValidator());
+ bind(context, noModelToTarget, developUpdateStrategy, DEVELOP_BRANCH_PROPERTY, developText);
+
+ UpdateValueStrategy masterUpdateStrategy = new UpdateValueStrategy();
+ masterUpdateStrategy.setBeforeSetValidator(new BranchValidator());
+ masterUpdateStrategy.setAfterConvertValidator(new BranchExistsValidator(branchList));
+ bind(context, noModelToTarget, masterUpdateStrategy, MASTER_BRANCH_PROPERTY, masterText);
UpdateValueStrategy prefixTargetToModel = new UpdateValueStrategy();
prefixTargetToModel.setBeforeSetValidator(new IValidator() {
@Override
public IStatus validate(Object value) {
- if (value == null || !isValidRefName(Constants.R_HEADS + value + DUMMY_POSTFIX)) {
+ if (value == null
+ || !isValidRefName(R_HEADS + value + DUMMY_POSTFIX)) {
return error(NLS.bind(InitDialog_invalidPrefix, value));
}
return Status.OK_STATUS;
@@ -190,9 +240,11 @@ public class InitDialog extends TitleAreaDialog {
private void bind(DataBindingContext dataBindingContext,
UpdateValueStrategy noModelToTargetUpdate,
UpdateValueStrategy targetToModel, String modelProperty, Text widget) {
- dataBindingContext.bindValue(text(Modify).observe(widget),
+ Binding binding = dataBindingContext.bindValue(
+ text(Modify).observe(widget),
value(modelProperty).observe(gitflowInitConfig), targetToModel,
noModelToTargetUpdate);
+ ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);
}
@Override
@@ -211,6 +263,38 @@ public class InitDialog extends TitleAreaDialog {
return true;
}
+ @Override
+ protected void okPressed() {
+ String master = gitflowInitConfig.getMaster();
+ Repository repository = gfRepo.getRepository();
+ if (isMasterBranchAvailable(master, repository)) {
+ super.okPressed();
+ return;
+ }
+ boolean createBranch = openQuestion(getShell(),
+ InitDialog_masterBranchIsMissing,
+ NLS.bind(InitDialog_selectedMasterBranchDoesNotExistCreateNow, master));
+ if (!createBranch) {
+ return;
+ }
+
+ try {
+ RevCommit head = gfRepo.findHead();
+ new CreateLocalBranchOperation(repository, master, head).execute(null);
+ } catch (CoreException | WrongGitFlowStateException e) {
+ throw new RuntimeException(e);
+ }
+ super.okPressed();
+ }
+
+ private boolean isMasterBranchAvailable(String master, Repository repository) {
+ try {
+ return repository.getRef(R_HEADS + master) != null;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* @return User inputs
*/
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
index 59bbd4fc1..fdc7c1047 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
@@ -34,6 +34,7 @@ HotfixFinishHandler_hotfixFinishConflicts=Finishing hotfix resulted in conflicts
HotfixStartHandler_pleaseProvideANameForTheNewHotfix=Please provide a name for the new hotfix.
HotfixStartHandler_provideHotfixName=Provide hotfix name
HotfixStartHandler_startingNewHotfix=Starting new Hotfix...
+InitDialog_branchDoesNotExistYetAndWillBeCreated=Branch ''{0}''does not yet exist, and will have to be created.
InitDialog_chooseBranchNamesAndPrefixes=Choose branch names and prefixes for your Gitflow repository.
InitDialog_developBranch=Develop branch
InitDialog_featureBranchPrefix=Feature branch prefix
@@ -42,8 +43,13 @@ InitDialog_initializeRepository=Initialize repository
InitDialog_invalidBranchName=Invalid branch name: ''{0}''
InitDialog_invalidPrefix=Invalid prefix: ''{0}''
InitDialog_masterBranch=Master branch
+InitDialog_masterBranchIsMissing=Master branch missing
InitDialog_releaseBranchPrefix=Release branch prefix
+InitDialog_selectedMasterBranchDoesNotExistCreateNow=Selected master branch ''{0}'' does not exist. Do you want to create it now?
InitDialog_versionTagPrefix=Version tag prefix
+InitHandler_doYouWantToInitNow=This repository is empty. Do you want to initialize it now with an empty commit?
+InitHandler_emptyRepository=Empty repository
+InitHandler_initialCommit=Initial Commit
InitHandler_initializing=Initializing...
ReleaseFinishHandler_Conflicts=Conflicts
ReleaseFinishHandler_finishingRelease=Finishing release...
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java
index dc64e8993..24df273d2 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java
@@ -86,6 +86,9 @@ public class CoreText extends NLS {
public static String InitOperation_initialCommit;
/** */
+ public static String InitOperation_localMasterDoesNotExist;
+
+ /** */
public static String ReleaseFinishOperation_releaseOf;
/** */
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties
index 1dfe4a386..f031c5400 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties
@@ -25,6 +25,7 @@ GitFlowRepository_gitFlowRepositoryMayNotBeEmpty=Git flow repository may not be
HotfixFinishOperation_hotfix=Hotifx {0}
HotfixFinishOperation_mergeFromHotfixToMasterFailed=Merge from Hotfix to Master branch failed. This shouldn't happen in GitFlow.
InitOperation_initialCommit=Git Flow inital commit
+InitOperation_localMasterDoesNotExist=Local branch ''{0}'' does not exist.
ReleaseFinishOperation_releaseOf=Release of {0}
ReleaseStartOperation_notOn=Not on {0}
ReleaseStartOperation_releaseNameAlreadyExists=The release name '%s' already exists.
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/InitOperation.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/InitOperation.java
index 46001bee9..5f1b472ec 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/InitOperation.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/InitOperation.java
@@ -16,6 +16,7 @@ import static org.eclipse.egit.gitflow.GitFlowConfig.MASTER_KEY;
import static org.eclipse.egit.gitflow.GitFlowConfig.RELEASE_KEY;
import static org.eclipse.egit.gitflow.GitFlowConfig.VERSION_TAG_KEY;
import static org.eclipse.egit.gitflow.GitFlowDefaults.VERSION_TAG;
+import static org.eclipse.jgit.lib.Constants.R_HEADS;
import java.io.IOException;
@@ -33,6 +34,7 @@ import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.osgi.util.NLS;
/**
* git flow init
@@ -129,6 +131,10 @@ public final class InitOperation extends GitFlowOperation {
}
try {
+ if (!isMasterBranchAvailable()) {
+ throw new CoreException(error(NLS.bind(CoreText.InitOperation_localMasterDoesNotExist, master)));
+ }
+
RevCommit head = repository.findHead();
if (!repository.hasBranch(develop)) {
CreateLocalBranchOperation branchFromHead = createBranchFromHead(
@@ -159,4 +165,12 @@ public final class InitOperation extends GitFlowOperation {
config.setBranch(DEVELOP_KEY, develop);
config.setBranch(MASTER_KEY, master);
}
+
+ private boolean isMasterBranchAvailable() throws CoreException {
+ try {
+ return repository.getRepository().getRef(R_HEADS + master) != null;
+ } catch (IOException e) {
+ throw new CoreException(error(e.getMessage(), e));
+ }
+ }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java
index cc16bef23..07786071c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java
@@ -8,18 +8,34 @@
*******************************************************************************/
package org.eclipse.egit.ui.gitflow;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_developBranch;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_featureBranchPrefix;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_hotfixBranchPrefix;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_masterBranch;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_releaseBranchPrefix;
+import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_versionTagPrefix;
+import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.gitflow.GitFlowConfig;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
-
-import static org.eclipse.egit.gitflow.ui.internal.UIText.*;
-
+import org.eclipse.egit.gitflow.ui.internal.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
@@ -35,7 +51,11 @@ import org.junit.runner.RunWith;
@RunWith(SWTBotJunit4ClassRunner.class)
public class InitHandlerTest extends AbstractGitflowHandlerTest {
private static final String DEVELOP_BRANCH = "a";
- private static final String MASTER_BRANCH = "b";
+
+ private static final String MASTER_BRANCH_MISSING = "b";
+
+ private static final String MASTER_BRANCH = "master";
+
private static final String FEATURE_BRANCH_PREFIX = "c";
private static final String RELEASE_BRANCH_PREFIX = "d";
private static final String HOTFIX_BRANCH_PREFIX = "e";
@@ -45,7 +65,12 @@ public class InitHandlerTest extends AbstractGitflowHandlerTest {
@Test
public void testInit() throws Exception {
- init();
+ selectProject(PROJ1);
+ clickInit();
+ fillDialog(MASTER_BRANCH);
+
+ bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY,
+ "Git flow jobs"));
GitFlowRepository gitFlowRepository = new GitFlowRepository(repository);
GitFlowConfig config = gitFlowRepository.getConfig();
@@ -56,40 +81,111 @@ public class InitHandlerTest extends AbstractGitflowHandlerTest {
assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());
+ }
+
+ @Test
+ public void testInitMissingMaster() throws Exception {
+ selectProject(PROJ1);
+ clickInit();
+ fillDialog(MASTER_BRANCH_MISSING);
+
+ bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing));
+ bot.button("Yes").click();
+ bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY,
+ "Git flow jobs"));
+
+ GitFlowRepository gitFlowRepository = new GitFlowRepository(repository);
+ GitFlowConfig config = gitFlowRepository.getConfig();
+
+ assertEquals(DEVELOP_BRANCH, repository.getBranch());
+ assertEquals(MASTER_BRANCH_MISSING, config.getMaster());
+ assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
+ assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
+ assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
+ assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());
+
+ assertNotNull(repository.getRef(Constants.R_HEADS + DEVELOP_BRANCH));
+ }
+
+ @Test
+ public void testInitEmptyRepoMissingMaster() throws Exception {
+ String projectName = "AnyProjectName";
+ TestRepository testRepository = createAndShare(projectName);
+
+ selectProject(projectName);
+ clickInit();
+ bot.button("Yes").click();
+ fillDialog(MASTER_BRANCH_MISSING);
+ bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing));
+ bot.button("Yes").click();
+ bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY,
+ "Git flow jobs"));
+
+ Repository localRepository = testRepository.getRepository();
+ GitFlowRepository gitFlowRepository = new GitFlowRepository(localRepository);
+ GitFlowConfig config = gitFlowRepository.getConfig();
+
+ assertEquals(DEVELOP_BRANCH, localRepository.getBranch());
+ assertEquals(MASTER_BRANCH_MISSING, config.getMaster());
+ assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
+ assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
+ assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
+ assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());
+ assertNotNull(localRepository.getRef(Constants.R_HEADS + DEVELOP_BRANCH));
}
- private void init() {
+ private void selectProject(String projectName) {
final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
- getProjectItem(projectExplorerTree, PROJ1).select();
- final String[] menuPath = new String[] {
- util.getPluginLocalizedValue("TeamMenu.label"),
- util.getPluginLocalizedValue("TeamGitFlowInit.name", false, Activator.getDefault().getBundle()) };
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- ContextMenuHelper.clickContextMenuSync(projectExplorerTree,
- menuPath);
- }
- });
+ getProjectItem(projectExplorerTree, projectName).select();
+ }
+ private void fillDialog(String masterBranch) {
SWTBotText developText = bot.textWithLabel(InitDialog_developBranch);
developText.selectAll();
developText.typeText(ILLEGAL_BRANCH_NAME);
-
SWTBotButton ok = bot.button("OK");
assertFalse(ok.isEnabled());
typeInto(InitDialog_developBranch, DEVELOP_BRANCH);
- typeInto(InitDialog_masterBranch, MASTER_BRANCH);
+ typeInto(InitDialog_masterBranch, masterBranch);
typeInto(InitDialog_featureBranchPrefix, FEATURE_BRANCH_PREFIX);
typeInto(InitDialog_releaseBranchPrefix, RELEASE_BRANCH_PREFIX);
typeInto(InitDialog_hotfixBranchPrefix, HOTFIX_BRANCH_PREFIX);
typeInto(InitDialog_versionTagPrefix, VERSION_TAG_PREFIX);
ok.click();
- bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));
+ }
+
+ private void clickInit() {
+ final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ final String[] menuPath = new String[] {
+ util.getPluginLocalizedValue("TeamMenu.label"),
+ util.getPluginLocalizedValue("TeamGitFlowInit.name", false, Activator.getDefault().getBundle()) };
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ ContextMenuHelper.clickContextMenuSync(projectExplorerTree,
+ menuPath);
+ }
+ });
+ }
+
+ private TestRepository createAndShare(String projectName) throws Exception {
+ IProgressMonitor progressMonitor = new NullProgressMonitor();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = root.getProject(projectName);
+ project.create(progressMonitor);
+ project.open(progressMonitor);
+ TestUtil.waitForJobs(50, 5000);
+
+ File gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
+ TestRepository testRepository = new TestRepository(gitDir);
+ testRepository.connect(project.getProject());
+ TestUtil.waitForJobs(50, 5000);
+
+ return testRepository;
}
private void typeInto(String textLabel, String textInput) {

Back to the top