blob: a8fa07f70fef9a6377e7a1de7625f971b46c48d3 (
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
93
94
|
/******************************************************************************
* Copyright (c) 2011 GitHub Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
package org.eclipse.egit.core.op;
import java.text.MessageFormat;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.egit.core.internal.CoreText;
import org.eclipse.egit.core.internal.util.ProjectUtil;
import org.eclipse.jgit.api.CherryPickCommand;
import org.eclipse.jgit.api.CherryPickResult;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.team.core.TeamException;
/**
* Cherry pick operation
*/
public class CherryPickOperation implements IEGitOperation {
private final Repository repo;
private final RevCommit commit;
private CherryPickResult result;
/**
* Create cherry pick operation
*
* @param repository
* @param commit
*/
public CherryPickOperation(Repository repository, RevCommit commit) {
this.repo = repository;
this.commit = commit;
}
/**
* @return cherry pick result
*/
public CherryPickResult getResult() {
return result;
}
public void execute(IProgressMonitor m) throws CoreException {
IProgressMonitor monitor = m != null ? m : new NullProgressMonitor();
IWorkspaceRunnable action = new IWorkspaceRunnable() {
public void run(IProgressMonitor pm) throws CoreException {
pm.beginTask("", 2); //$NON-NLS-1$
pm.subTask(MessageFormat.format(
CoreText.CherryPickOperation_cherryPicking,
commit.name()));
CherryPickCommand command = new Git(repo).cherryPick().include(
commit.getId());
try {
result = command.call();
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(),
e.getCause());
}
pm.worked(1);
ProjectUtil.refreshValidProjects(
ProjectUtil.getValidOpenProjects(repo),
new SubProgressMonitor(pm, 1));
pm.done();
}
};
ResourcesPlugin.getWorkspace().run(action, monitor);
}
public ISchedulingRule getSchedulingRule() {
return ResourcesPlugin.getWorkspace().getRoot();
}
}
|