Implement open(URIish) for TransportLocal
Can be used for listing remote refs for a repository on the file system without having a local repository. Bug: 413400 Change-Id: I397f5092c5eafb62236e9f9e74d9183f56903cc6 Signed-off-by: Robin Stocker <robin@nibor.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
This commit is contained in:
parent
8b6bbf094f
commit
a76a4acf87
|
@ -57,7 +57,9 @@
|
|||
|
||||
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -226,6 +228,20 @@ public void testLocalTransportWithRelativePath() throws Exception {
|
|||
transport = Transport.open(db, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalTransportFetchWithoutLocalRepository()
|
||||
throws Exception {
|
||||
URIish uri = new URIish("file://" + db.getWorkTree().getPath());
|
||||
transport = Transport.open(uri);
|
||||
FetchConnection fetchConnection = transport.openFetch();
|
||||
try {
|
||||
Ref head = fetchConnection.getRef(Constants.HEAD);
|
||||
assertNotNull(head);
|
||||
} finally {
|
||||
fetchConnection.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpi() {
|
||||
List<TransportProtocol> protocols = Transport.getTransportProtocols();
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
import org.eclipse.jgit.errors.TransportException;
|
||||
import org.eclipse.jgit.internal.JGitText;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.util.FS;
|
||||
|
||||
class TransportBundleFile extends Transport implements TransportBundle {
|
||||
static final TransportProtocol PROTO_BUNDLE = new TransportProtocol() {
|
||||
|
@ -104,6 +105,15 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
//
|
||||
return TransportLocal.PROTO_LOCAL.open(uri, local, remoteName);
|
||||
}
|
||||
|
||||
public Transport open(URIish uri) throws NotSupportedException,
|
||||
TransportException {
|
||||
if ("bundle".equals(uri.getScheme())) { //$NON-NLS-1$
|
||||
File path = FS.DETECTED.resolve(new File("."), uri.getPath()); //$NON-NLS-1$
|
||||
return new TransportBundleFile(uri, path);
|
||||
}
|
||||
return TransportLocal.PROTO_LOCAL.open(uri);
|
||||
}
|
||||
};
|
||||
|
||||
private final File bundle;
|
||||
|
@ -113,6 +123,11 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
bundle = bundlePath;
|
||||
}
|
||||
|
||||
public TransportBundleFile(URIish uri, File bundlePath) {
|
||||
super(uri);
|
||||
bundle = bundlePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchConnection openFetch() throws NotSupportedException,
|
||||
TransportException {
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.lib.RepositoryBuilder;
|
||||
import org.eclipse.jgit.lib.RepositoryCache;
|
||||
import org.eclipse.jgit.util.FS;
|
||||
import org.eclipse.jgit.util.io.MessageWriter;
|
||||
import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
|
||||
import org.eclipse.jgit.util.io.StreamCopyThread;
|
||||
|
@ -130,6 +131,21 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
throw new NoRemoteRepositoryException(uri, JGitText.get().notFound);
|
||||
return new TransportLocal(local, uri, gitDir);
|
||||
}
|
||||
|
||||
public Transport open(URIish uri) throws NotSupportedException,
|
||||
TransportException {
|
||||
File path = FS.DETECTED.resolve(new File("."), uri.getPath()); //$NON-NLS-1$
|
||||
// If the reference is to a local file, C Git behavior says
|
||||
// assume this is a bundle, since repositories are directories.
|
||||
if (path.isFile())
|
||||
return new TransportBundleFile(uri, path);
|
||||
|
||||
File gitDir = RepositoryCache.FileKey.resolve(path, FS.DETECTED);
|
||||
if (gitDir == null)
|
||||
throw new NoRemoteRepositoryException(uri,
|
||||
JGitText.get().notFound);
|
||||
return new TransportLocal(uri, gitDir);
|
||||
}
|
||||
};
|
||||
|
||||
private final File remoteGitDir;
|
||||
|
@ -139,6 +155,11 @@ public Transport open(URIish uri, Repository local, String remoteName)
|
|||
remoteGitDir = gitDir;
|
||||
}
|
||||
|
||||
TransportLocal(URIish uri, File gitDir) {
|
||||
super(uri);
|
||||
remoteGitDir = gitDir;
|
||||
}
|
||||
|
||||
UploadPack createUploadPack(final Repository dst) {
|
||||
return new UploadPack(dst);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue