Git fork
at reftables-rust 782 lines 26 kB view raw
1#!/bin/sh 2 3test_description='partial clone' 4 5. ./test-lib.sh 6. "$TEST_DIRECTORY"/lib-terminal.sh 7 8# When enabled, some commands will write commit-graphs. This causes fsck 9# to fail when delete_object() is called because fsck will attempt to 10# verify the out-of-sync commit graph. 11GIT_TEST_COMMIT_GRAPH=0 12 13delete_object () { 14 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|') 15} 16 17pack_as_from_promisor () { 18 HASH=$(git -C repo pack-objects .git/objects/pack/pack) && 19 >repo/.git/objects/pack/pack-$HASH.promisor && 20 echo $HASH 21} 22 23promise_and_delete () { 24 HASH=$(git -C repo rev-parse "$1") && 25 git -C repo tag -a -m message my_annotated_tag "$HASH" && 26 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor && 27 # tag -d prints a message to stdout, so redirect it 28 git -C repo tag -d my_annotated_tag >/dev/null && 29 delete_object repo "$HASH" 30} 31 32test_expect_success 'extensions.partialclone without filter' ' 33 test_create_repo server && 34 git clone --filter="blob:none" "file://$(pwd)/server" client && 35 git -C client config --unset remote.origin.partialclonefilter && 36 git -C client fetch origin 37' 38 39test_expect_success 'convert shallow clone to partial clone' ' 40 rm -fr server client && 41 test_create_repo server && 42 test_commit -C server my_commit 1 && 43 test_commit -C server my_commit2 1 && 44 git clone --depth=1 "file://$(pwd)/server" client && 45 git -C client fetch --unshallow --filter="blob:none" && 46 test_cmp_config -C client true remote.origin.promisor && 47 test_cmp_config -C client blob:none remote.origin.partialclonefilter && 48 test_cmp_config -C client 1 core.repositoryformatversion 49' 50 51test_expect_success DEFAULT_REPO_FORMAT 'convert to partial clone with noop extension' ' 52 rm -fr server client && 53 test_create_repo server && 54 test_commit -C server my_commit 1 && 55 test_commit -C server my_commit2 1 && 56 git clone --depth=1 "file://$(pwd)/server" client && 57 test_cmp_config -C client 0 core.repositoryformatversion && 58 git -C client config extensions.noop true && 59 git -C client fetch --unshallow --filter="blob:none" 60' 61 62test_expect_success DEFAULT_REPO_FORMAT 'converting to partial clone fails with unrecognized extension' ' 63 rm -fr server client && 64 test_create_repo server && 65 test_commit -C server my_commit 1 && 66 test_commit -C server my_commit2 1 && 67 git clone --depth=1 "file://$(pwd)/server" client && 68 test_cmp_config -C client 0 core.repositoryformatversion && 69 git -C client config extensions.nonsense true && 70 test_must_fail git -C client fetch --unshallow --filter="blob:none" 71' 72 73test_expect_success 'missing reflog object, but promised by a commit, passes fsck' ' 74 rm -rf repo && 75 test_create_repo repo && 76 test_commit -C repo my_commit && 77 78 A=$(git -C repo commit-tree -m a HEAD^{tree}) && 79 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) && 80 81 # Reference $A only from reflog, and delete it 82 git -C repo branch my_branch "$A" && 83 git -C repo branch -f my_branch my_commit && 84 delete_object repo "$A" && 85 86 # State that we got $C, which refers to $A, from promisor 87 printf "$C\n" | pack_as_from_promisor && 88 89 # Normally, it fails 90 test_must_fail git -C repo fsck && 91 92 # But with the extension, it succeeds 93 git -C repo config core.repositoryformatversion 1 && 94 git -C repo config extensions.partialclone "arbitrary string" && 95 git -C repo fsck 96' 97 98test_expect_success 'missing reflog object, but promised by a tag, passes fsck' ' 99 rm -rf repo && 100 test_create_repo repo && 101 test_commit -C repo my_commit && 102 103 A=$(git -C repo commit-tree -m a HEAD^{tree}) && 104 git -C repo tag -a -m d my_tag_name $A && 105 T=$(git -C repo rev-parse my_tag_name) && 106 git -C repo tag -d my_tag_name && 107 108 # Reference $A only from reflog, and delete it 109 git -C repo branch my_branch "$A" && 110 git -C repo branch -f my_branch my_commit && 111 delete_object repo "$A" && 112 113 # State that we got $T, which refers to $A, from promisor 114 printf "$T\n" | pack_as_from_promisor && 115 116 git -C repo config core.repositoryformatversion 1 && 117 git -C repo config extensions.partialclone "arbitrary string" && 118 git -C repo fsck 119' 120 121test_expect_success 'missing reflog object alone fails fsck, even with extension set' ' 122 rm -rf repo && 123 test_create_repo repo && 124 test_commit -C repo my_commit && 125 126 A=$(git -C repo commit-tree -m a HEAD^{tree}) && 127 B=$(git -C repo commit-tree -m b HEAD^{tree}) && 128 129 # Reference $A only from reflog, and delete it 130 git -C repo branch my_branch "$A" && 131 git -C repo branch -f my_branch my_commit && 132 delete_object repo "$A" && 133 134 git -C repo config core.repositoryformatversion 1 && 135 git -C repo config extensions.partialclone "arbitrary string" && 136 test_must_fail git -C repo fsck 137' 138 139test_expect_success 'missing ref object, but promised, passes fsck' ' 140 rm -rf repo && 141 test_create_repo repo && 142 test_commit -C repo my_commit && 143 144 A=$(git -C repo commit-tree -m a HEAD^{tree}) && 145 146 # Reference $A only from ref 147 git -C repo branch my_branch "$A" && 148 promise_and_delete "$A" && 149 150 git -C repo config core.repositoryformatversion 1 && 151 git -C repo config extensions.partialclone "arbitrary string" && 152 git -C repo fsck 153' 154 155test_expect_success 'missing object, but promised, passes fsck' ' 156 rm -rf repo && 157 test_create_repo repo && 158 test_commit -C repo 1 && 159 test_commit -C repo 2 && 160 test_commit -C repo 3 && 161 git -C repo tag -a annotated_tag -m "annotated tag" && 162 163 C=$(git -C repo rev-parse 1) && 164 T=$(git -C repo rev-parse 2^{tree}) && 165 B=$(git hash-object repo/3.t) && 166 AT=$(git -C repo rev-parse annotated_tag) && 167 168 promise_and_delete "$C" && 169 promise_and_delete "$T" && 170 promise_and_delete "$B" && 171 promise_and_delete "$AT" && 172 173 git -C repo config core.repositoryformatversion 1 && 174 git -C repo config extensions.partialclone "arbitrary string" && 175 git -C repo fsck 176' 177 178test_expect_success 'missing CLI object, but promised, passes fsck' ' 179 rm -rf repo && 180 test_create_repo repo && 181 test_commit -C repo my_commit && 182 183 A=$(git -C repo commit-tree -m a HEAD^{tree}) && 184 promise_and_delete "$A" && 185 186 git -C repo config core.repositoryformatversion 1 && 187 git -C repo config extensions.partialclone "arbitrary string" && 188 git -C repo fsck "$A" 189' 190 191test_expect_success 'fetching of missing objects' ' 192 rm -rf repo err && 193 test_create_repo server && 194 test_commit -C server foo && 195 git -C server repack -a -d --write-bitmap-index && 196 197 git clone "file://$(pwd)/server" repo && 198 HASH=$(git -C repo rev-parse foo) && 199 rm -rf repo/.git/objects/* && 200 201 git -C repo config core.repositoryformatversion 1 && 202 git -C repo config extensions.partialclone "origin" && 203 git -C repo cat-file -p "$HASH" 2>err && 204 205 # Ensure that no spurious FETCH_HEAD messages are written 206 ! grep FETCH_HEAD err && 207 208 # Ensure that the .promisor file is written, and check that its 209 # associated packfile contains the object 210 ls repo/.git/objects/pack/pack-*.promisor >promisorlist && 211 test_line_count = 1 promisorlist && 212 IDX=$(sed "s/promisor$/idx/" promisorlist) && 213 git verify-pack --verbose "$IDX" >out && 214 grep "$HASH" out 215' 216 217test_expect_success 'fetching of a promised object that promisor remote no longer has' ' 218 rm -f err && 219 test_create_repo unreliable-server && 220 git -C unreliable-server config uploadpack.allowanysha1inwant 1 && 221 git -C unreliable-server config uploadpack.allowfilter 1 && 222 test_commit -C unreliable-server foo && 223 224 git clone --filter=blob:none --no-checkout "file://$(pwd)/unreliable-server" unreliable-client && 225 226 rm -rf unreliable-server/.git/objects/* && 227 test_must_fail git -C unreliable-client checkout HEAD 2>err && 228 grep "could not fetch.*from promisor remote" err 229' 230 231test_expect_success 'fetching of missing objects works with ref-in-want enabled' ' 232 # ref-in-want requires protocol version 2 233 git -C server config protocol.version 2 && 234 git -C server config uploadpack.allowrefinwant 1 && 235 git -C repo config protocol.version 2 && 236 237 rm -rf repo/.git/objects/* && 238 rm -f trace && 239 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" && 240 grep "fetch< fetch=.*ref-in-want" trace 241' 242 243test_expect_success 'fetching from another promisor remote' ' 244 git clone "file://$(pwd)/server" server2 && 245 test_commit -C server2 bar && 246 git -C server2 repack -a -d --write-bitmap-index && 247 HASH2=$(git -C server2 rev-parse bar) && 248 249 git -C repo remote add server2 "file://$(pwd)/server2" && 250 git -C repo config remote.server2.promisor true && 251 git -C repo cat-file -p "$HASH2" && 252 253 git -C repo fetch server2 && 254 rm -rf repo/.git/objects/* && 255 git -C repo cat-file -p "$HASH2" && 256 257 # Ensure that the .promisor file is written, and check that its 258 # associated packfile contains the object 259 ls repo/.git/objects/pack/pack-*.promisor >promisorlist && 260 test_line_count = 1 promisorlist && 261 IDX=$(sed "s/promisor$/idx/" promisorlist) && 262 git verify-pack --verbose "$IDX" >out && 263 grep "$HASH2" out 264' 265 266test_expect_success 'fetching with --filter configures a promisor remote' ' 267 test_create_repo server3 && 268 test_commit -C server3 baz && 269 git -C server3 repack -a -d --write-bitmap-index && 270 HASH3=$(git -C server3 rev-parse baz) && 271 git -C server3 config uploadpack.allowfilter 1 && 272 273 rm repo/.git/objects/pack/pack-*.promisor && 274 275 git -C repo remote add server3 "file://$(pwd)/server3" && 276 git -C repo fetch --filter="blob:none" server3 $HASH3 && 277 278 test_cmp_config -C repo true remote.server3.promisor && 279 280 # Ensure that the .promisor file is written, and check that its 281 # associated packfile contains the object 282 ls repo/.git/objects/pack/pack-*.promisor >promisorlist && 283 test_line_count = 1 promisorlist && 284 IDX=$(sed "s/promisor$/idx/" promisorlist) && 285 git verify-pack --verbose "$IDX" >out && 286 grep "$HASH3" out 287' 288 289test_expect_success 'fetching of missing blobs works' ' 290 rm -rf server server2 repo && 291 rm -rf server server3 repo && 292 test_create_repo server && 293 test_commit -C server foo && 294 git -C server repack -a -d --write-bitmap-index && 295 296 git clone "file://$(pwd)/server" repo && 297 git hash-object repo/foo.t >blobhash && 298 rm -rf repo/.git/objects/* && 299 300 git -C server config uploadpack.allowanysha1inwant 1 && 301 git -C server config uploadpack.allowfilter 1 && 302 git -C repo config core.repositoryformatversion 1 && 303 git -C repo config extensions.partialclone "origin" && 304 305 git -C repo cat-file -p $(cat blobhash) 306' 307 308test_expect_success 'fetching of missing trees does not fetch blobs' ' 309 rm -rf server repo && 310 test_create_repo server && 311 test_commit -C server foo && 312 git -C server repack -a -d --write-bitmap-index && 313 314 git clone "file://$(pwd)/server" repo && 315 git -C repo rev-parse foo^{tree} >treehash && 316 git hash-object repo/foo.t >blobhash && 317 rm -rf repo/.git/objects/* && 318 319 git -C server config uploadpack.allowanysha1inwant 1 && 320 git -C server config uploadpack.allowfilter 1 && 321 git -C repo config core.repositoryformatversion 1 && 322 git -C repo config extensions.partialclone "origin" && 323 git -C repo cat-file -p $(cat treehash) && 324 325 # Ensure that the tree, but not the blob, is fetched 326 git -C repo rev-list --objects --missing=print $(cat treehash) >objects && 327 grep "^$(cat treehash)" objects && 328 grep "^[?]$(cat blobhash)" objects 329' 330 331test_expect_success 'rev-list stops traversal at missing and promised commit' ' 332 rm -rf repo && 333 test_create_repo repo && 334 test_commit -C repo foo && 335 test_commit -C repo bar && 336 337 FOO=$(git -C repo rev-parse foo) && 338 promise_and_delete "$FOO" && 339 340 git -C repo config core.repositoryformatversion 1 && 341 git -C repo config extensions.partialclone "arbitrary string" && 342 git -C repo rev-list --exclude-promisor-objects --objects bar >out && 343 grep $(git -C repo rev-parse bar) out && 344 ! grep $FOO out 345' 346 347test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' ' 348 rm -rf repo && 349 test_create_repo repo && 350 test_commit -C repo foo && 351 test_commit -C repo bar && 352 test_commit -C repo baz && 353 354 promise_and_delete $(git -C repo rev-parse bar^{tree}) && 355 promise_and_delete $(git -C repo rev-parse foo^{tree}) && 356 357 git -C repo config core.repositoryformatversion 1 && 358 git -C repo config extensions.partialclone "arbitrary string" && 359 360 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err && 361 test_must_be_empty rev_list_err && 362 # 3 commits, 3 blobs, and 1 tree 363 test_line_count = 7 objs && 364 365 # Do the same for --exclude-promisor-objects, but with all trees gone. 366 promise_and_delete $(git -C repo rev-parse baz^{tree}) && 367 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err && 368 test_must_be_empty rev_list_err && 369 # 3 commits, no blobs or trees 370 test_line_count = 3 objs 371' 372 373test_expect_success 'missing non-root tree object and rev-list' ' 374 rm -rf repo && 375 test_create_repo repo && 376 mkdir repo/dir && 377 echo foo >repo/dir/foo && 378 git -C repo add dir/foo && 379 git -C repo commit -m "commit dir/foo" && 380 381 promise_and_delete $(git -C repo rev-parse HEAD:dir) && 382 383 git -C repo config core.repositoryformatversion 1 && 384 git -C repo config extensions.partialclone "arbitrary string" && 385 386 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err && 387 test_must_be_empty rev_list_err && 388 # 1 commit and 1 tree 389 test_line_count = 2 objs 390' 391 392test_expect_success 'rev-list stops traversal at missing and promised tree' ' 393 rm -rf repo && 394 test_create_repo repo && 395 test_commit -C repo foo && 396 mkdir repo/a_dir && 397 echo something >repo/a_dir/something && 398 git -C repo add a_dir/something && 399 git -C repo commit -m bar && 400 401 # foo^{tree} (tree referenced from commit) 402 TREE=$(git -C repo rev-parse foo^{tree}) && 403 404 # a tree referenced by HEAD^{tree} (tree referenced from tree) 405 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) && 406 407 promise_and_delete "$TREE" && 408 promise_and_delete "$TREE2" && 409 410 git -C repo config core.repositoryformatversion 1 && 411 git -C repo config extensions.partialclone "arbitrary string" && 412 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && 413 grep $(git -C repo rev-parse foo) out && 414 ! grep $TREE out && 415 grep $(git -C repo rev-parse HEAD) out && 416 ! grep $TREE2 out 417' 418 419test_expect_success 'rev-list stops traversal at missing and promised blob' ' 420 rm -rf repo && 421 test_create_repo repo && 422 echo something >repo/something && 423 git -C repo add something && 424 git -C repo commit -m foo && 425 426 BLOB=$(git -C repo hash-object -w something) && 427 promise_and_delete "$BLOB" && 428 429 git -C repo config core.repositoryformatversion 1 && 430 git -C repo config extensions.partialclone "arbitrary string" && 431 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && 432 grep $(git -C repo rev-parse HEAD) out && 433 ! grep $BLOB out 434' 435 436test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' ' 437 rm -rf repo && 438 test_create_repo repo && 439 test_commit -C repo foo && 440 test_commit -C repo bar && 441 test_commit -C repo baz && 442 443 COMMIT=$(git -C repo rev-parse foo) && 444 TREE=$(git -C repo rev-parse bar^{tree}) && 445 BLOB=$(git hash-object repo/baz.t) && 446 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor && 447 448 git -C repo config core.repositoryformatversion 1 && 449 git -C repo config extensions.partialclone "arbitrary string" && 450 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && 451 ! grep $COMMIT out && 452 ! grep $TREE out && 453 ! grep $BLOB out && 454 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done 455' 456 457test_expect_success 'rev-list dies for missing objects on cmd line' ' 458 rm -rf repo && 459 test_create_repo repo && 460 test_commit -C repo foo && 461 test_commit -C repo bar && 462 test_commit -C repo baz && 463 464 COMMIT=$(git -C repo rev-parse foo) && 465 TREE=$(git -C repo rev-parse bar^{tree}) && 466 BLOB=$(git hash-object repo/baz.t) && 467 468 promise_and_delete $COMMIT && 469 promise_and_delete $TREE && 470 promise_and_delete $BLOB && 471 472 git -C repo config core.repositoryformatversion 1 && 473 git -C repo config extensions.partialclone "arbitrary string" && 474 475 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do 476 test_must_fail git -C repo rev-list --objects \ 477 --exclude-promisor-objects "$OBJ" && 478 test_must_fail git -C repo rev-list --objects-edge-aggressive \ 479 --exclude-promisor-objects "$OBJ" && 480 481 # Do not die or crash when --ignore-missing is passed. 482 git -C repo rev-list --ignore-missing --objects \ 483 --exclude-promisor-objects "$OBJ" && 484 git -C repo rev-list --ignore-missing --objects-edge-aggressive \ 485 --exclude-promisor-objects "$OBJ" || return 1 486 done 487' 488 489test_expect_success 'single promisor remote can be re-initialized gracefully' ' 490 # ensure one promisor is in the promisors list 491 rm -rf repo && 492 test_create_repo repo && 493 test_create_repo other && 494 git -C repo remote add foo "file://$(pwd)/other" && 495 git -C repo config remote.foo.promisor true && 496 git -C repo config extensions.partialclone foo && 497 498 # reinitialize the promisors list 499 git -C repo fetch --filter=blob:none foo 500' 501 502test_expect_success 'gc repacks promisor objects separately from non-promisor objects' ' 503 rm -rf repo && 504 test_create_repo repo && 505 test_commit -C repo one && 506 test_commit -C repo two && 507 508 TREE_ONE=$(git -C repo rev-parse one^{tree}) && 509 printf "$TREE_ONE\n" | pack_as_from_promisor && 510 TREE_TWO=$(git -C repo rev-parse two^{tree}) && 511 printf "$TREE_TWO\n" | pack_as_from_promisor && 512 513 git -C repo config core.repositoryformatversion 1 && 514 git -C repo config extensions.partialclone "arbitrary string" && 515 git -C repo gc && 516 517 # Ensure that exactly one promisor packfile exists, and that it 518 # contains the trees but not the commits 519 ls repo/.git/objects/pack/pack-*.promisor >promisorlist && 520 test_line_count = 1 promisorlist && 521 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) && 522 git verify-pack $PROMISOR_PACKFILE -v >out && 523 grep "$TREE_ONE" out && 524 grep "$TREE_TWO" out && 525 ! grep "$(git -C repo rev-parse one)" out && 526 ! grep "$(git -C repo rev-parse two)" out && 527 528 # Remove the promisor packfile and associated files 529 rm $(sed "s/.promisor//" <promisorlist).* && 530 531 # Ensure that the single other pack contains the commits, but not the 532 # trees 533 ls repo/.git/objects/pack/pack-*.pack >packlist && 534 test_line_count = 1 packlist && 535 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out && 536 grep "$(git -C repo rev-parse one)" out && 537 grep "$(git -C repo rev-parse two)" out && 538 ! grep "$TREE_ONE" out && 539 ! grep "$TREE_TWO" out 540' 541 542test_expect_success 'gc does not repack promisor objects if there are none' ' 543 rm -rf repo && 544 test_create_repo repo && 545 test_commit -C repo one && 546 547 git -C repo config core.repositoryformatversion 1 && 548 git -C repo config extensions.partialclone "arbitrary string" && 549 git -C repo gc && 550 551 # Ensure that only one pack exists 552 ls repo/.git/objects/pack/pack-*.pack >packlist && 553 test_line_count = 1 packlist 554' 555 556repack_and_check () { 557 rm -rf repo2 && 558 cp -r repo repo2 && 559 if test x"$1" = "x--must-fail" 560 then 561 shift 562 test_must_fail git -C repo2 repack $1 -d 563 else 564 git -C repo2 repack $1 -d 565 fi && 566 git -C repo2 fsck && 567 568 git -C repo2 cat-file -e $2 && 569 git -C repo2 cat-file -e $3 570} 571 572test_expect_success 'repack -d does not irreversibly delete promisor objects' ' 573 rm -rf repo && 574 test_create_repo repo && 575 git -C repo config core.repositoryformatversion 1 && 576 git -C repo config extensions.partialclone "arbitrary string" && 577 578 git -C repo commit --allow-empty -m one && 579 git -C repo commit --allow-empty -m two && 580 git -C repo commit --allow-empty -m three && 581 git -C repo commit --allow-empty -m four && 582 ONE=$(git -C repo rev-parse HEAD^^^) && 583 TWO=$(git -C repo rev-parse HEAD^^) && 584 THREE=$(git -C repo rev-parse HEAD^) && 585 586 printf "$TWO\n" | pack_as_from_promisor && 587 printf "$THREE\n" | pack_as_from_promisor && 588 delete_object repo "$ONE" && 589 590 repack_and_check --must-fail -ab "$TWO" "$THREE" && 591 repack_and_check -a "$TWO" "$THREE" && 592 repack_and_check -A "$TWO" "$THREE" && 593 repack_and_check -l "$TWO" "$THREE" 594' 595 596test_expect_success 'gc stops traversal when a missing but promised object is reached' ' 597 rm -rf repo && 598 test_create_repo repo && 599 test_commit -C repo my_commit && 600 601 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) && 602 HASH=$(promise_and_delete $TREE_HASH) && 603 604 git -C repo config core.repositoryformatversion 1 && 605 git -C repo config extensions.partialclone "arbitrary string" && 606 git -C repo gc && 607 608 # Ensure that the promisor packfile still exists, and remove it 609 test -e repo/.git/objects/pack/pack-$HASH.pack && 610 rm repo/.git/objects/pack/pack-$HASH.* && 611 612 # Ensure that the single other pack contains the commit, but not the tree 613 ls repo/.git/objects/pack/pack-*.pack >packlist && 614 test_line_count = 1 packlist && 615 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out && 616 grep "$(git -C repo rev-parse HEAD)" out && 617 ! grep "$TREE_HASH" out 618' 619 620test_expect_success 'do not fetch when checking existence of tree we construct ourselves' ' 621 rm -rf repo && 622 test_create_repo repo && 623 test_commit -C repo base && 624 test_commit -C repo side1 && 625 git -C repo checkout base && 626 test_commit -C repo side2 && 627 628 git -C repo config core.repositoryformatversion 1 && 629 git -C repo config extensions.partialclone "arbitrary string" && 630 631 git -C repo cherry-pick side1 632' 633 634test_expect_success 'exact rename does not need to fetch the blob lazily' ' 635 rm -rf repo partial.git && 636 test_create_repo repo && 637 content="some dummy content" && 638 test_commit -C repo create-a-file file.txt "$content" && 639 git -C repo mv file.txt new-file.txt && 640 git -C repo commit -m rename-the-file && 641 FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) && 642 test_config -C repo uploadpack.allowfilter 1 && 643 test_config -C repo uploadpack.allowanysha1inwant 1 && 644 645 git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git && 646 git -C partial.git rev-list --objects --missing=print HEAD >out && 647 grep "[?]$FILE_HASH" out && 648 git -C partial.git log --follow -- new-file.txt && 649 git -C partial.git rev-list --objects --missing=print HEAD >out && 650 grep "[?]$FILE_HASH" out 651' 652 653test_expect_success 'lazy-fetch when accessing object not in the_repository' ' 654 rm -rf full partial.git && 655 test_create_repo full && 656 test_commit -C full create-a-file file.txt && 657 658 test_config -C full uploadpack.allowfilter 1 && 659 test_config -C full uploadpack.allowanysha1inwant 1 && 660 git clone --filter=blob:none --bare "file://$(pwd)/full" partial.git && 661 FILE_HASH=$(git -C full rev-parse HEAD:file.txt) && 662 663 # Sanity check that the file is missing 664 git -C partial.git rev-list --objects --missing=print HEAD >out && 665 grep "[?]$FILE_HASH" out && 666 667 # The no-lazy-fetch mechanism prevents Git from fetching 668 test_must_fail env GIT_NO_LAZY_FETCH=1 \ 669 git -C partial.git cat-file -e "$FILE_HASH" && 670 671 # The same with command line option to "git" 672 test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" && 673 674 # The same, forcing a subprocess via an alias 675 test_must_fail git --no-lazy-fetch -C partial.git \ 676 -c alias.foo="!git cat-file" foo -e "$FILE_HASH" && 677 678 # Sanity check that the file is still missing 679 git -C partial.git rev-list --objects --missing=print HEAD >out && 680 grep "[?]$FILE_HASH" out && 681 682 git -C full cat-file -s "$FILE_HASH" >expect && 683 test-tool partial-clone object-info partial.git "$FILE_HASH" >actual && 684 test_cmp expect actual && 685 686 # Sanity check that the file is now present 687 git -C partial.git rev-list --objects --missing=print HEAD >out && 688 ! grep "[?]$FILE_HASH" out 689' 690 691test_expect_success 'push should not fetch new commit objects' ' 692 rm -rf server client && 693 test_create_repo server && 694 test_config -C server uploadpack.allowfilter 1 && 695 test_config -C server uploadpack.allowanysha1inwant 1 && 696 test_commit -C server server1 && 697 698 git clone --filter=blob:none "file://$(pwd)/server" client && 699 test_commit -C client client1 && 700 701 test_commit -C server server2 && 702 COMMIT=$(git -C server rev-parse server2) && 703 704 test_must_fail git -C client push 2>err && 705 grep "fetch first" err && 706 git -C client rev-list --objects --missing=print "$COMMIT" >objects && 707 grep "^[?]$COMMIT" objects 708' 709 710test_expect_success 'setup for promisor.quiet tests' ' 711 rm -rf server && 712 test_create_repo server && 713 test_commit -C server foo && 714 git -C server rm foo.t && 715 git -C server commit -m remove && 716 git -C server config uploadpack.allowanysha1inwant 1 && 717 git -C server config uploadpack.allowfilter 1 718' 719 720test_expect_success TTY 'promisor.quiet=false shows progress messages' ' 721 rm -rf repo && 722 git clone --filter=blob:none "file://$(pwd)/server" repo && 723 git -C repo config promisor.quiet "false" && 724 725 test_terminal git -C repo cat-file -p foo:foo.t 2>err && 726 727 # Ensure that progress messages are written 728 grep "Receiving objects" err 729' 730 731test_expect_success TTY 'promisor.quiet=true does not show progress messages' ' 732 rm -rf repo && 733 git clone --filter=blob:none "file://$(pwd)/server" repo && 734 git -C repo config promisor.quiet "true" && 735 736 test_terminal git -C repo cat-file -p foo:foo.t 2>err && 737 738 # Ensure that no progress messages are written 739 ! grep "Receiving objects" err 740' 741 742test_expect_success TTY 'promisor.quiet=unconfigured shows progress messages' ' 743 rm -rf repo && 744 git clone --filter=blob:none "file://$(pwd)/server" repo && 745 746 test_terminal git -C repo cat-file -p foo:foo.t 2>err && 747 748 # Ensure that progress messages are written 749 grep "Receiving objects" err 750' 751 752. "$TEST_DIRECTORY"/lib-httpd.sh 753start_httpd 754 755test_expect_success 'fetching of missing objects from an HTTP server' ' 756 rm -rf repo && 757 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && 758 test_create_repo "$SERVER" && 759 test_commit -C "$SERVER" foo && 760 git -C "$SERVER" repack -a -d --write-bitmap-index && 761 762 git clone $HTTPD_URL/smart/server repo && 763 HASH=$(git -C repo rev-parse foo) && 764 rm -rf repo/.git/objects/* && 765 766 git -C repo config core.repositoryformatversion 1 && 767 git -C repo config extensions.partialclone "origin" && 768 git -C repo cat-file -p "$HASH" && 769 770 # Ensure that the .promisor file is written, and check that its 771 # associated packfile contains the object 772 ls repo/.git/objects/pack/pack-*.promisor >promisorlist && 773 test_line_count = 1 promisorlist && 774 IDX=$(sed "s/promisor$/idx/" promisorlist) && 775 git verify-pack --verbose "$IDX" >out && 776 grep "$HASH" out 777' 778 779# DO NOT add non-httpd-specific tests here, because the last part of this 780# test script is only executed when httpd is available and enabled. 781 782test_done