3 test_description
='test protocol v2 server commands'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
16 cat >expect.base <<-EOF &&
18 agent=git/$(git version | cut -d" " -f3)
20 fetch=shallow wait-for-done
22 object-format=$(test_oid algo)
25 cat >expect.trailer <<-EOF &&
28 cat expect.base expect.trailer >expect &&
30 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
31 --advertise-capabilities >out &&
32 test-tool pkt-line unpack <out >actual &&
33 test_cmp expect actual
36 test_expect_success
'stateless-rpc flag does not list capabilities' '
38 test-tool pkt-line pack >in <<-EOF &&
41 test-tool serve-v2 --stateless-rpc >out <in &&
42 test_must_be_empty out &&
45 test-tool serve-v2 --stateless-rpc >out &&
46 test_must_be_empty out
49 test_expect_success
'request invalid capability' '
50 test-tool pkt-line pack >in <<-EOF &&
54 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
55 test_i18ngrep "unknown capability" err
58 test_expect_success
'request with no command' '
59 test-tool pkt-line pack >in <<-EOF &&
61 object-format=$(test_oid algo)
64 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
65 test_i18ngrep "no command requested" err
68 test_expect_success
'request invalid command' '
69 test-tool pkt-line pack >in <<-EOF &&
71 object-format=$(test_oid algo)
75 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
76 test_i18ngrep "invalid command" err
79 test_expect_success
'request capability as command' '
80 test-tool pkt-line pack >in <<-EOF &&
82 object-format=$(test_oid algo)
85 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
86 grep invalid.command.*agent err
89 test_expect_success
'request command as capability' '
90 test-tool pkt-line pack >in <<-EOF &&
92 object-format=$(test_oid algo)
96 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
97 grep unknown.capability err
100 test_expect_success
'requested command is command=value' '
101 test-tool pkt-line pack >in <<-EOF &&
102 command=ls-refs=whatever
103 object-format=$(test_oid algo)
106 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
107 grep invalid.command.*ls-refs=whatever err
110 test_expect_success
'wrong object-format' '
111 test-tool pkt-line pack >in <<-EOF &&
114 object-format=$(test_oid wrong_algo)
117 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
118 test_i18ngrep "mismatched object format" err
121 # Test the basics of ls-refs
123 test_expect_success
'setup some refs and tags' '
125 git branch dev main &&
127 git symbolic-ref refs/heads/release refs/heads/main &&
128 git tag -a -m "annotated tag" annotated-tag
131 test_expect_success
'basics of ls-refs' '
132 test-tool pkt-line pack >in <<-EOF &&
134 object-format=$(test_oid algo)
138 cat >expect <<-EOF &&
139 $(git rev-parse HEAD) HEAD
140 $(git rev-parse refs/heads/dev) refs/heads/dev
141 $(git rev-parse refs/heads/main) refs/heads/main
142 $(git rev-parse refs/heads/release) refs/heads/release
143 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
144 $(git rev-parse refs/tags/one) refs/tags/one
145 $(git rev-parse refs/tags/two) refs/tags/two
149 test-tool serve-v2 --stateless-rpc <in >out &&
150 test-tool pkt-line unpack <out >actual &&
151 test_cmp expect actual
154 test_expect_success
'ls-refs complains about unknown options' '
155 test-tool pkt-line pack >in <<-EOF &&
157 object-format=$(test_oid algo)
163 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
164 grep unexpected.line.*no-such-arg err
167 test_expect_success
'basic ref-prefixes' '
168 test-tool pkt-line pack >in <<-EOF &&
170 object-format=$(test_oid algo)
172 ref-prefix refs/heads/main
173 ref-prefix refs/tags/one
177 cat >expect <<-EOF &&
178 $(git rev-parse refs/heads/main) refs/heads/main
179 $(git rev-parse refs/tags/one) refs/tags/one
183 test-tool serve-v2 --stateless-rpc <in >out &&
184 test-tool pkt-line unpack <out >actual &&
185 test_cmp expect actual
188 test_expect_success
'refs/heads prefix' '
189 test-tool pkt-line pack >in <<-EOF &&
191 object-format=$(test_oid algo)
193 ref-prefix refs/heads/
197 cat >expect <<-EOF &&
198 $(git rev-parse refs/heads/dev) refs/heads/dev
199 $(git rev-parse refs/heads/main) refs/heads/main
200 $(git rev-parse refs/heads/release) refs/heads/release
204 test-tool serve-v2 --stateless-rpc <in >out &&
205 test-tool pkt-line unpack <out >actual &&
206 test_cmp expect actual
209 test_expect_success
'ignore very large set of prefixes' '
210 # generate a large number of ref-prefixes that we expect
211 # to match nothing; the value here exceeds TOO_MANY_PREFIXES
214 echo command=ls-refs &&
215 echo object-format=$(test_oid algo) &&
217 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
220 test-tool pkt-line pack >in &&
222 # and then confirm that we see unmatched prefixes anyway (i.e.,
223 # that the prefix was not applied).
224 cat >expect <<-EOF &&
225 $(git rev-parse HEAD) HEAD
226 $(git rev-parse refs/heads/dev) refs/heads/dev
227 $(git rev-parse refs/heads/main) refs/heads/main
228 $(git rev-parse refs/heads/release) refs/heads/release
229 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
230 $(git rev-parse refs/tags/one) refs/tags/one
231 $(git rev-parse refs/tags/two) refs/tags/two
235 test-tool serve-v2 --stateless-rpc <in >out &&
236 test-tool pkt-line unpack <out >actual &&
237 test_cmp expect actual
240 test_expect_success
'peel parameter' '
241 test-tool pkt-line pack >in <<-EOF &&
243 object-format=$(test_oid algo)
246 ref-prefix refs/tags/
250 cat >expect <<-EOF &&
251 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
252 $(git rev-parse refs/tags/one) refs/tags/one
253 $(git rev-parse refs/tags/two) refs/tags/two
257 test-tool serve-v2 --stateless-rpc <in >out &&
258 test-tool pkt-line unpack <out >actual &&
259 test_cmp expect actual
262 test_expect_success
'symrefs parameter' '
263 test-tool pkt-line pack >in <<-EOF &&
265 object-format=$(test_oid algo)
268 ref-prefix refs/heads/
272 cat >expect <<-EOF &&
273 $(git rev-parse refs/heads/dev) refs/heads/dev
274 $(git rev-parse refs/heads/main) refs/heads/main
275 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
279 test-tool serve-v2 --stateless-rpc <in >out &&
280 test-tool pkt-line unpack <out >actual &&
281 test_cmp expect actual
284 test_expect_success
'sending server-options' '
285 test-tool pkt-line pack >in <<-EOF &&
287 object-format=$(test_oid algo)
295 cat >expect <<-EOF &&
296 $(git rev-parse HEAD) HEAD
300 test-tool serve-v2 --stateless-rpc <in >out &&
301 test-tool pkt-line unpack <out >actual &&
302 test_cmp expect actual
305 test_expect_success
'unexpected lines are not allowed in fetch request' '
308 test-tool pkt-line pack >in <<-EOF &&
310 object-format=$(test_oid algo)
312 this-is-not-a-command
318 test_must_fail test-tool serve-v2 --stateless-rpc
319 ) <in >/dev/null 2>err &&
320 grep "unexpected line: .this-is-not-a-command." err
323 # Test the basics of object-info
325 test_expect_success
'basics of object-info' '
326 test-tool pkt-line pack >in <<-EOF &&
328 object-format=$(test_oid algo)
331 oid $(git rev-parse two:two.t)
332 oid $(git rev-parse two:two.t)
336 cat >expect <<-EOF &&
338 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
339 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
343 test-tool serve-v2 --stateless-rpc <in >out &&
344 test-tool pkt-line unpack <out >actual &&
345 test_cmp expect actual
348 test_expect_success
'test capability advertisement with uploadpack.advertiseBundleURIs' '
349 test_config uploadpack.advertiseBundleURIs true &&
351 cat >expect.extra <<-EOF &&
356 expect.trailer >expect &&
358 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
359 --advertise-capabilities >out &&
360 test-tool pkt-line unpack <out >actual &&
361 test_cmp expect actual
364 test_expect_success
'basics of bundle-uri: dies if not enabled' '
365 test-tool pkt-line pack >in <<-EOF &&
370 cat >err.expect <<-\EOF &&
371 fatal: invalid command '"'"'bundle-uri'"'"'
374 cat >expect <<-\EOF &&
375 ERR serve: invalid command '"'"'bundle-uri'"'"'
378 test_must_fail test-tool serve-v2 --stateless-rpc <in >out 2>err.actual &&
379 test_cmp err.expect err.actual &&
380 test_must_be_empty out