Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-05-22 01:33:46 +0000
committerMatthias Sohn2016-05-25 11:34:13 +0000
commitd739b391bbb9791a1c0afa0b0bd11f5c6f88eb4e (patch)
treeec96f6883192f07e0de84b33a643d1c9370f7289
parentd58c936fa4cc6e1d412a419aa9f931dbd645f7f2 (diff)
downloadegit-d739b391bbb9791a1c0afa0b0bd11f5c6f88eb4e.tar.gz
egit-d739b391bbb9791a1c0afa0b0bd11f5c6f88eb4e.tar.xz
egit-d739b391bbb9791a1c0afa0b0bd11f5c6f88eb4e.zip
Harmonize Gerrit fetch and push operation availability
Determining whether a refspec is for Gerrit must be in synch with the ResourcePropertyTester. Moreover, fetch and push refspecs must be considered separately. With that in place, add new properties to the property tester: canFetchFromGerrit and canPushToGerrit. Use these properties to determine visibility of the "Push to Gerrit..." and "Fetch from Gerrit..." commands such that they are visible only if they can be performed. Bug: 493352 Change-Id: Idc66e6a912134d8979b3fad4ce6db4395388a1e2 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/gerrit/GerritUtil.java31
-rw-r--r--org.eclipse.egit.ui/plugin.xml12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/ResourcePropertyTester.java78
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java2
5 files changed, 93 insertions, 32 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/gerrit/GerritUtil.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/gerrit/GerritUtil.java
index 4fd57e3b24..95af64fb86 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/gerrit/GerritUtil.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/gerrit/GerritUtil.java
@@ -1,9 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2013, 2015 Robin Stocker <robin@nibor.org> and others.
+ * Copyright (c) 2013, 2016 Robin Stocker <robin@nibor.org> and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493352
*******************************************************************************/
package org.eclipse.egit.core.internal.gerrit;
@@ -140,9 +143,10 @@ public class GerritUtil {
/**
* @param rc
* the remote configuration
- * @return {@code true} if the remote configuration is configured for Gerrit
+ * @return {@code true} if the remote configuration is configured for
+ * pushing to Gerrit
*/
- public static boolean isGerritRemote(RemoteConfig rc) {
+ public static boolean isGerritPush(RemoteConfig rc) {
for (RefSpec pushSpec : rc.getPushRefSpecs()) {
String destination = pushSpec.getDestination();
if (destination == null) {
@@ -156,4 +160,25 @@ public class GerritUtil {
}
return false;
}
+
+ /**
+ * @param rc
+ * the remote configuration
+ * @return {@code true} if the remote configuration is configured for
+ * fetching from Gerrit
+ */
+ public static boolean isGerritFetch(RemoteConfig rc) {
+ for (RefSpec fetchSpec : rc.getFetchRefSpecs()) {
+ String source = fetchSpec.getSource();
+ String destination = fetchSpec.getDestination();
+ if (source == null || destination == null) {
+ continue;
+ }
+ if (source.startsWith(Constants.R_NOTES)
+ && destination.startsWith(Constants.R_NOTES)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 39bce40930..527ca63b9e 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3126,7 +3126,7 @@
value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode">
</instanceof>
<test
- property="GitRepository.hasGerritConfiguration">
+ property="GitRepository.canPushToGerrit">
</test>
</and>
</iterate>
@@ -3149,7 +3149,7 @@
value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode">
</instanceof>
<test
- property="GitRepository.hasGerritConfiguration">
+ property="GitRepository.canFetchFromGerrit">
</test>
</and>
</iterate>
@@ -4007,7 +4007,7 @@
checkEnabled="false">
<test
property="GitSelection.projectsSingleRepository"
- args="hasGerritConfiguration">
+ args="canPushToGerrit">
</test>
</visibleWhen>
</command>
@@ -4019,7 +4019,7 @@
checkEnabled="false">
<test
property="GitSelection.projectsSingleRepository"
- args="hasGerritConfiguration">
+ args="canFetchFromGerrit">
</test>
</visibleWhen>
</command>
@@ -5355,14 +5355,14 @@
class="org.eclipse.egit.ui.internal.repository.tree.RepositoriesViewPropertyTester"
id="org.eclipse.egit.ui.RepositoryTester"
namespace="GitRepository"
- properties="isBare,isSafe,canCommit,canAmend,canResetHead,canStash,isRefCheckedOut,isLocalBranch,fetchExists,pushExists,canMerge,canAbortRebase,canContinueRebase,isSubmodule,containsHead,hasGerritConfiguration"
+ properties="isBare,isSafe,canCommit,canAmend,canResetHead,canStash,isRefCheckedOut,isLocalBranch,fetchExists,pushExists,canMerge,canAbortRebase,canContinueRebase,isSubmodule,containsHead,hasGerritConfiguration,canFetchFromGerrit,canPushToGerrit"
type="org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode">
</propertyTester>
<propertyTester
class="org.eclipse.egit.ui.internal.ResourcePropertyTester"
id="org.eclipse.egit.ui.ResourceTester"
namespace="GitResource"
- properties="isShared,isContainer,isSafe,canCommit,canAmend,canResetHead,canAbortRebase,canContinueRebase,hasGerritConfiguration"
+ properties="isShared,isContainer,isSafe,canCommit,canAmend,canResetHead,canAbortRebase,canContinueRebase,hasGerritConfiguration,canFetchFromGerrit,canPushToGerrit"
type="org.eclipse.core.resources.IResource">
</propertyTester>
<propertyTester
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/ResourcePropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/ResourcePropertyTester.java
index 36267f0f1d..c694b44cf0 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/ResourcePropertyTester.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/ResourcePropertyTester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 SAP AG and others.
+ * Copyright (c) 2011, 2016 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Mathias Kinzler (SAP AG) - initial implementation
* Dariusz Luksza <dariusz@luksza.org> - add 'isSafe' implementation
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493352
*******************************************************************************/
package org.eclipse.egit.ui.internal;
@@ -22,10 +23,8 @@ import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.internal.trace.GitTraceLocation;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
-import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
/**
@@ -104,9 +103,15 @@ public class ResourcePropertyTester extends PropertyTester {
if ("isShared".equals(property)) //$NON-NLS-1$
return repository != null;
if (repository != null) {
- if ("hasGerritConfiguration".equals(property)) //$NON-NLS-1$
+ if ("hasGerritConfiguration".equals(property)) { //$NON-NLS-1$
return hasGerritConfiguration(repository);
-
+ }
+ if ("canFetchFromGerrit".equals(property)) { //$NON-NLS-1$
+ return canFetchFromGerrit(repository);
+ }
+ if ("canPushToGerrit".equals(property)) { //$NON-NLS-1$
+ return canPushToGerrit(repository);
+ }
RepositoryState state = repository.getRepositoryState();
if ("canAbortRebase".equals(property)) //$NON-NLS-1$
@@ -160,26 +165,15 @@ public class ResourcePropertyTester extends PropertyTester {
public static boolean hasGerritConfiguration(
@NonNull Repository repository) {
Config config = repository.getConfig();
- if (GerritUtil.getCreateChangeId(config))
+ if (GerritUtil.getCreateChangeId(config)) {
return true;
+ }
try {
List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config);
for (RemoteConfig remoteConfig : remoteConfigs) {
- for (RefSpec pushSpec : remoteConfig.getPushRefSpecs()) {
- String destination = pushSpec.getDestination();
- if (destination == null)
- continue;
- if (destination.startsWith(GerritUtil.REFS_FOR))
- return true;
- }
- for (RefSpec fetchSpec : remoteConfig.getFetchRefSpecs()) {
- String source = fetchSpec.getSource();
- String destination = fetchSpec.getDestination();
- if (source == null || destination == null)
- continue;
- if (source.startsWith(Constants.R_NOTES)
- && destination.startsWith(Constants.R_NOTES))
- return true;
+ if (GerritUtil.isGerritPush(remoteConfig)
+ || GerritUtil.isGerritFetch(remoteConfig)) {
+ return true;
}
}
} catch (URISyntaxException e) {
@@ -189,4 +183,46 @@ public class ResourcePropertyTester extends PropertyTester {
return false;
}
+ /**
+ * @param repository
+ * @return {@code true} if repository has been configured to fetch from
+ * Gerrit
+ */
+ public static boolean canFetchFromGerrit(@NonNull Repository repository) {
+ Config config = repository.getConfig();
+ try {
+ List<RemoteConfig> remoteConfigs = RemoteConfig
+ .getAllRemoteConfigs(config);
+ for (RemoteConfig remoteConfig : remoteConfigs) {
+ if (GerritUtil.isGerritFetch(remoteConfig)) {
+ return true;
+ }
+ }
+ } catch (URISyntaxException e) {
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * @param repository
+ * @return {@code true} if repository has been configured for pushing to
+ * Gerrit
+ */
+ public static boolean canPushToGerrit(@NonNull Repository repository) {
+ Config config = repository.getConfig();
+ try {
+ List<RemoteConfig> remoteConfigs = RemoteConfig
+ .getAllRemoteConfigs(config);
+ for (RemoteConfig remoteConfig : remoteConfigs) {
+ if (GerritUtil.isGerritPush(remoteConfig)) {
+ return true;
+ }
+ }
+ } catch (URISyntaxException e) {
+ return false;
+ }
+ return false;
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 040c5e6979..488207186f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -389,7 +389,7 @@ public class FetchGerritChangePage extends WizardPage {
try {
for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository
.getConfig())) {
- if (GerritUtil.isGerritRemote(rc)) {
+ if (GerritUtil.isGerritFetch(rc)) {
if (rc.getURIs().size() > 0) {
uris.add(rc.getURIs().get(0).toPrivateString());
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
index fdb57bb061..9366c2ba32 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
@@ -236,7 +236,7 @@ class PushToGerritPage extends WizardPage {
try {
for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository
.getConfig())) {
- if (GerritUtil.isGerritRemote(rc)) {
+ if (GerritUtil.isGerritPush(rc)) {
if (rc.getURIs().size() > 0) {
uris.add(rc.getURIs().get(0).toPrivateString());
}

Back to the top