Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4fac5011fe3efad7e6381a03bcf07969dea933f5 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.egit.ui.gitflow;

import static org.junit.Assert.assertEquals;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.op.FeatureCheckoutOperation;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
import org.eclipse.egit.gitflow.ui.internal.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RebaseResult;
import org.eclipse.jgit.api.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.PlatformUI;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests for the Team->Gitflow->Rebase Feature actions
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class FeatureRebaseHandlerTest extends AbstractGitflowHandlerTest {

	private static void disableAutomatedMode() {
		// if AUTOMATED_MODE is true, we wouldn't get the error
		// dialog which is part of what we want to test here
		ErrorDialog.AUTOMATED_MODE = false;
	}

	@Test
	public void testRebaseFailOnConflict() throws Exception {
		disableAutomatedMode();

		Git git = Git.wrap(repository);

		init();

		createFeature(FEATURE_NAME);
		setContentAddAndCommit("foo");

		checkoutBranch(DEVELOP);
		setContentAddAndCommit("bar");

		checkoutFeature(FEATURE_NAME);

		rebaseFeature();
		acceptError(RebaseResult.Status.STOPPED);

		Status status = git.status().call();
		Object[] conflicting = status.getConflicting().toArray();
		assertEquals(1, conflicting.length);
		assertEquals(FILE1_PATH, conflicting[0]);

		assertEquals("org.eclipse.egit.ui.InteractiveRebaseView", bot.activeView().getReference().getId());
	}

	private void acceptError(org.eclipse.jgit.api.RebaseResult.Status status) {
		bot.button("Details >>").click();
		bot.list().select(NLS.bind(
				UIText.FeatureRebaseHandler_statusWas, status.toString()));
		bot.button("OK").click();
	}

	@Test
	public void testRebaseFailOnDirtyWorkingDirectory() throws Exception {
		disableAutomatedMode();

		Git git = Git.wrap(repository);

		init();
		setContentAddAndCommit("bar");

		createFeature(FEATURE_NAME);
		setContentAddAndCommit("foo");

		setTestFileContent("foobar");

		rebaseFeature();
		acceptError(RebaseResult.Status.UNCOMMITTED_CHANGES);

		Status status = git.status().call();
		Object[] uncommitted = status.getUncommittedChanges().toArray();
		assertEquals(1, uncommitted.length);
		assertEquals(FILE1_PATH, uncommitted[0]);
	}

	@Override
	protected void checkoutFeature(String featureName) throws CoreException {
		new FeatureCheckoutOperation(new GitFlowRepository(repository), featureName).execute(null);
	}

	private void checkoutBranch(String branchToCheckout) throws CoreException {
		new BranchOperation(repository, branchToCheckout).execute(null);
	}

	private void rebaseFeature() {
		final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		final String[] menuPath = new String[] {
				util.getPluginLocalizedValue("TeamMenu.label"),
				util.getPluginLocalizedValue("TeamGitFlowMenu.name", false, Activator.getDefault().getBundle()),
				util.getPluginLocalizedValue("TeamGitFlowFeatureRebase.name", false, Activator.getDefault().getBundle()) };

		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
			@Override
			public void run() {
				ContextMenuHelper.clickContextMenuSync(projectExplorerTree, menuPath);
			}
		});
		bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));
	}
}

Back to the top