Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2018-05-13 18:06:14 +0000
committerMax Hohenegger2019-03-17 10:16:49 +0000
commitbeb460a56a10e620e3827b974e0fb40583055a94 (patch)
tree9eade71da1193bc69cdf8a9bca47e199f72fa8df /org.eclipse.egit.gitflow.ui
parent3678f186301a9d9565defd502d1a95680b92a3de (diff)
downloadegit-beb460a56a10e620e3827b974e0fb40583055a94.tar.gz
egit-beb460a56a10e620e3827b974e0fb40583055a94.tar.xz
egit-beb460a56a10e620e3827b974e0fb40583055a94.zip
Gitflow: Validate branch name only different in case
Test whether the new branch name can be resolved in the repository already. That way we avoid trying to create branches with the same name (but different case) on case sensitive file systems. Using egit.core for input validation, and deprecated redundant code. Change-Id: I9cedb648ad0a8b640954fb26925255bbce2a5336 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de> Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu> Bug: 534616
Diffstat (limited to 'org.eclipse.egit.gitflow.ui')
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties2
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/BranchNameInputValidator.java54
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/FeatureNameValidator.java15
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/HotfixNameValidator.java11
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/ReleaseNameValidator.java15
6 files changed, 49 insertions, 54 deletions
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 fd70717a6e..3819f5d7c2 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
@@ -224,12 +224,6 @@ public class UIText extends NLS {
/** */
public static String HotfixPublishHandler_publishingHotfix;
- /** */
- public static String NameValidator_invalidName;
-
- /** */
- public static String NameValidator_nameAlreadyExists;
-
/** */
public static String FeatureCheckoutHandler_cleanupDialog_title;
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 b0d96b0b4a..e773f6fff9 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
@@ -73,8 +73,6 @@ FeatureCheckoutHandler_selectFeature=Select Feature
FeaturePublishHandler_publishingFeature=Publishing feature...
ReleasePublishHandler_publishingRelease=Publishing release...
HotfixPublishHandler_publishingHotfix=Publishing hotfix...
-NameValidator_invalidName='%s' is not a valid name. None of the following characters is allowed: '%s'
-NameValidator_nameAlreadyExists=Name '%s' already exists
FeatureCheckoutHandler_cleanupDialog_title=Cannot Rebase Repository ''{0}''
FeatureCheckoutHandler_cleanupDialog_text=You have uncommitted changes. Either commit the changes, stash the changes, or discard the changes by resetting the current branch.
FinishFeatureDialog_ButtonOK=&Finish
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/BranchNameInputValidator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/BranchNameInputValidator.java
index a1e3e5e4b0..69707f2ee8 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/BranchNameInputValidator.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/BranchNameInputValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ * Copyright (C) 2019, 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
@@ -10,37 +10,49 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.validation;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.egit.gitflow.BranchNameValidator;
-import org.eclipse.egit.gitflow.ui.internal.UIText;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.egit.core.internal.Utils;
+import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.jface.dialogs.IInputValidator;
/**
- * Validates Git Flow branch names.
+ * Validates Gitflow branch names.
*/
abstract public class BranchNameInputValidator implements IInputValidator {
+
+ /**
+ * Gitflow repository to perform validation on.
+ */
+ protected final GitFlowRepository repository;
+
+ /**
+ * @param repository
+ * Gitflow repository to perform validation on.
+ */
+ protected BranchNameInputValidator(GitFlowRepository repository) {
+ this.repository = repository;
+ }
+
@Override
public String isValid(String newText) {
- try {
- if (branchExists(newText)) {
- return String.format(UIText.NameValidator_nameAlreadyExists,
- newText);
- }
- if (!BranchNameValidator.isBranchNameValid(newText)) {
- return String.format(UIText.NameValidator_invalidName, newText,
- BranchNameValidator.ILLEGAL_CHARS);
- }
- } catch (CoreException e) {
+ String fullBranchName = getFullBranchName(newText);
+ IStatus status = Utils.validateNewRefName(fullBranchName,
+ repository.getRepository(), "", //$NON-NLS-1$
+ false);
+
+ if (status.isOK()) {
return null;
}
- return null;
+
+ return status.getMessage();
}
/**
- * @param newText
- * @return Whether or not newText corresponds to an existing branch.
- * @throws CoreException
+ *
+ * @param gitFlowBranch
+ * The name segment of e.g. a feature branch.
+ * @return Full branch name of the given gitFlowBranch. E.g.:
+ * refs/heads/feature/name
*/
- abstract protected boolean branchExists(String newText)
- throws CoreException;
+ abstract protected String getFullBranchName(String gitFlowBranch);
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/FeatureNameValidator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/FeatureNameValidator.java
index dee8c11b04..d2305e3c0b 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/FeatureNameValidator.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/FeatureNameValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ * Copyright (C) 2019, 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
@@ -10,25 +10,22 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.validation;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.egit.gitflow.BranchNameValidator;
import org.eclipse.egit.gitflow.GitFlowRepository;
/**
* Validate feature branch name.
*/
public class FeatureNameValidator extends BranchNameInputValidator {
- private final GitFlowRepository repository;
/**
- * @param gfRepo
+ * @param repository
*/
- public FeatureNameValidator(GitFlowRepository gfRepo) {
- this.repository = gfRepo;
+ public FeatureNameValidator(GitFlowRepository repository) {
+ super(repository);
}
@Override
- protected boolean branchExists(String newText) throws CoreException {
- return BranchNameValidator.featureExists(repository, newText);
+ protected String getFullBranchName(String newText) {
+ return repository.getConfig().getFullFeatureBranchName(newText);
}
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/HotfixNameValidator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/HotfixNameValidator.java
index 322d6a6369..35dfc749c3 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/HotfixNameValidator.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/HotfixNameValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ * Copyright (C) 2019, 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
@@ -10,25 +10,22 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.validation;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.egit.gitflow.BranchNameValidator;
import org.eclipse.egit.gitflow.GitFlowRepository;
/**
* Validate name of hotfix branch.
*/
public class HotfixNameValidator extends BranchNameInputValidator {
- private final GitFlowRepository repository;
/**
* @param repository
*/
public HotfixNameValidator(GitFlowRepository repository) {
- this.repository = repository;
+ super(repository);
}
@Override
- protected boolean branchExists(String newText) throws CoreException {
- return BranchNameValidator.hotfixExists(repository, newText);
+ protected String getFullBranchName(String newText) {
+ return repository.getConfig().getFullHotfixBranchName(newText);
}
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/ReleaseNameValidator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/ReleaseNameValidator.java
index f00749a9c3..6ff3710714 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/ReleaseNameValidator.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/validation/ReleaseNameValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ * Copyright (C) 2019, 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
@@ -10,25 +10,22 @@
*******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.validation;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.egit.gitflow.BranchNameValidator;
import org.eclipse.egit.gitflow.GitFlowRepository;
/**
* Validate release branch name.
*/
public class ReleaseNameValidator extends BranchNameInputValidator {
- private final GitFlowRepository repository;
/**
- * @param gfRepo
+ * @param repository
*/
- public ReleaseNameValidator(GitFlowRepository gfRepo) {
- this.repository = gfRepo;
+ public ReleaseNameValidator(GitFlowRepository repository) {
+ super(repository);
}
@Override
- protected boolean branchExists(String newText) throws CoreException {
- return BranchNameValidator.releaseExists(repository, newText);
+ protected String getFullBranchName(String newText) {
+ return repository.getConfig().getReleaseBranchName(newText);
}
}

Back to the top