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