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