Merge branch 'ib/rebase-reschedule-doc'
[git/gitster.git] / t / t5701-git-serve.sh
blob3591bc2417119c75181cc1884ea9e48a7a87646a
1 #!/bin/sh
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
9 . ./test-lib.sh
11 test_expect_success 'test capability advertisement' '
12 test_oid_cache <<-EOF &&
13 wrong_algo sha1:sha256
14 wrong_algo sha256:sha1
15 EOF
16 cat >expect.base <<-EOF &&
17 version 2
18 agent=git/$(git version | cut -d" " -f3)
19 ls-refs=unborn
20 fetch=shallow wait-for-done
21 server-option
22 object-format=$(test_oid algo)
23 object-info
24 EOF
25 cat >expect.trailer <<-EOF &&
26 0000
27 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' '
37 # Empty request
38 test-tool pkt-line pack >in <<-EOF &&
39 0000
40 EOF
41 test-tool serve-v2 --stateless-rpc >out <in &&
42 test_must_be_empty out &&
44 # EOF
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 &&
51 foobar
52 0000
53 EOF
54 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
55 test_grep "unknown capability" err
58 test_expect_success 'request with no command' '
59 test-tool pkt-line pack >in <<-EOF &&
60 agent=git/test
61 object-format=$(test_oid algo)
62 0000
63 EOF
64 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
65 test_grep "no command requested" err
68 test_expect_success 'request invalid command' '
69 test-tool pkt-line pack >in <<-EOF &&
70 command=foo
71 object-format=$(test_oid algo)
72 agent=git/test
73 0000
74 EOF
75 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
76 test_grep "invalid command" err
79 test_expect_success 'request capability as command' '
80 test-tool pkt-line pack >in <<-EOF &&
81 command=agent
82 object-format=$(test_oid algo)
83 0000
84 EOF
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 &&
91 command=ls-refs
92 object-format=$(test_oid algo)
93 fetch
94 0000
95 EOF
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)
104 0000
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 &&
112 command=fetch
113 agent=git/test
114 object-format=$(test_oid wrong_algo)
115 0000
117 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
118 test_grep "mismatched object format" err
121 # Test the basics of ls-refs
123 test_expect_success 'setup some refs and tags' '
124 test_commit one &&
125 git branch dev main &&
126 test_commit two &&
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 &&
133 command=ls-refs
134 object-format=$(test_oid algo)
135 0000
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
146 0000
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 &&
156 command=ls-refs
157 object-format=$(test_oid algo)
158 0001
159 no-such-arg
160 0000
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 &&
169 command=ls-refs
170 object-format=$(test_oid algo)
171 0001
172 ref-prefix refs/heads/main
173 ref-prefix refs/tags/one
174 0000
177 cat >expect <<-EOF &&
178 $(git rev-parse refs/heads/main) refs/heads/main
179 $(git rev-parse refs/tags/one) refs/tags/one
180 0000
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 &&
190 command=ls-refs
191 object-format=$(test_oid algo)
192 0001
193 ref-prefix refs/heads/
194 0000
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
201 0000
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
212 # from ls-refs.c.
214 echo command=ls-refs &&
215 echo object-format=$(test_oid algo) &&
216 echo 0001 &&
217 perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
218 echo 0000
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
232 0000
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 &&
242 command=ls-refs
243 object-format=$(test_oid algo)
244 0001
245 peel
246 ref-prefix refs/tags/
247 0000
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
254 0000
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 &&
264 command=ls-refs
265 object-format=$(test_oid algo)
266 0001
267 symrefs
268 ref-prefix refs/heads/
269 0000
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
276 0000
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 &&
286 command=ls-refs
287 object-format=$(test_oid algo)
288 server-option=hello
289 server-option=world
290 0001
291 ref-prefix HEAD
292 0000
295 cat >expect <<-EOF &&
296 $(git rev-parse HEAD) HEAD
297 0000
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' '
306 git init server &&
308 test-tool pkt-line pack >in <<-EOF &&
309 command=fetch
310 object-format=$(test_oid algo)
311 0001
312 this-is-not-a-command
313 0000
317 cd server &&
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 &&
327 command=object-info
328 object-format=$(test_oid algo)
329 0001
330 size
331 oid $(git rev-parse two:two.t)
332 oid $(git rev-parse two:two.t)
333 0000
336 cat >expect <<-EOF &&
337 size
338 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
339 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
340 0000
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 &&
352 bundle-uri
354 cat expect.base \
355 expect.extra \
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 &&
366 command=bundle-uri
367 0000
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
383 test_done