t5312: create bogus ref as necessary

Some tests in t5312 create an illegally-named ref, and then see how
various operations handle it. But between those operations, we also do
some more setup (e.g., repacking), and we are subtly depending on how
those setup steps react to the illegal ref.

To future-proof us against those behaviors changing, let's instead
create and clean up our bogus ref on demand in the tests that need it.

This has two small extra advantages:

 - the tests are more stand-alone; we do not need an extra test to clean
   up the ref before moving on to other parts of the script

 - the creation and cleanup is together in one helper function. Because
   these depend on touching the refs in the filesystem directly, they
   may need to be tweaked for a world with alternate backends (they have
   not been noticed so far in the reftable work because with a non-file
   backend the tests don't fail; they simply become uninteresting noops
   because the broken ref isn't read at all).

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2021-09-24 14:36:18 -04:00 коммит произвёл Junio C Hamano
Родитель 2ac0cbc9b0
Коммит f805844676
1 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -18,18 +18,23 @@ test_expect_success 'disable reflogs' '
git reflog expire --expire=all --all git reflog expire --expire=all --all
' '
create_bogus_ref () {
test_when_finished 'rm -f .git/refs/heads/bogus..name' &&
echo $bogus >.git/refs/heads/bogus..name
}
test_expect_success 'create history reachable only from a bogus-named ref' ' test_expect_success 'create history reachable only from a bogus-named ref' '
test_tick && git commit --allow-empty -m main && test_tick && git commit --allow-empty -m main &&
base=$(git rev-parse HEAD) && base=$(git rev-parse HEAD) &&
test_tick && git commit --allow-empty -m bogus && test_tick && git commit --allow-empty -m bogus &&
bogus=$(git rev-parse HEAD) && bogus=$(git rev-parse HEAD) &&
git cat-file commit $bogus >saved && git cat-file commit $bogus >saved &&
echo $bogus >.git/refs/heads/bogus..name &&
git reset --hard HEAD^ git reset --hard HEAD^
' '
test_expect_success 'pruning does not drop bogus object' ' test_expect_success 'pruning does not drop bogus object' '
test_when_finished "git hash-object -w -t commit saved" && test_when_finished "git hash-object -w -t commit saved" &&
create_bogus_ref &&
test_might_fail git prune --expire=now && test_might_fail git prune --expire=now &&
git cat-file -e $bogus git cat-file -e $bogus
' '
@ -42,17 +47,13 @@ test_expect_success 'put bogus object into pack' '
' '
test_expect_success 'destructive repack keeps packed object' ' test_expect_success 'destructive repack keeps packed object' '
create_bogus_ref &&
test_might_fail git repack -Ad --unpack-unreachable=now && test_might_fail git repack -Ad --unpack-unreachable=now &&
git cat-file -e $bogus && git cat-file -e $bogus &&
test_might_fail git repack -ad && test_might_fail git repack -ad &&
git cat-file -e $bogus git cat-file -e $bogus
' '
# subsequent tests will have different corruptions
test_expect_success 'clean up bogus ref' '
rm .git/refs/heads/bogus..name
'
# We create two new objects here, "one" and "two". Our # We create two new objects here, "one" and "two". Our
# main branch points to "two", which is deleted, # main branch points to "two", which is deleted,
# corrupting the repository. But we'd like to make sure # corrupting the repository. But we'd like to make sure