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