]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5702-protocol-v2.sh
Merge branch 'jk/p5303-sed-portability-fix'
[thirdparty/git.git] / t / t5702-protocol-v2.sh
CommitLineData
e52449b6
BW
1#!/bin/sh
2
3test_description='test git wire-protocol version 2'
4
5TEST_NO_CREATE_REPO=1
6
95cf2c01 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
e52449b6
BW
10. ./test-lib.sh
11
12# Test protocol v2 with 'git://' transport
13#
14. "$TEST_DIRECTORY"/lib-git-daemon.sh
15start_git_daemon --export-all --enable=receive-pack
16daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
17
18test_expect_success 'create repo to be served by git-daemon' '
19 git init "$daemon_parent" &&
20 test_commit -C "$daemon_parent" one
21'
22
23test_expect_success 'list refs with git:// using protocol v2' '
24 test_when_finished "rm -f log" &&
25
26 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
27 ls-remote --symref "$GIT_DAEMON_URL/parent" >actual &&
28
29 # Client requested to use protocol v2
30 grep "git> .*\\\0\\\0version=2\\\0$" log &&
31 # Server responded using protocol v2
32 grep "git< version 2" log &&
33
34 git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
dcbaa0b3 35 test_cmp expect actual
e52449b6
BW
36'
37
4dc8b1c1 38test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
b4be7410
BW
39 test_when_finished "rm -f log" &&
40
41 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
95cf2c01 42 ls-remote "$GIT_DAEMON_URL/parent" main >actual &&
b4be7410
BW
43
44 cat >expect <<-EOF &&
95cf2c01 45 $(git -C "$daemon_parent" rev-parse refs/heads/main)$(printf "\t")refs/heads/main
b4be7410
BW
46 EOF
47
dcbaa0b3 48 test_cmp expect actual
b4be7410
BW
49'
50
685fbd32
BW
51test_expect_success 'clone with git:// using protocol v2' '
52 test_when_finished "rm -f log" &&
53
54 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
55 clone "$GIT_DAEMON_URL/parent" daemon_child &&
56
57 git -C daemon_child log -1 --format=%s >actual &&
58 git -C "$daemon_parent" log -1 --format=%s >expect &&
59 test_cmp expect actual &&
60
61 # Client requested to use protocol v2
62 grep "clone> .*\\\0\\\0version=2\\\0$" log &&
63 # Server responded using protocol v2
64 grep "clone< version 2" log
65'
66
67test_expect_success 'fetch with git:// using protocol v2' '
68 test_when_finished "rm -f log" &&
69
70 test_commit -C "$daemon_parent" two &&
71
72 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
73 fetch &&
74
95cf2c01 75 git -C daemon_child log -1 --format=%s origin/main >actual &&
685fbd32
BW
76 git -C "$daemon_parent" log -1 --format=%s >expect &&
77 test_cmp expect actual &&
78
79 # Client requested to use protocol v2
80 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
81 # Server responded using protocol v2
82 grep "fetch< version 2" log
83'
84
e70a3030
JT
85test_expect_success 'fetch by hash without tag following with protocol v2 does not list refs' '
86 test_when_finished "rm -f log" &&
87
88 test_commit -C "$daemon_parent" two_a &&
89 git -C "$daemon_parent" rev-parse two_a >two_a_hash &&
90
91 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
92 fetch --no-tags origin $(cat two_a_hash) &&
93
94 grep "fetch< version 2" log &&
95 ! grep "fetch> command=ls-refs" log
96'
97
685fbd32
BW
98test_expect_success 'pull with git:// using protocol v2' '
99 test_when_finished "rm -f log" &&
100
101 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
102 pull &&
103
104 git -C daemon_child log -1 --format=%s >actual &&
105 git -C "$daemon_parent" log -1 --format=%s >expect &&
106 test_cmp expect actual &&
107
108 # Client requested to use protocol v2
109 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
110 # Server responded using protocol v2
111 grep "fetch< version 2" log
112'
113
1aa8dded
BW
114test_expect_success 'push with git:// and a config of v2 does not request v2' '
115 test_when_finished "rm -f log" &&
116
117 # Till v2 for push is designed, make sure that if a client has
118 # protocol.version configured to use v2, that the client instead falls
119 # back and uses v0.
120
121 test_commit -C daemon_child three &&
122
123 # Push to another branch, as the target repository has the
95cf2c01 124 # main branch checked out and we cannot push into it.
1aa8dded
BW
125 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
126 push origin HEAD:client_branch &&
127
128 git -C daemon_child log -1 --format=%s >actual &&
129 git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
130 test_cmp expect actual &&
131
132 # Client requested to use protocol v2
133 ! grep "push> .*\\\0\\\0version=2\\\0$" log &&
134 # Server responded using protocol v2
135 ! grep "push< version 2" log
136'
137
e52449b6
BW
138stop_git_daemon
139
140# Test protocol v2 with 'file://' transport
141#
142test_expect_success 'create repo to be served by file:// transport' '
143 git init file_parent &&
144 test_commit -C file_parent one
145'
146
147test_expect_success 'list refs with file:// using protocol v2' '
148 test_when_finished "rm -f log" &&
149
150 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
151 ls-remote --symref "file://$(pwd)/file_parent" >actual &&
152
153 # Server responded using protocol v2
154 grep "git< version 2" log &&
155
156 git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
dcbaa0b3 157 test_cmp expect actual
e52449b6
BW
158'
159
4dc8b1c1 160test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
b4be7410
BW
161 test_when_finished "rm -f log" &&
162
163 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
95cf2c01 164 ls-remote "file://$(pwd)/file_parent" main >actual &&
b4be7410
BW
165
166 cat >expect <<-EOF &&
95cf2c01 167 $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
b4be7410
BW
168 EOF
169
dcbaa0b3 170 test_cmp expect actual
b4be7410
BW
171'
172
ff473221
BW
173test_expect_success 'server-options are sent when using ls-remote' '
174 test_when_finished "rm -f log" &&
175
176 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
95cf2c01 177 ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual &&
ff473221
BW
178
179 cat >expect <<-EOF &&
95cf2c01 180 $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
ff473221
BW
181 EOF
182
dcbaa0b3 183 test_cmp expect actual &&
ff473221
BW
184 grep "server-option=hello" log &&
185 grep "server-option=world" log
186'
187
35eb8240
JT
188test_expect_success 'warn if using server-option with ls-remote with legacy protocol' '
189 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
95cf2c01 190 ls-remote -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
35eb8240
JT
191
192 test_i18ngrep "see protocol.version in" err &&
193 test_i18ngrep "server options require protocol version 2 or later" err
194'
ff473221 195
685fbd32
BW
196test_expect_success 'clone with file:// using protocol v2' '
197 test_when_finished "rm -f log" &&
198
199 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
200 clone "file://$(pwd)/file_parent" file_child &&
201
202 git -C file_child log -1 --format=%s >actual &&
203 git -C file_parent log -1 --format=%s >expect &&
204 test_cmp expect actual &&
205
206 # Server responded using protocol v2
402c47d9
BW
207 grep "clone< version 2" log &&
208
209 # Client sent ref-prefixes to filter the ref-advertisement
210 grep "ref-prefix HEAD" log &&
211 grep "ref-prefix refs/heads/" log &&
212 grep "ref-prefix refs/tags/" log
685fbd32
BW
213'
214
215test_expect_success 'fetch with file:// using protocol v2' '
216 test_when_finished "rm -f log" &&
217
218 test_commit -C file_parent two &&
219
220 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
221 fetch origin &&
222
95cf2c01 223 git -C file_child log -1 --format=%s origin/main >actual &&
685fbd32
BW
224 git -C file_parent log -1 --format=%s >expect &&
225 test_cmp expect actual &&
226
227 # Server responded using protocol v2
228 grep "fetch< version 2" log
229'
230
4dc8b1c1 231test_expect_success 'ref advertisement is filtered during fetch using protocol v2' '
685fbd32
BW
232 test_when_finished "rm -f log" &&
233
234 test_commit -C file_parent three &&
2b554353 235 git -C file_parent branch unwanted-branch three &&
685fbd32
BW
236
237 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
95cf2c01 238 fetch origin main &&
685fbd32 239
95cf2c01 240 git -C file_child log -1 --format=%s origin/main >actual &&
685fbd32
BW
241 git -C file_parent log -1 --format=%s >expect &&
242 test_cmp expect actual &&
243
95cf2c01 244 grep "refs/heads/main" log &&
2b554353 245 ! grep "refs/heads/unwanted-branch" log
685fbd32
BW
246'
247
5e3548ef
BW
248test_expect_success 'server-options are sent when fetching' '
249 test_when_finished "rm -f log" &&
250
251 test_commit -C file_parent four &&
252
253 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
95cf2c01 254 fetch -o hello -o world origin main &&
5e3548ef 255
95cf2c01 256 git -C file_child log -1 --format=%s origin/main >actual &&
5e3548ef
BW
257 git -C file_parent log -1 --format=%s >expect &&
258 test_cmp expect actual &&
259
260 grep "server-option=hello" log &&
261 grep "server-option=world" log
262'
263
35eb8240
JT
264test_expect_success 'warn if using server-option with fetch with legacy protocol' '
265 test_when_finished "rm -rf temp_child" &&
266
267 git init temp_child &&
268
269 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C temp_child -c protocol.version=0 \
95cf2c01 270 fetch -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
35eb8240
JT
271
272 test_i18ngrep "see protocol.version in" err &&
273 test_i18ngrep "server options require protocol version 2 or later" err
274'
275
6e983059
JT
276test_expect_success 'server-options are sent when cloning' '
277 test_when_finished "rm -rf log myclone" &&
278
279 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
280 clone --server-option=hello --server-option=world \
281 "file://$(pwd)/file_parent" myclone &&
282
283 grep "server-option=hello" log &&
284 grep "server-option=world" log
285'
286
287test_expect_success 'warn if using server-option with clone with legacy protocol' '
288 test_when_finished "rm -rf myclone" &&
289
290 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
291 clone --server-option=hello --server-option=world \
292 "file://$(pwd)/file_parent" myclone 2>err &&
293
294 test_i18ngrep "see protocol.version in" err &&
295 test_i18ngrep "server options require protocol version 2 or later" err
296'
297
54592687
JT
298test_expect_success 'upload-pack respects config using protocol v2' '
299 git init server &&
300 write_script server/.git/hook <<-\EOF &&
301 touch hookout
302 "$@"
303 EOF
304 test_commit -C server one &&
305
306 test_config_global uploadpack.packobjectshook ./hook &&
307 test_path_is_missing server/.git/hookout &&
308 git -c protocol.version=2 clone "file://$(pwd)/server" client &&
309 test_path_is_file server/.git/hookout
310'
311
ba95710a
JT
312test_expect_success 'setup filter tests' '
313 rm -rf server client &&
314 git init server &&
315
316 # 1 commit to create a file, and 1 commit to modify it
317 test_commit -C server message1 a.txt &&
318 test_commit -C server message2 a.txt &&
319 git -C server config protocol.version 2 &&
320 git -C server config uploadpack.allowfilter 1 &&
321 git -C server config uploadpack.allowanysha1inwant 1 &&
322 git -C server config protocol.version 2
323'
324
325test_expect_success 'partial clone' '
326 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
327 clone --filter=blob:none "file://$(pwd)/server" client &&
328 grep "version 2" trace &&
329
330 # Ensure that the old version of the file is missing
95cf2c01 331 git -C client rev-list --quiet --objects --missing=print main \
ba95710a
JT
332 >observed.oids &&
333 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
334
335 # Ensure that client passes fsck
336 git -C client fsck
337'
338
339test_expect_success 'dynamically fetch missing object' '
340 rm "$(pwd)/trace" &&
341 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
342 cat-file -p $(git -C server rev-parse message1:a.txt) &&
343 grep "version 2" trace
344'
345
01775651
JT
346test_expect_success 'when dynamically fetching missing object, do not list refs' '
347 ! grep "git> command=ls-refs" trace
348'
349
ba95710a
JT
350test_expect_success 'partial fetch' '
351 rm -rf client "$(pwd)/trace" &&
352 git init client &&
353 SERVER="file://$(pwd)/server" &&
ba95710a
JT
354
355 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
95cf2c01 356 fetch --filter=blob:none "$SERVER" main:refs/heads/other &&
ba95710a
JT
357 grep "version 2" trace &&
358
359 # Ensure that the old version of the file is missing
8d6ba495 360 git -C client rev-list --quiet --objects --missing=print other \
ba95710a
JT
361 >observed.oids &&
362 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
363
364 # Ensure that client passes fsck
365 git -C client fsck
366'
367
368test_expect_success 'do not advertise filter if not configured to do so' '
369 SERVER="file://$(pwd)/server" &&
370
371 rm "$(pwd)/trace" &&
372 git -C server config uploadpack.allowfilter 1 &&
373 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
374 ls-remote "$SERVER" &&
375 grep "fetch=.*filter" trace &&
376
377 rm "$(pwd)/trace" &&
378 git -C server config uploadpack.allowfilter 0 &&
379 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
380 ls-remote "$SERVER" &&
381 grep "fetch=" trace >fetch_capabilities &&
382 ! grep filter fetch_capabilities
383'
384
385test_expect_success 'partial clone warns if filter is not advertised' '
386 rm -rf client &&
387 git -C server config uploadpack.allowfilter 0 &&
388 git -c protocol.version=2 \
389 clone --filter=blob:none "file://$(pwd)/server" client 2>err &&
390 test_i18ngrep "filtering not recognized by server, ignoring" err
391'
392
393test_expect_success 'even with handcrafted request, filter does not work if not advertised' '
394 git -C server config uploadpack.allowfilter 0 &&
395
396 # Custom request that tries to filter even though it is not advertised.
8ea40cc5 397 test-tool pkt-line pack >in <<-EOF &&
ba95710a 398 command=fetch
8fc70035 399 object-format=$(test_oid algo)
ba95710a 400 0001
95cf2c01 401 want $(git -C server rev-parse main)
ba95710a
JT
402 filter blob:none
403 0000
404 EOF
405
b7ce24d0
JS
406 test_must_fail test-tool -C server serve-v2 --stateless-rpc \
407 <in >/dev/null 2>err &&
ba95710a
JT
408 grep "unexpected line: .filter blob:none." err &&
409
410 # Exercise to ensure that if advertised, filter works
411 git -C server config uploadpack.allowfilter 1 &&
b7ce24d0 412 test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
ba95710a
JT
413'
414
dcc73cf7
BW
415test_expect_success 'default refspec is used to filter ref when fetchcing' '
416 test_when_finished "rm -f log" &&
417
418 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
419 fetch origin &&
420
421 git -C file_child log -1 --format=%s three >actual &&
422 git -C file_parent log -1 --format=%s three >expect &&
423 test_cmp expect actual &&
424
425 grep "ref-prefix refs/heads/" log &&
426 grep "ref-prefix refs/tags/" log
427'
428
15cfc985
JT
429test_expect_success 'fetch supports various ways of have lines' '
430 rm -rf server client trace &&
431 git init server &&
432 test_commit -C server dwim &&
433 TREE=$(git -C server rev-parse HEAD^{tree}) &&
434 git -C server tag exact \
435 $(git -C server commit-tree -m a "$TREE") &&
436 git -C server tag dwim-unwanted \
437 $(git -C server commit-tree -m b "$TREE") &&
438 git -C server tag exact-unwanted \
439 $(git -C server commit-tree -m c "$TREE") &&
440 git -C server tag prefix1 \
441 $(git -C server commit-tree -m d "$TREE") &&
442 git -C server tag prefix2 \
443 $(git -C server commit-tree -m e "$TREE") &&
444 git -C server tag fetch-by-sha1 \
445 $(git -C server commit-tree -m f "$TREE") &&
446 git -C server tag completely-unrelated \
447 $(git -C server commit-tree -m g "$TREE") &&
448
449 git init client &&
450 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
451 fetch "file://$(pwd)/server" \
452 dwim \
453 refs/tags/exact \
454 refs/tags/prefix*:refs/tags/prefix* \
455 "$(git -C server rev-parse fetch-by-sha1)" &&
456
457 # Ensure that the appropriate prefixes are sent (using a sample)
458 grep "fetch> ref-prefix dwim" trace &&
459 grep "fetch> ref-prefix refs/heads/dwim" trace &&
460 grep "fetch> ref-prefix refs/tags/prefix" trace &&
461
462 # Ensure that the correct objects are returned
463 git -C client cat-file -e $(git -C server rev-parse dwim) &&
464 git -C client cat-file -e $(git -C server rev-parse exact) &&
465 git -C client cat-file -e $(git -C server rev-parse prefix1) &&
466 git -C client cat-file -e $(git -C server rev-parse prefix2) &&
467 git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) &&
468 test_must_fail git -C client cat-file -e \
469 $(git -C server rev-parse dwim-unwanted) &&
470 test_must_fail git -C client cat-file -e \
471 $(git -C server rev-parse exact-unwanted) &&
472 test_must_fail git -C client cat-file -e \
473 $(git -C server rev-parse completely-unrelated)
474'
475
2b554353
JT
476test_expect_success 'fetch supports include-tag and tag following' '
477 rm -rf server client trace &&
478 git init server &&
479
480 test_commit -C server to_fetch &&
481 git -C server tag -a annotated_tag -m message &&
482
483 git init client &&
484 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
485 fetch "$(pwd)/server" to_fetch:to_fetch &&
486
487 grep "fetch> ref-prefix to_fetch" trace &&
488 grep "fetch> ref-prefix refs/tags/" trace &&
489 grep "fetch> include-tag" trace &&
490
491 git -C client cat-file -e $(git -C client rev-parse annotated_tag)
492'
493
d1035cac
JT
494test_expect_success 'upload-pack respects client shallows' '
495 rm -rf server client trace &&
496
497 git init server &&
498 test_commit -C server base &&
499 test_commit -C server client_has &&
500
501 git clone --depth=1 "file://$(pwd)/server" client &&
502
503 # Add extra commits to the client so that the whole fetch takes more
504 # than 1 request (due to negotiation)
9516345e 505 test_commit_bulk -C client --id=c 32 &&
d1035cac
JT
506
507 git -C server checkout -b newbranch base &&
508 test_commit -C server client_wants &&
509
510 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
511 fetch origin newbranch &&
512 # Ensure that protocol v2 is used
513 grep "fetch< version 2" trace
bd0b42ae
JT
514'
515
516test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
517 rm -rf server client trace &&
518
519 test_create_repo server &&
520 test_commit -C server one &&
521 test_commit -C server two &&
522 test_commit -C server three &&
523 git clone --shallow-exclude two "file://$(pwd)/server" client &&
524
525 git -C server tag -a -m "an annotated tag" twotag two &&
526
527 # Triggers tag following (thus, 2 fetches in one process)
528 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
529 fetch --shallow-exclude one origin &&
530 # Ensure that protocol v2 is used
531 grep "fetch< version 2" trace
d1035cac
JT
532'
533
5056cf4a
JT
534test_expect_success 'deepen-relative' '
535 rm -rf server client trace &&
536
537 test_create_repo server &&
538 test_commit -C server one &&
539 test_commit -C server two &&
540 test_commit -C server three &&
541 git clone --depth 1 "file://$(pwd)/server" client &&
542 test_commit -C server four &&
543
544 # Sanity check that only "three" is downloaded
95cf2c01 545 git -C client log --pretty=tformat:%s main >actual &&
5056cf4a
JT
546 echo three >expected &&
547 test_cmp expected actual &&
548
549 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
550 fetch --deepen=1 origin &&
551 # Ensure that protocol v2 is used
552 grep "fetch< version 2" trace &&
553
95cf2c01 554 git -C client log --pretty=tformat:%s origin/main >actual &&
5056cf4a
JT
555 cat >expected <<-\EOF &&
556 four
557 three
558 two
559 EOF
560 test_cmp expected actual
561'
562
0f1dc53f
BW
563# Test protocol v2 with 'http://' transport
564#
565. "$TEST_DIRECTORY"/lib-httpd.sh
566start_httpd
567
568test_expect_success 'create repo to be served by http:// transport' '
569 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
570 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
571 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
572'
573
574test_expect_success 'clone with http:// using protocol v2' '
575 test_when_finished "rm -f log" &&
576
577 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
578 clone "$HTTPD_URL/smart/http_parent" http_child &&
579
580 git -C http_child log -1 --format=%s >actual &&
581 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
582 test_cmp expect actual &&
583
584 # Client requested to use protocol v2
585 grep "Git-Protocol: version=2" log &&
586 # Server responded using protocol v2
a97d0079
JT
587 grep "git< version 2" log &&
588 # Verify that the chunked encoding sending codepath is NOT exercised
589 ! grep "Send header: Transfer-Encoding: chunked" log
590'
591
74b082ad
DL
592test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' '
593 test_when_finished "rm -f log" &&
594
595 git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" &&
596 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file &&
597
598 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
599 clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err &&
600
601 # Client requested to use protocol v2
602 grep "Git-Protocol: version=2" log &&
603 # Server responded using protocol v2
604 grep "git< version 2" log &&
605 # Client reported appropriate failure
606 test_i18ngrep "bytes of length header were received" err
607'
608
609test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' '
610 test_when_finished "rm -f log" &&
611
612 git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" &&
613 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file &&
614
615 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
616 clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err &&
617
618 # Client requested to use protocol v2
619 grep "Git-Protocol: version=2" log &&
620 # Server responded using protocol v2
621 grep "git< version 2" log &&
622 # Client reported appropriate failure
623 test_i18ngrep "bytes of body are still expected" err
624'
625
b0df0c16
DL
626test_expect_success 'clone with http:// using protocol v2 and invalid parameters' '
627 test_when_finished "rm -f log" &&
628
629 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \
630 git -c protocol.version=2 \
631 clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid &&
632
633 # Client requested to use protocol v2
634 grep "Git-Protocol: version=2" log &&
635 # Server responded using protocol v2
636 grep "git< version 2" log
637'
638
a97d0079
JT
639test_expect_success 'clone big repository with http:// using protocol v2' '
640 test_when_finished "rm -f log" &&
641
642 git init "$HTTPD_DOCUMENT_ROOT_PATH/big" &&
643 # Ensure that the list of wants is greater than http.postbuffer below
644 for i in $(test_seq 1 1500)
645 do
646 # do not use here-doc, because it requires a process
647 # per loop iteration
648 echo "commit refs/heads/too-many-refs-$i" &&
649 echo "committer git <git@example.com> $i +0000" &&
650 echo "data 0" &&
651 echo "M 644 inline bla.txt" &&
652 echo "data 4" &&
653 echo "bla"
654 done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
655
656 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
657 -c protocol.version=2 -c http.postbuffer=65536 \
658 clone "$HTTPD_URL/smart/big" big_child &&
659
660 # Client requested to use protocol v2
661 grep "Git-Protocol: version=2" log &&
662 # Server responded using protocol v2
663 grep "git< version 2" log &&
664 # Verify that the chunked encoding sending codepath is exercised
665 grep "Send header: Transfer-Encoding: chunked" log
0f1dc53f
BW
666'
667
668test_expect_success 'fetch with http:// using protocol v2' '
669 test_when_finished "rm -f log" &&
670
671 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
672
673 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
674 fetch &&
675
95cf2c01 676 git -C http_child log -1 --format=%s origin/main >actual &&
0f1dc53f
BW
677 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
678 test_cmp expect actual &&
679
680 # Server responded using protocol v2
681 grep "git< version 2" log
682'
683
ac3fda82
JT
684test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
685 test_when_finished "rm -f log" &&
686
687 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
688 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
689
690 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
691 fetch --no-tags origin $(cat two_a_hash) &&
692
693 grep "fetch< version 2" log &&
694 ! grep "fetch> command=ls-refs" log
695'
696
e2f41a0a
JT
697test_expect_success 'fetch from namespaced repo respects namespaces' '
698 test_when_finished "rm -f log" &&
699
700 git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
701 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
702 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
703 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
95cf2c01 704 update-ref refs/namespaces/ns/refs/heads/main one &&
e2f41a0a
JT
705
706 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
707 fetch "$HTTPD_URL/smart_namespace/nsrepo" \
95cf2c01 708 refs/heads/main:refs/heads/theirs &&
e2f41a0a
JT
709
710 # Server responded using protocol v2
711 grep "fetch< version 2" log &&
712
713 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
714 git -C http_child rev-parse theirs >actual &&
715 test_cmp expect actual
716'
717
4d8cab95
JK
718test_expect_success 'ls-remote with v2 http sends only one POST' '
719 test_when_finished "rm -f log" &&
720
721 git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect &&
722 GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
723 ls-remote "$HTTPD_URL/smart/http_parent" >actual &&
724 test_cmp expect actual &&
725
726 grep "Send header: POST" log >posts &&
727 test_line_count = 1 posts
728'
729
a4d78ce2
BW
730test_expect_success 'push with http:// and a config of v2 does not request v2' '
731 test_when_finished "rm -f log" &&
732 # Till v2 for push is designed, make sure that if a client has
733 # protocol.version configured to use v2, that the client instead falls
734 # back and uses v0.
735
736 test_commit -C http_child three &&
737
738 # Push to another branch, as the target repository has the
95cf2c01 739 # main branch checked out and we cannot push into it.
a4d78ce2
BW
740 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
741 push origin HEAD:client_branch &&
742
743 git -C http_child log -1 --format=%s >actual &&
744 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
745 test_cmp expect actual &&
746
7a40cf15 747 # Client did not request to use protocol v2
a4d78ce2 748 ! grep "Git-Protocol: version=2" log &&
7a40cf15 749 # Server did not respond using protocol v2
a4d78ce2
BW
750 ! grep "git< version 2" log
751'
752
5400b2a2
JT
753test_expect_success 'when server sends "ready", expect DELIM' '
754 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child &&
755
756 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
757 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
758
759 git clone "$HTTPD_URL/smart/http_parent" http_child &&
760
761 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
762
763 # After "ready" in the acknowledgments section, pretend that a FLUSH
764 # (0000) was sent instead of a DELIM (0001).
eafff6e4
JS
765 printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
766 >"$HTTPD_ROOT_PATH/one-time-perl" &&
5400b2a2
JT
767
768 test_must_fail git -C http_child -c protocol.version=2 \
eafff6e4 769 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
5400b2a2
JT
770 test_i18ngrep "expected packfile to be sent after .ready." err
771'
772
773test_expect_success 'when server does not send "ready", expect FLUSH' '
774 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child log &&
775
776 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
777 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
778
779 git clone "$HTTPD_URL/smart/http_parent" http_child &&
780
781 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
782
783 # Create many commits to extend the negotiation phase across multiple
784 # requests, so that the server does not send "ready" in the first
785 # request.
9516345e 786 test_commit_bulk -C http_child --id=c 32 &&
5400b2a2
JT
787
788 # After the acknowledgments section, pretend that a DELIM
789 # (0001) was sent instead of a FLUSH (0000).
eafff6e4
JS
790 printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
791 >"$HTTPD_ROOT_PATH/one-time-perl" &&
5400b2a2
JT
792
793 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
794 -c protocol.version=2 \
eafff6e4 795 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
07c3c2aa
JT
796 grep "fetch< .*acknowledgments" log &&
797 ! grep "fetch< .*ready" log &&
5400b2a2
JT
798 test_i18ngrep "expected no other sections to be sent after no .ready." err
799'
a4d78ce2 800
dd4b732d
JT
801configure_exclusion () {
802 git -C "$1" hash-object "$2" >objh &&
803 git -C "$1" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
804 git -C "$1" config --add \
805 "uploadpack.blobpackfileuri" \
806 "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
807 cat objh
808}
809
810test_expect_success 'part of packfile response provided as URI' '
811 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
812 rm -rf "$P" http_child log &&
813
814 git init "$P" &&
815 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
816
817 echo my-blob >"$P/my-blob" &&
818 git -C "$P" add my-blob &&
819 echo other-blob >"$P/other-blob" &&
820 git -C "$P" add other-blob &&
821 git -C "$P" commit -m x &&
822
823 configure_exclusion "$P" my-blob >h &&
824 configure_exclusion "$P" other-blob >h2 &&
825
826 GIT_TRACE=1 GIT_TRACE_PACKET="$(pwd)/log" GIT_TEST_SIDEBAND_ALL=1 \
827 git -c protocol.version=2 \
828 -c fetch.uriprotocols=http,https \
829 clone "$HTTPD_URL/smart/http_parent" http_child &&
830
831 # Ensure that my-blob and other-blob are in separate packfiles.
832 for idx in http_child/.git/objects/pack/*.idx
833 do
e74b606d 834 git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
dd4b732d
JT
835 {
836 grep "^[0-9a-f]\{16,\} " out || :
837 } >out.objectlist &&
838 if test_line_count = 1 out.objectlist
839 then
840 if grep $(cat h) out
841 then
842 >hfound
843 fi &&
844 if grep $(cat h2) out
845 then
846 >h2found
847 fi
848 fi
849 done &&
850 test -f hfound &&
851 test -f h2found &&
852
853 # Ensure that there are exactly 6 files (3 .pack and 3 .idx).
854 ls http_child/.git/objects/pack/* >filelist &&
855 test_line_count = 6 filelist
856'
857
858test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
859 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
860 rm -rf "$P" http_child log &&
861
862 git init "$P" &&
863 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
864
865 echo my-blob >"$P/my-blob" &&
866 git -C "$P" add my-blob &&
867 echo other-blob >"$P/other-blob" &&
868 git -C "$P" add other-blob &&
869 git -C "$P" commit -m x &&
870
871 configure_exclusion "$P" my-blob >h &&
872 # Configure a URL for other-blob. Just reuse the hash of the object as
873 # the hash of the packfile, since the hash does not matter for this
874 # test as long as it is not the hash of the pack, and it is of the
875 # expected length.
876 git -C "$P" hash-object other-blob >objh &&
877 git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
878 git -C "$P" config --add \
879 "uploadpack.blobpackfileuri" \
880 "$(cat objh) $(cat objh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
881
882 test_must_fail env GIT_TEST_SIDEBAND_ALL=1 \
883 git -c protocol.version=2 \
884 -c fetch.uriprotocols=http,https \
885 clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
886 test_i18ngrep "pack downloaded from.*does not match expected hash" err
887'
888
0bd96bea
JT
889test_expect_success 'packfile-uri with transfer.fsckobjects' '
890 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
891 rm -rf "$P" http_child log &&
892
893 git init "$P" &&
894 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
895
896 echo my-blob >"$P/my-blob" &&
897 git -C "$P" add my-blob &&
898 git -C "$P" commit -m x &&
899
900 configure_exclusion "$P" my-blob >h &&
901
902 sane_unset GIT_TEST_SIDEBAND_ALL &&
903 git -c protocol.version=2 -c transfer.fsckobjects=1 \
904 -c fetch.uriprotocols=http,https \
905 clone "$HTTPD_URL/smart/http_parent" http_child &&
906
907 # Ensure that there are exactly 4 files (2 .pack and 2 .idx).
908 ls http_child/.git/objects/pack/* >filelist &&
909 test_line_count = 4 filelist
910'
911
912test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' '
913 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
914 rm -rf "$P" http_child log &&
915
916 git init "$P" &&
917 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
918
919 cat >bogus-commit <<-EOF &&
920 tree $EMPTY_TREE
921 author Bugs Bunny 1234567890 +0000
922 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
923
924 This commit object intentionally broken
925 EOF
926 BOGUS=$(git -C "$P" hash-object -t commit -w --stdin <bogus-commit) &&
927 git -C "$P" branch bogus-branch "$BOGUS" &&
928
929 echo my-blob >"$P/my-blob" &&
930 git -C "$P" add my-blob &&
931 git -C "$P" commit -m x &&
932
933 configure_exclusion "$P" my-blob >h &&
934
935 sane_unset GIT_TEST_SIDEBAND_ALL &&
936 test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
937 -c fetch.uriprotocols=http,https \
938 clone "$HTTPD_URL/smart/http_parent" http_child 2>error &&
939 test_i18ngrep "invalid author/committer line - missing email" error
940'
941
decfe05b
SG
942# DO NOT add non-httpd-specific tests here, because the last part of this
943# test script is only executed when httpd is available and enabled.
944
e52449b6 945test_done