aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2013-07-20 16:26:05 +0200
committerChris Aniszczyk <caniszczyk@gmail.com>2013-07-21 22:15:31 -0500
commit8b6bbf094f75cb07205006c1a85b0b6147e9c843 (patch)
treec1a0350563780df0363d0d400aa16002ee78ec0e
parenta2b33a8ac33c63eea82f300b802a26af54a3d61d (diff)
downloadjgit-8b6bbf094f75cb07205006c1a85b0b6147e9c843.tar.gz
jgit-8b6bbf094f75cb07205006c1a85b0b6147e9c843.zip
Fix NPE in openFetch on Transport without local repository
Setting the walk and other fields to null will result in NPEs when the user e.g. calls fetch on the connection, but at least the advertised refs can be read like that without having a local repository. Bug: 413389 Change-Id: I39c8363e81a1c7e6cb3412ba88542ead669e69ed Signed-off-by: Robin Stocker <robin@nibor.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java41
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java6
3 files changed, 49 insertions, 14 deletions
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
index b686d160b1..6fb130231a 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
@@ -376,4 +376,20 @@ public class HttpClientTests extends HttpTestCase {
t.close();
}
}
+
+ @Test
+ public void testListRemoteWithoutLocalRepository() throws Exception {
+ Transport t = Transport.open(smartAuthNoneURI);
+ try {
+ FetchConnection c = t.openFetch();
+ try {
+ Ref head = c.getRef(Constants.HEAD);
+ assertNotNull(head);
+ } finally {
+ c.close();
+ }
+ } finally {
+ t.close();
+ }
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
index 1b13d0ba2a..7a30d251ad 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -239,21 +239,33 @@ public abstract class BasePackFetchConnection extends BasePackConnection
public BasePackFetchConnection(final PackTransport packTransport) {
super(packTransport);
- final FetchConfig cfg = local.getConfig().get(FetchConfig.KEY);
+ if (local != null) {
+ final FetchConfig cfg = local.getConfig().get(FetchConfig.KEY);
+ allowOfsDelta = cfg.allowOfsDelta;
+ } else {
+ allowOfsDelta = true;
+ }
includeTags = transport.getTagOpt() != TagOpt.NO_TAGS;
thinPack = transport.isFetchThin();
- allowOfsDelta = cfg.allowOfsDelta;
-
- walk = new RevWalk(local);
- reachableCommits = new RevCommitList<RevCommit>();
- REACHABLE = walk.newFlag("REACHABLE"); //$NON-NLS-1$
- COMMON = walk.newFlag("COMMON"); //$NON-NLS-1$
- STATE = walk.newFlag("STATE"); //$NON-NLS-1$
- ADVERTISED = walk.newFlag("ADVERTISED"); //$NON-NLS-1$
-
- walk.carry(COMMON);
- walk.carry(REACHABLE);
- walk.carry(ADVERTISED);
+
+ if (local != null) {
+ walk = new RevWalk(local);
+ reachableCommits = new RevCommitList<RevCommit>();
+ REACHABLE = walk.newFlag("REACHABLE"); //$NON-NLS-1$
+ COMMON = walk.newFlag("COMMON"); //$NON-NLS-1$
+ STATE = walk.newFlag("STATE"); //$NON-NLS-1$
+ ADVERTISED = walk.newFlag("ADVERTISED"); //$NON-NLS-1$
+
+ walk.carry(COMMON);
+ walk.carry(REACHABLE);
+ walk.carry(ADVERTISED);
+ } else {
+ walk = null;
+ REACHABLE = null;
+ COMMON = null;
+ STATE = null;
+ ADVERTISED = null;
+ }
}
private static class FetchConfig {
@@ -357,7 +369,8 @@ public abstract class BasePackFetchConnection extends BasePackConnection
@Override
public void close() {
- walk.release();
+ if (walk != null)
+ walk.release();
super.close();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index 3c196109d7..dd04ce50c2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -559,6 +559,9 @@ public abstract class Transport {
/**
* Open a new transport with no local repository.
+ * <p>
+ * Note that the resulting transport instance can not be used for fetching
+ * or pushing, but only for reading remote refs.
*
* @param uri
* @return new Transport instance
@@ -1238,6 +1241,9 @@ public abstract class Transport {
/**
* Begins a new connection for fetching from the remote repository.
+ * <p>
+ * If the transport has no local repository, the fetch connection can only
+ * be used for reading remote refs.
*
* @return a fresh connection to fetch from the remote repository.
* @throws NotSupportedException