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