Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 11c05b30599dfb2f741eed9248f9a995cb055db9 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
/*******************************************************************************
 * Copyright (c) 2010, 2013 SAP AG and others.
 * 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
 *
 * Contributors:
 *    Mathias Kinzler (SAP AG) - initial implementation
 *    Chris Aniszczyk <caniszczyk@gmail.com> - tag API changes
 *******************************************************************************/
package org.eclipse.egit.ui.test.team.actions;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.TagOperation;
import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.utils.TableCollection;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE.SharedImages;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests for the Team->Branch action
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class BranchAndResetActionTest extends LocalRepositoryTestCase {

	private static String LOCAL_BRANCHES;
	private static String TAGS;

	private File repositoryFile;

	@Before
	public void setup() throws Exception {
		repositoryFile = createProjectAndCommitToRepository();
		Repository repo = lookupRepository(repositoryFile);

		TagBuilder tag = new TagBuilder();
		tag.setTag("SomeTag");
		tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
		tag.setMessage("I'm just a little tag");
		tag.setObjectId(repo.resolve(repo.getFullBranch()),
				Constants.OBJ_COMMIT);
		TagOperation top = new TagOperation(repo, tag, false);
		top.execute(null);
		touchAndSubmit(null);

		LOCAL_BRANCHES = UIText.RepositoriesViewLabelProvider_LocalNodetext;
		TAGS = UIText.RepositoriesViewLabelProvider_TagsNodeText;
	}

	@Test
	public void testCheckoutLocalBranches() throws Exception {
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "master" });
	}

	@Test
	public void testCheckoutWithConflicts() throws Exception {
		String charset = ResourcesPlugin.getWorkspace().getRoot().getProject(
				PROJ1).getDefaultCharset();
		try {
			checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
			ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
					.getFolder(FOLDER).getFile(FILE1).setContents(
							new ByteArrayInputStream("New content"
									.getBytes(charset)), IResource.NONE, null);
			checkout(new String[] { LOCAL_BRANCHES, "master" });
			SWTBotShell showConflicts = bot
					.shell(UIText.BranchResultDialog_CheckoutConflictsTitle);
			assertEquals(FILE1, showConflicts.bot().tree().getAllItems()[0]
					.getItems()[0].getItems()[0].getText());
			showConflicts.close();
		} finally {
			ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
					.getFolder(FOLDER).getFile(FILE1).setContents(
							new ByteArrayInputStream("Hello, world"
									.getBytes(charset)), IResource.NONE, null);
		}
	}

	private void checkoutWithConflictsAndReset(boolean stage)
			throws Exception {
		String charset = ResourcesPlugin.getWorkspace().getRoot()
				.getProject(PROJ1).getDefaultCharset();
		String file1Content = getTestFileContent();
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
		ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
				.getFolder(FOLDER).getFile(FILE1).setContents(
						new ByteArrayInputStream(
								"New content".getBytes(charset)),
						IResource.NONE, null);
		if (stage) {
			try (Git git = new Git(lookupRepository(repositoryFile))) {
				git.add().addFilepattern(FILE1_PATH).call();
			}
		}
		String file2Content = "Also changed";
		ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
				.getFolder(FOLDER).getFile(FILE2).setContents(
						new ByteArrayInputStream(
								file2Content.getBytes(charset)),
						IResource.NONE, null);
		checkout(new String[] { LOCAL_BRANCHES, "master" });
		SWTBotShell showConflicts = bot
				.shell(UIText.BranchResultDialog_CheckoutConflictsTitle);
		SWTBot shellBot = showConflicts.bot();
		SWTBotTreeItem[] items = shellBot.tree().getAllItems();
		assertEquals(1, items.length);
		assertEquals(FILE1, items[0].getItems()[0].getItems()[0].getText());
		shellBot.button(UIText.BranchResultDialog_buttonDiscardChanges).click();
		TestUtils.waitForJobs(500, 5000, JobFamilies.DISCARD_CHANGES);
		TestUtil.joinJobs(JobFamilies.CHECKOUT);
		assertEquals(file1Content, getTestFileContent());
		// FILE2 should _not_ have been reset since it didn't conflict with the
		// checkout and wasn't shown in the conflict dialog
		assertEquals(file2Content, getTestFileContent(FILE2));
	}

	@Test
	public void testCheckoutWithConflictsAndReset() throws Exception {
		checkoutWithConflictsAndReset(false);
	}

	@Test
	public void testCheckoutWithStagedConflictsAndReset() throws Exception {
		checkoutWithConflictsAndReset(true);
	}

	@Test
	public void testCheckoutWithNonDeleted() throws Exception {
		// we need to check if this file system has problems to
		// delete a file with an open FileInputStrem
		IFile test = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
				.getFolder(FOLDER).getFile("temp.txt");
		test.create(new ByteArrayInputStream(new byte[0]), false, null);
		File testFile = new File(test.getLocation().toString());
		assertTrue(testFile.exists());
		try (InputStream fis = Files.newInputStream(testFile.toPath())) {
			FileUtils.delete(testFile);
			return;
		} catch (IOException e) {
			// the test makes sense only if deletion of
			// a file with open stream fails
		} finally {
			if (testFile.exists()) {
				FileUtils.delete(testFile);
			}
		}
		final Image folderImage = PlatformUI.getWorkbench().getSharedImages()
				.getImage(ISharedImages.IMG_OBJ_FOLDER);

		final Image projectImage = PlatformUI.getWorkbench().getSharedImages()
				.getImage(SharedImages.IMG_OBJ_PROJECT);
		// checkout stable
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
		// add a file
		IFile toBeDeleted = ResourcesPlugin.getWorkspace().getRoot()
				.getProject(PROJ1).getFolder(FOLDER).getFile("ToBeDeleted");
		toBeDeleted.create(new ByteArrayInputStream(new byte[0]), false, null);

		ArrayList<IFile> untracked = new ArrayList<>();
		untracked.add(toBeDeleted);
		// commit to stable
		CommitOperation op = new CommitOperation(new IFile[] { toBeDeleted },
				untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER,
				"Add to stable");
		op.execute(null);

		try (InputStream is = toBeDeleted.getContents()) {
			checkout(new String[] { LOCAL_BRANCHES, "master" });
			final SWTBotShell showUndeleted = bot
					.shell(UIText.NonDeletedFilesDialog_NonDeletedFilesTitle);
			// repo relative path
			assertEquals("ToBeDeleted", showUndeleted.bot().tree()
					.getAllItems()[0].getItems()[0].getItems()[0].getText());
			PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
				@Override
				public void run() {
					assertSame(folderImage, showUndeleted.bot().tree()
							.getAllItems()[0].widget.getImage());
				}
			});

			SWTBotToolbarDropDownButton pathButton = showUndeleted.bot().toolbarDropDownButton();
			pathButton.menuItem(UIText.NonDeletedFilesTree_FileSystemPathsButton).click();
			// see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
			pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
			// fs path
			IPath path = new Path(lookupRepository(repositoryFile)
					.getWorkTree().getPath()).append(PROJ1).append(FOLDER)
					.append("ToBeDeleted");
			SWTBotTreeItem[] items = showUndeleted.bot().tree().getAllItems();
			for (int i = 0; i < path.segmentCount(); i++) {
				boolean found = false;
				String segment = path.segment(i);
				for (SWTBotTreeItem item : items)
					if (item.getText().equals(segment)) {
						found = true;
						items = item.getItems();
					}
				assertTrue(found);
			}
			pathButton.menuItem(UIText.NonDeletedFilesTree_ResourcePathsButton).click();
			// see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
			pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
			// resource path
			assertEquals("ToBeDeleted", showUndeleted.bot().tree()
					.getAllItems()[0].getItems()[0].getItems()[0].getText());
			PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
				@Override
				public void run() {
					assertSame(projectImage, showUndeleted.bot().tree()
							.getAllItems()[0].widget.getImage());
				}
			});

			ICondition treeEmpty = new ICondition() {

				@Override
				public boolean test() throws Exception {
					return showUndeleted.bot().tree().getAllItems().length == 0;
				}

				@Override
				public void init(SWTBot actBot) {
					// nothing
				}

				@Override
				public String getFailureMessage() {
					return "Not deleted";
				}
			};

			showUndeleted.bot().button(
					UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
			try {
				showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
				fail("Should have failed");
			} catch (TimeoutException e) {
				// expected
			}
			is.close();
			showUndeleted.bot().button(
					UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
			showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
			showUndeleted.close();
		}
	}

	@Test
	public void testResetToLocalBranch() throws Exception {
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
		String stable = getTestFileContent();
		checkoutAndVerify(new String[] { LOCAL_BRANCHES, "master" });
		String master = getTestFileContent();
		assertFalse(stable.equals(master));
		SWTBotShell resetDialog = openResetDialog();
		SWTBotTreeItem localBranches = TestUtil.expandAndWait(
				resetDialog.bot().tree().getTreeItem(LOCAL_BRANCHES));
		TestUtil.getChildNode(localBranches, "stable").select();
		resetDialog.bot().radio(
				UIText.ResetTargetSelectionDialog_ResetTypeHardButton).click();

		resetDialog.bot().button(UIText.ResetTargetSelectionDialog_ResetButton)
				.click();

		bot.shell(UIText.ResetTargetSelectionDialog_ResetConfirmTitle).bot()
				.button(UIText.CommandConfirmationHardResetDialog_resetButtonLabel)
				.click();

		Job.getJobManager().join(JobFamilies.RESET, null);
		String reset = getTestFileContent();
		assertEquals("Wrong content after reset", stable, reset);
	}

	@Test
	public void testCreateDeleteBranch() throws Exception {
		assertNull(lookupRepository(repositoryFile).resolve("newBranch"));

		SWTBotShell newBranchDialog = openCreateBranchDialog();
		newBranchDialog.bot().textWithId("BranchName").setText("newBranch");
		newBranchDialog.bot().checkBox(UIText.CreateBranchPage_CheckoutButton).deselect();
		newBranchDialog.bot().button(IDialogConstants.FINISH_LABEL).click();

		TestUtil.joinJobs(JobFamilies.CHECKOUT);
		assertNotNull(lookupRepository(repositoryFile).resolve("newBranch"));

		SWTBotShell deleteBranchDialog = openDeleteBranchDialog();
		SWTBotTreeItem localBranches = TestUtil.expandAndWait(
				deleteBranchDialog.bot().tree().getTreeItem(LOCAL_BRANCHES));
		TestUtil.getChildNode(localBranches, "newBranch").select();
		deleteBranchDialog.bot().button(IDialogConstants.OK_LABEL).click();

		TestUtil.joinJobs(JobFamilies.CHECKOUT);
		assertNull(lookupRepository(repositoryFile).resolve("newBranch"));
	}

	@Test
	public void testCreateBranchSelectSource() throws Exception {
		Repository repo = lookupRepository(repositoryFile);
		assertNull(repo.resolve("branch-from-tag"));

		SWTBotShell createBranchDialog = openCreateBranchDialog();
		createBranchDialog.bot()
				.button(UIText.CreateBranchPage_SourceSelectButton).click();

		SWTBotShell sourceSelectionDialog = bot
				.shell(UIText.CreateBranchPage_SourceSelectionDialogTitle);
		SWTBotTree tree = sourceSelectionDialog.bot().tree();
		SWTBotTreeItem tags = tree
				.expandNode(UIText.RepositoriesViewLabelProvider_TagsNodeText);
		TestUtil.getChildNode(tags, "SomeTag").select();
		sourceSelectionDialog.bot().button(IDialogConstants.OK_LABEL).click();

		SWTBotStyledText sourceLabel = createBranchDialog.bot().styledText(0);
		assertEquals("SomeTag", sourceLabel.getText());

		createBranchDialog.bot().textWithId("BranchName")
				.setText("branch-from-tag");
		createBranchDialog.bot()
				.checkBox(UIText.CreateBranchPage_CheckoutButton).deselect();
		createBranchDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
		TestUtil.waitForJobs(100, 5000);

		ObjectId resolvedBranch = repo.resolve("branch-from-tag");
		ObjectId resolvedTagCommit = repo.resolve("SomeTag^{commit}");
		assertNotNull(resolvedBranch);
		assertEquals(resolvedTagCommit, resolvedBranch);
	}

	private SWTBotShell openCheckoutBranchDialog() {
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		String[] menuPath = new String[] {
				util.getPluginLocalizedValue("TeamMenu.label"),
				util.getPluginLocalizedValue("SwitchToMenu.label"),
				UIText.SwitchToMenu_OtherMenuLabel };
		ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
		SWTBotShell dialog = bot
				.shell(UIText.BranchSelectionAndEditDialog_WindowTitle);
		return dialog;
	}

	private SWTBotShell openCreateBranchDialog() {
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
			getProjectItem(projectExplorerTree, PROJ1).select();
			String[] menuPath = new String[] {
					util.getPluginLocalizedValue("TeamMenu.label"),
					util.getPluginLocalizedValue("SwitchToMenu.label"),
					UIText.SwitchToMenu_NewBranchMenuLabel };
			ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
		SWTBotShell dialog = bot
				.shell(UIText.CreateBranchWizard_NewBranchTitle);
		return dialog;
	}

	private SWTBotShell openRenameBranchDialog() {
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		String[] menuPath = new String[] {
				util.getPluginLocalizedValue("TeamMenu.label"),
				util.getPluginLocalizedValue("AdvancedMenu.label"),
				util.getPluginLocalizedValue("RenameBranchMenu.label") };
		ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
		SWTBotShell dialog = bot.shell(UIText.RenameBranchDialog_WindowTitle);
		return dialog;
	}

	private SWTBotShell openDeleteBranchDialog() {
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		String[] menuPath = new String[] {
				util.getPluginLocalizedValue("TeamMenu.label"),
				util.getPluginLocalizedValue("AdvancedMenu.label"),
				util.getPluginLocalizedValue("DeleteBranchMenu.label") };
		ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
		SWTBotShell dialog = bot.shell(UIText.DeleteBranchDialog_WindowTitle);
		return dialog;
	}

	private SWTBotShell openResetDialog() {
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		String menuString = util.getPluginLocalizedValue("ResetAction_label");
		ContextMenuHelper.clickContextMenu(projectExplorerTree, util
				.getPluginLocalizedValue("TeamMenu.label"), menuString);
		SWTBotShell dialog = bot
				.shell(UIText.ResetTargetSelectionDialog_WindowTitle);
		return dialog;
	}

	@Test
	public void testRenameBranch() throws Exception {
		SWTBotShell dialog = openRenameBranchDialog();

		SWTBotTreeItem localBranches = TestUtil
				.expandAndWait(dialog.bot().tree().getTreeItem(LOCAL_BRANCHES));
		TestUtil.getChildNode(localBranches, "stable").select();
		dialog.bot().button(UIText.RenameBranchDialog_RenameButtonLabel)
				.click();
		// rename stable to renamed
		SWTBotShell newNameDialog = bot.shell(UIText.BranchRenameDialog_Title);
		newNameDialog.bot().text().setText("master");
		assertFalse(newNameDialog.bot()
				.button(UIText.RenameBranchDialog_RenameButtonLabel)
				.isEnabled());

		newNameDialog.bot().text().setText("renamed");
		newNameDialog.bot().button(UIText.RenameBranchDialog_RenameButtonLabel)
				.click();

		TestUtil.joinJobs(JobFamilies.CHECKOUT);

		dialog = openRenameBranchDialog();
		SWTBotTreeItem localBranches2 = TestUtil
				.expandAndWait(dialog.bot().tree().getTreeItem(LOCAL_BRANCHES));
		TestUtil.getChildNode(localBranches2, "renamed").select();
		dialog.bot().button(UIText.RenameBranchDialog_RenameButtonLabel)
				.click();
		// rename renamed to stable
		newNameDialog = bot.shell(UIText.BranchRenameDialog_Title);

		newNameDialog.bot().text().setText("stable");
		newNameDialog.bot().button(UIText.RenameBranchDialog_RenameButtonLabel)
				.click();

		TestUtil.joinJobs(JobFamilies.CHECKOUT);
		dialog = openRenameBranchDialog();
		SWTBotTreeItem localBranches3 = TestUtil
				.expandAndWait(dialog.bot().tree().getTreeItem(LOCAL_BRANCHES));
		TestUtil.getChildNode(localBranches3, "stable").select();
		dialog.close();
	}

	@Test
	public void testCheckoutTags() throws Exception {
		checkoutAndVerify(new String[] { TAGS, "SomeTag" });
	}

	private void checkoutAndVerify(String[] nodeTexts)
			throws IOException, Exception {
		SWTBotShell dialog = openCheckoutBranchDialog();
		TableCollection tc = dialog.bot().tree().selection();
		assertEquals("Wrong selection count", 0, tc.rowCount());

		TestUtil.navigateTo(dialog.bot().tree(), nodeTexts).select();
		tc = dialog.bot().tree().selection();
		assertEquals("Wrong selection count", 1, tc.rowCount());
		assertTrue("Wrong item selected", tc.get(0, 0).startsWith(nodeTexts[1]));

		Repository repo = lookupRepository(repositoryFile);

		dialog.bot().button(UIText.CheckoutDialog_OkCheckout).click();
		TestUtil.joinJobs(JobFamilies.CHECKOUT);
		if (ObjectId.isId(repo.getBranch())) {
			String mapped = Activator.getDefault().getRepositoryUtil()
					.mapCommitToRef(repo, repo.getBranch(), false);
			assertEquals("Wrong branch", nodeTexts[1],
					mapped.substring(mapped
					.lastIndexOf('/') + 1));
		} else
			assertEquals("Wrong branch", nodeTexts[1], repo.getBranch());
	}

	private void checkout(String[] nodeTexts) throws Exception {
		SWTBotShell dialog = openCheckoutBranchDialog();
		TestUtil.navigateTo(dialog.bot().tree(), nodeTexts).select();
		TableCollection tc = dialog.bot().tree().selection();
		assertEquals("Wrong selection count", 1, tc.rowCount());
		assertTrue("Wrong item selected", tc.get(0, 0).startsWith(nodeTexts[1]));

		dialog.bot().button(UIText.CheckoutDialog_OkCheckout).click();
		TestUtil.joinJobs(JobFamilies.CHECKOUT);
	}

}

Back to the top