]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5702-protocol-v2.sh
parse-options: simplify positivation handling
[thirdparty/git.git] / t / t5702-protocol-v2.sh
1 #!/bin/sh
2
3 test_description='test git wire-protocol version 2'
4
5 TEST_NO_CREATE_REPO=1
6
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10 . ./test-lib.sh
11
12 # Test protocol v2 with 'git://' transport
13 #
14 . "$TEST_DIRECTORY"/lib-git-daemon.sh
15 start_git_daemon --export-all --enable=receive-pack
16 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
17
18 test_expect_success 'create repo to be served by git-daemon' '
19 git init "$daemon_parent" &&
20 test_commit -C "$daemon_parent" one
21 '
22
23 test_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 "ls-remote> .*\\\0\\\0version=2\\\0$" log &&
31 # Server responded using protocol v2
32 grep "ls-remote< version 2" log &&
33
34 git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
35 test_cmp expect actual
36 '
37
38 test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
39 test_when_finished "rm -f log" &&
40
41 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
42 ls-remote "$GIT_DAEMON_URL/parent" main >actual &&
43
44 cat >expect <<-EOF &&
45 $(git -C "$daemon_parent" rev-parse refs/heads/main)$(printf "\t")refs/heads/main
46 EOF
47
48 test_cmp expect actual
49 '
50
51 test_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
67 test_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
75 git -C daemon_child log -1 --format=%s origin/main >actual &&
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
85 test_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
98 test_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
114 test_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
124 # main branch checked out and we cannot push into it.
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
138 stop_git_daemon
139
140 # Test protocol v2 with 'file://' transport
141 #
142 test_expect_success 'create repo to be served by file:// transport' '
143 git init file_parent &&
144 test_commit -C file_parent one
145 '
146
147 test_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 "ls-remote< version 2" log &&
155
156 git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
157 test_cmp expect actual
158 '
159
160 test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
161 test_when_finished "rm -f log" &&
162
163 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
164 ls-remote "file://$(pwd)/file_parent" main >actual &&
165
166 cat >expect <<-EOF &&
167 $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
168 EOF
169
170 test_cmp expect actual
171 '
172
173 test_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 \
177 ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual &&
178
179 cat >expect <<-EOF &&
180 $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
181 EOF
182
183 test_cmp expect actual &&
184 grep "server-option=hello" log &&
185 grep "server-option=world" log
186 '
187
188 test_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 \
190 ls-remote -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
191
192 test_grep "see protocol.version in" err &&
193 test_grep "server options require protocol version 2 or later" err
194 '
195
196 test_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
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
213 '
214
215 test_expect_success 'clone of empty repo propagates name of default branch' '
216 test_when_finished "rm -rf file_empty_parent file_empty_child" &&
217
218 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
219 git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
220
221 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
222 git -c init.defaultBranch=main -c protocol.version=2 \
223 clone "file://$(pwd)/file_empty_parent" file_empty_child &&
224 grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD
225 '
226
227 test_expect_success '...but not if explicitly forbidden by config' '
228 test_when_finished "rm -rf file_empty_parent file_empty_child" &&
229
230 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
231 git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
232 test_config -C file_empty_parent lsrefs.unborn ignore &&
233
234 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
235 git -c init.defaultBranch=main -c protocol.version=2 \
236 clone "file://$(pwd)/file_empty_parent" file_empty_child &&
237 ! grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD
238 '
239
240 test_expect_success 'bare clone propagates empty default branch' '
241 test_when_finished "rm -rf file_empty_parent file_empty_child.git" &&
242
243 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
244 git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
245
246 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
247 git -c init.defaultBranch=main -c protocol.version=2 \
248 clone --bare \
249 "file://$(pwd)/file_empty_parent" file_empty_child.git &&
250 grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD
251 '
252
253 test_expect_success 'clone propagates unborn HEAD from non-empty repo' '
254 test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
255
256 git init file_unborn_parent &&
257 (
258 cd file_unborn_parent &&
259 git checkout -b branchwithstuff &&
260 test_commit --no-tag stuff &&
261 git symbolic-ref HEAD refs/heads/mydefaultbranch
262 ) &&
263
264 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
265 git -c init.defaultBranch=main -c protocol.version=2 \
266 clone "file://$(pwd)/file_unborn_parent" \
267 file_unborn_child 2>stderr &&
268 grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD &&
269 grep "warning: remote HEAD refers to nonexistent ref" stderr
270 '
271
272 test_expect_success 'clone propagates object-format from empty repo' '
273 test_when_finished "rm -fr src256 dst256" &&
274
275 echo sha256 >expect &&
276 git init --object-format=sha256 src256 &&
277 git clone src256 dst256 &&
278 git -C dst256 rev-parse --show-object-format >actual &&
279
280 test_cmp expect actual
281 '
282
283 test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
284 test_when_finished "rm -rf file_unborn_parent file_unborn_child.git" &&
285
286 git init file_unborn_parent &&
287 (
288 cd file_unborn_parent &&
289 git checkout -b branchwithstuff &&
290 test_commit --no-tag stuff &&
291 git symbolic-ref HEAD refs/heads/mydefaultbranch
292 ) &&
293
294 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
295 git -c init.defaultBranch=main -c protocol.version=2 \
296 clone --bare "file://$(pwd)/file_unborn_parent" \
297 file_unborn_child.git 2>stderr &&
298 grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD &&
299 ! grep "warning:" stderr
300 '
301
302 test_expect_success 'defaulted HEAD uses remote branch if available' '
303 test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
304
305 git init file_unborn_parent &&
306 (
307 cd file_unborn_parent &&
308 git config lsrefs.unborn ignore &&
309 git checkout -b branchwithstuff &&
310 test_commit --no-tag stuff &&
311 git symbolic-ref HEAD refs/heads/mydefaultbranch
312 ) &&
313
314 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
315 git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \
316 clone "file://$(pwd)/file_unborn_parent" \
317 file_unborn_child 2>stderr &&
318 grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD &&
319 test_path_is_file file_unborn_child/stuff.t &&
320 ! grep "warning:" stderr
321 '
322
323 test_expect_success 'fetch with file:// using protocol v2' '
324 test_when_finished "rm -f log" &&
325
326 test_commit -C file_parent two &&
327
328 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
329 fetch origin &&
330
331 git -C file_child log -1 --format=%s origin/main >actual &&
332 git -C file_parent log -1 --format=%s >expect &&
333 test_cmp expect actual &&
334
335 # Server responded using protocol v2
336 grep "fetch< version 2" log
337 '
338
339 test_expect_success 'ref advertisement is filtered during fetch using protocol v2' '
340 test_when_finished "rm -f log" &&
341
342 test_commit -C file_parent three &&
343 git -C file_parent branch unwanted-branch three &&
344
345 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
346 fetch origin main &&
347
348 git -C file_child log -1 --format=%s origin/main >actual &&
349 git -C file_parent log -1 --format=%s >expect &&
350 test_cmp expect actual &&
351
352 grep "refs/heads/main" log &&
353 ! grep "refs/heads/unwanted-branch" log
354 '
355
356 test_expect_success 'server-options are sent when fetching' '
357 test_when_finished "rm -f log" &&
358
359 test_commit -C file_parent four &&
360
361 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
362 fetch -o hello -o world origin main &&
363
364 git -C file_child log -1 --format=%s origin/main >actual &&
365 git -C file_parent log -1 --format=%s >expect &&
366 test_cmp expect actual &&
367
368 grep "server-option=hello" log &&
369 grep "server-option=world" log
370 '
371
372 test_expect_success 'warn if using server-option with fetch with legacy protocol' '
373 test_when_finished "rm -rf temp_child" &&
374
375 git init temp_child &&
376
377 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C temp_child -c protocol.version=0 \
378 fetch -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
379
380 test_grep "see protocol.version in" err &&
381 test_grep "server options require protocol version 2 or later" err
382 '
383
384 test_expect_success 'server-options are sent when cloning' '
385 test_when_finished "rm -rf log myclone" &&
386
387 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
388 clone --server-option=hello --server-option=world \
389 "file://$(pwd)/file_parent" myclone &&
390
391 grep "server-option=hello" log &&
392 grep "server-option=world" log
393 '
394
395 test_expect_success 'warn if using server-option with clone with legacy protocol' '
396 test_when_finished "rm -rf myclone" &&
397
398 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
399 clone --server-option=hello --server-option=world \
400 "file://$(pwd)/file_parent" myclone 2>err &&
401
402 test_grep "see protocol.version in" err &&
403 test_grep "server options require protocol version 2 or later" err
404 '
405
406 test_expect_success 'upload-pack respects config using protocol v2' '
407 git init server &&
408 write_script server/.git/hook <<-\EOF &&
409 touch hookout
410 "$@"
411 EOF
412 test_commit -C server one &&
413
414 test_config_global uploadpack.packobjectshook ./hook &&
415 test_path_is_missing server/.git/hookout &&
416 git -c protocol.version=2 clone "file://$(pwd)/server" client &&
417 test_path_is_file server/.git/hookout
418 '
419
420 test_expect_success 'setup filter tests' '
421 rm -rf server client &&
422 git init server &&
423
424 # 1 commit to create a file, and 1 commit to modify it
425 test_commit -C server message1 a.txt &&
426 test_commit -C server message2 a.txt &&
427 git -C server config protocol.version 2 &&
428 git -C server config uploadpack.allowfilter 1 &&
429 git -C server config uploadpack.allowanysha1inwant 1 &&
430 git -C server config protocol.version 2
431 '
432
433 test_expect_success 'partial clone' '
434 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
435 clone --filter=blob:none "file://$(pwd)/server" client &&
436 grep "version 2" trace &&
437
438 # Ensure that the old version of the file is missing
439 git -C client rev-list --quiet --objects --missing=print main \
440 >observed.oids &&
441 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
442
443 # Ensure that client passes fsck
444 git -C client fsck
445 '
446
447 test_expect_success 'dynamically fetch missing object' '
448 rm "$(pwd)/trace" &&
449 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
450 cat-file -p $(git -C server rev-parse message1:a.txt) &&
451 grep "version 2" trace
452 '
453
454 test_expect_success 'when dynamically fetching missing object, do not list refs' '
455 ! grep "git> command=ls-refs" trace
456 '
457
458 test_expect_success 'partial fetch' '
459 rm -rf client "$(pwd)/trace" &&
460 git init client &&
461 SERVER="file://$(pwd)/server" &&
462
463 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
464 fetch --filter=blob:none "$SERVER" main:refs/heads/other &&
465 grep "version 2" trace &&
466
467 # Ensure that the old version of the file is missing
468 git -C client rev-list --quiet --objects --missing=print other \
469 >observed.oids &&
470 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
471
472 # Ensure that client passes fsck
473 git -C client fsck
474 '
475
476 test_expect_success 'do not advertise filter if not configured to do so' '
477 SERVER="file://$(pwd)/server" &&
478
479 rm "$(pwd)/trace" &&
480 git -C server config uploadpack.allowfilter 1 &&
481 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
482 ls-remote "$SERVER" &&
483 grep "fetch=.*filter" trace &&
484
485 rm "$(pwd)/trace" &&
486 git -C server config uploadpack.allowfilter 0 &&
487 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
488 ls-remote "$SERVER" &&
489 grep "fetch=" trace >fetch_capabilities &&
490 ! grep filter fetch_capabilities
491 '
492
493 test_expect_success 'partial clone warns if filter is not advertised' '
494 rm -rf client &&
495 git -C server config uploadpack.allowfilter 0 &&
496 git -c protocol.version=2 \
497 clone --filter=blob:none "file://$(pwd)/server" client 2>err &&
498 test_grep "filtering not recognized by server, ignoring" err
499 '
500
501 test_expect_success 'even with handcrafted request, filter does not work if not advertised' '
502 git -C server config uploadpack.allowfilter 0 &&
503
504 # Custom request that tries to filter even though it is not advertised.
505 test-tool pkt-line pack >in <<-EOF &&
506 command=fetch
507 object-format=$(test_oid algo)
508 0001
509 want $(git -C server rev-parse main)
510 filter blob:none
511 0000
512 EOF
513
514 test_must_fail test-tool -C server serve-v2 --stateless-rpc \
515 <in >/dev/null 2>err &&
516 grep "unexpected line: .filter blob:none." err &&
517
518 # Exercise to ensure that if advertised, filter works
519 git -C server config uploadpack.allowfilter 1 &&
520 test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
521 '
522
523 test_expect_success 'default refspec is used to filter ref when fetchcing' '
524 test_when_finished "rm -f log" &&
525
526 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
527 fetch origin &&
528
529 git -C file_child log -1 --format=%s three >actual &&
530 git -C file_parent log -1 --format=%s three >expect &&
531 test_cmp expect actual &&
532
533 grep "ref-prefix refs/heads/" log &&
534 grep "ref-prefix refs/tags/" log
535 '
536
537 test_expect_success 'fetch supports various ways of have lines' '
538 rm -rf server client trace &&
539 git init server &&
540 test_commit -C server dwim &&
541 TREE=$(git -C server rev-parse HEAD^{tree}) &&
542 git -C server tag exact \
543 $(git -C server commit-tree -m a "$TREE") &&
544 git -C server tag dwim-unwanted \
545 $(git -C server commit-tree -m b "$TREE") &&
546 git -C server tag exact-unwanted \
547 $(git -C server commit-tree -m c "$TREE") &&
548 git -C server tag prefix1 \
549 $(git -C server commit-tree -m d "$TREE") &&
550 git -C server tag prefix2 \
551 $(git -C server commit-tree -m e "$TREE") &&
552 git -C server tag fetch-by-sha1 \
553 $(git -C server commit-tree -m f "$TREE") &&
554 git -C server tag completely-unrelated \
555 $(git -C server commit-tree -m g "$TREE") &&
556
557 git init client &&
558 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
559 fetch "file://$(pwd)/server" \
560 dwim \
561 refs/tags/exact \
562 refs/tags/prefix*:refs/tags/prefix* \
563 "$(git -C server rev-parse fetch-by-sha1)" &&
564
565 # Ensure that the appropriate prefixes are sent (using a sample)
566 grep "fetch> ref-prefix dwim" trace &&
567 grep "fetch> ref-prefix refs/heads/dwim" trace &&
568 grep "fetch> ref-prefix refs/tags/prefix" trace &&
569
570 # Ensure that the correct objects are returned
571 git -C client cat-file -e $(git -C server rev-parse dwim) &&
572 git -C client cat-file -e $(git -C server rev-parse exact) &&
573 git -C client cat-file -e $(git -C server rev-parse prefix1) &&
574 git -C client cat-file -e $(git -C server rev-parse prefix2) &&
575 git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) &&
576 test_must_fail git -C client cat-file -e \
577 $(git -C server rev-parse dwim-unwanted) &&
578 test_must_fail git -C client cat-file -e \
579 $(git -C server rev-parse exact-unwanted) &&
580 test_must_fail git -C client cat-file -e \
581 $(git -C server rev-parse completely-unrelated)
582 '
583
584 test_expect_success 'fetch supports include-tag and tag following' '
585 rm -rf server client trace &&
586 git init server &&
587
588 test_commit -C server to_fetch &&
589 git -C server tag -a annotated_tag -m message &&
590
591 git init client &&
592 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
593 fetch "$(pwd)/server" to_fetch:to_fetch &&
594
595 grep "fetch> ref-prefix to_fetch" trace &&
596 grep "fetch> ref-prefix refs/tags/" trace &&
597 grep "fetch> include-tag" trace &&
598
599 git -C client cat-file -e $(git -C client rev-parse annotated_tag)
600 '
601
602 test_expect_success 'upload-pack respects client shallows' '
603 rm -rf server client trace &&
604
605 git init server &&
606 test_commit -C server base &&
607 test_commit -C server client_has &&
608
609 git clone --depth=1 "file://$(pwd)/server" client &&
610
611 # Add extra commits to the client so that the whole fetch takes more
612 # than 1 request (due to negotiation)
613 test_commit_bulk -C client --id=c 32 &&
614
615 git -C server checkout -b newbranch base &&
616 test_commit -C server client_wants &&
617
618 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
619 fetch origin newbranch &&
620 # Ensure that protocol v2 is used
621 grep "fetch< version 2" trace
622 '
623
624 test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
625 rm -rf server client trace &&
626
627 test_create_repo server &&
628 test_commit -C server one &&
629 test_commit -C server two &&
630 test_commit -C server three &&
631 git clone --shallow-exclude two "file://$(pwd)/server" client &&
632
633 git -C server tag -a -m "an annotated tag" twotag two &&
634
635 # Triggers tag following (thus, 2 fetches in one process)
636 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
637 fetch --shallow-exclude one origin &&
638 # Ensure that protocol v2 is used
639 grep "fetch< version 2" trace
640 '
641
642 test_expect_success 'deepen-relative' '
643 rm -rf server client trace &&
644
645 test_create_repo server &&
646 test_commit -C server one &&
647 test_commit -C server two &&
648 test_commit -C server three &&
649 git clone --depth 1 "file://$(pwd)/server" client &&
650 test_commit -C server four &&
651
652 # Sanity check that only "three" is downloaded
653 git -C client log --pretty=tformat:%s main >actual &&
654 echo three >expected &&
655 test_cmp expected actual &&
656
657 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
658 fetch --deepen=1 origin &&
659 # Ensure that protocol v2 is used
660 grep "fetch< version 2" trace &&
661
662 git -C client log --pretty=tformat:%s origin/main >actual &&
663 cat >expected <<-\EOF &&
664 four
665 three
666 two
667 EOF
668 test_cmp expected actual
669 '
670
671 setup_negotiate_only () {
672 SERVER="$1"
673 URI="$2"
674
675 rm -rf "$SERVER" client
676
677 git init "$SERVER"
678 test_commit -C "$SERVER" one
679 test_commit -C "$SERVER" two
680
681 git clone "$URI" client
682 test_commit -C client three
683 }
684
685 test_expect_success 'usage: --negotiate-only without --negotiation-tip' '
686 SERVER="server" &&
687 URI="file://$(pwd)/server" &&
688
689 setup_negotiate_only "$SERVER" "$URI" &&
690
691 cat >err.expect <<-\EOF &&
692 fatal: --negotiate-only needs one or more --negotiation-tip=*
693 EOF
694
695 test_must_fail git -c protocol.version=2 -C client fetch \
696 --negotiate-only \
697 origin 2>err.actual &&
698 test_cmp err.expect err.actual
699 '
700
701 test_expect_success 'usage: --negotiate-only with --recurse-submodules' '
702 cat >err.expect <<-\EOF &&
703 fatal: options '\''--negotiate-only'\'' and '\''--recurse-submodules'\'' cannot be used together
704 EOF
705
706 test_must_fail git -c protocol.version=2 -C client fetch \
707 --negotiate-only \
708 --recurse-submodules \
709 origin 2>err.actual &&
710 test_cmp err.expect err.actual
711 '
712
713 test_expect_success 'file:// --negotiate-only' '
714 SERVER="server" &&
715 URI="file://$(pwd)/server" &&
716
717 setup_negotiate_only "$SERVER" "$URI" &&
718
719 git -c protocol.version=2 -C client fetch \
720 --no-tags \
721 --negotiate-only \
722 --negotiation-tip=$(git -C client rev-parse HEAD) \
723 origin >out &&
724 COMMON=$(git -C "$SERVER" rev-parse two) &&
725 grep "$COMMON" out
726 '
727
728 test_expect_success 'file:// --negotiate-only with protocol v0' '
729 SERVER="server" &&
730 URI="file://$(pwd)/server" &&
731
732 setup_negotiate_only "$SERVER" "$URI" &&
733
734 test_must_fail git -c protocol.version=0 -C client fetch \
735 --no-tags \
736 --negotiate-only \
737 --negotiation-tip=$(git -C client rev-parse HEAD) \
738 origin 2>err &&
739 test_grep "negotiate-only requires protocol v2" err
740 '
741
742 test_expect_success 'push with custom path does not request v2' '
743 rm -f env.trace &&
744 git -C client push \
745 --receive-pack="env >../env.trace; git-receive-pack" \
746 origin HEAD:refs/heads/custom-push-test &&
747 test_path_is_file env.trace &&
748 ! grep ^GIT_PROTOCOL env.trace
749 '
750
751 test_expect_success 'fetch with custom path does request v2' '
752 rm -f env.trace &&
753 git -C client fetch \
754 --upload-pack="env >../env.trace; git-upload-pack" \
755 origin HEAD &&
756 grep ^GIT_PROTOCOL=version=2 env.trace
757 '
758
759 test_expect_success 'archive with custom path does not request v2' '
760 rm -f env.trace &&
761 git -C client archive \
762 --exec="env >../env.trace; git-upload-archive" \
763 --remote=origin \
764 HEAD >/dev/null &&
765 test_path_is_file env.trace &&
766 ! grep ^GIT_PROTOCOL env.trace
767 '
768
769 # Test protocol v2 with 'http://' transport
770 #
771 . "$TEST_DIRECTORY"/lib-httpd.sh
772 start_httpd
773
774 test_expect_success 'create repo to be served by http:// transport' '
775 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
776 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
777 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
778 '
779
780 test_expect_success 'clone with http:// using protocol v2' '
781 test_when_finished "rm -f log" &&
782
783 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
784 clone "$HTTPD_URL/smart/http_parent" http_child &&
785
786 git -C http_child log -1 --format=%s >actual &&
787 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
788 test_cmp expect actual &&
789
790 # Client requested to use protocol v2
791 grep "Git-Protocol: version=2" log &&
792 # Server responded using protocol v2
793 grep "git< version 2" log &&
794 # Verify that the chunked encoding sending codepath is NOT exercised
795 ! grep "Send header: Transfer-Encoding: chunked" log
796 '
797
798 test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' '
799 test_when_finished "rm -f log" &&
800
801 git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" &&
802 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file &&
803
804 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
805 clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err &&
806
807 # Client requested to use protocol v2
808 grep "Git-Protocol: version=2" log &&
809 # Server responded using protocol v2
810 grep "git< version 2" log &&
811 # Client reported appropriate failure
812 test_grep "bytes of length header were received" err
813 '
814
815 test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' '
816 test_when_finished "rm -f log" &&
817
818 git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" &&
819 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file &&
820
821 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
822 clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err &&
823
824 # Client requested to use protocol v2
825 grep "Git-Protocol: version=2" log &&
826 # Server responded using protocol v2
827 grep "git< version 2" log &&
828 # Client reported appropriate failure
829 test_grep "bytes of body are still expected" err
830 '
831
832 test_expect_success 'clone with http:// using protocol v2 and invalid parameters' '
833 test_when_finished "rm -f log" &&
834
835 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \
836 git -c protocol.version=2 \
837 clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid &&
838
839 # Client requested to use protocol v2
840 grep "Git-Protocol: version=2" log &&
841 # Server responded using protocol v2
842 grep "git< version 2" log
843 '
844
845 test_expect_success 'clone big repository with http:// using protocol v2' '
846 test_when_finished "rm -f log" &&
847
848 git init "$HTTPD_DOCUMENT_ROOT_PATH/big" &&
849 # Ensure that the list of wants is greater than http.postbuffer below
850 for i in $(test_seq 1 1500)
851 do
852 # do not use here-doc, because it requires a process
853 # per loop iteration
854 echo "commit refs/heads/too-many-refs-$i" &&
855 echo "committer git <git@example.com> $i +0000" &&
856 echo "data 0" &&
857 echo "M 644 inline bla.txt" &&
858 echo "data 4" &&
859 echo "bla" || return 1
860 done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
861
862 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
863 -c protocol.version=2 -c http.postbuffer=65536 \
864 clone "$HTTPD_URL/smart/big" big_child &&
865
866 # Client requested to use protocol v2
867 grep "Git-Protocol: version=2" log &&
868 # Server responded using protocol v2
869 grep "git< version 2" log &&
870 # Verify that the chunked encoding sending codepath is exercised
871 grep "Send header: Transfer-Encoding: chunked" log
872 '
873
874 test_expect_success 'fetch with http:// using protocol v2' '
875 test_when_finished "rm -f log" &&
876
877 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
878
879 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
880 fetch &&
881
882 git -C http_child log -1 --format=%s origin/main >actual &&
883 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
884 test_cmp expect actual &&
885
886 # Server responded using protocol v2
887 grep "git< version 2" log
888 '
889
890 test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
891 test_when_finished "rm -f log" &&
892
893 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
894 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
895
896 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
897 fetch --no-tags origin $(cat two_a_hash) &&
898
899 grep "fetch< version 2" log &&
900 ! grep "fetch> command=ls-refs" log
901 '
902
903 test_expect_success 'fetch from namespaced repo respects namespaces' '
904 test_when_finished "rm -f log" &&
905
906 git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
907 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
908 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
909 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
910 update-ref refs/namespaces/ns/refs/heads/main one &&
911
912 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
913 fetch "$HTTPD_URL/smart_namespace/nsrepo" \
914 refs/heads/main:refs/heads/theirs &&
915
916 # Server responded using protocol v2
917 grep "fetch< version 2" log &&
918
919 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
920 git -C http_child rev-parse theirs >actual &&
921 test_cmp expect actual
922 '
923
924 test_expect_success 'ls-remote with v2 http sends only one POST' '
925 test_when_finished "rm -f log" &&
926
927 git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect &&
928 GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
929 ls-remote "$HTTPD_URL/smart/http_parent" >actual &&
930 test_cmp expect actual &&
931
932 grep "Send header: POST" log >posts &&
933 test_line_count = 1 posts
934 '
935
936 test_expect_success 'push with http:// and a config of v2 does not request v2' '
937 test_when_finished "rm -f log" &&
938 # Till v2 for push is designed, make sure that if a client has
939 # protocol.version configured to use v2, that the client instead falls
940 # back and uses v0.
941
942 test_commit -C http_child three &&
943
944 # Push to another branch, as the target repository has the
945 # main branch checked out and we cannot push into it.
946 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
947 push origin HEAD:client_branch &&
948
949 git -C http_child log -1 --format=%s >actual &&
950 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
951 test_cmp expect actual &&
952
953 # Client did not request to use protocol v2
954 ! grep "Git-Protocol: version=2" log &&
955 # Server did not respond using protocol v2
956 ! grep "git< version 2" log
957 '
958
959 test_expect_success 'when server sends "ready", expect DELIM' '
960 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child &&
961
962 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
963 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
964
965 git clone "$HTTPD_URL/smart/http_parent" http_child &&
966
967 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
968
969 # After "ready" in the acknowledgments section, pretend that a FLUSH
970 # (0000) was sent instead of a DELIM (0001).
971 printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
972 >"$HTTPD_ROOT_PATH/one-time-perl" &&
973
974 test_must_fail git -C http_child -c protocol.version=2 \
975 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
976 test_grep "expected packfile to be sent after .ready." err
977 '
978
979 test_expect_success 'when server does not send "ready", expect FLUSH' '
980 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child log &&
981
982 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
983 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
984
985 git clone "$HTTPD_URL/smart/http_parent" http_child &&
986
987 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
988
989 # Create many commits to extend the negotiation phase across multiple
990 # requests, so that the server does not send "ready" in the first
991 # request.
992 test_commit_bulk -C http_child --id=c 32 &&
993
994 # After the acknowledgments section, pretend that a DELIM
995 # (0001) was sent instead of a FLUSH (0000).
996 printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
997 >"$HTTPD_ROOT_PATH/one-time-perl" &&
998
999 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
1000 -c protocol.version=2 \
1001 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
1002 grep "fetch< .*acknowledgments" log &&
1003 ! grep "fetch< .*ready" log &&
1004 test_grep "expected no other sections to be sent after no .ready." err
1005 '
1006
1007 configure_exclusion () {
1008 git -C "$1" hash-object "$2" >objh &&
1009 git -C "$1" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
1010 git -C "$1" config --add \
1011 "uploadpack.blobpackfileuri" \
1012 "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
1013 cat objh
1014 }
1015
1016 test_expect_success 'part of packfile response provided as URI' '
1017 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1018 rm -rf "$P" http_child log &&
1019
1020 git init "$P" &&
1021 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1022
1023 echo my-blob >"$P/my-blob" &&
1024 git -C "$P" add my-blob &&
1025 echo other-blob >"$P/other-blob" &&
1026 git -C "$P" add other-blob &&
1027 git -C "$P" commit -m x &&
1028
1029 configure_exclusion "$P" my-blob >h &&
1030 configure_exclusion "$P" other-blob >h2 &&
1031
1032 GIT_TRACE=1 GIT_TRACE_PACKET="$(pwd)/log" GIT_TEST_SIDEBAND_ALL=1 \
1033 git -c protocol.version=2 \
1034 -c fetch.uriprotocols=http,https \
1035 clone "$HTTPD_URL/smart/http_parent" http_child &&
1036
1037 # Ensure that my-blob and other-blob are in separate packfiles.
1038 for idx in http_child/.git/objects/pack/*.idx
1039 do
1040 git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
1041 {
1042 grep -E "^[0-9a-f]{16,} " out || :
1043 } >out.objectlist &&
1044 if test_line_count = 1 out.objectlist
1045 then
1046 if grep $(cat h) out
1047 then
1048 >hfound
1049 fi &&
1050 if grep $(cat h2) out
1051 then
1052 >h2found
1053 fi
1054 fi || return 1
1055 done &&
1056 test -f hfound &&
1057 test -f h2found &&
1058
1059 # Ensure that there are exactly 3 packfiles with associated .idx
1060 ls http_child/.git/objects/pack/*.pack \
1061 http_child/.git/objects/pack/*.idx >filelist &&
1062 test_line_count = 6 filelist
1063 '
1064
1065 test_expect_success 'packfile URIs with fetch instead of clone' '
1066 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1067 rm -rf "$P" http_child log &&
1068
1069 git init "$P" &&
1070 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1071
1072 echo my-blob >"$P/my-blob" &&
1073 git -C "$P" add my-blob &&
1074 git -C "$P" commit -m x &&
1075
1076 configure_exclusion "$P" my-blob >h &&
1077
1078 git init http_child &&
1079
1080 GIT_TEST_SIDEBAND_ALL=1 \
1081 git -C http_child -c protocol.version=2 \
1082 -c fetch.uriprotocols=http,https \
1083 fetch "$HTTPD_URL/smart/http_parent"
1084 '
1085
1086 test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
1087 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1088 rm -rf "$P" http_child log &&
1089
1090 git init "$P" &&
1091 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1092
1093 echo my-blob >"$P/my-blob" &&
1094 git -C "$P" add my-blob &&
1095 echo other-blob >"$P/other-blob" &&
1096 git -C "$P" add other-blob &&
1097 git -C "$P" commit -m x &&
1098
1099 configure_exclusion "$P" my-blob >h &&
1100 # Configure a URL for other-blob. Just reuse the hash of the object as
1101 # the hash of the packfile, since the hash does not matter for this
1102 # test as long as it is not the hash of the pack, and it is of the
1103 # expected length.
1104 git -C "$P" hash-object other-blob >objh &&
1105 git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
1106 git -C "$P" config --add \
1107 "uploadpack.blobpackfileuri" \
1108 "$(cat objh) $(cat objh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
1109
1110 test_must_fail env GIT_TEST_SIDEBAND_ALL=1 \
1111 git -c protocol.version=2 \
1112 -c fetch.uriprotocols=http,https \
1113 clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
1114 test_grep "pack downloaded from.*does not match expected hash" err
1115 '
1116
1117 test_expect_success 'packfile-uri with transfer.fsckobjects' '
1118 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1119 rm -rf "$P" http_child log &&
1120
1121 git init "$P" &&
1122 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1123
1124 echo my-blob >"$P/my-blob" &&
1125 git -C "$P" add my-blob &&
1126 git -C "$P" commit -m x &&
1127
1128 configure_exclusion "$P" my-blob >h &&
1129
1130 sane_unset GIT_TEST_SIDEBAND_ALL &&
1131 git -c protocol.version=2 -c transfer.fsckobjects=1 \
1132 -c fetch.uriprotocols=http,https \
1133 clone "$HTTPD_URL/smart/http_parent" http_child &&
1134
1135 # Ensure that there are exactly 2 packfiles with associated .idx
1136 ls http_child/.git/objects/pack/*.pack \
1137 http_child/.git/objects/pack/*.idx >filelist &&
1138 test_line_count = 4 filelist
1139 '
1140
1141 test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' '
1142 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1143 rm -rf "$P" http_child log &&
1144
1145 git init "$P" &&
1146 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1147
1148 cat >bogus-commit <<-EOF &&
1149 tree $EMPTY_TREE
1150 author Bugs Bunny 1234567890 +0000
1151 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
1152
1153 This commit object intentionally broken
1154 EOF
1155 BOGUS=$(git -C "$P" hash-object -t commit -w --stdin --literally <bogus-commit) &&
1156 git -C "$P" branch bogus-branch "$BOGUS" &&
1157
1158 echo my-blob >"$P/my-blob" &&
1159 git -C "$P" add my-blob &&
1160 git -C "$P" commit -m x &&
1161
1162 configure_exclusion "$P" my-blob >h &&
1163
1164 sane_unset GIT_TEST_SIDEBAND_ALL &&
1165 test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
1166 -c fetch.uriprotocols=http,https \
1167 clone "$HTTPD_URL/smart/http_parent" http_child 2>error &&
1168 test_grep "invalid author/committer line - missing email" error
1169 '
1170
1171 test_expect_success 'packfile-uri with transfer.fsckobjects succeeds when .gitmodules is separate from tree' '
1172 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1173 rm -rf "$P" http_child &&
1174
1175 git init "$P" &&
1176 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1177
1178 echo "[submodule libfoo]" >"$P/.gitmodules" &&
1179 echo "path = include/foo" >>"$P/.gitmodules" &&
1180 echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" &&
1181 git -C "$P" add .gitmodules &&
1182 git -C "$P" commit -m x &&
1183
1184 configure_exclusion "$P" .gitmodules >h &&
1185
1186 sane_unset GIT_TEST_SIDEBAND_ALL &&
1187 git -c protocol.version=2 -c transfer.fsckobjects=1 \
1188 -c fetch.uriprotocols=http,https \
1189 clone "$HTTPD_URL/smart/http_parent" http_child &&
1190
1191 # Ensure that there are exactly 2 packfiles with associated .idx
1192 ls http_child/.git/objects/pack/*.pack \
1193 http_child/.git/objects/pack/*.idx >filelist &&
1194 test_line_count = 4 filelist
1195 '
1196
1197 test_expect_success 'packfile-uri with transfer.fsckobjects fails when .gitmodules separate from tree is invalid' '
1198 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1199 rm -rf "$P" http_child err &&
1200
1201 git init "$P" &&
1202 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1203
1204 echo "[submodule \"..\"]" >"$P/.gitmodules" &&
1205 echo "path = include/foo" >>"$P/.gitmodules" &&
1206 echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" &&
1207 git -C "$P" add .gitmodules &&
1208 git -C "$P" commit -m x &&
1209
1210 configure_exclusion "$P" .gitmodules >h &&
1211
1212 sane_unset GIT_TEST_SIDEBAND_ALL &&
1213 test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
1214 -c fetch.uriprotocols=http,https \
1215 clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
1216 test_grep "disallowed submodule name" err
1217 '
1218
1219 test_expect_success 'packfile-uri path redacted in trace' '
1220 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1221 rm -rf "$P" http_child log &&
1222
1223 git init "$P" &&
1224 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1225
1226 echo my-blob >"$P/my-blob" &&
1227 git -C "$P" add my-blob &&
1228 git -C "$P" commit -m x &&
1229
1230 git -C "$P" hash-object my-blob >objh &&
1231 git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
1232 git -C "$P" config --add \
1233 "uploadpack.blobpackfileuri" \
1234 "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
1235
1236 GIT_TRACE_PACKET="$(pwd)/log" \
1237 git -c protocol.version=2 \
1238 -c fetch.uriprotocols=http,https \
1239 clone "$HTTPD_URL/smart/http_parent" http_child &&
1240
1241 grep -F "clone< \\1$(cat packh) $HTTPD_URL/<redacted>" log
1242 '
1243
1244 test_expect_success 'packfile-uri path not redacted in trace when GIT_TRACE_REDACT=0' '
1245 P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
1246 rm -rf "$P" http_child log &&
1247
1248 git init "$P" &&
1249 git -C "$P" config "uploadpack.allowsidebandall" "true" &&
1250
1251 echo my-blob >"$P/my-blob" &&
1252 git -C "$P" add my-blob &&
1253 git -C "$P" commit -m x &&
1254
1255 git -C "$P" hash-object my-blob >objh &&
1256 git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
1257 git -C "$P" config --add \
1258 "uploadpack.blobpackfileuri" \
1259 "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
1260
1261 GIT_TRACE_PACKET="$(pwd)/log" \
1262 GIT_TRACE_REDACT=0 \
1263 git -c protocol.version=2 \
1264 -c fetch.uriprotocols=http,https \
1265 clone "$HTTPD_URL/smart/http_parent" http_child &&
1266
1267 grep -F "clone< \\1$(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" log
1268 '
1269
1270 test_expect_success 'http:// --negotiate-only' '
1271 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
1272 URI="$HTTPD_URL/smart/server" &&
1273
1274 setup_negotiate_only "$SERVER" "$URI" &&
1275
1276 git -c protocol.version=2 -C client fetch \
1277 --no-tags \
1278 --negotiate-only \
1279 --negotiation-tip=$(git -C client rev-parse HEAD) \
1280 origin >out &&
1281 COMMON=$(git -C "$SERVER" rev-parse two) &&
1282 grep "$COMMON" out
1283 '
1284
1285 test_expect_success 'http:// --negotiate-only without wait-for-done support' '
1286 SERVER="server" &&
1287 URI="$HTTPD_URL/one_time_perl/server" &&
1288
1289 setup_negotiate_only "$SERVER" "$URI" &&
1290
1291 echo "s/ wait-for-done/ xxxx-xxx-xxxx/" \
1292 >"$HTTPD_ROOT_PATH/one-time-perl" &&
1293
1294 test_must_fail git -c protocol.version=2 -C client fetch \
1295 --no-tags \
1296 --negotiate-only \
1297 --negotiation-tip=$(git -C client rev-parse HEAD) \
1298 origin 2>err &&
1299 test_grep "server does not support wait-for-done" err
1300 '
1301
1302 test_expect_success 'http:// --negotiate-only with protocol v0' '
1303 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
1304 URI="$HTTPD_URL/smart/server" &&
1305
1306 setup_negotiate_only "$SERVER" "$URI" &&
1307
1308 test_must_fail git -c protocol.version=0 -C client fetch \
1309 --no-tags \
1310 --negotiate-only \
1311 --negotiation-tip=$(git -C client rev-parse HEAD) \
1312 origin 2>err &&
1313 test_grep "negotiate-only requires protocol v2" err
1314 '
1315
1316 # DO NOT add non-httpd-specific tests here, because the last part of this
1317 # test script is only executed when httpd is available and enabled.
1318
1319 test_done