]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-refs: reject unknown arguments
authorJeff King <peff@peff.net>
Wed, 15 Sep 2021 18:36:38 +0000 (14:36 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Sep 2021 19:25:19 +0000 (12:25 -0700)
The v2 ls-refs command may receive extra arguments from the client, one
per pkt-line. The spec is pretty clear that the arguments must come from
a specified set, but we silently ignore any unknown entries. For a
well-behaved client this doesn't matter, but it makes testing and
debugging more confusing. Let's tighten this up to match the spec.

In theory this liberal behavior _could_ be useful for extending the
protocol. But:

  - every other part of the protocol requires that the server first
    indicate that it supports the argument; this includes the fetch and
    object-info commands, plus the "unborn" capability added to ls-refs
    itself

  - it's not a very good extension mechanism anyway; without the server
    advertising support, clients would have no idea if the argument was
    silently ignored, or accepted and simply had no effect

So we're not really losing anything by tightening this.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ls-refs.c
t/t5701-git-serve.sh

index 07429f3a1c4ac2dc0254479a612ee415fc9414d1..883c0c58b2bcad080035eafbaa9e986e252debe5 100644 (file)
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -170,6 +170,8 @@ int ls_refs(struct repository *r, struct packet_reader *request)
                }
                else if (!strcmp("unborn", arg))
                        data.unborn = allow_unborn;
+               else
+                       die(_("unexpected line: '%s'"), arg);
        }
 
        if (request->status != PACKET_READ_FLUSH)
index 3928424e1bb81c9342a84ae19205343b562668ad..aa1827d841d47779ef3bb081aba8205802395fb2 100755 (executable)
@@ -147,6 +147,19 @@ test_expect_success 'basics of ls-refs' '
        test_cmp expect actual
 '
 
+test_expect_success 'ls-refs complains about unknown options' '
+       test-tool pkt-line pack >in <<-EOF &&
+       command=ls-refs
+       object-format=$(test_oid algo)
+       0001
+       no-such-arg
+       0000
+       EOF
+
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
+       grep unexpected.line.*no-such-arg err
+'
+
 test_expect_success 'basic ref-prefixes' '
        test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs