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>
maint
Jeff King 2021-09-24 14:33:00 -04:00 committed by Junio C Hamano
parent b4724242fa
commit e9de7a52a5
1 changed files with 9 additions and 9 deletions

View File

@ -662,10 +662,10 @@ test_expect_success 'push does not update local refs on failure' '


test_expect_success 'allow deleting an invalid remote ref' ' test_expect_success 'allow deleting an invalid remote ref' '


mk_test testrepo heads/main && mk_test testrepo heads/branch &&
rm -f testrepo/.git/objects/??/* && rm -f testrepo/.git/objects/??/* &&
git push testrepo :refs/heads/main && git push testrepo :refs/heads/branch &&
(cd testrepo && test_must_fail git rev-parse --verify refs/heads/main) (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)


' '


@ -706,25 +706,25 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho
' '


test_expect_success 'deleting dangling ref triggers hooks with correct args' ' test_expect_success 'deleting dangling ref triggers hooks with correct args' '
mk_test_with_hooks testrepo heads/main && mk_test_with_hooks testrepo heads/branch &&
rm -f testrepo/.git/objects/??/* && rm -f testrepo/.git/objects/??/* &&
git push testrepo :refs/heads/main && git push testrepo :refs/heads/branch &&
( (
cd testrepo/.git && cd testrepo/.git &&
cat >pre-receive.expect <<-EOF && cat >pre-receive.expect <<-EOF &&
$ZERO_OID $ZERO_OID refs/heads/main $ZERO_OID $ZERO_OID refs/heads/branch
EOF EOF


cat >update.expect <<-EOF && cat >update.expect <<-EOF &&
refs/heads/main $ZERO_OID $ZERO_OID refs/heads/branch $ZERO_OID $ZERO_OID
EOF EOF


cat >post-receive.expect <<-EOF && cat >post-receive.expect <<-EOF &&
$ZERO_OID $ZERO_OID refs/heads/main $ZERO_OID $ZERO_OID refs/heads/branch
EOF EOF


cat >post-update.expect <<-EOF && cat >post-update.expect <<-EOF &&
refs/heads/main refs/heads/branch
EOF EOF


test_cmp pre-receive.expect pre-receive.actual && test_cmp pre-receive.expect pre-receive.actual &&