Fix resolving of relative file URIs in TransportLocal
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>
This commit is contained in:
parent
d47403ea94
commit
beee7b86af
|
@ -58,6 +58,7 @@
|
|||
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 void testFindRemoteRefUpdatesTrackingRef() throws IOException {
|
|||
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();
|
||||
|
|
|
@ -118,10 +118,10 @@ public boolean canHandle(URIish uri, Repository local, String remoteName) {
|
|||
@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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue