summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRobin Stocker2012-07-27 05:53:51 (EDT)
committer Robin Stocker2012-07-27 06:05:13 (EDT)
commitbeee7b86afd5d4e1e9185c1f81640b83d74398f3 (patch)
tree0c9299f4a1bc6c8f857c50e24e1ef9f0a3c063dd
parentd47403ea941e38377425fe55c71c43a45ceef8ca (diff)
downloadjgit-beee7b86afd5d4e1e9185c1f81640b83d74398f3.zip
jgit-beee7b86afd5d4e1e9185c1f81640b83d74398f3.tar.gz
jgit-beee7b86afd5d4e1e9185c1f81640b83d74398f3.tar.bz2
Fix resolving of relative file URIs in TransportLocalrefs/changes/96/6996/1
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>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java4
2 files changed, 15 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
index 9899d14..4e7b5e4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
@@ -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;
@@ -214,6 +215,18 @@ public class TransportTest extends SampleDataRepositoryTestCase {
}
@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();
assertNotNull(protocols);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
index 8be940d..5a23ae1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
@@ -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);