From a27199f6dabc2951f2b27300d075b780ef75f884 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Tue, 22 Mar 2016 20:24:02 +0100 Subject: Handle linked resources in the same repository This already worked kind of if both the link source and the link target were in EGit-managed projects. It didn't work if the link target was in the same repository, but not in a project. * ResourceUtil.getRepository(IPath): don't even try the RepositoryMapping. If one only needs the repository, going through the RepositoryCache is sufficient, and assuming there are less repositories than projects and RepositoryMappings, which in my experience is usually the case, also faster. * Add a new operation to ResourceUtil to get the repository-relative path. * Make GitResourceDeltaVisitor handle linked resources. Bug: 489657 Change-Id: I7006339d9fc380988305c7530a4cdb71e0aff0f3 Signed-off-by: Thomas Wolf --- .../egit/core/test/LinkedResourcesTest.java | 41 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'org.eclipse.egit.core.test') diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java index 670057ed8a..11451f6497 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/LinkedResourcesTest.java @@ -16,6 +16,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.Arrays; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -24,6 +27,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; import org.eclipse.egit.core.Activator; import org.eclipse.egit.core.GitProvider; import org.eclipse.egit.core.IteratorService; @@ -43,6 +47,10 @@ public class LinkedResourcesTest { File project2Dir; + File otherFolder; + + File rootFile; + TestRepository repository1; TestRepository repository2; @@ -63,14 +71,27 @@ public class LinkedResourcesTest { public void setUp() throws Exception { testUtils = new TestUtils(); // Create first repo and project - project1 = testUtils.createProjectInLocalFileSystem(project1Name); + File rootDir = testUtils.createTempDir("FirstRepository"); + project1 = testUtils.createProjectInLocalFileSystem(rootDir, + project1Name); project1Dir = project1.getRawLocation().toFile(); - repository1 = new TestRepository(new File(project1Dir, + otherFolder = new File(rootDir, "other_folder"); + assertTrue(otherFolder.mkdirs()); + File otherFile = new File(otherFolder, "otherFile.txt"); + rootFile = new File(rootDir, "rootFile.txt"); + Files.write(otherFile.toPath(), + Arrays. asList("Hello", "otherFile"), + Charset.defaultCharset()); + Files.write(rootFile.toPath(), Arrays. asList("Hi", "rootFile"), + Charset.defaultCharset()); + repository1 = new TestRepository(new File(rootDir, Constants.DOT_GIT)); testUtils.addFileToProject(project1, "project1folder1/project1folder1file1.txt", "Hello world"); repository1.connect(project1); repository1.trackAllFiles(project1); + repository1.track(otherFile); + repository1.track(rootFile); repository1.commit("Initial commit"); // Create 2nd repo and project project2 = testUtils.createProjectInLocalFileSystem(project2Name); @@ -143,6 +164,22 @@ public class LinkedResourcesTest { "/project2/project2folder1/project2folder1file1.txt" }); } + @Test + public void testLinkTargetsInSameRepositoryNotIgnoredByGitResourceDeltaVisitor() + throws Exception { + IFile file = project1.getFile("link2rootFile"); + file.createLink(Path.fromOSString(rootFile.getAbsolutePath()), 0, null); + IFolder folder = project1.getFolder("link2otherFolder"); + folder.createLink(Path.fromOSString(otherFolder.getAbsolutePath()), 0, + null); + project1.refreshLocal(IResource.DEPTH_INFINITE, null); + project1.getFile("link2rootFile").touch(null); + project1.getFile("link2otherFolder/otherFile.txt").touch(null); + resourceDeltaTestHelper1.assertChangedResources( + new String[] { "/project1/.project", "/project1/link2rootFile", + "/project1/link2otherFolder/otherFile.txt" }); + } + @Test public void testLinkedResourcesIgnoredByIteratorService() throws Exception { // Create linked folder in project1 that points to project2 -- cgit v1.2.3