Search in sources :

Example 1 with StashApplyCommand

use of org.eclipse.jgit.api.StashApplyCommand in project egit by eclipse.

the class StashApplyOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            SubMonitor progress = SubMonitor.convert(pm, 3);
            try {
                IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
                progress.worked(1);
                StashApplyCommand command = Git.wrap(repository).stashApply().setStashRef(commit.name());
                MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                if (strategy != null) {
                    command.setStrategy(strategy);
                }
                command.call();
                progress.worked(1);
                ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
            } catch (JGitInternalException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) StashApplyCommand(org.eclipse.jgit.api.StashApplyCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProject (org.eclipse.core.resources.IProject)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 StashApplyCommand (org.eclipse.jgit.api.StashApplyCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1 MergeStrategy (org.eclipse.jgit.merge.MergeStrategy)1 TeamException (org.eclipse.team.core.TeamException)1