Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-03-15 22:18:34 +0000
committerThomas Wolf2016-03-15 22:58:17 +0000
commita8bcee9ea7a58e6db797b86c735f0bdb9e774c18 (patch)
treeb8cb713626ba372401373a96f96227cdff30f625 /org.eclipse.egit.ui.test
parent821fb8f9e6f6166e09c9394eaae75572151e9729 (diff)
downloadegit-a8bcee9ea7a58e6db797b86c735f0bdb9e774c18.tar.gz
egit-a8bcee9ea7a58e6db797b86c735f0bdb9e774c18.tar.xz
egit-a8bcee9ea7a58e6db797b86c735f0bdb9e774c18.zip
Refresh decorations after re-connecting a project
Re-connecting a previously connected, then disconnected project did not refresh the decorations in the project explorer. RepositoryChangeListener was unused, and likewise GitProjectData.addRepositoryChangeListener(). Therefore, all calls to RepositoryMapping.fireRepositoryChanged() had absolutely no effect. Thus I have removed all these calls and the method. Interesting bit of EGit history: the very first version (even before EGit became an Eclipse project) of GitProjectData contained what is now known as the RepositoryCache (the one in EGit). The RepositoryChangeListener indeed was notified on changes in a repository. In that original commit, there was exactly one such listener: in the git decorator. Through various refactorings, RepositoryCache was extracted from GitProjectData, and then IndexDiffChangedListener appeared. RepositoryChangeListener became unused; GitLightweightDecorator was changed to listen on index diff changes in commit f332331. Nowadays, this RepositoryChangeListener is notified not on repository changes, but whenever a new RepositoryMapping is added to the Eclipse resource tree. And that is exactly what is needed to fix bug 489696: when a previously connected, now disconnected project is re-connected, there will be no resource change events (the project is known in Eclipse's resource tree already, and adding new RepositoryMappings as session properties doesn't trigger a resource delta). There also will be no repository or index diff related events (provided the repository is still known to EGit, for instance because it is in the Repositories view, or because there are other projects from that repository.) So the GitLightweightDecorator will not refresh decorations. Using a RepositoryChangeListener (again, after 5 years) the GitLightweightDecorator can correctly refresh the project explorer in this case. Since this listener is no longer invoked when a repository changes, but when a new RepositoryMapping appears, I have renamed and re-purposed the interface to RepositoryMappingChangeListener. Bug: 489696 Change-Id: I2b59cea1f1500cbdde554fff28b676456c8462d8 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java17
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java6
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java33
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java10
4 files changed, 47 insertions, 19 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
index 7b77a7fa40..ece1f6ab95 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
@@ -195,7 +195,7 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree,
file.getFullPath().segments());
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertTrue(node.getText().startsWith("> " + file.getName()));
node.select();
ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
@@ -207,7 +207,7 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
IResourceState state = ResourceStateFactory.getInstance()
.get(cache.getIndexDiff(), file);
assertTrue("File should be staged", state.isStaged());
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertFalse(node.getText().startsWith("> "));
ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
util.getPluginLocalizedValue("RemoveFromIndexAction_label"));
@@ -216,7 +216,7 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
file);
assertFalse("File should not be staged", state.isStaged());
assertTrue("File should be dirty", state.isDirty());
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertTrue(node.getText().startsWith("> " + file.getName()));
}
@@ -267,15 +267,15 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree,
childFolder.getFullPath().segments());
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertTrue("Folder should have repo/branch decoration",
node.getText().contains("[master"));
node = TestUtil.getChildNode(node.expand(), CHILDPROJECT);
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertFalse("Folder should not have repo/branch decoration",
node.getText().contains("["));
node = TestUtil.navigateTo(projectExplorerTree, CHILDPROJECT);
- waitForDecorations();
+ TestUtil.waitForDecorations();
assertTrue("Project should have subrepo/branch decoration",
node.getText().contains("[child"));
}
@@ -344,9 +344,4 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
historyBot.bot().table().rowCount());
}
- @SuppressWarnings("restriction")
- private void waitForDecorations() throws Exception {
- TestUtil.joinJobs(
- org.eclipse.ui.internal.decorators.DecoratorManager.FAMILY_DECORATE);
- }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 7cc571ac7a..5f47d337b3 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -195,6 +195,12 @@ public class TestUtil {
TestUtil.processUIEvents();
}
+ @SuppressWarnings("restriction")
+ public static void waitForDecorations() throws InterruptedException {
+ TestUtil.joinJobs(
+ org.eclipse.ui.internal.decorators.DecoratorManager.FAMILY_DECORATE);
+ }
+
/**
* Utility for waiting until the execution of jobs of any family has
* finished or timeout is reached. If no jobs are running, the method waits
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java
index cc2fd3e272..4a55ea6569 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java
@@ -10,12 +10,15 @@
*******************************************************************************/
package org.eclipse.egit.ui.test.team.actions;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.UIText;
@@ -25,6 +28,7 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -69,6 +73,35 @@ public class DisconnectConnectTest extends LocalRepositoryTestCase {
assertNotNull(mapping);
}
+ @Test
+ public void testDecorations() throws Exception {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1);
+ RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+ assertNotNull(mapping);
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ TestUtil.navigateTo(projectExplorerTree,
+ new Path(FILE1_PATH).segments());
+ touch("File modified");
+ clickOnDisconnect();
+ TestUtil.waitForJobs(500, 5000);
+ TestUtil.waitForDecorations();
+ assertFalse("Project should not have git decorations",
+ getProjectItem(projectExplorerTree, PROJ1).getText()
+ .contains("["));
+ SWTBotShell connectDialog = openConnectDialog();
+ connectDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ TestUtil.waitForJobs(500, 5000);
+ TestUtil.waitForDecorations();
+ assertTrue("Project should have git decorations",
+ getProjectItem(projectExplorerTree, PROJ1).getText()
+ .contains("[FirstRepository"));
+ SWTBotTreeItem fileNode = TestUtil.navigateTo(projectExplorerTree,
+ new Path(FILE1_PATH).segments());
+ assertTrue("File should have git decorations",
+ fileNode.getText().startsWith(">"));
+ }
+
private void clickOnDisconnect() throws Exception {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
getProjectItem(projectExplorerTree, PROJ1).select();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java
index 0399bed316..89a9fbf4ca 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java
@@ -165,7 +165,7 @@ public class GitRepositoriesViewRepoDeletionTest extends
assertTrue(repositoryFile.exists());
assertTrue(
new File(repositoryFile.getParentFile(), PROJ1).isDirectory());
- waitForDecorations();
+ TestUtil.waitForDecorations();
closeGitViews();
TestUtil.waitForJobs(500, 5000);
// Session properties are stored in the Eclipse resource tree as part of
@@ -228,7 +228,7 @@ public class GitRepositoriesViewRepoDeletionTest extends
org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Is this job doing something when the view is hidden?
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);
- waitForDecorations();
+ TestUtil.waitForDecorations();
} catch (InterruptedException e) {
results[0] = "Interrupted";
Thread.currentThread().interrupt();
@@ -317,12 +317,6 @@ public class GitRepositoriesViewRepoDeletionTest extends
assertFalse(subRepo.getWorkTree().exists());
}
- @SuppressWarnings("restriction")
- private void waitForDecorations() throws InterruptedException {
- TestUtil.joinJobs(
- org.eclipse.ui.internal.decorators.DecoratorManager.FAMILY_DECORATE);
- }
-
/**
* Best-effort attempt to get finalization to occur.
*

Back to the top