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