Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Nittka2020-02-22 14:23:51 +0000
committerThomas Wolf2020-02-25 15:53:25 +0000
commit6f46e09be6e1ec6425b21c4650f6504a2a386eee (patch)
treea15a2fb8b3af4e199f433e1d35e9bf4e87710f1b
parent9680c04610188d9210e0df5056803cec452ac4f3 (diff)
downloadegit-6f46e09be6e1ec6425b21c4650f6504a2a386eee.tar.gz
egit-6f46e09be6e1ec6425b21c4650f6504a2a386eee.tar.xz
egit-6f46e09be6e1ec6425b21c4650f6504a2a386eee.zip
Dynamic label for Push to/Fetch from Upstream
Let push to and fetch from upstream contributions implement IElementUpdater in order to inform the user about the push target/fetch source. This is useful when working with several remotes for the same repository. Bug: 441940 Change-Id: I130437f59fd309566db85e30054baac4e9268760 Signed-off-by: Alexander Nittka <alex@nittka.de>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushToUpstreamTest.java24
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimpleFetchActionHandler.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimplePushActionHandler.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java28
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
10 files changed, 133 insertions, 17 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushToUpstreamTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushToUpstreamTest.java
index ad3511410d..5f604e1c38 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushToUpstreamTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushToUpstreamTest.java
@@ -57,24 +57,26 @@ public class PushToUpstreamTest extends LocalRepositoryTestCase {
public void pushWithExistingUpstreamConfiguration() throws Exception {
checkoutNewLocalBranch("bar");
// Existing configuration
+ String remoteName = "fetch";
repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION,
- "bar", ConfigConstants.CONFIG_KEY_REMOTE, "fetch");
+ "bar", ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION,
"bar", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/bar");
- pushToUpstream();
+ pushToUpstream(remoteName);
assertBranchPushed("bar", remoteRepository);
}
@Test
public void pushWithDefaultRemoteWithPushRefSpecs() throws Exception {
checkoutNewLocalBranch("baz");
- repository.getConfig().setString("remote", "origin", "pushurl",
+ String remoteName = "origin";
+ repository.getConfig().setString("remote", remoteName, "pushurl",
repository.getConfig().getString("remote", "push", "pushurl"));
- repository.getConfig().setString("remote", "origin", "push",
+ repository.getConfig().setString("remote", remoteName, "push",
"refs/heads/*:refs/heads/*");
- pushToUpstream();
+ pushToUpstream(remoteName);
assertBranchPushed("baz", remoteRepository);
}
@@ -105,12 +107,13 @@ public class PushToUpstreamTest extends LocalRepositoryTestCase {
return projectExplorerTree;
}
- private void pushToUpstream() {
+ private void pushToUpstream(String remoteName) {
SWTBotTree project = selectProject();
JobJoiner joiner = JobJoiner.startListening(JobFamilies.PUSH, 20,
TimeUnit.SECONDS);
ContextMenuHelper
- .clickContextMenu(project, getPushToUpstreamMenuPath());
+ .clickContextMenu(project,
+ getPushToUpstreamMenuPath(remoteName));
TestUtil.openJobResultDialog(joiner.join());
SWTBotShell resultDialog = TestUtil
.botForShellStartingWith("Push Results");
@@ -120,12 +123,11 @@ public class PushToUpstreamTest extends LocalRepositoryTestCase {
private void assertPushToUpstreamDisabled() {
SWTBotTree project = selectProject();
boolean enabled = ContextMenuHelper.isContextMenuItemEnabled(project,
- getPushToUpstreamMenuPath());
+ getPushToUpstreamMenuPath("Upstream"));
assertFalse("Expected Push to Upstream to be disabled", enabled);
}
- private String[] getPushToUpstreamMenuPath() {
- return new String[] { "Team",
- util.getPluginLocalizedValue("PushToUpstreamCommand.label") };
+ private String[] getPushToUpstreamMenuPath(String remoteName) {
+ return new String[] { "Team", "Push to " + remoteName };
}
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
index b74ebb3656..e5ee3cf1cb 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
@@ -160,8 +160,7 @@ public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
private void fetch() throws Exception {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
getProjectItem(projectExplorerTree, PROJ1).select();
- String menuString = util
- .getPluginLocalizedValue("FetchFromUpstreamAction.label");
+ String menuString = "Fetch from origin";
JobJoiner jobJoiner = JobJoiner.startListening(JobFamilies.FETCH, 20, TimeUnit.SECONDS);
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
menuString);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index c1612b7231..2816c06679 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -5242,6 +5242,9 @@ public class UIText extends NLS {
public static String SimpleConfigureFetchDialog_WindowTitle;
/** */
+ public static String SimpleConfigureFetchDialog_FetchFromLabel;
+
+ /** */
public static String SimpleConfigurePushDialog_AddPushUriButton;
/** */
@@ -5272,6 +5275,9 @@ public class UIText extends NLS {
public static String SimpleConfigurePushDialog_WindowTitle;
/** */
+ public static String SimpleConfigurePushDialog_PushToLabel;
+
+ /** */
public static String SimpleFetchActionHandler_NothingToFetchDialogMessage;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimpleFetchActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimpleFetchActionHandler.java
index bbd76a4f9f..3d51de7c32 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimpleFetchActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimpleFetchActionHandler.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
+import java.util.Map;
+
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.Activator;
@@ -20,11 +22,14 @@ import org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.menus.UIElement;
/**
* Action for "Simple fetch"
*/
-public class SimpleFetchActionHandler extends RepositoryActionHandler {
+public class SimpleFetchActionHandler extends RepositoryActionHandler
+ implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(true, event);
@@ -53,4 +58,14 @@ public class SimpleFetchActionHandler extends RepositoryActionHandler {
&& SimpleConfigureFetchDialog
.getConfiguredRemoteCached(repository) != null;
}
+
+ @Override
+ public void updateElement(UIElement element, Map parameters) {
+ RemoteConfig config = SimpleConfigureFetchDialog
+ .getConfiguredRemoteCached(getRepository());
+ if (config != null) {
+ element.setText(SimpleConfigureFetchDialog
+ .getSimpleFetchCommandLabel(config));
+ }
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimplePushActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimplePushActionHandler.java
index c57c91eca1..f5ce69a4c5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimplePushActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SimplePushActionHandler.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
+import java.util.Map;
+
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.internal.UIText;
@@ -18,11 +20,14 @@ import org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.menus.UIElement;
/**
* Action for "Simple Push"
*/
-public class SimplePushActionHandler extends RepositoryActionHandler {
+public class SimplePushActionHandler extends RepositoryActionHandler
+ implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Repository repository = getRepository(true, event);
@@ -49,4 +54,14 @@ public class SimplePushActionHandler extends RepositoryActionHandler {
&& SimpleConfigurePushDialog
.getConfiguredRemoteCached(repository) != null;
}
+
+ @Override
+ public void updateElement(UIElement element, Map parameters) {
+ RemoteConfig config = SimpleConfigurePushDialog
+ .getConfiguredRemoteCached(getRepository());
+ if (config != null) {
+ element.setText(SimpleConfigurePushDialog
+ .getSimplePushCommandLabel(config));
+ }
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
index c117a29bc0..276dc8ae5a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
@@ -29,6 +29,7 @@ import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
@@ -119,6 +120,20 @@ public class SimpleConfigureFetchDialog extends AbstractConfigureRemoteDialog {
}
/**
+ * Computes a specific fetch label for the given remote config
+ *
+ * @param config
+ * @return the menu item label
+ *
+ */
+ public static String getSimpleFetchCommandLabel(
+ @NonNull RemoteConfig config) {
+ String target = config.getName();
+ return NLS.bind(UIText.SimpleConfigureFetchDialog_FetchFromLabel,
+ target);
+ }
+
+ /**
* @param branch
* currently checked out
* @param config
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
index f14ae688ac..75781d87ce 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
@@ -35,6 +35,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
@@ -131,6 +132,19 @@ public class SimpleConfigurePushDialog extends AbstractConfigureRemoteDialog {
SelectionRepositoryStateCache.INSTANCE.getConfig(repository));
}
+ /**
+ * Computes a specific push label for the given remote config
+ *
+ * @param config
+ * @return the menu item label
+ *
+ */
+ public static String getSimplePushCommandLabel(
+ @NonNull RemoteConfig config) {
+ String target = config.getName();
+ return NLS.bind(UIText.SimpleConfigurePushDialog_PushToLabel, target);
+ }
+
private static RemoteConfig getConfiguredRemote(String branch,
Config config) {
if (branch == null) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java
index 1c40521967..40cf2fffb5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java
@@ -16,6 +16,8 @@
package org.eclipse.egit.ui.internal.repository.tree.command;
import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Map;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -31,12 +33,15 @@ import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.selection.SelectionRepositoryStateCache;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.menus.UIElement;
/**
* Fetches from the remote
*/
public class FetchConfiguredRemoteCommand extends
- RepositoriesViewCommandHandler<RepositoryTreeNode> {
+ RepositoriesViewCommandHandler<RepositoryTreeNode>
+ implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryTreeNode node = getSelectedNodes(event).get(0);
@@ -107,4 +112,25 @@ public class FetchConfiguredRemoteCommand extends
}
return null;
}
+
+ @Override
+ public void updateElement(UIElement element, Map parameters) {
+ List<RepositoryTreeNode> nodes = getSelectedNodes();
+ if (nodes.size() == 1) {
+ RepositoryTreeNode node = nodes.get(0);
+ if (node instanceof FetchNode || node instanceof RemoteNode) {
+ // do nothing
+ } else {
+ try {
+ RemoteConfig config = getRemoteConfigCached(node);
+ if (config != null) {
+ element.setText(SimpleConfigureFetchDialog
+ .getSimpleFetchCommandLabel(config));
+ }
+ } catch (ExecutionException e) {
+ // ignore - no label update
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java
index 8ec3dbc674..6f59e48dac 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java
@@ -17,6 +17,8 @@
package org.eclipse.egit.ui.internal.repository.tree.command;
import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Map;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -30,12 +32,15 @@ import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.selection.SelectionRepositoryStateCache;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.menus.UIElement;
/**
* Pushes to the remote
*/
public class PushConfiguredRemoteCommand extends
- RepositoriesViewCommandHandler<RepositoryTreeNode<?>> {
+ RepositoriesViewCommandHandler<RepositoryTreeNode<?>>
+ implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryTreeNode node = getSelectedNodes(event).get(0);
@@ -110,4 +115,21 @@ public class PushConfiguredRemoteCommand extends
}
return null;
}
+
+ @Override
+ public void updateElement(UIElement element, Map parameters) {
+ List<RepositoryTreeNode<?>> nodes = getSelectedNodes();
+ if (nodes.size() == 1) {
+ RepositoryTreeNode<?> node = nodes.get(0);
+ if (node instanceof PushNode || node instanceof RemoteNode) {
+ // do nothing
+ } else {
+ RemoteConfig config = getRemoteConfigCached(node);
+ if (config != null) {
+ element.setText(SimpleConfigurePushDialog
+ .getSimplePushCommandLabel(config));
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 872cbe05cd..007869bf42 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1870,6 +1870,7 @@ SimpleConfigureFetchDialog_DialogTitle=Configure fetch for remote ''{0}''
SimpleConfigureFetchDialog_MissingMappingMessage=Please provide a ref mapping
SimpleConfigureFetchDialog_SaveAndFetchButton=Save and Fetch
SimpleConfigureFetchDialog_WindowTitle=Configure Fetch
+SimpleConfigureFetchDialog_FetchFromLabel=&Fetch from {0}
SimpleConfigurePushDialog_UseUriForPushUriMessage=No Push URIs, will use URI {0}
SimpleConfigurePushDialog_WindowTitle=Configure Push
@@ -1881,6 +1882,7 @@ SimpleConfigurePushDialog_DialogMessage=In order to use a remote for push, you m
SimpleConfigurePushDialog_DialogTitle=Configure push for remote ''{0}''
SimpleConfigurePushDialog_PushUrisLabel=Push URIs
SimpleConfigurePushDialog_SaveAndPushButton=Save and Push
+SimpleConfigurePushDialog_PushToLabel=&Push to {0}
SkipRebaseCommand_CancelDialogMessage=The skip operation was canceled.
SkipRebaseCommand_JobName=Skipping commit during Rebase

Back to the top