Git fork

Merge branch 'dl/push-missing-object-error' into maint-2.51

"git push" had a code path that led to BUG() but it should have
been a die(), as it is a response to a usual but invalid end-user
action to attempt pushing an object that does not exist.
cf. <xmqqo6spiyqp.fsf@gitster.g>

* dl/push-missing-object-error:
remote.c: convert if-else ladder to switch
remote.c: remove BUG in show_push_unqualified_ref_name_error()
t5516: remove surrounding empty lines in test bodies

+19 -59
+15 -9
remote.c
··· 1171 1171 const char *matched_src_name) 1172 1172 { 1173 1173 struct object_id oid; 1174 - enum object_type type; 1175 1174 1176 1175 /* 1177 1176 * TRANSLATORS: "matches '%s'%" is the <dst> part of "git push ··· 1196 1195 BUG("'%s' is not a valid object, " 1197 1196 "match_explicit_lhs() should catch this!", 1198 1197 matched_src_name); 1199 - type = odb_read_object_info(the_repository->objects, &oid, NULL); 1200 - if (type == OBJ_COMMIT) { 1198 + 1199 + switch (odb_read_object_info(the_repository->objects, &oid, NULL)) { 1200 + case OBJ_COMMIT: 1201 1201 advise(_("The <src> part of the refspec is a commit object.\n" 1202 1202 "Did you mean to create a new branch by pushing to\n" 1203 1203 "'%s:refs/heads/%s'?"), 1204 1204 matched_src_name, dst_value); 1205 - } else if (type == OBJ_TAG) { 1205 + break; 1206 + case OBJ_TAG: 1206 1207 advise(_("The <src> part of the refspec is a tag object.\n" 1207 1208 "Did you mean to create a new tag by pushing to\n" 1208 1209 "'%s:refs/tags/%s'?"), 1209 1210 matched_src_name, dst_value); 1210 - } else if (type == OBJ_TREE) { 1211 + break; 1212 + case OBJ_TREE: 1211 1213 advise(_("The <src> part of the refspec is a tree object.\n" 1212 1214 "Did you mean to tag a new tree by pushing to\n" 1213 1215 "'%s:refs/tags/%s'?"), 1214 1216 matched_src_name, dst_value); 1215 - } else if (type == OBJ_BLOB) { 1217 + break; 1218 + case OBJ_BLOB: 1216 1219 advise(_("The <src> part of the refspec is a blob object.\n" 1217 1220 "Did you mean to tag a new blob by pushing to\n" 1218 1221 "'%s:refs/tags/%s'?"), 1219 1222 matched_src_name, dst_value); 1220 - } else { 1221 - BUG("'%s' should be commit/tag/tree/blob, is '%d'", 1222 - matched_src_name, type); 1223 + break; 1224 + default: 1225 + advise(_("The <src> part of the refspec ('%s') " 1226 + "is an object ID that doesn't exist.\n"), 1227 + matched_src_name); 1228 + break; 1223 1229 } 1224 1230 } 1225 1231
+4 -50
t/t5516-fetch-push.sh
··· 105 105 } 106 106 107 107 test_expect_success setup ' 108 - 109 108 >path1 && 110 109 git add path1 && 111 110 test_tick && ··· 117 116 test_tick && 118 117 git commit -a -m second && 119 118 the_commit=$(git show-ref -s --verify refs/heads/main) 120 - 121 119 ' 122 120 123 121 for cmd in push fetch ··· 322 320 ' 323 321 324 322 test_expect_success 'push with matching heads' ' 325 - 326 323 mk_test testrepo heads/main && 327 324 git push testrepo : && 328 325 check_push_result testrepo $the_commit heads/main 329 - 330 326 ' 331 327 332 328 test_expect_success 'push with matching heads on the command line' ' 333 - 334 329 mk_test testrepo heads/main && 335 330 git push testrepo : && 336 331 check_push_result testrepo $the_commit heads/main 337 - 338 332 ' 339 333 340 334 test_expect_success 'failed (non-fast-forward) push with matching heads' ' 341 - 342 335 mk_test testrepo heads/main && 343 336 git push testrepo : && 344 337 git commit --amend -massaged && 345 338 test_must_fail git push testrepo && 346 339 check_push_result testrepo $the_commit heads/main && 347 340 git reset --hard $the_commit 348 - 349 341 ' 350 342 351 343 test_expect_success 'push --force with matching heads' ' 352 - 353 344 mk_test testrepo heads/main && 354 345 git push testrepo : && 355 346 git commit --amend -massaged && 356 347 git push --force testrepo : && 357 348 ! check_push_result testrepo $the_commit heads/main && 358 349 git reset --hard $the_commit 359 - 360 350 ' 361 351 362 352 test_expect_success 'push with matching heads and forced update' ' 363 - 364 353 mk_test testrepo heads/main && 365 354 git push testrepo : && 366 355 git commit --amend -massaged && 367 356 git push testrepo +: && 368 357 ! check_push_result testrepo $the_commit heads/main && 369 358 git reset --hard $the_commit 370 - 371 359 ' 372 360 373 361 test_expect_success 'push with no ambiguity (1)' ' 374 - 375 362 mk_test testrepo heads/main && 376 363 git push testrepo main:main && 377 364 check_push_result testrepo $the_commit heads/main 378 - 379 365 ' 380 366 381 367 test_expect_success 'push with no ambiguity (2)' ' 382 - 383 368 mk_test testrepo remotes/origin/main && 384 369 git push testrepo main:origin/main && 385 370 check_push_result testrepo $the_commit remotes/origin/main 386 - 387 371 ' 388 372 389 373 test_expect_success 'push with colon-less refspec, no ambiguity' ' 390 - 391 374 mk_test testrepo heads/main heads/t/main && 392 375 git branch -f t/main main && 393 376 git push testrepo main && 394 377 check_push_result testrepo $the_commit heads/main && 395 378 check_push_result testrepo $the_first_commit heads/t/main 396 - 397 379 ' 398 380 399 381 test_expect_success 'push with weak ambiguity (1)' ' 400 - 401 382 mk_test testrepo heads/main remotes/origin/main && 402 383 git push testrepo main:main && 403 384 check_push_result testrepo $the_commit heads/main && 404 385 check_push_result testrepo $the_first_commit remotes/origin/main 405 - 406 386 ' 407 387 408 388 test_expect_success 'push with weak ambiguity (2)' ' 409 - 410 389 mk_test testrepo heads/main remotes/origin/main remotes/another/main && 411 390 git push testrepo main:main && 412 391 check_push_result testrepo $the_commit heads/main && 413 392 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main 414 - 415 393 ' 416 394 417 395 test_expect_success 'push with ambiguity' ' 418 - 419 396 mk_test testrepo heads/frotz tags/frotz && 420 397 test_must_fail git push testrepo main:frotz && 421 398 check_push_result testrepo $the_first_commit heads/frotz tags/frotz 422 - 423 399 ' 424 400 425 401 test_expect_success 'push with onelevel ref' ' ··· 428 404 ' 429 405 430 406 test_expect_success 'push with colon-less refspec (1)' ' 431 - 432 407 mk_test testrepo heads/frotz tags/frotz && 433 408 git branch -f frotz main && 434 409 git push testrepo frotz && 435 410 check_push_result testrepo $the_commit heads/frotz && 436 411 check_push_result testrepo $the_first_commit tags/frotz 437 - 438 412 ' 439 413 440 414 test_expect_success 'push with colon-less refspec (2)' ' 441 - 442 415 mk_test testrepo heads/frotz tags/frotz && 443 416 if git show-ref --verify -q refs/heads/frotz 444 417 then ··· 448 421 git push -f testrepo frotz && 449 422 check_push_result testrepo $the_commit tags/frotz && 450 423 check_push_result testrepo $the_first_commit heads/frotz 451 - 452 424 ' 453 425 454 426 test_expect_success 'push with colon-less refspec (3)' ' ··· 465 437 ' 466 438 467 439 test_expect_success 'push with colon-less refspec (4)' ' 468 - 469 440 mk_test testrepo && 470 441 if git show-ref --verify -q refs/heads/frotz 471 442 then ··· 475 446 git push testrepo frotz && 476 447 check_push_result testrepo $the_commit tags/frotz && 477 448 test 1 = $( cd testrepo && git show-ref | wc -l ) 478 - 479 449 ' 480 450 481 451 test_expect_success 'push head with non-existent, incomplete dest' ' 482 - 483 452 mk_test testrepo && 484 453 git push testrepo main:branch && 485 454 check_push_result testrepo $the_commit heads/branch 486 - 487 455 ' 488 456 489 457 test_expect_success 'push tag with non-existent, incomplete dest' ' 490 - 491 458 mk_test testrepo && 492 459 git tag -f v1.0 && 493 460 git push testrepo v1.0:tag && 494 461 check_push_result testrepo $the_commit tags/tag 495 - 496 462 ' 497 463 498 464 test_expect_success 'push oid with non-existent, incomplete dest' ' 499 - 500 465 mk_test testrepo && 501 466 test_must_fail git push testrepo $(git rev-parse main):foo 502 - 503 467 ' 504 468 505 469 test_expect_success 'push ref expression with non-existent, incomplete dest' ' 506 - 507 470 mk_test testrepo && 508 471 test_must_fail git push testrepo main^:branch 472 + ' 509 473 474 + test_expect_success 'push ref expression with non-existent oid src' ' 475 + mk_test testrepo && 476 + test_must_fail git push testrepo $(test_oid 001):branch 510 477 ' 511 478 512 479 for head in HEAD @ ··· 550 517 git checkout main && 551 518 git push testrepo $head:branch && 552 519 check_push_result testrepo $the_commit heads/branch 553 - 554 520 ' 555 521 556 522 test_expect_success "push with config remote.*.push = $head" ' ··· 596 562 ' 597 563 598 564 test_expect_success 'push with config remote.*.pushurl' ' 599 - 600 565 mk_test testrepo heads/main && 601 566 git checkout main && 602 567 test_config remote.there.url test2repo && ··· 655 620 ' 656 621 657 622 test_expect_success 'push with dry-run' ' 658 - 659 623 mk_test testrepo heads/main && 660 624 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) && 661 625 git push --dry-run testrepo : && ··· 663 627 ' 664 628 665 629 test_expect_success 'push updates local refs' ' 666 - 667 630 mk_test testrepo heads/main && 668 631 mk_child testrepo child && 669 632 ( ··· 673 636 test $(git rev-parse main) = \ 674 637 $(git rev-parse remotes/origin/main) 675 638 ) 676 - 677 639 ' 678 640 679 641 test_expect_success 'push updates up-to-date local refs' ' 680 - 681 642 mk_test testrepo heads/main && 682 643 mk_child testrepo child1 && 683 644 mk_child testrepo child2 && ··· 689 650 test $(git rev-parse main) = \ 690 651 $(git rev-parse remotes/origin/main) 691 652 ) 692 - 693 653 ' 694 654 695 655 test_expect_success 'push preserves up-to-date packed refs' ' 696 - 697 656 mk_test testrepo heads/main && 698 657 mk_child testrepo child && 699 658 ( ··· 701 660 git push && 702 661 ! test -f .git/refs/remotes/origin/main 703 662 ) 704 - 705 663 ' 706 664 707 665 test_expect_success 'push does not update local refs on failure' ' 708 - 709 666 mk_test testrepo heads/main && 710 667 mk_child testrepo child && 711 668 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && ··· 717 674 test $(git rev-parse main) != \ 718 675 $(git rev-parse remotes/origin/main) 719 676 ) 720 - 721 677 ' 722 678 723 679 test_expect_success 'allow deleting an invalid remote ref' ' 724 - 725 680 mk_test testrepo heads/branch && 726 681 rm -f testrepo/.git/objects/??/* && 727 682 git push testrepo :refs/heads/branch && 728 683 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch) 729 - 730 684 ' 731 685 732 686 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '