Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-02-07 12:58:34 +0000
committerMatthias Sohn2016-02-23 23:03:55 +0000
commit005b828c74505df76dc8f237f7e2dab36eada45c (patch)
treea7d9ea7ee3c2935b91862c93f643dcb3a484f847 /org.eclipse.egit.core.test
parent5e8710b3c4f72877eb157ec6ea2b0e9edc440685 (diff)
downloadegit-005b828c74505df76dc8f237f7e2dab36eada45c.tar.gz
egit-005b828c74505df76dc8f237f7e2dab36eada45c.tar.xz
egit-005b828c74505df76dc8f237f7e2dab36eada45c.zip
Make RepositoryMapping use java.nio.file.Path
org.eclipse.resources.Path.fromOSString normalizes paths. However, the FileRepositoryBuilder returns paths like /some/path/container/../.git/modules/... . If that get's normalized, we end up with /some/path/.git/modules/... , which defeats the subsequent attempt to relativize the string to ../.git/modules/... . Using java.nio.file.Path, we can avoid this premature normalization, and moreover we can create relative paths in way more cases. Change-Id: I19da4aed3a4a8476f6cb4b1466fa5ab75b095f66 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java
index ccc158573c..0d22fdfc57 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertNull;
import java.io.File;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
@@ -118,6 +119,51 @@ public class RepositoryMappingTest extends GitTestCase {
mapping.getGitDirAbsolutePath());
}
+ /**
+ * Tests that a {@link RepositoryMapping} internally uses a relative path if
+ * at all possible.
+ */
+ @Test
+ public void shouldResolveAsRelativePath() {
+ IProject proj = project.getProject();
+ IPath projectPath = proj.getLocation()
+ .removeTrailingSeparator();
+ String gitHereTest = ".git";
+ String gitTest = "../../.git";
+ String gitSubdirTest = "foobar/.git";
+ String gitSubmoduleTest = "../../.git/modules/submodule";
+ // Construct an absolute path different from the project location:
+ // should be preserved. upToSegment ensures we don't loose the root
+ // component.
+ String gitAbsolute = projectPath.uptoSegment(0)
+ .append(projectPath.segment(0) + "fake").append(".git")
+ .toOSString();
+ String parents = "";
+ while (projectPath.segmentCount() > 2) {
+ String pathString = projectPath.toOSString();
+ assertRepoMappingPath(proj, pathString, gitHereTest, parents);
+ assertRepoMappingPath(proj, pathString, gitTest, parents);
+ assertRepoMappingPath(proj, pathString, gitSubdirTest, parents);
+ assertRepoMappingPath(proj, pathString, gitSubmoduleTest, parents);
+ assertRepoMappingPath(proj, pathString, gitAbsolute, "");
+ projectPath = projectPath.removeLastSegments(1);
+ parents += "../";
+ }
+ }
+
+ private void assertRepoMappingPath(IProject testProject, String path,
+ String testDir, String parents) {
+ String testDirOS = testDir.replace('/', File.separatorChar);
+ File testFile = new File(testDirOS);
+ if (!testFile.isAbsolute()) {
+ testFile = new File(new File(path), testDirOS);
+ }
+ RepositoryMapping mapping = RepositoryMapping.create(testProject,
+ testFile);
+ assertEquals(parents + testDir,
+ mapping.getGitDirPath().toPortableString());
+ }
+
private IPath getWorkTreePath() {
return new Path(repository.getWorkTree().getAbsolutePath());
}

Back to the top