Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-08-09 07:27:18 -0400
committerThomas Wolf2019-08-09 10:13:09 -0400
commit629c4a6ff266225837ec323051ca56c2af3df7ba (patch)
treee4090307b8412c5ebd3ff90a12a8b7951bc35539
parent27f697e7169474370f6e7b24f7e4364a074048cd (diff)
downloadegit-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>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java116
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/StashedCommitNode.java11
3 files changed, 141 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 94c0bd1b7..15dcbe6ca 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 df7e6886a..5190cf918 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);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/StashedCommitNode.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/StashedCommitNode.java
index 463ff357a..e107c9519 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/StashedCommitNode.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/StashedCommitNode.java
@@ -42,4 +42,15 @@ public class StashedCommitNode extends RepositoryTreeNode<RevCommit> {
public int getIndex() {
return index;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj) && (obj instanceof StashedCommitNode)
+ && index == ((StashedCommitNode) obj).getIndex();
+ }
+
+ @Override
+ public int hashCode() {
+ return Integer.hashCode(index) * 31 + super.hashCode();
+ }
}

Back to the top