3 test_description='test git wire-protocol version 2'
9 # Test protocol v2 with 'git://' transport
11 . "$TEST_DIRECTORY"/lib-git-daemon.sh
12 start_git_daemon --export-all --enable=receive-pack
13 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
15 test_expect_success 'create repo to be served by git-daemon' '
17 git init "$daemon_parent" &&
18 test_commit -C "$daemon_parent" one
21 test_expect_success 'list refs with git:// using protocol v2' '
22 test_when_finished "rm -f log" &&
24 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
25 ls-remote --symref "$GIT_DAEMON_URL/parent" >actual &&
27 # Client requested to use protocol v2
28 grep "git> .*\\\0\\\0version=2\\\0$" log &&
29 # Server responded using protocol v2
30 grep "git< version 2" log &&
32 git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
33 test_cmp expect actual
36 test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
37 test_when_finished "rm -f log" &&
39 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
40 ls-remote "$GIT_DAEMON_URL/parent" master >actual &&
43 $(git -C "$daemon_parent" rev-parse refs/heads/master)$(printf "\t")refs/heads/master
46 test_cmp expect actual
49 test_expect_success 'clone with git:// using protocol v2' '
50 test_when_finished "rm -f log" &&
52 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
53 clone "$GIT_DAEMON_URL/parent" daemon_child &&
55 git -C daemon_child log -1 --format=%s >actual &&
56 git -C "$daemon_parent" log -1 --format=%s >expect &&
57 test_cmp expect actual &&
59 # Client requested to use protocol v2
60 grep "clone> .*\\\0\\\0version=2\\\0$" log &&
61 # Server responded using protocol v2
62 grep "clone< version 2" log
65 test_expect_success 'fetch with git:// using protocol v2' '
66 test_when_finished "rm -f log" &&
68 test_commit -C "$daemon_parent" two &&
70 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
73 git -C daemon_child log -1 --format=%s origin/master >actual &&
74 git -C "$daemon_parent" log -1 --format=%s >expect &&
75 test_cmp expect actual &&
77 # Client requested to use protocol v2
78 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
79 # Server responded using protocol v2
80 grep "fetch< version 2" log
83 test_expect_success 'fetch by hash without tag following with protocol v2 does not list refs' '
84 test_when_finished "rm -f log" &&
86 test_commit -C "$daemon_parent" two_a &&
87 git -C "$daemon_parent" rev-parse two_a >two_a_hash &&
89 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
90 fetch --no-tags origin $(cat two_a_hash) &&
92 grep "fetch< version 2" log &&
93 ! grep "fetch> command=ls-refs" log
96 test_expect_success 'pull with git:// using protocol v2' '
97 test_when_finished "rm -f log" &&
99 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
102 git -C daemon_child log -1 --format=%s >actual &&
103 git -C "$daemon_parent" log -1 --format=%s >expect &&
104 test_cmp expect actual &&
106 # Client requested to use protocol v2
107 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
108 # Server responded using protocol v2
109 grep "fetch< version 2" log
112 test_expect_success 'push with git:// and a config of v2 does not request v2' '
113 test_when_finished "rm -f log" &&
115 # Till v2 for push is designed, make sure that if a client has
116 # protocol.version configured to use v2, that the client instead falls
119 test_commit -C daemon_child three &&
121 # Push to another branch, as the target repository has the
122 # master branch checked out and we cannot push into it.
123 GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
124 push origin HEAD:client_branch &&
126 git -C daemon_child log -1 --format=%s >actual &&
127 git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
128 test_cmp expect actual &&
130 # Client requested to use protocol v2
131 ! grep "push> .*\\\0\\\0version=2\\\0$" log &&
132 # Server responded using protocol v2
133 ! grep "push< version 2" log
138 # Test protocol v2 with 'file://' transport
140 test_expect_success 'create repo to be served by file:// transport' '
141 git init file_parent &&
142 test_commit -C file_parent one
145 test_expect_success 'list refs with file:// using protocol v2' '
146 test_when_finished "rm -f log" &&
148 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
149 ls-remote --symref "file://$(pwd)/file_parent" >actual &&
151 # Server responded using protocol v2
152 grep "git< version 2" log &&
154 git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
155 test_cmp expect actual
158 test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' '
159 test_when_finished "rm -f log" &&
161 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
162 ls-remote "file://$(pwd)/file_parent" master >actual &&
164 cat >expect <<-EOF &&
165 $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
168 test_cmp expect actual
171 test_expect_success 'server-options are sent when using ls-remote' '
172 test_when_finished "rm -f log" &&
174 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
175 ls-remote -o hello -o world "file://$(pwd)/file_parent" master >actual &&
177 cat >expect <<-EOF &&
178 $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
181 test_cmp expect actual &&
182 grep "server-option=hello" log &&
183 grep "server-option=world" log
186 test_expect_success 'warn if using server-option with ls-remote with legacy protocol' '
187 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
188 ls-remote -o hello -o world "file://$(pwd)/file_parent" master 2>err &&
190 test_i18ngrep "see protocol.version in" err &&
191 test_i18ngrep "server options require protocol version 2 or later" err
194 test_expect_success 'clone with file:// using protocol v2' '
195 test_when_finished "rm -f log" &&
197 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
198 clone "file://$(pwd)/file_parent" file_child &&
200 git -C file_child log -1 --format=%s >actual &&
201 git -C file_parent log -1 --format=%s >expect &&
202 test_cmp expect actual &&
204 # Server responded using protocol v2
205 grep "clone< version 2" log &&
207 # Client sent ref-prefixes to filter the ref-advertisement
208 grep "ref-prefix HEAD" log &&
209 grep "ref-prefix refs/heads/" log &&
210 grep "ref-prefix refs/tags/" log
213 test_expect_success 'fetch with file:// using protocol v2' '
214 test_when_finished "rm -f log" &&
216 test_commit -C file_parent two &&
218 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
221 git -C file_child log -1 --format=%s origin/master >actual &&
222 git -C file_parent log -1 --format=%s >expect &&
223 test_cmp expect actual &&
225 # Server responded using protocol v2
226 grep "fetch< version 2" log
229 test_expect_success 'ref advertisement is filtered during fetch using protocol v2' '
230 test_when_finished "rm -f log" &&
232 test_commit -C file_parent three &&
233 git -C file_parent branch unwanted-branch three &&
235 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
236 fetch origin master &&
238 git -C file_child log -1 --format=%s origin/master >actual &&
239 git -C file_parent log -1 --format=%s >expect &&
240 test_cmp expect actual &&
242 grep "refs/heads/master" log &&
243 ! grep "refs/heads/unwanted-branch" log
246 test_expect_success 'server-options are sent when fetching' '
247 test_when_finished "rm -f log" &&
249 test_commit -C file_parent four &&
251 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
252 fetch -o hello -o world origin master &&
254 git -C file_child log -1 --format=%s origin/master >actual &&
255 git -C file_parent log -1 --format=%s >expect &&
256 test_cmp expect actual &&
258 grep "server-option=hello" log &&
259 grep "server-option=world" log
262 test_expect_success 'warn if using server-option with fetch with legacy protocol' '
263 test_when_finished "rm -rf temp_child" &&
265 git init temp_child &&
267 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C temp_child -c protocol.version=0 \
268 fetch -o hello -o world "file://$(pwd)/file_parent" master 2>err &&
270 test_i18ngrep "see protocol.version in" err &&
271 test_i18ngrep "server options require protocol version 2 or later" err
274 test_expect_success 'server-options are sent when cloning' '
275 test_when_finished "rm -rf log myclone" &&
277 GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
278 clone --server-option=hello --server-option=world \
279 "file://$(pwd)/file_parent" myclone &&
281 grep "server-option=hello" log &&
282 grep "server-option=world" log
285 test_expect_success 'warn if using server-option with clone with legacy protocol' '
286 test_when_finished "rm -rf myclone" &&
288 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
289 clone --server-option=hello --server-option=world \
290 "file://$(pwd)/file_parent" myclone 2>err &&
292 test_i18ngrep "see protocol.version in" err &&
293 test_i18ngrep "server options require protocol version 2 or later" err
296 test_expect_success 'upload-pack respects config using protocol v2' '
298 write_script server/.git/hook <<-\EOF &&
302 test_commit -C server one &&
304 test_config_global uploadpack.packobjectshook ./hook &&
305 test_path_is_missing server/.git/hookout &&
306 git -c protocol.version=2 clone "file://$(pwd)/server" client &&
307 test_path_is_file server/.git/hookout
310 test_expect_success 'setup filter tests' '
311 rm -rf server client &&
314 # 1 commit to create a file, and 1 commit to modify it
315 test_commit -C server message1 a.txt &&
316 test_commit -C server message2 a.txt &&
317 git -C server config protocol.version 2 &&
318 git -C server config uploadpack.allowfilter 1 &&
319 git -C server config uploadpack.allowanysha1inwant 1 &&
320 git -C server config protocol.version 2
323 test_expect_success 'partial clone' '
324 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
325 clone --filter=blob:none "file://$(pwd)/server" client &&
326 grep "version 2" trace &&
328 # Ensure that the old version of the file is missing
329 git -C client rev-list --quiet --objects --missing=print master \
331 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
333 # Ensure that client passes fsck
337 test_expect_success 'dynamically fetch missing object' '
339 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
340 cat-file -p $(git -C server rev-parse message1:a.txt) &&
341 grep "version 2" trace
344 test_expect_success 'when dynamically fetching missing object, do not list refs' '
345 ! grep "git> command=ls-refs" trace
348 test_expect_success 'partial fetch' '
349 rm -rf client "$(pwd)/trace" &&
351 SERVER="file://$(pwd)/server" &&
352 test_config -C client extensions.partialClone "$SERVER" &&
354 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
355 fetch --filter=blob:none "$SERVER" master:refs/heads/other &&
356 grep "version 2" trace &&
358 # Ensure that the old version of the file is missing
359 git -C client rev-list --quiet --objects --missing=print other \
361 grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
363 # Ensure that client passes fsck
367 test_expect_success 'do not advertise filter if not configured to do so' '
368 SERVER="file://$(pwd)/server" &&
371 git -C server config uploadpack.allowfilter 1 &&
372 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
373 ls-remote "$SERVER" &&
374 grep "fetch=.*filter" trace &&
377 git -C server config uploadpack.allowfilter 0 &&
378 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
379 ls-remote "$SERVER" &&
380 grep "fetch=" trace >fetch_capabilities &&
381 ! grep filter fetch_capabilities
384 test_expect_success 'partial clone warns if filter is not advertised' '
386 git -C server config uploadpack.allowfilter 0 &&
387 git -c protocol.version=2 \
388 clone --filter=blob:none "file://$(pwd)/server" client 2>err &&
389 test_i18ngrep "filtering not recognized by server, ignoring" err
392 test_expect_success 'even with handcrafted request, filter does not work if not advertised' '
393 git -C server config uploadpack.allowfilter 0 &&
395 # Custom request that tries to filter even though it is not advertised.
396 test-tool pkt-line pack >in <<-EOF &&
398 object-format=$(test_oid algo)
400 want $(git -C server rev-parse master)
405 test_must_fail test-tool -C server serve-v2 --stateless-rpc \
406 <in >/dev/null 2>err &&
407 grep "unexpected line: .filter blob:none." err &&
409 # Exercise to ensure that if advertised, filter works
410 git -C server config uploadpack.allowfilter 1 &&
411 test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
414 test_expect_success 'default refspec is used to filter ref when fetchcing' '
415 test_when_finished "rm -f log" &&
417 GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
420 git -C file_child log -1 --format=%s three >actual &&
421 git -C file_parent log -1 --format=%s three >expect &&
422 test_cmp expect actual &&
424 grep "ref-prefix refs/heads/" log &&
425 grep "ref-prefix refs/tags/" log
428 test_expect_success 'fetch supports various ways of have lines' '
429 rm -rf server client trace &&
431 test_commit -C server dwim &&
432 TREE=$(git -C server rev-parse HEAD^{tree}) &&
433 git -C server tag exact \
434 $(git -C server commit-tree -m a "$TREE") &&
435 git -C server tag dwim-unwanted \
436 $(git -C server commit-tree -m b "$TREE") &&
437 git -C server tag exact-unwanted \
438 $(git -C server commit-tree -m c "$TREE") &&
439 git -C server tag prefix1 \
440 $(git -C server commit-tree -m d "$TREE") &&
441 git -C server tag prefix2 \
442 $(git -C server commit-tree -m e "$TREE") &&
443 git -C server tag fetch-by-sha1 \
444 $(git -C server commit-tree -m f "$TREE") &&
445 git -C server tag completely-unrelated \
446 $(git -C server commit-tree -m g "$TREE") &&
449 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
450 fetch "file://$(pwd)/server" \
453 refs/tags/prefix*:refs/tags/prefix* \
454 "$(git -C server rev-parse fetch-by-sha1)" &&
456 # Ensure that the appropriate prefixes are sent (using a sample)
457 grep "fetch> ref-prefix dwim" trace &&
458 grep "fetch> ref-prefix refs/heads/dwim" trace &&
459 grep "fetch> ref-prefix refs/tags/prefix" trace &&
461 # Ensure that the correct objects are returned
462 git -C client cat-file -e $(git -C server rev-parse dwim) &&
463 git -C client cat-file -e $(git -C server rev-parse exact) &&
464 git -C client cat-file -e $(git -C server rev-parse prefix1) &&
465 git -C client cat-file -e $(git -C server rev-parse prefix2) &&
466 git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) &&
467 test_must_fail git -C client cat-file -e \
468 $(git -C server rev-parse dwim-unwanted) &&
469 test_must_fail git -C client cat-file -e \
470 $(git -C server rev-parse exact-unwanted) &&
471 test_must_fail git -C client cat-file -e \
472 $(git -C server rev-parse completely-unrelated)
475 test_expect_success 'fetch supports include-tag and tag following' '
476 rm -rf server client trace &&
479 test_commit -C server to_fetch &&
480 git -C server tag -a annotated_tag -m message &&
483 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
484 fetch "$(pwd)/server" to_fetch:to_fetch &&
486 grep "fetch> ref-prefix to_fetch" trace &&
487 grep "fetch> ref-prefix refs/tags/" trace &&
488 grep "fetch> include-tag" trace &&
490 git -C client cat-file -e $(git -C client rev-parse annotated_tag)
493 test_expect_success 'upload-pack respects client shallows' '
494 rm -rf server client trace &&
497 test_commit -C server base &&
498 test_commit -C server client_has &&
500 git clone --depth=1 "file://$(pwd)/server" client &&
502 # Add extra commits to the client so that the whole fetch takes more
503 # than 1 request (due to negotiation)
504 test_commit_bulk -C client --id=c 32 &&
506 git -C server checkout -b newbranch base &&
507 test_commit -C server client_wants &&
509 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
510 fetch origin newbranch &&
511 # Ensure that protocol v2 is used
512 grep "fetch< version 2" trace
515 test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' '
516 rm -rf server client trace &&
518 test_create_repo server &&
519 test_commit -C server one &&
520 test_commit -C server two &&
521 test_commit -C server three &&
522 git clone --shallow-exclude two "file://$(pwd)/server" client &&
524 git -C server tag -a -m "an annotated tag" twotag two &&
526 # Triggers tag following (thus, 2 fetches in one process)
527 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
528 fetch --shallow-exclude one origin &&
529 # Ensure that protocol v2 is used
530 grep "fetch< version 2" trace
533 test_expect_success 'deepen-relative' '
534 rm -rf server client trace &&
536 test_create_repo server &&
537 test_commit -C server one &&
538 test_commit -C server two &&
539 test_commit -C server three &&
540 git clone --depth 1 "file://$(pwd)/server" client &&
541 test_commit -C server four &&
543 # Sanity check that only "three" is downloaded
544 git -C client log --pretty=tformat:%s master >actual &&
545 echo three >expected &&
546 test_cmp expected actual &&
548 GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
549 fetch --deepen=1 origin &&
550 # Ensure that protocol v2 is used
551 grep "fetch< version 2" trace &&
553 git -C client log --pretty=tformat:%s origin/master >actual &&
554 cat >expected <<-\EOF &&
559 test_cmp expected actual
562 # Test protocol v2 with 'http://' transport
564 . "$TEST_DIRECTORY"/lib-httpd.sh
567 test_expect_success 'create repo to be served by http:// transport' '
568 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
569 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
570 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
573 test_expect_success 'clone with http:// using protocol v2' '
574 test_when_finished "rm -f log" &&
576 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
577 clone "$HTTPD_URL/smart/http_parent" http_child &&
579 git -C http_child log -1 --format=%s >actual &&
580 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
581 test_cmp expect actual &&
583 # Client requested to use protocol v2
584 grep "Git-Protocol: version=2" log &&
585 # Server responded using protocol v2
586 grep "git< version 2" log &&
587 # Verify that the chunked encoding sending codepath is NOT exercised
588 ! grep "Send header: Transfer-Encoding: chunked" log
591 test_expect_success 'clone big repository with http:// using protocol v2' '
592 test_when_finished "rm -f log" &&
594 git init "$HTTPD_DOCUMENT_ROOT_PATH/big" &&
595 # Ensure that the list of wants is greater than http.postbuffer below
596 for i in $(test_seq 1 1500)
598 # do not use here-doc, because it requires a process
600 echo "commit refs/heads/too-many-refs-$i" &&
601 echo "committer git <git@example.com> $i +0000" &&
603 echo "M 644 inline bla.txt" &&
606 done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
608 GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
609 -c protocol.version=2 -c http.postbuffer=65536 \
610 clone "$HTTPD_URL/smart/big" big_child &&
612 # Client requested to use protocol v2
613 grep "Git-Protocol: version=2" log &&
614 # Server responded using protocol v2
615 grep "git< version 2" log &&
616 # Verify that the chunked encoding sending codepath is exercised
617 grep "Send header: Transfer-Encoding: chunked" log
620 test_expect_success 'fetch with http:// using protocol v2' '
621 test_when_finished "rm -f log" &&
623 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
625 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
628 git -C http_child log -1 --format=%s origin/master >actual &&
629 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
630 test_cmp expect actual &&
632 # Server responded using protocol v2
633 grep "git< version 2" log
636 test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
637 test_when_finished "rm -f log" &&
639 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
640 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
642 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
643 fetch --no-tags origin $(cat two_a_hash) &&
645 grep "fetch< version 2" log &&
646 ! grep "fetch> command=ls-refs" log
649 test_expect_success 'fetch from namespaced repo respects namespaces' '
650 test_when_finished "rm -f log" &&
652 git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
653 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
654 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
655 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
656 update-ref refs/namespaces/ns/refs/heads/master one &&
658 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
659 fetch "$HTTPD_URL/smart_namespace/nsrepo" \
660 refs/heads/master:refs/heads/theirs &&
662 # Server responded using protocol v2
663 grep "fetch< version 2" log &&
665 git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
666 git -C http_child rev-parse theirs >actual &&
667 test_cmp expect actual
670 test_expect_success 'ls-remote with v2 http sends only one POST' '
671 test_when_finished "rm -f log" &&
673 git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect &&
674 GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
675 ls-remote "$HTTPD_URL/smart/http_parent" >actual &&
676 test_cmp expect actual &&
678 grep "Send header: POST" log >posts &&
679 test_line_count = 1 posts
682 test_expect_success 'push with http:// and a config of v2 does not request v2' '
683 test_when_finished "rm -f log" &&
684 # Till v2 for push is designed, make sure that if a client has
685 # protocol.version configured to use v2, that the client instead falls
688 test_commit -C http_child three &&
690 # Push to another branch, as the target repository has the
691 # master branch checked out and we cannot push into it.
692 GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
693 push origin HEAD:client_branch &&
695 git -C http_child log -1 --format=%s >actual &&
696 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
697 test_cmp expect actual &&
699 # Client did not request to use protocol v2
700 ! grep "Git-Protocol: version=2" log &&
701 # Server did not respond using protocol v2
702 ! grep "git< version 2" log
705 test_expect_success 'when server sends "ready", expect DELIM' '
706 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child &&
708 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
709 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
711 git clone "$HTTPD_URL/smart/http_parent" http_child &&
713 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
715 # After "ready" in the acknowledgments section, pretend that a FLUSH
716 # (0000) was sent instead of a DELIM (0001).
717 printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
718 >"$HTTPD_ROOT_PATH/one-time-perl" &&
720 test_must_fail git -C http_child -c protocol.version=2 \
721 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
722 test_i18ngrep "expected packfile to be sent after .ready." err
725 test_expect_success 'when server does not send "ready", expect FLUSH' '
726 rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child log &&
728 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
729 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one &&
731 git clone "$HTTPD_URL/smart/http_parent" http_child &&
733 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
735 # Create many commits to extend the negotiation phase across multiple
736 # requests, so that the server does not send "ready" in the first
738 test_commit_bulk -C http_child --id=c 32 &&
740 # After the acknowledgments section, pretend that a DELIM
741 # (0001) was sent instead of a FLUSH (0000).
742 printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
743 >"$HTTPD_ROOT_PATH/one-time-perl" &&
745 test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
746 -c protocol.version=2 \
747 fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
748 grep "fetch< .*acknowledgments" log &&
749 ! grep "fetch< .*ready" log &&
750 test_i18ngrep "expected no other sections to be sent after no .ready." err
753 # DO NOT add non-httpd-specific tests here, because the last part of this
754 # test script is only executed when httpd is available and enabled.