1 /******************************************************************************
2 * Copyright (c) 2012, 2014 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 *****************************************************************************/
13 package org
.eclipse
.egit
.core
.op
;
15 import org
.eclipse
.core
.resources
.IWorkspace
;
16 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
17 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
21 import org
.eclipse
.egit
.core
.internal
.job
.RuleUtil
;
22 import org
.eclipse
.jgit
.api
.Git
;
23 import org
.eclipse
.jgit
.api
.StashCreateCommand
;
24 import org
.eclipse
.jgit
.api
.errors
.GitAPIException
;
25 import org
.eclipse
.jgit
.api
.errors
.JGitInternalException
;
26 import org
.eclipse
.jgit
.lib
.Repository
;
27 import org
.eclipse
.jgit
.revwalk
.RevCommit
;
28 import org
.eclipse
.team
.core
.TeamException
;
31 * Operation that creates a stashed commit for a repository
33 public class StashCreateOperation
implements IEGitOperation
{
35 private final Repository repository
;
37 private final String message
;
39 private RevCommit commit
;
41 private final boolean includeUntracked
;
44 * Create operation for repository
48 public StashCreateOperation(final Repository repository
) {
49 this(repository
, null, false);
53 * Create operation for repository
58 public StashCreateOperation(final Repository repository
,
59 final String message
) {
60 this(repository
, message
, false);
64 * Create operation for repository
68 * @param includeUntracked
70 public StashCreateOperation(final Repository repository
,
71 final String message
, final boolean includeUntracked
) {
72 this.repository
= repository
;
73 this.message
= message
;
74 this.includeUntracked
= includeUntracked
;
82 public RevCommit
getCommit() {
87 public void execute(IProgressMonitor monitor
) throws CoreException
{
88 IWorkspaceRunnable action
= new IWorkspaceRunnable() {
91 public void run(IProgressMonitor pm
) throws CoreException
{
93 StashCreateCommand command
= Git
.wrap(repository
).stashCreate();
95 command
.setWorkingDirectoryMessage(message
);
96 command
.setIncludeUntracked(includeUntracked
);
97 commit
= command
.call();
98 } catch (JGitInternalException e
) {
99 throw new TeamException(e
.getLocalizedMessage(),
101 } catch (GitAPIException e
) {
102 throw new TeamException(e
.getLocalizedMessage(),
105 if (commit
!= null) {
106 repository
.notifyIndexChanged(true);
111 ResourcesPlugin
.getWorkspace().run(action
, getSchedulingRule(),
112 IWorkspace
.AVOID_UPDATE
, monitor
);
116 public ISchedulingRule
getSchedulingRule() {
117 return RuleUtil
.getRule(repository
);