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/t5701-git-serve.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 / t5701-git-serve.sh` 534 lines ยท 12449 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test protocol v2 server commands' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 unknown_oid=$(printf "test" | git hash-object --stdin) 11 12 test_expect_success 'setup to generate files with expected content' ' 13 printf "agent=git/%s" "$(git version | cut -d" " -f3)" >agent_capability && 14 15 test_oid_cache <<-EOF && 16 wrong_algo sha1:sha256 17 wrong_algo sha256:sha1 18 EOF 19 20 if test_have_prereq WINDOWS 21 then 22 printf "agent=FAKE\n" >agent_capability 23 else 24 printf -- "-%s\n" $(uname -s | test_redact_non_printables) >>agent_capability 25 fi && 26 cat >expect.base <<-EOF && 27 version 2 28 $(cat agent_capability) 29 ls-refs=unborn 30 fetch=shallow wait-for-done 31 server-option 32 object-format=$(test_oid algo) 33 EOF 34 cat >expect.trailer <<-EOF 35 0000 36 EOF 37 ' 38 39 test_expect_success 'test capability advertisement' ' 40 cat expect.base expect.trailer >expect && 41 42 if test_have_prereq WINDOWS 43 then 44 GIT_USER_AGENT=FAKE && export GIT_USER_AGENT 45 fi && 46 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ 47 --advertise-capabilities >out && 48 test-tool pkt-line unpack actual && 49 test_cmp expect actual 50 ' 51 52 test_expect_success 'stateless-rpc flag does not list capabilities' ' 53 # Empty request 54 test-tool pkt-line pack >in <<-EOF && 55 0000 56 EOF 57 test-tool serve-v2 --stateless-rpc >out out && 62 test_must_be_empty out 63 ' 64 65 test_expect_success 'request invalid capability' ' 66 test-tool pkt-line pack >in <<-EOF && 67 foobar 68 0000 69 EOF 70 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 76 command=ls-refs 77 object-format=$(test_oid algo) 78 promisor-remote 79 0000 80 EOF 81 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 87 agent=git/test 88 object-format=$(test_oid algo) 89 0000 90 EOF 91 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 97 command=foo 98 object-format=$(test_oid algo) 99 agent=git/test 100 0000 101 EOF 102 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 108 command=agent 109 object-format=$(test_oid algo) 110 0000 111 EOF 112 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 118 command=ls-refs 119 object-format=$(test_oid algo) 120 fetch 121 0000 122 EOF 123 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 129 command=ls-refs=whatever 130 object-format=$(test_oid algo) 131 0000 132 EOF 133 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 139 command=fetch 140 agent=git/test 141 object-format=$(test_oid wrong_algo) 142 0000 143 EOF 144 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 160 command=ls-refs 161 object-format=$(test_oid algo) 162 0000 163 EOF 164 165 cat >expect <<-EOF && 166 $(git rev-parse HEAD) HEAD 167 $(git rev-parse refs/heads/dev) refs/heads/dev 168 $(git rev-parse refs/heads/main) refs/heads/main 169 $(git rev-parse refs/heads/release) refs/heads/release 170 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag 171 $(git rev-parse refs/tags/one) refs/tags/one 172 $(git rev-parse refs/tags/two) refs/tags/two 173 0000 174 EOF 175 176 test-tool serve-v2 --stateless-rpc out && 177 test-tool pkt-line unpack actual && 178 test_cmp expect actual 179 ' 180 181 test_expect_success 'ls-refs complains about unknown options' ' 182 test-tool pkt-line pack >in <<-EOF && 183 command=ls-refs 184 object-format=$(test_oid algo) 185 0001 186 no-such-arg 187 0000 188 EOF 189 190 test_must_fail test-tool serve-v2 --stateless-rpc 2>err in <<-EOF && 196 command=ls-refs 197 object-format=$(test_oid algo) 198 0001 199 ref-prefix refs/heads/main 200 ref-prefix refs/tags/one 201 0000 202 EOF 203 204 cat >expect <<-EOF && 205 $(git rev-parse refs/heads/main) refs/heads/main 206 $(git rev-parse refs/tags/one) refs/tags/one 207 0000 208 EOF 209 210 test-tool serve-v2 --stateless-rpc out && 211 test-tool pkt-line unpack actual && 212 test_cmp expect actual 213 ' 214 215 test_expect_success 'refs/heads prefix' ' 216 test-tool pkt-line pack >in <<-EOF && 217 command=ls-refs 218 object-format=$(test_oid algo) 219 0001 220 ref-prefix refs/heads/ 221 0000 222 EOF 223 224 cat >expect <<-EOF && 225 $(git rev-parse refs/heads/dev) refs/heads/dev 226 $(git rev-parse refs/heads/main) refs/heads/main 227 $(git rev-parse refs/heads/release) refs/heads/release 228 0000 229 EOF 230 231 test-tool serve-v2 --stateless-rpc out && 232 test-tool pkt-line unpack actual && 233 test_cmp expect actual 234 ' 235 236 test_expect_success 'ignore very large set of prefixes' ' 237 # generate a large number of ref-prefixes that we expect 238 # to match nothing; the value here exceeds TOO_MANY_PREFIXES 239 # from ls-refs.c. 240 { 241 echo command=ls-refs && 242 echo object-format=$(test_oid algo) && 243 echo 0001 && 244 awk "{ 245 for (i = 1; i <= 65536; i++) 246 print \"ref-prefix refs/heads/\", \$i 247 }" && 248 echo 0000 249 } | 250 test-tool pkt-line pack >in && 251 252 # and then confirm that we see unmatched prefixes anyway (i.e., 253 # that the prefix was not applied). 254 cat >expect <<-EOF && 255 $(git rev-parse HEAD) HEAD 256 $(git rev-parse refs/heads/dev) refs/heads/dev 257 $(git rev-parse refs/heads/main) refs/heads/main 258 $(git rev-parse refs/heads/release) refs/heads/release 259 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag 260 $(git rev-parse refs/tags/one) refs/tags/one 261 $(git rev-parse refs/tags/two) refs/tags/two 262 0000 263 EOF 264 265 test-tool serve-v2 --stateless-rpc out && 266 test-tool pkt-line unpack actual && 267 test_cmp expect actual 268 ' 269 270 test_expect_success 'peel parameter' ' 271 test-tool pkt-line pack >in <<-EOF && 272 command=ls-refs 273 object-format=$(test_oid algo) 274 0001 275 peel 276 ref-prefix refs/tags/ 277 0000 278 EOF 279 280 cat >expect <<-EOF && 281 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{}) 282 $(git rev-parse refs/tags/one) refs/tags/one 283 $(git rev-parse refs/tags/two) refs/tags/two 284 0000 285 EOF 286 287 test-tool serve-v2 --stateless-rpc out && 288 test-tool pkt-line unpack actual && 289 test_cmp expect actual 290 ' 291 292 test_expect_success 'symrefs parameter' ' 293 test-tool pkt-line pack >in <<-EOF && 294 command=ls-refs 295 object-format=$(test_oid algo) 296 0001 297 symrefs 298 ref-prefix refs/heads/ 299 0000 300 EOF 301 302 cat >expect <<-EOF && 303 $(git rev-parse refs/heads/dev) refs/heads/dev 304 $(git rev-parse refs/heads/main) refs/heads/main 305 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main 306 0000 307 EOF 308 309 test-tool serve-v2 --stateless-rpc out && 310 test-tool pkt-line unpack actual && 311 test_cmp expect actual 312 ' 313 314 test_expect_success 'sending server-options' ' 315 test-tool pkt-line pack >in <<-EOF && 316 command=ls-refs 317 object-format=$(test_oid algo) 318 server-option=hello 319 server-option=world 320 0001 321 ref-prefix HEAD 322 0000 323 EOF 324 325 cat >expect <<-EOF && 326 $(git rev-parse HEAD) HEAD 327 0000 328 EOF 329 330 test-tool serve-v2 --stateless-rpc out && 331 test-tool pkt-line unpack actual && 332 test_cmp expect actual 333 ' 334 335 test_expect_success 'unexpected lines are not allowed in fetch request' ' 336 git init server && 337 338 test-tool pkt-line pack >in <<-EOF && 339 command=fetch 340 object-format=$(test_oid algo) 341 0001 342 this-is-not-a-command 343 0000 344 EOF 345 346 ( 347 cd server && 348 test_must_fail test-tool serve-v2 --stateless-rpc 349 ) /dev/null 2>err && 350 test_grep "unexpected line: .this-is-not-a-command." err 351 ' 352 353 # Test the basics of object-info 354 # 355 test_expect_success 'basics of object-info' ' 356 test_config transfer.advertiseObjectInfo true && 357 358 two_oid=$(git rev-parse two:two.t) && 359 two_size=$(test_file_size two.t) && 360 361 test-tool pkt-line pack >in <<-EOF && 362 command=object-info 363 object-format=$(test_oid algo) 364 0001 365 size 366 oid $two_oid 367 oid $two_oid 368 0000 369 EOF 370 371 cat >expect <<-EOF && 372 size 373 $two_oid $two_size 374 $two_oid $two_size 375 0000 376 EOF 377 378 test-tool serve-v2 --stateless-rpc out && 379 test-tool pkt-line unpack actual && 380 test_cmp expect actual 381 ' 382 383 test_expect_success 'object-info supports type' ' 384 test_config transfer.advertiseObjectInfo true && 385 386 two_oid=$(git rev-parse two:two.t) && 387 two_size=$(test_file_size two.t) && 388 389 test-tool pkt-line pack >in <<-EOF && 390 command=object-info 391 object-format=$(test_oid algo) 392 0001 393 size 394 type 395 oid $two_oid 396 oid $two_oid 397 0000 398 EOF 399 400 cat >expect <<-EOF && 401 size 402 type 403 $two_oid $two_size blob 404 $two_oid $two_size blob 405 0000 406 EOF 407 408 test-tool serve-v2 --stateless-rpc out && 409 test-tool pkt-line unpack actual && 410 test_cmp expect actual 411 ' 412 413 test_expect_success 'bare OID request' ' 414 test_config transfer.advertiseObjectInfo true && 415 416 test-tool pkt-line pack >in <<-EOF && 417 command=object-info 418 object-format=$(test_oid algo) 419 0001 420 oid $(git rev-parse two:two.t) 421 0000 422 EOF 423 424 cat >expect <<-EOF && 425 $(git rev-parse two:two.t) 426 0000 427 EOF 428 429 test-tool serve-v2 --stateless-rpc out && 430 test-tool pkt-line unpack actual && 431 test_cmp expect actual 432 ' 433 434 test_expect_success 'object-info with bare unrecognized OID' ' 435 test_config transfer.advertiseObjectInfo true && 436 437 test-tool pkt-line pack >in <<-EOF && 438 command=object-info 439 object-format=$(test_oid algo) 440 0001 441 oid $unknown_oid 442 0000 443 EOF 444 445 printf "%s \n" "$unknown_oid" >expect && 446 printf "0000\n" >>expect && 447 448 test-tool serve-v2 --stateless-rpc out && 449 test-tool pkt-line unpack actual && 450 test_cmp expect actual 451 ' 452 453 test_expect_success 'object-info with size for unrecognized OID' ' 454 test_config transfer.advertiseObjectInfo true && 455 456 test-tool pkt-line pack >in <<-EOF && 457 command=object-info 458 object-format=$(test_oid algo) 459 0001 460 size 461 oid $unknown_oid 462 0000 463 EOF 464 465 printf "size\n" >expect && 466 printf "%s \n" "$unknown_oid" >>expect && 467 printf "0000\n" >>expect && 468 469 test-tool serve-v2 --stateless-rpc out && 470 test-tool pkt-line unpack actual && 471 test_cmp expect actual 472 ' 473 474 test_expect_success 'test capability advertisement with uploadpack.advertiseBundleURIs' ' 475 test_config uploadpack.advertiseBundleURIs true && 476 477 cat >expect.extra <<-EOF && 478 bundle-uri 479 EOF 480 cat expect.base \ 481 expect.extra \ 482 expect.trailer >expect && 483 484 if test_have_prereq WINDOWS 485 then 486 GIT_USER_AGENT=FAKE && export GIT_USER_AGENT 487 fi && 488 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ 489 --advertise-capabilities >out && 490 test-tool pkt-line unpack actual && 491 test_cmp expect actual 492 ' 493 494 test_expect_success 'basics of bundle-uri: dies if not enabled' ' 495 test-tool pkt-line pack >in <<-EOF && 496 command=bundle-uri 497 0000 498 EOF 499 500 cat >err.expect <<-\EOF && 501 fatal: invalid command '"'"'bundle-uri'"'"' 502 EOF 503 504 cat >expect <<-\EOF && 505 ERR serve: invalid command '"'"'bundle-uri'"'"' 506 EOF 507 508 test_must_fail test-tool serve-v2 --stateless-rpc out 2>err.actual && 509 test_cmp err.expect err.actual && 510 test_must_be_empty out 511 ' 512 513 test_expect_success 'object-info missing from capabilities when disabled' ' 514 test_config transfer.advertiseObjectInfo false && 515 516 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ 517 --advertise-capabilities >out && 518 test-tool pkt-line unpack actual && 519 520 test_grep ! object.info actual 521 ' 522 523 test_expect_success 'object-info commands rejected when disabled' ' 524 test_config transfer.advertiseObjectInfo false && 525 526 test-tool pkt-line pack >in <<-EOF && 527 command=object-info 528 EOF 529 530 test_must_fail test-tool serve-v2 --stateless-rpc err && 531 test_grep invalid.command err 532 ' 533 534 test_done