t5516: don't use HEAD ref for invalid ref-deletion tests

A few tests in t5516 want to assert that we can delete a corrupted ref whose pointed-to object is missing. They do so by using the "main" branch, which is also pointed to by HEAD. This does work, but only because of a subtle assumption about the implementation. We do not block the deletion because of the invalid ref, but we _also_ do not notice that the deleted branch is pointed to by HEAD. And so the safety rule of "do not allow HEAD to be deleted in a non-bare repository" does not kick in, and the test passes. Let's instead use a non-HEAD branch. That still tests what we care about here (deleting a corrupt ref), but without implicitly depending on our failure to notice that we're deleting HEAD. That will future proof the test against that behavior changing. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2021 at 14:33 UTC e9de7a52a5cb1d6647a33a3ce0eedb947e04f3fc
1 file changed +9 -9
t/t5516-fetch-push.sh
+9 -9
@@ -662,10 +662,10 @@ test_expect_success 'push does not update local refs on failure' '
662
663 test_expect_success 'allow deleting an invalid remote ref' '
664
665 - mk_test testrepo heads/main &&
665 + mk_test testrepo heads/branch &&
666 rm -f testrepo/.git/objects/??/* &&
667 - git push testrepo :refs/heads/main &&
668 - (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
667 + git push testrepo :refs/heads/branch &&
668 + (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
669
670 '
671
@@ -706,25 +706,25 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho
706 '
707
708 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
709 - mk_test_with_hooks testrepo heads/main &&
709 + mk_test_with_hooks testrepo heads/branch &&
710 rm -f testrepo/.git/objects/??/* &&
711 - git push testrepo :refs/heads/main &&
711 + git push testrepo :refs/heads/branch &&
712 (
713 cd testrepo/.git &&
714 cat >pre-receive.expect <<-EOF &&
715 - $ZERO_OID $ZERO_OID refs/heads/main
715 + $ZERO_OID $ZERO_OID refs/heads/branch
716 EOF
717
718 cat >update.expect <<-EOF &&
719 - refs/heads/main $ZERO_OID $ZERO_OID
719 + refs/heads/branch $ZERO_OID $ZERO_OID
720 EOF
721
722 cat >post-receive.expect <<-EOF &&
723 - $ZERO_OID $ZERO_OID refs/heads/main
723 + $ZERO_OID $ZERO_OID refs/heads/branch
724 EOF
725
726 cat >post-update.expect <<-EOF &&
727 - refs/heads/main
727 + refs/heads/branch
728 EOF
729
730 test_cmp pre-receive.expect pre-receive.actual &&