Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2012-02-10 20:10:49 -0500
committerMatthias Sohn2012-02-10 20:10:49 -0500
commit5fa082ee31d6f1b13c5f0027a4736215db78ef00 (patch)
treed3e301ed1cb7322404315f8103990e602315cb23 /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule
parent227df83c0394e3bbc940ad663c9b7fd89407afd2 (diff)
downloadegit-5fa082ee31d6f1b13c5f0027a4736215db78ef00.tar.gz
egit-5fa082ee31d6f1b13c5f0027a4736215db78ef00.tar.xz
egit-5fa082ee31d6f1b13c5f0027a4736215db78ef00.zip
[repoView] Add submodule add/sync/update support
The Submodules node and all child repository nodes now have an Update and Sync action available from the context menu. Root repositories and 'Submodules' nodes now have an Add action that opens a wizard to configure a new submodule that will be configured in the parent repository and cloned on completion. Change-Id: I2afea7dca9e40a2748c10a7f835b2deae301ba73 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleAddTest.java91
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleSyncTest.java119
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleTests.java27
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleUpdateTest.java101
4 files changed, 338 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleAddTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleAddTest.java
new file mode 100644
index 000000000..e9e4bfbfb
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleAddTest.java
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * Copyright (c) 2012 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.ui.submodule;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.storage.file.FileRepository;
+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.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Unit tests for adding submodules to a repository
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class SubmoduleAddTest extends GitRepositoriesViewTestBase {
+
+ private static final String ADD_SUBMODULE_CONTEXT_MENU_LABEL = "SubmoduleAddCommand.label";
+
+ private static File repositoryFile;
+
+ @Before
+ public void before() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ }
+
+ @Test
+ public void addAtRoot() throws Exception {
+ deleteAllProjects();
+ assertProjectExistence(PROJ1, false);
+ clearView();
+ Activator.getDefault().getRepositoryUtil()
+ .addConfiguredRepository(repositoryFile);
+ shareProjects(repositoryFile);
+ assertProjectExistence(PROJ1, true);
+ refreshAndWait();
+ assertHasRepo(repositoryFile);
+ FileRepository repo = lookupRepository(repositoryFile);
+
+ SWTBotTree tree = getOrOpenView().bot().tree();
+ tree.getAllItems()[0].select();
+ ContextMenuHelper.clickContextMenu(tree, myUtil
+ .getPluginLocalizedValue(ADD_SUBMODULE_CONTEXT_MENU_LABEL));
+ SWTBotShell shell = bot.shell(UIText.AddSubmoduleWizard_WindowTitle);
+ shell.activate();
+ shell.bot().textWithLabel(UIText.SubmodulePathWizardPage_PathLabel)
+ .setText("sub");
+ shell.bot().button(IDialogConstants.NEXT_LABEL).click();
+
+ shell.bot()
+ .textWithLabel(UIText.RepositorySelectionPage_promptURI + ":")
+ .setText(repo.getDirectory().toURI().toString());
+
+ shell.bot().button(IDialogConstants.FINISH_LABEL).click();
+ waitInUI();
+ TestUtil.joinJobs(JobFamilies.SUBMODULE_ADD);
+ refreshAndWait();
+
+ tree = getOrOpenView().bot().tree();
+ SWTBotTreeItem submodules = tree.getAllItems()[0]
+ .select()
+ .expand()
+ .getNode(
+ UIText.RepositoriesViewLabelProvider_SubmodulesNodeText);
+ assertNotNull(submodules);
+ submodules.expand();
+ assertEquals(1, submodules.rowCount());
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleSyncTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleSyncTest.java
new file mode 100644
index 000000000..6bbcfea38
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleSyncTest.java
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * Copyright (c) 2012 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.ui.submodule;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
+import org.eclipse.jgit.api.SubmoduleAddCommand;
+import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Unit tests of running a submodule sync
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class SubmoduleSyncTest extends GitRepositoriesViewTestBase {
+
+ private static final String SYNC_SUBMODULE_CONTEXT_MENU_LABEL = "SubmoduleSyncCommand.label";
+
+ private static File repositoryFile;
+
+ @Before
+ public void before() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ }
+
+ @Test
+ public void syncSubmodule() throws Exception {
+ deleteAllProjects();
+ assertProjectExistence(PROJ1, false);
+ clearView();
+ Activator.getDefault().getRepositoryUtil()
+ .addConfiguredRepository(repositoryFile);
+ shareProjects(repositoryFile);
+ assertProjectExistence(PROJ1, true);
+ refreshAndWait();
+ assertHasRepo(repositoryFile);
+ FileRepository repo = lookupRepository(repositoryFile);
+
+ SubmoduleAddCommand command = new SubmoduleAddCommand(repo);
+ String path = "sub";
+ command.setPath(path);
+ String uri = new URIish(repo.getDirectory().toURI().toString())
+ .toString();
+ command.setURI(uri);
+ Repository subRepo = command.call();
+ assertNotNull(subRepo);
+
+ String newUri = "git://server/repo.git";
+ File modulesFile = new File(repo.getWorkTree(),
+ Constants.DOT_GIT_MODULES);
+ FileBasedConfig config = new FileBasedConfig(modulesFile, repo.getFS());
+ config.load();
+ config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_URL, newUri);
+ config.save();
+
+ assertEquals(
+ uri,
+ repo.getConfig().getString(
+ ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_URL));
+ assertEquals(
+ uri,
+ subRepo.getConfig().getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+
+ refreshAndWait();
+ SWTBotTree tree = getOrOpenView().bot().tree();
+ tree.getAllItems()[0]
+ .expand()
+ .expandNode(
+ UIText.RepositoriesViewLabelProvider_SubmodulesNodeText)
+ .select();
+ ContextMenuHelper.clickContextMenu(tree, myUtil
+ .getPluginLocalizedValue(SYNC_SUBMODULE_CONTEXT_MENU_LABEL));
+ TestUtil.joinJobs(JobFamilies.SUBMODULE_SYNC);
+ refreshAndWait();
+
+ assertEquals(
+ newUri,
+ repo.getConfig().getString(
+ ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_URL));
+ assertEquals(
+ newUri,
+ subRepo.getConfig().getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleTests.java
new file mode 100644
index 000000000..1e4b20fca
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleTests.java
@@ -0,0 +1,27 @@
+/******************************************************************************
+ * Copyright (c) 2012 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.ui.submodule;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Search unit test suite
+ */
+@RunWith(Suite.class)
+@SuiteClasses({ SubmoduleAddTest.class, //
+ SubmoduleSyncTest.class, //
+ SubmoduleUpdateTest.class, //
+})
+public class SubmoduleTests {
+ // Intentionally left blank
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleUpdateTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleUpdateTest.java
new file mode 100644
index 000000000..4f9dd9fe4
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/submodule/SubmoduleUpdateTest.java
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * Copyright (c) 2012 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *****************************************************************************/
+package org.eclipse.egit.ui.submodule;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
+import org.eclipse.jgit.api.SubmoduleAddCommand;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Unit tests for running a submodule update
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class SubmoduleUpdateTest extends GitRepositoriesViewTestBase {
+
+ private static final String UPDATE_SUBMODULE_CONTEXT_MENU_LABEL = "SubmoduleUpdateCommand.label";
+
+ private static File repositoryFile;
+
+ @Before
+ public void before() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ }
+
+ @Test
+ public void updateSubmodule() throws Exception {
+ deleteAllProjects();
+ assertProjectExistence(PROJ1, false);
+ clearView();
+ Activator.getDefault().getRepositoryUtil()
+ .addConfiguredRepository(repositoryFile);
+ shareProjects(repositoryFile);
+ assertProjectExistence(PROJ1, true);
+ refreshAndWait();
+ assertHasRepo(repositoryFile);
+ FileRepository repo = lookupRepository(repositoryFile);
+ ObjectId repoHead = repo.resolve(Constants.HEAD);
+
+ SubmoduleAddCommand command = new SubmoduleAddCommand(repo);
+ String path = "sub";
+ command.setPath(path);
+ String uri = new URIish(repo.getDirectory().toURI().toString())
+ .toString();
+ command.setURI(uri);
+ Repository subRepo = command.call();
+ assertNotNull(subRepo);
+
+ Ref head = subRepo.getRef(Constants.HEAD);
+ assertNotNull(head);
+ assertTrue(head.isSymbolic());
+ assertEquals(Constants.R_HEADS + Constants.MASTER, head.getLeaf()
+ .getName());
+ assertEquals(repoHead, head.getObjectId());
+
+ refreshAndWait();
+ SWTBotTree tree = getOrOpenView().bot().tree();
+ tree.getAllItems()[0]
+ .expand()
+ .expandNode(
+ UIText.RepositoriesViewLabelProvider_SubmodulesNodeText)
+ .select();
+ ContextMenuHelper.clickContextMenu(tree, myUtil
+ .getPluginLocalizedValue(UPDATE_SUBMODULE_CONTEXT_MENU_LABEL));
+ TestUtil.joinJobs(JobFamilies.SUBMODULE_UPDATE);
+ refreshAndWait();
+
+ head = subRepo.getRef(Constants.HEAD);
+ assertNotNull(head);
+ assertFalse(head.isSymbolic());
+ assertEquals(repoHead, head.getObjectId());
+ }
+}

Back to the top