1 /******************************************************************************
2 * Copyright (c) 2012 GitHub Inc.
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 *****************************************************************************/
13 package org
.eclipse
.egit
.core
.op
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Collection
;
19 import org
.eclipse
.core
.resources
.IWorkspace
;
20 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
21 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
25 import org
.eclipse
.jgit
.api
.Git
;
26 import org
.eclipse
.jgit
.api
.SubmoduleSyncCommand
;
27 import org
.eclipse
.jgit
.api
.errors
.GitAPIException
;
28 import org
.eclipse
.jgit
.lib
.Repository
;
29 import org
.eclipse
.team
.core
.TeamException
;
32 * Operation that syncs a repository's submodule configurations
34 public class SubmoduleSyncOperation
implements IEGitOperation
{
36 private final Repository repository
;
38 private final Collection
<String
> paths
;
41 * Create submodule sync operation
45 public SubmoduleSyncOperation(final Repository repository
) {
46 this.repository
= repository
;
47 paths
= new ArrayList
<>();
51 * Add path of submodule to update
54 * @return this operation
56 public SubmoduleSyncOperation
addPath(final String path
) {
62 public void execute(final IProgressMonitor monitor
) throws CoreException
{
63 IWorkspaceRunnable action
= new IWorkspaceRunnable() {
66 public void run(IProgressMonitor pm
) throws CoreException
{
67 Map
<String
, String
> updates
= null;
69 SubmoduleSyncCommand sync
= Git
.wrap(repository
)
71 for (String path
: paths
) {
74 updates
= sync
.call();
75 } catch (GitAPIException e
) {
76 throw new TeamException(e
.getLocalizedMessage(),
79 if (updates
!= null && !updates
.isEmpty()) {
80 repository
.notifyIndexChanged(true);
85 ResourcesPlugin
.getWorkspace().run(action
, getSchedulingRule(),
86 IWorkspace
.AVOID_UPDATE
, monitor
);
90 public ISchedulingRule
getSchedulingRule() {