Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuís Copetti2018-08-25 14:12:57 +0000
committerLuís Copetti2018-09-27 02:37:30 +0000
commite4dc3eaf0900a469e605b0307a8387c464bb60e9 (patch)
tree43e4ef98e0ec618555ffdf2c1bf40f5de37dc95d /org.eclipse.egit.ui.test
parentc0f622a5a3e23bbcf43185f045de616839aa37c3 (diff)
downloadegit-e4dc3eaf.tar.gz
egit-e4dc3eaf.tar.xz
egit-e4dc3eaf.zip
Add support for multi repository selection for switching branches
When multiple repositories are selected the Switch To... option will display only the branches that are present in all of the repositories. By clicking in any of them, the user will concurrently switch branches for all the repositories. If the list of branches is to be empty, a disabled menu item will be added to show that no matching branches were found. Change-Id: I0f850baeb94cb8cb4169d8684bb37756b5c0c372 Signed-off-by: Luís Copetti <lhcopetti@gmail.com>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
index 311d42a736..768dc3892f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
@@ -17,12 +17,17 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jgit.api.Git;
@@ -33,6 +38,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.services.IServiceLocator;
@@ -41,6 +47,12 @@ import org.junit.Test;
public class SwitchToMenuTest extends LocalRepositoryTestCase {
+ private static final String TEAM_LABEL = util
+ .getPluginLocalizedValue("TeamMenu.label");
+
+ private static final String SWITCH_TO_LABEL_MULTIPLE = util
+ .getPluginLocalizedValue("SwitchToMenuMultiple.label");
+
private SwitchToMenu switchToMenu;
private IHandlerService handlerService;
@@ -152,12 +164,109 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
assertTextEquals(UIText.SwitchToMenu_OtherMenuLabel, items[23]);
}
+ @Test
+ public void validateMenuEntriesForMultiSelectionWithMultipleRepositories()
+ throws Exception {
+ File gitOne = createProjectAndCommitToRepository(REPO1, PROJ1);
+ File gitTwo = createProjectAndCommitToRepository(REPO2, PROJ2);
+
+ Repository repoOne = lookupRepository(gitOne);
+ Repository repoTwo = lookupRepository(gitTwo);
+ for (int i = 0; i < SwitchToMenu.MAX_NUM_MENU_ENTRIES; i++) {
+ createBranch(repoOne, "refs/heads/change/" + i);
+ createBranch(repoTwo, "refs/heads/change/" + (i + 15));
+ }
+
+ mockMultiProjectSelection(PROJ1, PROJ2);
+
+ MenuItem[] items = fillMenu();
+ assertTextEquals("change/15", items[0]);
+ assertTextEquals("change/16", items[1]);
+ assertTextEquals("change/17", items[2]);
+ assertTextEquals("change/18", items[3]);
+ assertTextEquals("change/19", items[4]);
+ assertTextEquals("master", items[5]);
+ assertTextEquals("stable", items[6]);
+ }
+
+ @Test
+ public void validateBranchSwitchingForForMultiSelectionWithMultipleRepositories()
+ throws Exception {
+
+ File gitOne = createProjectAndCommitToRepository(REPO1, PROJ1);
+ File gitTwo = createProjectAndCommitToRepository(REPO2, PROJ2);
+ Repository repoOne = lookupRepository(gitOne);
+ Repository repoTwo = lookupRepository(gitTwo);
+
+ // Set up different branch sources
+ try (Git git = new Git(repoOne)) {
+ git.checkout().setName("master").call();
+ }
+
+ try (Git git = new Git(repoTwo)) {
+ git.checkout().setName("stable").call();
+ }
+
+ String branchName = "commonBranchAmongRepositories";
+ String branchRef = "refs/heads/" + branchName;
+ createBranch(repoOne, branchRef);
+ createBranch(repoTwo, branchRef);
+
+ assertEquals("master", repoOne.getBranch());
+ assertEquals("stable", repoTwo.getBranch());
+
+ // Multi repository Switch To
+ SWTBotTree tree = TestUtil.getExplorerTree();
+ SWTBotTree select = tree.select(tree.getAllItems());
+ ContextMenuHelper.clickContextMenu(select, TEAM_LABEL,
+ SWITCH_TO_LABEL_MULTIPLE, branchName);
+ TestUtil.joinJobs(JobFamilies.CHECKOUT);
+
+ assertEquals(branchName, repoOne.getBranch());
+ assertEquals(branchName, repoTwo.getBranch());
+ }
+
+ @Test
+ public void multipleSelectionWithMultipleRepositoriesAndNoCommonBranches()
+ throws Exception {
+ File gitOne = createProjectAndCommitToRepository(REPO1, PROJ1);
+ File gitTwo = createProjectAndCommitToRepository(REPO2, PROJ2);
+
+ try (Git git = new Git(lookupRepository(gitOne))) {
+ git.checkout().setName("stable").call();
+ git.branchDelete().setBranchNames("master").setForce(true).call();
+ }
+
+ try (Git git = new Git(lookupRepository(gitTwo))) {
+ git.branchDelete().setBranchNames("stable").setForce(true).call();
+ }
+
+ mockMultiProjectSelection(PROJ1, PROJ2);
+
+ MenuItem[] items = fillMenu();
+ assertTextEquals(UIText.SwitchToMenu_NoCommonBranchesFound, items[0]);
+
+ // delete reflog again to not confuse other tests
+ new File(gitOne, Constants.LOGS + "/" + Constants.HEAD).delete();
+ new File(gitTwo, Constants.LOGS + "/" + Constants.HEAD).delete();
+ }
+
private void mockSelection(ISelection selection) {
EvaluationContext context = new EvaluationContext(null, new Object());
context.addVariable(ISources.ACTIVE_MENU_SELECTION_NAME, selection);
when(handlerService.getCurrentState()).thenReturn(context);
}
+ private void mockMultiProjectSelection(String... projNames) {
+
+ List<IProject> projects = new ArrayList<>();
+ for (String s : projNames) {
+ projects.add(
+ ResourcesPlugin.getWorkspace().getRoot().getProject(s));
+ }
+ mockSelection(new StructuredSelection(projects));
+ }
+
private MenuItem[] fillMenu() {
final MenuItem[][] items = new MenuItem[1][];
Display.getDefault().syncExec(new Runnable() {

Back to the top