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