summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2018-04-30 13:21:43 -0700
committerJonathan Nieder <jrn@google.com>2018-06-04 22:09:07 -0700
commit7dbd2bfe7e0598097cf35aedd700d86b468bec7d (patch)
tree86fe7a44b54b68e7503ec12da695ccb644e5e8ca /org.eclipse.jgit.test
parentc9d4609ecbe3e8ed74f8fc169d541a1d7c8c5f15 (diff)
downloadjgit-7dbd2bfe7e0598097cf35aedd700d86b468bec7d.tar.gz
jgit-7dbd2bfe7e0598097cf35aedd700d86b468bec7d.zip
Teach UploadPack "filter" in protocol v2 fetch
If the configuration variable uploadpack.allowfilter is true, advertise that "filter" is supported, and support it if the client sends such an argument. Change-Id: I7de66c0a0ada46ff71c5ba124d4ffa7c47254c3b Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java60
1 files changed, 60 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 d1a31720b6..ef083da183 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
@@ -410,6 +410,22 @@ public class UploadPackTest {
}
@Test
+ public void testV2CapabilitiesAllowFilter() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ // TODO(jonathantanmy) This check overspecifies the
+ // order of the capabilities of "fetch".
+ hasItems("ls-refs", "fetch=filter shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
@SuppressWarnings("boxing")
public void testV2EmptyRequest() throws Exception {
ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END);
@@ -1018,6 +1034,50 @@ public class UploadPackTest {
PacketLineIn.END);
}
+ @Test
+ public void testV2FetchFilter() throws Exception {
+ RevBlob big = remote.blob("foobar");
+ RevBlob small = remote.blob("fooba");
+ RevTree tree = remote.tree(remote.file("1", big),
+ remote.file("2", small));
+ RevCommit commit = remote.commit(tree);
+ remote.update("master", commit);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "filter blob:limit=5\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+
+ assertFalse(client.hasObject(big.toObjectId()));
+ assertTrue(client.hasObject(small.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchFilterWhenNotAllowed() throws Exception {
+ RevCommit commit = remote.commit().message("0").create();
+ remote.update("master", commit);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", false);
+
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected filter blob:limit=5");
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want " + commit.toObjectId().getName() + "\n",
+ "filter blob:limit=5\n",
+ "done\n",
+ PacketLineIn.END);
+ }
+
private static class RejectAllRefFilter implements RefFilter {
@Override
public Map<String, Ref> filter(Map<String, Ref> refs) {