Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2c26f16ba0efecaf9715e9b3895d9ccd4421d80e (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
/*******************************************************************************
 * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
 *
 * 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
 *******************************************************************************/
package org.eclipse.egit.gitflow.ui.internal.actions;

import static org.eclipse.egit.gitflow.ui.Activator.error;
import static org.eclipse.egit.gitflow.ui.internal.JobFamilies.GITFLOW_FAMILY;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.internal.job.JobUtil;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.op.FeatureRebaseOperation;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
import org.eclipse.egit.gitflow.ui.internal.UIText;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.api.RebaseResult;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/**
 * git flow feature rebase
 */
public class FeatureRebaseHandler extends AbstractHandler {
	private static final String INTERACTIVE_REBASE_VIEW_ID = "org.eclipse.egit.ui.InteractiveRebaseView"; //$NON-NLS-1$

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);

		FeatureRebaseOperation featureRebaseOperation = new FeatureRebaseOperation(gfRepo);
		JobUtil.scheduleUserWorkspaceJob(featureRebaseOperation,
				UIText.FeatureRebaseHandler_rebasingFeature,
				JobFamilies.GITFLOW_FAMILY);
		IJobManager jobMan = Job.getJobManager();
		try {
			jobMan.join(GITFLOW_FAMILY, null);
		} catch (OperationCanceledException | InterruptedException e) {
			return error(e.getMessage(), e);
		}

		RebaseResult.Status status = featureRebaseOperation
				.getOperationResult().getStatus();
		if (RebaseResult.Status.FAILED.equals(status)) {
			return error(UIText.FeatureRebaseHandler_rebaseFailed);
		}
		if (!RebaseResult.Status.STOPPED.equals(status)) {
			return null;
		}
		MessageDialog.openWarning(null,
				UIText.FeatureRebaseHandler_conflicts,
				UIText.FeatureRebaseHandler_resolveConflictsManually);
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow()
					.getActivePage().showView(INTERACTIVE_REBASE_VIEW_ID);
		} catch (PartInitException e) {
			return error(e.getMessage(), e);
		}

		return null;
	}
}

Back to the top