Raw
1 #!/bin/sh
2
3 test_description='git cat-file --batch-command with remote-object-info command'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-cat-file.sh
7
8 hello_content="Hello World"
9 hello_size=$(strlen "$hello_content")
10 hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
11 hello_short_oid=$(git rev-parse --short "$hello_oid")
12
13 unstored_content="Hello Git"
14 unstored_oid=$(echo_without_newline "$unstored_content" | git hash-object --stdin)
15
16 # This is how we get 13:
17 # 13 = <file mode> + <a_space> + <file name> + <a_null>, where
18 # file mode is 100644, which is 6 characters;
19 # file name is hello, which is 5 characters
20 # a space is 1 character and a null is 1 character
21 tree_size=$(($(test_oid rawsz) + 13))
22
23 commit_message="Initial commit"
24
25 # This is how we get 137:
26 # 137 = <tree header> + <a_space> + <a newline> +
27 # <Author line> + <a newline> +
28 # <Committer line> + <a newline> +
29 # <a newline> +
30 # <commit message length>
31 # An easier way to calculate is: 1. use `git cat-file commit <commit hash> | wc -c`,
32 # to get 177, 2. then deduct 40 hex characters to get 137
33 commit_size=$(($(test_oid hexsz) + 137))
34
35 tag_header_without_oid="type blob
36 tag hellotag
37 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
38 tag_header_without_timestamp="object $hello_oid
39 $tag_header_without_oid"
40 tag_description="This is a tag"
41 tag_content="$tag_header_without_timestamp 0 +0000
42
43 $tag_description"
44
45 tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
46 tag_size=$(strlen "$tag_content")
47
48 set_transport_variables () {
49 hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
50 tree_oid=$(git -C "$1" write-tree)
51 commit_oid=$(echo_without_newline "$commit_message" | git -C "$1" commit-tree $tree_oid)
52 tag_oid=$(echo_without_newline "$tag_content" | git -C "$1" hash-object -t tag --stdin -w)
53 tag_size=$(strlen "$tag_content")
54 }
55
56 # This section tests --batch-command with remote-object-info command
57 # Since "%(objecttype)" is currently not supported by the command remote-object-info ,
58 # the filters are set to "%(objectname) %(objectsize)" in some test cases.
59
60 # Test --batch-command remote-object-info with 'git://' transport with
61 # transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
62 . "$TEST_DIRECTORY"/lib-git-daemon.sh
63 start_git_daemon --export-all
64 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
65
66 test_expect_success 'create repo to be served by git-daemon' '
67 git init "$daemon_parent" &&
68 echo_without_newline "$hello_content" > $daemon_parent/hello &&
69 git -C "$daemon_parent" update-index --add hello &&
70 git -C "$daemon_parent" config transfer.advertiseobjectinfo true &&
71 git clone "$GIT_DAEMON_URL/parent" -n "$daemon_parent/daemon_client_empty"
72 '
73
74 test_expect_success 'batch-command remote-object-info git://' '
75 (
76 set_transport_variables "$daemon_parent" &&
77 cd "$daemon_parent/daemon_client_empty" &&
78
79 # These results prove remote-object-info can get object info from the remote
80 echo "$hello_oid $hello_size" >expect &&
81 echo "$tree_oid $tree_size" >>expect &&
82 echo "$commit_oid $commit_size" >>expect &&
83 echo "$tag_oid $tag_size" >>expect &&
84
85 # These results prove remote-object-info did not download objects from the remote
86 echo "$hello_oid missing" >>expect &&
87 echo "$tree_oid missing" >>expect &&
88 echo "$commit_oid missing" >>expect &&
89 echo "$tag_oid missing" >>expect &&
90
91 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
92 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
93 remote-object-info "$GIT_DAEMON_URL/parent" $tree_oid
94 remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid
95 remote-object-info "$GIT_DAEMON_URL/parent" $tag_oid
96 info $hello_oid
97 info $tree_oid
98 info $commit_oid
99 info $tag_oid
100 EOF
101 test_cmp expect actual
102 )
103 '
104
105 test_expect_success 'batch-command remote-object-info git:// multiple sha1 per line' '
106 (
107 set_transport_variables "$daemon_parent" &&
108 cd "$daemon_parent/daemon_client_empty" &&
109
110 # These results prove remote-object-info can get object info from the remote
111 echo "$hello_oid $hello_size" >expect &&
112 echo "$tree_oid $tree_size" >>expect &&
113 echo "$commit_oid $commit_size" >>expect &&
114 echo "$tag_oid $tag_size" >>expect &&
115
116 # These results prove remote-object-info did not download objects from the remote
117 echo "$hello_oid missing" >>expect &&
118 echo "$tree_oid missing" >>expect &&
119 echo "$commit_oid missing" >>expect &&
120 echo "$tag_oid missing" >>expect &&
121
122 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
123 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid $commit_oid $tag_oid
124 info $hello_oid
125 info $tree_oid
126 info $commit_oid
127 info $tag_oid
128 EOF
129 test_cmp expect actual
130 )
131 '
132
133 test_expect_success 'batch-command remote-object-info git:// default filter' '
134 (
135 set_transport_variables "$daemon_parent" &&
136 cd "$daemon_parent/daemon_client_empty" &&
137
138 echo "$hello_oid $hello_size" >expect &&
139 echo "$tree_oid $tree_size" >>expect &&
140 echo "$commit_oid $commit_size" >>expect &&
141 echo "$tag_oid $tag_size" >>expect &&
142
143 git cat-file --batch-command >actual <<-EOF &&
144 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
145 remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid
146 EOF
147 test_cmp expect actual
148 )
149 '
150
151 test_expect_success 'remote-object-info does not change the default format of info' '
152 (
153 set_transport_variables "$daemon_parent" &&
154 cd "$daemon_parent/daemon_client_empty" &&
155
156 local_content="local object" &&
157 local_oid=$(echo_without_newline "$local_content" | git hash-object -w --stdin) &&
158 local_size=$(strlen "$local_content") &&
159
160 echo "$local_oid blob $local_size" >expect &&
161 echo "$hello_oid $hello_size" >>expect &&
162 echo "$local_oid blob $local_size" >>expect &&
163
164 git cat-file --batch-command >actual <<-EOF &&
165 info $local_oid
166 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
167 info $local_oid
168 EOF
169 test_cmp expect actual
170 )
171 '
172
173 test_expect_success 'batch-command --buffer remote-object-info git://' '
174 (
175 set_transport_variables "$daemon_parent" &&
176 cd "$daemon_parent/daemon_client_empty" &&
177
178 # These results prove remote-object-info can get object info from the remote
179 echo "$hello_oid $hello_size" >expect &&
180 echo "$tree_oid $tree_size" >>expect &&
181 echo "$commit_oid $commit_size" >>expect &&
182 echo "$tag_oid $tag_size" >>expect &&
183
184 # These results prove remote-object-info did not download objects from the remote
185 echo "$hello_oid missing" >>expect &&
186 echo "$tree_oid missing" >>expect &&
187 echo "$commit_oid missing" >>expect &&
188 echo "$tag_oid missing" >>expect &&
189
190 git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
191 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid $tree_oid
192 remote-object-info "$GIT_DAEMON_URL/parent" $commit_oid $tag_oid
193 info $hello_oid
194 info $tree_oid
195 info $commit_oid
196 info $tag_oid
197 flush
198 EOF
199 test_cmp expect actual
200 )
201 '
202
203 test_expect_success 'batch-command -Z remote-object-info git:// default filter' '
204 (
205 set_transport_variables "$daemon_parent" &&
206 cd "$daemon_parent/daemon_client_empty" &&
207
208 printf "%s\0" "$hello_oid $hello_size" >expect &&
209 printf "%s\0" "$tree_oid $tree_size" >>expect &&
210 printf "%s\0" "$commit_oid $commit_size" >>expect &&
211 printf "%s\0" "$tag_oid $tag_size" >>expect &&
212
213 printf "%s\0" "$hello_oid missing" >>expect &&
214 printf "%s\0" "$tree_oid missing" >>expect &&
215 printf "%s\0" "$commit_oid missing" >>expect &&
216 printf "%s\0" "$tag_oid missing" >>expect &&
217
218 batch_input="remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid
219 remote-object-info $GIT_DAEMON_URL/parent $commit_oid $tag_oid
220 info $hello_oid
221 info $tree_oid
222 info $commit_oid
223 info $tag_oid
224 " &&
225 echo_without_newline_nul "$batch_input" >commands_null_delimited &&
226
227 git cat-file --batch-command -Z < commands_null_delimited >actual &&
228 test_cmp expect actual
229 )
230 '
231
232 test_expect_success 'remote-object-info does not support short oids' '
233 (
234 set_transport_variables "$daemon_parent" &&
235 cd "$daemon_parent/daemon_client_empty" &&
236
237 test_must_fail git cat-file --batch-command 2>err <<-EOF &&
238 remote-object-info $GIT_DAEMON_URL/parent $hello_short_oid
239 EOF
240 test_grep "does not support short oids" err
241 )
242 '
243
244 test_expect_success 'remote-object-info does not die on missing oid like info' '
245 (
246 set_transport_variables "$daemon_parent" &&
247 cd "$daemon_parent/daemon_client_empty" &&
248
249 git cat-file --batch-command >local <<-EOF &&
250 info $unstored_oid
251 EOF
252 git cat-file --batch-command >remote <<-EOF &&
253 remote-object-info $GIT_DAEMON_URL/parent $unstored_oid
254 EOF
255 test_cmp local remote
256 )
257 '
258
259 # This tests depends on %(objecttype) not being supported yet, once supported
260 # it needs to be updated.
261 test_expect_success 'unsupported placeholder on remote returns empty string' '
262 (
263 set_transport_variables "$daemon_parent" &&
264 cd "$daemon_parent/daemon_client_empty" &&
265
266 echo "" >expect &&
267 git cat-file --batch-command="%(objecttype)" >actual <<-EOF &&
268 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
269 EOF
270 test_cmp expect actual
271 )
272 '
273
274 test_expect_success 'requesting only objectname echoes back' '
275 (
276 set_transport_variables "$daemon_parent" &&
277 cd "$daemon_parent/daemon_client_empty" &&
278
279 echo $hello_oid >expect &&
280 git cat-file --batch-command="%(objectname)" >actual <<-EOF &&
281 remote-object-info "$GIT_DAEMON_URL/parent" $hello_oid
282 EOF
283 test_cmp expect actual
284 )
285 '
286
287 test_expect_success 'objectname goes through existence check' '
288 (
289 set_transport_variables "$daemon_parent" &&
290 cd "$daemon_parent/daemon_client_empty" &&
291
292 echo "$unstored_oid missing" >expect &&
293
294 git cat-file --batch-command="%(objectname)" >actual <<-EOF &&
295 remote-object-info "$GIT_DAEMON_URL/parent" $unstored_oid
296 EOF
297
298 test_cmp expect actual
299 )
300 '
301
302 # Test --batch-command remote-object-info with 'git://' and
303 # transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
304 test_expect_success 'batch-command remote-object-info git:// fails when transfer.advertiseobjectinfo=false' '
305 (
306 git -C "$daemon_parent" config transfer.advertiseobjectinfo false &&
307 set_transport_variables "$daemon_parent" &&
308
309 test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
310 remote-object-info $GIT_DAEMON_URL/parent $hello_oid $tree_oid $commit_oid $tag_oid
311 EOF
312 test_grep "object-info capability is not enabled on the server" err &&
313
314 # revert server state back
315 git -C "$daemon_parent" config transfer.advertiseobjectinfo true
316
317 )
318 '
319
320 stop_git_daemon
321
322 # Test --batch-command remote-object-info with 'file://' transport with
323 # transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
324 # shellcheck disable=SC2016
325 test_expect_success 'create repo to be served by file:// transport' '
326 git init server &&
327 git -C server config protocol.version 2 &&
328 git -C server config transfer.advertiseobjectinfo true &&
329 echo_without_newline "$hello_content" > server/hello &&
330 git -C server update-index --add hello &&
331 git clone -n "file://$(pwd)/server" file_client_empty
332 '
333
334 test_expect_success 'batch-command remote-object-info file://' '
335 (
336 set_transport_variables "server" &&
337 server_path="$(pwd)/server" &&
338 cd file_client_empty &&
339
340 # These results prove remote-object-info can get object info from the remote
341 echo "$hello_oid $hello_size" >expect &&
342 echo "$tree_oid $tree_size" >>expect &&
343 echo "$commit_oid $commit_size" >>expect &&
344 echo "$tag_oid $tag_size" >>expect &&
345
346 # These results prove remote-object-info did not download objects from the remote
347 echo "$hello_oid missing" >>expect &&
348 echo "$tree_oid missing" >>expect &&
349 echo "$commit_oid missing" >>expect &&
350 echo "$tag_oid missing" >>expect &&
351
352 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
353 remote-object-info "file://${server_path}" $hello_oid
354 remote-object-info "file://${server_path}" $tree_oid
355 remote-object-info "file://${server_path}" $commit_oid
356 remote-object-info "file://${server_path}" $tag_oid
357 info $hello_oid
358 info $tree_oid
359 info $commit_oid
360 info $tag_oid
361 EOF
362 test_cmp expect actual
363 )
364 '
365
366 test_expect_success 'batch-command remote-object-info file:// multiple sha1 per line' '
367 (
368 set_transport_variables "server" &&
369 server_path="$(pwd)/server" &&
370 cd file_client_empty &&
371
372 # These results prove remote-object-info can get object info from the remote
373 echo "$hello_oid $hello_size" >expect &&
374 echo "$tree_oid $tree_size" >>expect &&
375 echo "$commit_oid $commit_size" >>expect &&
376 echo "$tag_oid $tag_size" >>expect &&
377
378 # These results prove remote-object-info did not download objects from the remote
379 echo "$hello_oid missing" >>expect &&
380 echo "$tree_oid missing" >>expect &&
381 echo "$commit_oid missing" >>expect &&
382 echo "$tag_oid missing" >>expect &&
383
384
385 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
386 remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid
387 info $hello_oid
388 info $tree_oid
389 info $commit_oid
390 info $tag_oid
391 EOF
392 test_cmp expect actual
393 )
394 '
395
396 test_expect_success 'batch-command --buffer remote-object-info file://' '
397 (
398 set_transport_variables "server" &&
399 server_path="$(pwd)/server" &&
400 cd file_client_empty &&
401
402 # These results prove remote-object-info can get object info from the remote
403 echo "$hello_oid $hello_size" >expect &&
404 echo "$tree_oid $tree_size" >>expect &&
405 echo "$commit_oid $commit_size" >>expect &&
406 echo "$tag_oid $tag_size" >>expect &&
407
408 # These results prove remote-object-info did not download objects from the remote
409 echo "$hello_oid missing" >>expect &&
410 echo "$tree_oid missing" >>expect &&
411 echo "$commit_oid missing" >>expect &&
412 echo "$tag_oid missing" >>expect &&
413
414 git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
415 remote-object-info "file://${server_path}" $hello_oid $tree_oid
416 remote-object-info "file://${server_path}" $commit_oid $tag_oid
417 info $hello_oid
418 info $tree_oid
419 info $commit_oid
420 info $tag_oid
421 flush
422 EOF
423 test_cmp expect actual
424 )
425 '
426
427 test_expect_success 'batch-command remote-object-info file:// default filter' '
428 (
429 set_transport_variables "server" &&
430 server_path="$(pwd)/server" &&
431 cd file_client_empty &&
432
433 echo "$hello_oid $hello_size" >expect &&
434 echo "$tree_oid $tree_size" >>expect &&
435 echo "$commit_oid $commit_size" >>expect &&
436 echo "$tag_oid $tag_size" >>expect &&
437
438 git cat-file --batch-command >actual <<-EOF &&
439 remote-object-info "file://${server_path}" $hello_oid $tree_oid
440 remote-object-info "file://${server_path}" $commit_oid $tag_oid
441 EOF
442 test_cmp expect actual
443 )
444 '
445
446 test_expect_success 'batch-command -Z remote-object-info file:// default filter' '
447 (
448 set_transport_variables "server" &&
449 server_path="$(pwd)/server" &&
450 cd file_client_empty &&
451
452 printf "%s\0" "$hello_oid $hello_size" >expect &&
453 printf "%s\0" "$tree_oid $tree_size" >>expect &&
454 printf "%s\0" "$commit_oid $commit_size" >>expect &&
455 printf "%s\0" "$tag_oid $tag_size" >>expect &&
456
457 printf "%s\0" "$hello_oid missing" >>expect &&
458 printf "%s\0" "$tree_oid missing" >>expect &&
459 printf "%s\0" "$commit_oid missing" >>expect &&
460 printf "%s\0" "$tag_oid missing" >>expect &&
461
462 batch_input="remote-object-info \"file://${server_path}\" $hello_oid $tree_oid
463 remote-object-info \"file://${server_path}\" $commit_oid $tag_oid
464 info $hello_oid
465 info $tree_oid
466 info $commit_oid
467 info $tag_oid
468 " &&
469 echo_without_newline_nul "$batch_input" >commands_null_delimited &&
470
471 git cat-file --batch-command -Z < commands_null_delimited >actual &&
472 test_cmp expect actual
473 )
474 '
475
476 # Test --batch-command remote-object-info with 'file://' and
477 # transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
478 test_expect_success 'batch-command remote-object-info file:// fails when transfer.advertiseobjectinfo=false' '
479 (
480 set_transport_variables "server" &&
481 server_path="$(pwd)/server" &&
482 git -C "${server_path}" config transfer.advertiseobjectinfo false &&
483
484 test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
485 remote-object-info "file://${server_path}" $hello_oid $tree_oid $commit_oid $tag_oid
486 EOF
487 test_grep "object-info capability is not enabled on the server" err &&
488
489 # revert server state back
490 git -C "${server_path}" config transfer.advertiseobjectinfo true
491 )
492 '
493
494 # Test --batch-command remote-object-info with 'http://' transport with
495 # transfer.advertiseobjectinfo set to true, i.e. server has object-info capability
496
497 . "$TEST_DIRECTORY"/lib-httpd.sh
498 start_httpd
499
500 test_expect_success 'create repo to be served by http:// transport' '
501 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
502 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
503 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true &&
504 echo_without_newline "$hello_content" > $HTTPD_DOCUMENT_ROOT_PATH/http_parent/hello &&
505 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" update-index --add hello &&
506 git clone "$HTTPD_URL/smart/http_parent" -n "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty"
507 '
508
509 test_expect_success 'batch-command remote-object-info http://' '
510 (
511 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
512 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
513
514 # These results prove remote-object-info can get object info from the remote
515 echo "$hello_oid $hello_size" >expect &&
516 echo "$tree_oid $tree_size" >>expect &&
517 echo "$commit_oid $commit_size" >>expect &&
518 echo "$tag_oid $tag_size" >>expect &&
519
520 # These results prove remote-object-info did not download objects from the remote
521 echo "$hello_oid missing" >>expect &&
522 echo "$tree_oid missing" >>expect &&
523 echo "$commit_oid missing" >>expect &&
524 echo "$tag_oid missing" >>expect &&
525
526 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
527 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
528 remote-object-info "$HTTPD_URL/smart/http_parent" $tree_oid
529 remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid
530 remote-object-info "$HTTPD_URL/smart/http_parent" $tag_oid
531 info $hello_oid
532 info $tree_oid
533 info $commit_oid
534 info $tag_oid
535 EOF
536 test_cmp expect actual
537 )
538 '
539
540 test_expect_success 'batch-command remote-object-info http:// one line' '
541 (
542 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
543 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
544
545 # These results prove remote-object-info can get object info from the remote
546 echo "$hello_oid $hello_size" >expect &&
547 echo "$tree_oid $tree_size" >>expect &&
548 echo "$commit_oid $commit_size" >>expect &&
549 echo "$tag_oid $tag_size" >>expect &&
550
551 # These results prove remote-object-info did not download objects from the remote
552 echo "$hello_oid missing" >>expect &&
553 echo "$tree_oid missing" >>expect &&
554 echo "$commit_oid missing" >>expect &&
555 echo "$tag_oid missing" >>expect &&
556
557 git cat-file --batch-command="%(objectname) %(objectsize)" >actual <<-EOF &&
558 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid
559 info $hello_oid
560 info $tree_oid
561 info $commit_oid
562 info $tag_oid
563 EOF
564 test_cmp expect actual
565 )
566 '
567
568 test_expect_success 'batch-command --buffer remote-object-info http://' '
569 (
570 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
571 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
572
573 # These results prove remote-object-info can get object info from the remote
574 echo "$hello_oid $hello_size" >expect &&
575 echo "$tree_oid $tree_size" >>expect &&
576 echo "$commit_oid $commit_size" >>expect &&
577 echo "$tag_oid $tag_size" >>expect &&
578
579 # These results prove remote-object-info did not download objects from the remote
580 echo "$hello_oid missing" >>expect &&
581 echo "$tree_oid missing" >>expect &&
582 echo "$commit_oid missing" >>expect &&
583 echo "$tag_oid missing" >>expect &&
584
585 git cat-file --batch-command="%(objectname) %(objectsize)" --buffer >actual <<-EOF &&
586 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
587 remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid
588 info $hello_oid
589 info $tree_oid
590 info $commit_oid
591 info $tag_oid
592 flush
593 EOF
594 test_cmp expect actual
595 )
596 '
597
598 test_expect_success 'batch-command remote-object-info http:// default filter' '
599 (
600 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
601 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
602
603 echo "$hello_oid $hello_size" >expect &&
604 echo "$tree_oid $tree_size" >>expect &&
605 echo "$commit_oid $commit_size" >>expect &&
606 echo "$tag_oid $tag_size" >>expect &&
607
608 git cat-file --batch-command >actual <<-EOF &&
609 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid
610 remote-object-info "$HTTPD_URL/smart/http_parent" $commit_oid $tag_oid
611 EOF
612 test_cmp expect actual
613 )
614 '
615
616 test_expect_success 'batch-command -Z remote-object-info http:// default filter' '
617 (
618 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
619 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_client_empty" &&
620
621 printf "%s\0" "$hello_oid $hello_size" >expect &&
622 printf "%s\0" "$tree_oid $tree_size" >>expect &&
623 printf "%s\0" "$commit_oid $commit_size" >>expect &&
624 printf "%s\0" "$tag_oid $tag_size" >>expect &&
625
626 batch_input="remote-object-info $HTTPD_URL/smart/http_parent $hello_oid $tree_oid
627 remote-object-info $HTTPD_URL/smart/http_parent $commit_oid $tag_oid
628 " &&
629 echo_without_newline_nul "$batch_input" >commands_null_delimited &&
630
631 git cat-file --batch-command -Z < commands_null_delimited >actual &&
632 test_cmp expect actual
633 )
634 '
635
636 test_expect_success 'remote-object-info fails on unsupported filter option (objectsize:disk)' '
637 (
638 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
639 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
640
641 echo "$hello_oid " >expect &&
642
643 git cat-file --batch-command="%(objectname) %(objectsize:disk)" >actual <<-EOF &&
644 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
645 EOF
646 test_cmp expect actual
647 )
648 '
649
650 test_expect_success 'remote-object-info fails on unsupported filter option (deltabase)' '
651 (
652 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
653 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
654
655 echo "" >expect &&
656
657 git cat-file --batch-command="%(deltabase)" >actual <<-EOF &&
658 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
659 EOF
660 test_cmp expect actual
661 )
662 '
663
664 test_expect_success 'remote-object-info fails on server with legacy protocol' '
665 (
666 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
667 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
668
669 test_must_fail git -c protocol.version=0 cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
670 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
671 EOF
672 test_grep "object-info requires protocol v2" err
673 )
674 '
675
676 test_expect_success 'remote-object-info fails on server with legacy protocol with default filter' '
677 (
678 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
679 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
680
681 test_must_fail git -c protocol.version=0 cat-file --batch-command 2>err <<-EOF &&
682 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid
683 EOF
684 test_grep "object-info requires protocol v2" err
685 )
686 '
687
688 test_expect_success 'remote-object-info fails on malformed OID' '
689 (
690 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
691 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
692 malformed_object_id="this_id_is_not_valid" &&
693
694 test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
695 remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id
696 EOF
697 test_grep "not a valid object name '$malformed_object_id'" err
698 )
699 '
700
701 test_expect_success 'remote-object-info fails on malformed OID with default filter' '
702 (
703 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
704 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
705 malformed_object_id="this_id_is_not_valid" &&
706
707 test_must_fail git cat-file --batch-command 2>err <<-EOF &&
708 remote-object-info "$HTTPD_URL/smart/http_parent" $malformed_object_id
709 EOF
710 test_grep "not a valid object name '$malformed_object_id'" err
711 )
712 '
713
714 test_expect_success 'remote-object-info fails on not providing OID' '
715 (
716 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
717 cd "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
718
719 test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
720 remote-object-info "$HTTPD_URL/smart/http_parent"
721 EOF
722 test_grep "remote-object-info requires objects" err
723 )
724 '
725
726
727 # Test --batch-command remote-object-info with 'http://' transport and
728 # transfer.advertiseobjectinfo set to false, i.e. server does not have object-info capability
729 test_expect_success 'batch-command remote-object-info http:// fails when transfer.advertiseobjectinfo=false ' '
730 (
731 set_transport_variables "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
732 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo false &&
733
734 test_must_fail git cat-file --batch-command="%(objectname) %(objectsize)" 2>err <<-EOF &&
735 remote-object-info "$HTTPD_URL/smart/http_parent" $hello_oid $tree_oid $commit_oid $tag_oid
736 EOF
737 test_grep "object-info capability is not enabled on the server" err &&
738
739 # revert server state back
740 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config transfer.advertiseobjectinfo true
741 )
742 '
743
744 # DO NOT add non-httpd-specific tests here, because the last part of this
745 # test script is only executed when httpd is available and enabled.
746
747 test_done