diff options
author | Thomas Wolf | 2019-08-09 11:27:18 +0000 |
---|---|---|
committer | Thomas Wolf | 2019-08-09 14:13:09 +0000 |
commit | 629c4a6ff266225837ec323051ca56c2af3df7ba (patch) | |
tree | e4090307b8412c5ebd3ff90a12a8b7951bc35539 /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui | |
parent | 27f697e7169474370f6e7b24f7e4364a074048cd (diff) | |
download | egit-629c4a6ff266225837ec323051ca56c2af3df7ba.tar.gz egit-629c4a6ff266225837ec323051ca56c2af3df7ba.tar.xz egit-629c4a6ff266225837ec323051ca56c2af3df7ba.zip |
Fix equals & hashCode of StashedCommitNode
Nodes in the repositories view for stashed commits must only be equal
if the commit _AND_ the index are equal. Otherwise the TreeViewer in
the repositories view gets confused and does not update the tree
correctly.
Bug: 464949
Change-Id: Iab7dc3e5471f71f4034735bb661e29ed8f3b6998
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui')
2 files changed, 130 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java index 94c0bd1b77..15dcbe6cab 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java @@ -16,6 +16,7 @@ package org.eclipse.egit.ui.view.repositories; import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.hasItem; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @@ -28,16 +29,19 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.egit.core.op.StashCreateOperation; import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.JobFamilies; import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.internal.UIText; +import org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode; import org.eclipse.egit.ui.test.ContextMenuHelper; import org.eclipse.egit.ui.test.TestUtil; import org.eclipse.jface.dialogs.IDialogConstants; @@ -751,6 +755,118 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase { assertThat(folder.getNodes(), hasItem(FILE2)); } + @Test + public void testStashDeleteCreate() throws Exception { + Repository repo = lookupRepository(repositoryFile); + IFile file = touch("Something"); + new StashCreateOperation(repo, "First stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + touch("Something else"); + new StashCreateOperation(repo, "Second stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + touch("Something else again"); + new StashCreateOperation(repo, "Third stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + SWTBotTree tree = getOrOpenView().bot().tree(); + refreshAndWait(); + + SWTBotTreeItem item = myRepoViewUtil.getStashesItem(tree, + repositoryFile); + item = TestUtil.expandAndWait(item); + assertEquals("Unexpected number of stashed commits", 3, + item.getItems().length); + item.getNode(0).select(); + ContextMenuHelper.clickContextMenu(tree, + myUtil.getPluginLocalizedValue("StashDropCommand.label")); + SWTBotShell confirm = bot.shell(UIText.StashDropCommand_confirmTitle); + confirm.bot().button(UIText.StashDropCommand_buttonDelete).click(); + bot.waitUntil(shellCloses(confirm)); + TestUtil.joinJobs(JobFamilies.STASH); + TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH); + touch("Something different"); + tree.getAllItems()[0].select(); + ContextMenuHelper.clickContextMenu(tree, + myUtil.getPluginLocalizedValue("StashesMenu.label"), + UIText.StashesMenu_StashChangesActionText); + confirm = bot.shell(UIText.StashCreateCommand_titleEnterCommitMessage); + confirm.bot().button(UIText.StashCreateCommand_ButtonOK).click(); + bot.waitUntil(shellCloses(confirm)); + TestUtil.joinJobs(JobFamilies.STASH); + TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH); + item = myRepoViewUtil.getStashesItem(tree, repositoryFile); + assertStashes(item.getItems(), 3); + } + + @Test + public void testStashDeleteMultiple() throws Exception { + Repository repo = lookupRepository(repositoryFile); + IFile file = touch("Something"); + new StashCreateOperation(repo, "First stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + touch("Something else"); + new StashCreateOperation(repo, "Second stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + touch("Something else again"); + new StashCreateOperation(repo, "Third stash").execute(null); + file.refreshLocal(IResource.DEPTH_ZERO, null); + SWTBotTree tree = getOrOpenView().bot().tree(); + refreshAndWait(); + + SWTBotTreeItem item = myRepoViewUtil.getStashesItem(tree, + repositoryFile); + item = TestUtil.expandAndWait(item); + assertEquals("Unexpected number of stashed commits", 3, + item.getItems().length); + item.select(1, 2); + ContextMenuHelper.clickContextMenu(tree, + myUtil.getPluginLocalizedValue("StashDropCommand.label")); + SWTBotShell confirm = bot.shell(UIText.StashDropCommand_confirmTitle); + confirm.bot().button(UIText.StashDropCommand_buttonDelete).click(); + bot.waitUntil(shellCloses(confirm)); + TestUtil.joinJobs(JobFamilies.STASH); + TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH); + item = myRepoViewUtil.getStashesItem(tree, repositoryFile); + assertStashes(item.getItems(), 1, "Third stash"); + } + + private void assertStashes(SWTBotTreeItem[] children, int expectedSize, + String... decorations) + throws Exception { + assertEquals("Expected " + expectedSize + " children", expectedSize, + children.length); + if (decorations != null && decorations.length > 0) { + TestUtil.waitForDecorations(); + } + int[] indices = new int[expectedSize]; + int[] expectedIndices = new int[expectedSize]; + for (int i = 0; i < indices.length; i++) { + indices[i] = -1; + expectedIndices[i] = i; + } + children[0].display.syncExec(() -> { + int j = 0; + for (SWTBotTreeItem child : children) { + Object data = child.widget.getData(); + if (data instanceof StashedCommitNode) { + indices[j++] = ((StashedCommitNode) data).getIndex(); + } + } + }); + assertArrayEquals("Unexpected stash indices", expectedIndices, indices); + for (int i = 0; i < children.length; i++) { + String text = children[i].getText(); + assertTrue("Stash " + i + " has wrong label: " + text, + text.startsWith("stash@{" + i + "}")); + if (decorations != null && i < decorations.length) { + String deco = decorations[i]; + if (deco != null) { + assertTrue("Label should contain '" + deco + "': " + text, + text.contains(deco)); + } + } + } + } + private void toggleLinkWithSelection() throws Exception { getOrOpenView().toolbarButton( myUtil.getPluginLocalizedValue("LinkWithSelectionCommand")) diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java index df7e6886ab..5190cf918b 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java @@ -22,6 +22,7 @@ import org.eclipse.egit.ui.internal.repository.tree.LocalNode; import org.eclipse.egit.ui.internal.repository.tree.RemoteTrackingNode; import org.eclipse.egit.ui.internal.repository.tree.RemotesNode; import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode; +import org.eclipse.egit.ui.internal.repository.tree.StashNode; import org.eclipse.egit.ui.internal.repository.tree.TagsNode; import org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode; import org.eclipse.egit.ui.test.TestUtil; @@ -158,6 +159,19 @@ public class GitRepositoriesViewTestUtils { return remotesItem; } + public SWTBotTreeItem getStashesItem(SWTBotTree tree, File repositoryFile) + throws Exception { + Repository repository = lookupRepository(repositoryFile); + RepositoryNode root = new RepositoryNode(null, repository); + StashNode stashes = new StashNode(root, repository); + + String rootText = labelProvider.getText(root); + String stashesText = labelProvider.getText(stashes); + SWTBotTreeItem stashesItem = TestUtil.navigateTo(tree, rootText, + stashesText); + return stashesItem; + } + public Repository lookupRepository(File directory) throws Exception { return org.eclipse.egit.core.Activator.getDefault() .getRepositoryCache().lookupRepository(directory); |