Avoid refresh on up-to-date pull operation
[egit/eclipse.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / op / StashCreateOperation.java
bloba6764c27257cc9af516c41e0b562b9025e16eb52
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
10 * Contributors:
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;
30 /**
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;
43 /**
44 * Create operation for repository
46 * @param repository
48 public StashCreateOperation(final Repository repository) {
49 this(repository, null, false);
52 /**
53 * Create operation for repository
55 * @param repository
56 * @param message
58 public StashCreateOperation(final Repository repository,
59 final String message) {
60 this(repository, message, false);
63 /**
64 * Create operation for repository
66 * @param repository
67 * @param message
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;
77 /**
78 * Get stashed commit
80 * @return commit
82 public RevCommit getCommit() {
83 return commit;
86 @Override
87 public void execute(IProgressMonitor monitor) throws CoreException {
88 IWorkspaceRunnable action = new IWorkspaceRunnable() {
90 @Override
91 public void run(IProgressMonitor pm) throws CoreException {
92 try {
93 StashCreateCommand command = Git.wrap(repository).stashCreate();
94 if (message != null)
95 command.setWorkingDirectoryMessage(message);
96 command.setIncludeUntracked(includeUntracked);
97 commit = command.call();
98 } catch (JGitInternalException e) {
99 throw new TeamException(e.getLocalizedMessage(),
100 e.getCause());
101 } catch (GitAPIException e) {
102 throw new TeamException(e.getLocalizedMessage(),
103 e.getCause());
104 } finally {
105 if (commit != null) {
106 repository.notifyIndexChanged(true);
111 ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(),
112 IWorkspace.AVOID_UPDATE, monitor);
115 @Override
116 public ISchedulingRule getSchedulingRule() {
117 return RuleUtil.getRule(repository);