Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84f491977aa9c7d6e456392c10ad0fdab7eddd8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
 * Copyright (C) 2015, Stephan Hackstedt <stephan.hackstedt@googlemail.com>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.egit.core.op;

import java.util.Collection;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.egit.core.internal.CoreText;
import org.eclipse.egit.core.internal.trace.GitTraceLocation;
import org.eclipse.team.core.RepositoryProvider;

/**
 * Disconnects the Git team provider from a project.
 * <p>
 * Once disconnected, Git operations will no longer be available on the project.
 * </p>
 */
public class DisconnectProviderOperation implements IEGitOperation {
	private final Collection<IProject> projectList;

	/**
	 * Create a new disconnect operation.
	 *
	 * @param projs
	 *            the collection of {@link IProject}s which should be
	 *            disconnected from the Git team provider, and returned to
	 *            untracked/unmanaged status.
	 */
	public DisconnectProviderOperation(final Collection<IProject> projs) {
		projectList = projs;
	}

	@Override
	public void execute(IProgressMonitor m) throws CoreException {

		SubMonitor progress = SubMonitor.convert(m,
				CoreText.DisconnectProviderOperation_disconnecting,
				projectList.size());
		for (IProject p : projectList) {
			// TODO is this the right location?
			if (GitTraceLocation.CORE.isActive()) {
				GitTraceLocation.getTrace().trace(
						GitTraceLocation.CORE.getLocation(),
						"disconnect " + p.getName()); //$NON-NLS-1$
			}
			unmarkTeamPrivate(p);
			RepositoryProvider.unmap(p);
			p.refreshLocal(IResource.DEPTH_INFINITE, progress.newChild(1));
		}
	}

	@Override
	public ISchedulingRule getSchedulingRule() {
		return new MultiRule(projectList.toArray(new IProject[projectList.size()]));
	}

	private void unmarkTeamPrivate(final IContainer p) throws CoreException {
		final IResource[] c;
		c = p.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
		if (c != null) {
			for (int k = 0; k < c.length; k++) {
				if (c[k] instanceof IContainer) {
					unmarkTeamPrivate((IContainer) c[k]);
				}
				if (c[k].isTeamPrivateMember()) {
					// TODO is this the right location?
					if (GitTraceLocation.CORE.isActive())
						GitTraceLocation.getTrace().trace(
								GitTraceLocation.CORE.getLocation(),
								"notTeamPrivate " + c[k]); //$NON-NLS-1$
					c[k].setTeamPrivateMember(false);
				}
			}
		}
	}
}

Back to the top