Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-06-24 16:27:21 -0400
committerThomas Wolf2019-06-24 17:04:18 -0400
commit58ba9fb83ae041fabed390261a79a7f34f40f9f3 (patch)
treed6cb213b3766cac4fed51e0e09e2f8959b1002e2
parent2a6d24376833d10036f81a79d8423be4a5c59b3c (diff)
downloadegit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.tar.gz
egit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.tar.xz
egit-58ba9fb83ae041fabed390261a79a7f34f40f9f3.zip
Enable the "Switch To..." menu for submodule folders
Commits 1f69fad3 and e4dc3eaf from the multi-repository branch switch had the effect that the "Switch To..." menu didn't work anymore for submodule folders in the package or project explorer. Add a new operation SelectionUtils.getAllRepositories() and use it in SwitchToMenu. Changing the existing SelectionUtils.getRepositories() to also return repositories for folders was deemed too risky since that would have changed the behavior of the multi-repository pull, which has always worked only for folders. Enabling that to also handle submodule folders might be an idea for a future commit, but might need more tests. Add a new test. The test only verifies that the menu has content by trying to invoke "New Branch..." and then closing the resulting "Create Branch" dialog. Interestingly this test succeeds even without the fix, which matches the experience described in the bug report: the problem could only be observed in official packages, but not in my development setup. Change verified manually by actually building EGit and installing it into standard Eclipse packages. Bug: 548158 Change-Id: Ic67578b46a89687a6bcfe73ef3d2d3d71d2a39e0 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java23
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java56
4 files changed, 80 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
index 26ee2031a..97a42f4b3 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
@@ -39,6 +39,7 @@ import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.clone.ProjectRecord;
import org.eclipse.egit.ui.internal.clone.ProjectUtils;
import org.eclipse.egit.ui.internal.resources.IResourceState;
@@ -52,6 +53,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.submodule.SubmoduleWalk;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IEditorReference;
@@ -230,6 +232,27 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
}
/**
+ * Tests that the Team->Switch To... menu item has content by clicking on
+ * "New Branch..." and then closing the resulting "Create Branch" dialog.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testSwitchToMenu() throws Exception {
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree,
+ childFolder.getFullPath().segments());
+ TestUtil.waitForDecorations();
+ node.select();
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ util.getPluginLocalizedValue("SwitchToMenu.label"),
+ UIText.SwitchToMenu_NewBranchMenuLabel);
+
+ SWTBotShell shell = bot.shell(UIText.CreateBranchWizard_NewBranchTitle);
+ shell.close();
+ }
+
+ /**
* Tests that a CompareWithHeadAction on a file from a submodule folder does
* open the right compare editor, comparing against the version from the
* submodule (as opposed to the version from the parent repo).
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
index 11b06f065..e6341b24f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
@@ -95,7 +95,7 @@ public class SwitchToMenu extends ContributionItem implements
return;
Repository[] repositories = SelectionUtils
- .getRepositories(handlerService.getCurrentState());
+ .getAllRepositories(handlerService.getCurrentState());
if (repositories.length > 0) {
createDynamicMenu(menu, repositories);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java
index 9f2071376..5b77d43a9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionPropertyTester.java
@@ -148,7 +148,7 @@ public class SelectionPropertyTester extends AbstractPropertyTester {
private boolean selectionContainsMoreThanOneRepository(
Collection<?> collection, Object[] args) {
IStructuredSelection selection = getStructuredSelection(collection);
- Repository[] repos = SelectionUtils.getRepositories(selection);
+ Repository[] repos = SelectionUtils.getAllRepositories(selection);
return testMultipleRepositoryProperties(Arrays.asList(repos), args);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java
index 338ccc273..a550cfd48 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/selection/SelectionUtils.java
@@ -83,7 +83,7 @@ public class SelectionUtils {
* Retrieves all the repositories associated with the current selection. It
* attempts to first identify the selections as projects and if that yields
* an empty result, it then changes to adapt the selections to the
- * repository class
+ * repository class.
*
* @param selection
* @return array of repositories
@@ -115,6 +115,60 @@ public class SelectionUtils {
}
/**
+ * Retrieves all the repositories associated with the current selection,
+ * even if associated with a folder instead of a project. If no repository
+ * can be determined for any object in the selection, returns an empty
+ * array.
+ *
+ * @param evaluationContext
+ * @return array of selected repositories
+ */
+ @NonNull
+ public static Repository[] getAllRepositories(
+ @Nullable IEvaluationContext evaluationContext) {
+ return getAllRepositories(getSelection(evaluationContext));
+ }
+
+ /**
+ * Retrieves all the repositories associated with the current selection,
+ * even if associated with a folder instead of a project. If no repository
+ * can be determined for any object in the selection, returns an empty
+ * array.
+ *
+ * @param selection
+ * @return array of repositories; may include submodule or nested
+ * repositories
+ */
+ @NonNull
+ public static Repository[] getAllRepositories(
+ @NonNull IStructuredSelection selection) {
+ if (selection.isEmpty()) {
+ return new Repository[0];
+ }
+ Set<Object> elements = getSelectionContents(selection);
+ Set<Repository> repos = new LinkedHashSet<>();
+ for (Object location : elements) {
+ Repository repo = null;
+ if (location instanceof Repository) {
+ repo = (Repository) location;
+ } else if (location instanceof IResource) {
+ repo = ResourceUtil.getRepository((IResource) location);
+ } else if (location instanceof IPath) {
+ repo = ResourceUtil.getRepository((IPath) location);
+ } else {
+ repo = Adapters.adapt(location, Repository.class);
+ }
+ if (repo != null) {
+ repos.add(repo);
+ } else {
+ // no repository found for one of the objects!
+ return new Repository[0];
+ }
+ }
+ return repos.toArray(new Repository[0]);
+ }
+
+ /**
* @param evaluationContext
* @return the single selected repository, or <code>null</code>
*/

Back to the top