diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2018-02-22 10:24:19 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2018-04-20 16:17:40 -0700 |
commit | 2661bc081340ae83d2a2ecba11994d3e8d56586b (patch) | |
tree | 81de3b39ccdd2f85a0e331d76e1662894e9b1aa8 /org.eclipse.jgit.test | |
parent | 75b07036928f4ef73e9a217bd7c898457e9c7120 (diff) | |
download | jgit-2661bc081340ae83d2a2ecba11994d3e8d56586b.tar.gz jgit-2661bc081340ae83d2a2ecba11994d3e8d56586b.zip |
Implement protocol v2 with no capabilities in UploadPack
Add initial support for protocol v2 of the fetch-pack/upload-pack
protocol. This protocol is described in the Git project in
"Documentation/technical/protocol-v2.txt".
This patch adds support for protocol v2 (without any capabilities) to
UploadPack. Adaptations of callers to make use of this support will
come in subsequent patches.
[jn: split from a larger patch; tweaked the API to make UploadPack
handle parsing the extra parameters and config instead of requiring
each caller to do such parsing]
Change-Id: I79399fa0dce533fdc8c1dbb6756748818cee45b0
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 5246b56bdc..88060c05a0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -1,9 +1,13 @@ package org.eclipse.jgit.transport; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.util.Collections; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; @@ -11,6 +15,7 @@ import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.Sets; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevTree; @@ -316,4 +321,63 @@ public class UploadPackTest { Collections.singletonList(new RefSpec(commit.name()))); } } + + private static ByteArrayInputStream send(String... lines) throws Exception { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + PacketLineOut pckOut = new PacketLineOut(os); + for (String line : lines) { + if (line == PacketLineIn.END) { + pckOut.end(); + } else if (line == PacketLineIn.DELIM) { + pckOut.writeDelim(); + } else { + pckOut.writeString(line); + } + } + byte[] a = os.toByteArray(); + return new ByteArrayInputStream(a); + } + + /* + * Invokes UploadPack with protocol v2 and sends it the given lines. + * Returns UploadPack's output stream, not including the capability + * advertisement by the server. + */ + private ByteArrayInputStream uploadPackV2(String... inputLines) throws Exception { + ByteArrayOutputStream send = new ByteArrayOutputStream(); + PacketLineOut pckOut = new PacketLineOut(send); + for (String line : inputLines) { + if (line == PacketLineIn.END) { + pckOut.end(); + } else if (line == PacketLineIn.DELIM) { + pckOut.writeDelim(); + } else { + pckOut.writeString(line); + } + } + + server.getConfig().setString("protocol", null, "version", "2"); + UploadPack up = new UploadPack(server); + up.setExtraParameters(Sets.of("version=2")); + + ByteArrayOutputStream recv = new ByteArrayOutputStream(); + up.upload(new ByteArrayInputStream(send.toByteArray()), recv, null); + + ByteArrayInputStream recvStream = new ByteArrayInputStream(recv.toByteArray()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + + // capability advertisement (always sent) + assertThat(pckIn.readString(), is("version 2")); + assertTrue(pckIn.readString() == PacketLineIn.END); + return recvStream; + } + + @Test + public void testV2EmptyRequest() throws Exception { + ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END); + // Verify that there is nothing more after the capability + // advertisement. + assertThat(recvStream.available(), is(0)); + } + } |