]> source.dussan.org Git - jgit.git/commitdiff
Fix resolving of relative file URIs in TransportLocal 96/6996/1
authorRobin Stocker <robin@nibor.org>
Fri, 27 Jul 2012 09:53:51 +0000 (11:53 +0200)
committerRobin Stocker <robin@nibor.org>
Fri, 27 Jul 2012 10:05:13 +0000 (12:05 +0200)
A configured remote url like "../repo" works with C Git.

In JGit, it only worked if Java's current working directory happened to
be the local repository working directory.

Change-Id: I33ba3f81b37d03cf17ca7ae25a90774a27e7e02b
Signed-off-by: Robin Stocker <robin@nibor.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java

index 9899d14d8d8712b4feaedecbcf60924de0bee9b0..4e7b5e420eeb668bdd8b82493a93dcc256d3d5f9 100644 (file)
@@ -58,6 +58,7 @@ import java.util.List;
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
+import org.eclipse.jgit.storage.file.FileRepository;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -213,6 +214,18 @@ public class TransportTest extends SampleDataRepositoryTestCase {
                assertEquals(ObjectId.zeroId(), tru.getOldObjectId());
        }
 
+       @Test
+       public void testLocalTransportWithRelativePath() throws Exception {
+               FileRepository other = createWorkRepository();
+               String otherDir = other.getWorkTree().getName();
+
+               RemoteConfig config = new RemoteConfig(db.getConfig(), "other");
+               config.addURI(new URIish("../" + otherDir));
+
+               // Should not throw NoRemoteRepositoryException
+               transport = Transport.open(db, config);
+       }
+
        @Test
        public void testSpi() {
                List<TransportProtocol> protocols = Transport.getTransportProtocols();
index 8be940d9d0af9f660db6bc34d10ba1a5ddaf93ca..5a23ae18d8258ae7a93f38b7c6321b243e834321 100644 (file)
@@ -118,10 +118,10 @@ class TransportLocal extends Transport implements PackTransport {
                @Override
                public Transport open(URIish uri, Repository local, String remoteName)
                                throws NoRemoteRepositoryException {
+                       File localPath = local.isBare() ? local.getDirectory() : local.getWorkTree();
+                       File path = local.getFS().resolve(localPath, uri.getPath());
                        // If the reference is to a local file, C Git behavior says
                        // assume this is a bundle, since repositories are directories.
-                       //
-                       File path = local.getFS().resolve(new File("."), uri.getPath());
                        if (path.isFile())
                                return new TransportBundleFile(local, uri, path);