Avoid refresh on up-to-date pull operation
[egit/eclipse.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / op / SubmoduleAddOperation.java
blobc4d1912126e305ece8ecd904ae190fce72dbb481
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
10 * Contributors:
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;
30 /**
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;
41 /**
42 * Create operation
44 * @param repo
45 * @param path
46 * @param uri
48 public SubmoduleAddOperation(final Repository repo, final String path,
49 final String uri) {
50 this.repo = repo;
51 this.path = path;
52 this.uri = uri;
55 @Override
56 public void execute(IProgressMonitor monitor) throws CoreException {
57 IWorkspaceRunnable action = new IWorkspaceRunnable() {
59 @Override
60 public void run(IProgressMonitor pm) throws CoreException {
61 final SubmoduleAddCommand add = Git.wrap(repo).submoduleAdd();
62 add.setProgressMonitor(new EclipseGitProgressTransformer(pm));
63 add.setPath(path);
64 add.setURI(uri);
65 try {
66 Repository subRepo = add.call();
67 if (subRepo != null) {
68 subRepo.close();
69 repo.notifyIndexChanged(true);
71 } catch (GitAPIException e) {
72 throw new TeamException(e.getLocalizedMessage(),
73 e.getCause());
77 ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(),
78 IWorkspace.AVOID_UPDATE, monitor);
81 @Override
82 public ISchedulingRule getSchedulingRule() {
83 return RuleUtil.getRule(repo);