diff options
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r-- | org.eclipse.egit.core.test/src/org/eclipse/egit/core/project/RepositoryMappingTest.java | 46 |
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()); } |