Search in sources :

Example 1 with SubmoduleAddCommand

use of org.eclipse.jgit.api.SubmoduleAddCommand in project egit by eclipse.

the class GitRepositoriesViewRepoDeletionTest method testDeleteSubmoduleRepository.

@Test
public void testDeleteSubmoduleRepository() throws Exception {
    deleteAllProjects();
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    Repository db = lookupRepository(repositoryFile);
    SubmoduleAddCommand command = new SubmoduleAddCommand(db);
    String path = "sub";
    command.setPath(path);
    String uri = db.getDirectory().toURI().toString();
    command.setURI(uri);
    Repository subRepo = command.call();
    assertNotNull(subRepo);
    subRepo.close();
    refreshAndWait();
    SWTBotTree tree = getOrOpenView().bot().tree();
    SWTBotTreeItem item = TestUtil.expandAndWait(tree.getAllItems()[0]);
    item = TestUtil.expandAndWait(item.getNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText));
    item.getItems()[0].select();
    ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue(DELETE_REPOSITORY_CONTEXT_MENU_LABEL));
    SWTBotShell shell = bot.shell(UIText.DeleteRepositoryConfirmDialog_DeleteRepositoryWindowTitle);
    shell.activate();
    shell.bot().checkBox(UIText.DeleteRepositoryConfirmDialog_DeleteGitDirCheckbox).select();
    shell.bot().checkBox(UIText.DeleteRepositoryConfirmDialog_DeleteWorkingDirectoryCheckbox).select();
    shell.bot().button(UIText.DeleteRepositoryConfirmDialog_DeleteRepositoryConfirmButton).click();
    TestUtil.joinJobs(JobFamilies.REPOSITORY_DELETE);
    refreshAndWait();
    assertFalse(subRepo.getDirectory().exists());
    assertFalse(subRepo.getWorkTree().exists());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) SubmoduleAddCommand(org.eclipse.jgit.api.SubmoduleAddCommand) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Test(org.junit.Test)

Example 2 with SubmoduleAddCommand

use of org.eclipse.jgit.api.SubmoduleAddCommand in project egit by eclipse.

the class SubmoduleSyncTest method syncSubmodule.

@Test
public void syncSubmodule() throws Exception {
    deleteAllProjects();
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    Repository 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);
    subRepo.close();
    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();
    TestUtil.expandAndWait(tree.getAllItems()[0]).getNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select();
    ContextMenuHelper.clickContextMenuSync(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));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) SubmoduleAddCommand(org.eclipse.jgit.api.SubmoduleAddCommand) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) Test(org.junit.Test)

Example 3 with SubmoduleAddCommand

use of org.eclipse.jgit.api.SubmoduleAddCommand in project egit by eclipse.

the class SubmoduleUpdateTest method updateSubmodule.

@Test
public void updateSubmodule() throws Exception {
    deleteAllProjects();
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    Repository 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);
    subRepo.close();
    Ref head = subRepo.exactRef(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();
    SWTBotTreeItem item = TestUtil.expandAndWait(tree.getAllItems()[0]);
    TestUtil.expandAndWait(item.getNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText)).select();
    ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue(UPDATE_SUBMODULE_CONTEXT_MENU_LABEL));
    TestUtil.joinJobs(JobFamilies.SUBMODULE_UPDATE);
    refreshAndWait();
    head = subRepo.exactRef(Constants.HEAD);
    assertNotNull(head);
    assertFalse(head.isSymbolic());
    assertEquals(repoHead, head.getObjectId());
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) SubmoduleAddCommand(org.eclipse.jgit.api.SubmoduleAddCommand) ObjectId(org.eclipse.jgit.lib.ObjectId) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Test(org.junit.Test)

Example 4 with SubmoduleAddCommand

use of org.eclipse.jgit.api.SubmoduleAddCommand in project egit by eclipse.

the class SubmoduleAddOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            final SubmoduleAddCommand add = Git.wrap(repo).submoduleAdd();
            add.setProgressMonitor(new EclipseGitProgressTransformer(pm));
            add.setPath(path);
            add.setURI(uri);
            try {
                Repository subRepo = add.call();
                if (subRepo != null) {
                    subRepo.close();
                    repo.notifyIndexChanged();
                }
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) SubmoduleAddCommand(org.eclipse.jgit.api.SubmoduleAddCommand) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer)

Aggregations

SubmoduleAddCommand (org.eclipse.jgit.api.SubmoduleAddCommand)4 Repository (org.eclipse.jgit.lib.Repository)4 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)3 Test (org.junit.Test)3 URIish (org.eclipse.jgit.transport.URIish)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 File (java.io.File)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 Ref (org.eclipse.jgit.lib.Ref)1 FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)1 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)1 TeamException (org.eclipse.team.core.TeamException)1