Skip to content

Commit ccf0947

Browse files
peffgitster
authored andcommitted
ls-refs: reject unknown arguments
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>
1 parent 0ab7eec commit ccf0947

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ls-refs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ int ls_refs(struct repository *r, struct packet_reader *request)
170170
}
171171
else if (!strcmp("unborn", arg))
172172
data.unborn = allow_unborn;
173+
else
174+
die(_("unexpected line: '%s'"), arg);
173175
}
174176

175177
if (request->status != PACKET_READ_FLUSH)

t/t5701-git-serve.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ test_expect_success 'basics of ls-refs' '
147147
test_cmp expect actual
148148
'
149149

150+
test_expect_success 'ls-refs complains about unknown options' '
151+
test-tool pkt-line pack >in <<-EOF &&
152+
command=ls-refs
153+
object-format=$(test_oid algo)
154+
0001
155+
no-such-arg
156+
0000
157+
EOF
158+
159+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
160+
grep unexpected.line.*no-such-arg err
161+
'
162+
150163
test_expect_success 'basic ref-prefixes' '
151164
test-tool pkt-line pack >in <<-EOF &&
152165
command=ls-refs

0 commit comments

Comments
 (0)