1 /******************************************************************************
2 * Copyright (c) 2012, 2013 GitHub Inc and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License 2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-2.0/
8 * SPDX-License-Identifier: EPL-2.0
11 * Kevin Sawicki (GitHub Inc.) - initial API and implementation
12 * Laurent Goubet <laurent.goubet@obeo.fr - 404121
13 *****************************************************************************/
14 package org
.eclipse
.egit
.core
.op
;
16 import org
.eclipse
.core
.resources
.IWorkspace
;
17 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
18 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
22 import org
.eclipse
.egit
.core
.EclipseGitProgressTransformer
;
23 import org
.eclipse
.egit
.core
.internal
.job
.RuleUtil
;
24 import org
.eclipse
.jgit
.api
.Git
;
25 import org
.eclipse
.jgit
.api
.SubmoduleAddCommand
;
26 import org
.eclipse
.jgit
.api
.errors
.GitAPIException
;
27 import org
.eclipse
.jgit
.lib
.Repository
;
28 import org
.eclipse
.team
.core
.TeamException
;
31 * Operation to add a submodule to a repository
33 public class SubmoduleAddOperation
implements IEGitOperation
{
35 private final Repository repo
;
37 private final String path
;
39 private final String uri
;
48 public SubmoduleAddOperation(final Repository repo
, final String path
,
56 public void execute(IProgressMonitor monitor
) throws CoreException
{
57 IWorkspaceRunnable action
= new IWorkspaceRunnable() {
60 public void run(IProgressMonitor pm
) throws CoreException
{
61 final SubmoduleAddCommand add
= Git
.wrap(repo
).submoduleAdd();
62 add
.setProgressMonitor(new EclipseGitProgressTransformer(pm
));
66 Repository subRepo
= add
.call();
67 if (subRepo
!= null) {
69 repo
.notifyIndexChanged(true);
71 } catch (GitAPIException e
) {
72 throw new TeamException(e
.getLocalizedMessage(),
77 ResourcesPlugin
.getWorkspace().run(action
, getSchedulingRule(),
78 IWorkspace
.AVOID_UPDATE
, monitor
);
82 public ISchedulingRule
getSchedulingRule() {
83 return RuleUtil
.getRule(repo
);