From e6b0a8fab8e5a29f11faef898905e0b3c700e683 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:26 +0000 Subject: [PATCH 01/11] t6050: use git-update-ref rather than filesystem access Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index e33d512ec1..2500acc2ef 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -132,7 +132,7 @@ tagger T A Gger <> 0 +0000 EOF test_expect_success 'tag replaced commit' ' - git mktag .git/refs/tags/mytag + git update-ref refs/tags/mytag $(git mktag Date: Mon, 2 Aug 2021 16:53:27 +0000 Subject: [PATCH 02/11] t1503: mark symlink test as REFFILES Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t1503-rev-parse-verify.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh index bf08102391..40958615eb 100755 --- a/t/t1503-rev-parse-verify.sh +++ b/t/t1503-rev-parse-verify.sh @@ -142,7 +142,7 @@ test_expect_success 'main@{n} for various n' ' test_must_fail git rev-parse --verify main@{$Np1} ' -test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' ' +test_expect_success SYMLINKS,REFFILES 'ref resolution not confused by broken symlinks' ' ln -s does-not-exist .git/refs/heads/broken && test_must_fail git rev-parse --verify broken ' From e46775cf9e1c6ddca0ada3c1ca24876b79a23d9a Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:28 +0000 Subject: [PATCH 03/11] t6120: use git-update-ref rather than filesystem access Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 1a501ee09e..bae2419150 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -107,7 +107,8 @@ test_expect_success 'describe --contains defaults to HEAD without commit-ish' ' check_describe tags/A --all A^0 test_expect_success 'renaming tag A to Q locally produces a warning' " - mv .git/refs/tags/A .git/refs/tags/Q && + git update-ref refs/tags/Q $(git rev-parse refs/tags/A) && + git update-ref -d refs/tags/A && git describe HEAD 2>err >out && cat >expected <<-\EOF && warning: tag 'Q' is externally known as 'A' @@ -135,7 +136,8 @@ test_expect_success 'abbrev=0 will not break misplaced tag (2)' ' ' test_expect_success 'rename tag Q back to A' ' - mv .git/refs/tags/Q .git/refs/tags/A + git update-ref refs/tags/A $(git rev-parse refs/tags/Q) && + git update-ref -d refs/tags/Q ' test_expect_success 'pack tag refs' 'git pack-refs' From 2f566d665ac3ef97715617aae839fa2e6f7fce93 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:29 +0000 Subject: [PATCH 04/11] t3320: use git-symbolic-ref rather than filesystem access Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t3320-notes-merge-worktrees.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/t/t3320-notes-merge-worktrees.sh b/t/t3320-notes-merge-worktrees.sh index 052516e6c6..6b2d507f3e 100755 --- a/t/t3320-notes-merge-worktrees.sh +++ b/t/t3320-notes-merge-worktrees.sh @@ -46,8 +46,9 @@ test_expect_success 'create some new worktrees' ' test_expect_success 'merge z into y fails and sets NOTES_MERGE_REF' ' git config core.notesRef refs/notes/y && test_must_fail git notes merge z && - echo "ref: refs/notes/y" >expect && - test_cmp expect .git/NOTES_MERGE_REF + echo "refs/notes/y" >expect && + git symbolic-ref NOTES_MERGE_REF >actual && + test_cmp expect actual ' test_expect_success 'merge z into y while mid-merge in another workdir fails' ' @@ -57,7 +58,7 @@ test_expect_success 'merge z into y while mid-merge in another workdir fails' ' test_must_fail git notes merge z 2>err && test_i18ngrep "a notes merge into refs/notes/y is already in-progress at" err ) && - test_path_is_missing .git/worktrees/worktree/NOTES_MERGE_REF + test_must_fail git -C worktree symbolic-ref NOTES_MERGE_REF ' test_expect_success 'merge z into x while mid-merge on y succeeds' ' @@ -68,8 +69,9 @@ test_expect_success 'merge z into x while mid-merge on y succeeds' ' test_i18ngrep "Automatic notes merge failed" out && grep -v "A notes merge into refs/notes/x is already in-progress in" out ) && - echo "ref: refs/notes/x" >expect && - test_cmp expect .git/worktrees/worktree2/NOTES_MERGE_REF + echo "refs/notes/x" >expect && + git -C worktree2 symbolic-ref NOTES_MERGE_REF >actual && + test_cmp expect actual ' test_done From 100ac47bf364290768001b2b438a84993a7042f6 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:30 +0000 Subject: [PATCH 05/11] t2402: use ref-store test helper to create broken symlink Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t2402-worktree-list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index fedcefe8de..4012bd67b0 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -230,7 +230,7 @@ test_expect_success 'broken main worktree still at the top' ' EOF cd linked && echo "worktree $(pwd)" >expected && - echo "ref: .broken" >../.git/HEAD && + (cd ../ && test-tool ref-store main create-symref HEAD .broken ) && git worktree list --porcelain >out && head -n 3 out >actual && test_cmp ../expected actual && From ace40eab9e8ee4d087b8ba7b603db4958e8ad28c Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:31 +0000 Subject: [PATCH 06/11] t1405: use 'git reflog exists' to check reflog existence This fixes a test failure for reftable. Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t1405-main-ref-store.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index a237d9880e..92b0487324 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -98,12 +98,12 @@ test_expect_success 'reflog_exists(HEAD)' ' test_expect_success 'delete_reflog(HEAD)' ' $RUN delete-reflog HEAD && - ! test -f .git/logs/HEAD + test_must_fail git reflog exists HEAD ' test_expect_success 'create-reflog(HEAD)' ' $RUN create-reflog HEAD 1 && - test -f .git/logs/HEAD + git reflog exists HEAD ' test_expect_success 'delete_ref(refs/heads/foo)' ' From a50234b3be9d6ff75dfca9b0802e7cf97179ff11 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:32 +0000 Subject: [PATCH 07/11] t1405: mark test for 'git pack-refs' as REFFILES The tests verifies that "pack-refs" causes loose refs to be packed. As both loose and packed refs are concepts specific to the files backend, mark the test as REFFILES. Check the outcome of the pack-refs operation. This was apparently forgotten in the commit introducing this test: 16feb99d (Mar 26 2017, "t1405: some basic tests on main ref store"). Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t1405-main-ref-store.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 92b0487324..49718b7ea7 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -9,12 +9,18 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME RUN="test-tool ref-store main" -test_expect_success 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' ' - test_commit one && + +test_expect_success 'setup' ' + test_commit one +' + +test_expect_success REFFILES 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' ' N=`find .git/refs -type f | wc -l` && test "$N" != 0 && - $RUN pack-refs 3 && - N=`find .git/refs -type f | wc -l` + ALL_OR_PRUNE_FLAG=3 && + $RUN pack-refs ${ALL_OR_PRUNE_FLAG} && + N=`find .git/refs -type f` && + test -z "$N" ' test_expect_success 'create_symref(FOO, refs/heads/main)' ' From fe1443152689fcecbbaf0213a7bebcc23ee24a37 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:33 +0000 Subject: [PATCH 08/11] t1410: mark test as REFFILES This test takes a lock on the target of a symref, and then verifies that it is possible to expire the symref's reflog. In reftable, one can only take a global lock (which would prevent the symref reflog from being expired altogether.) Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t1410-reflog.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 27b9080251..d42f067ff8 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -374,7 +374,9 @@ test_expect_failure 'reflog with non-commit entries displays all entries' ' test_line_count = 3 actual ' -test_expect_success 'reflog expire operates on symref not referrent' ' +# This test takes a lock on an individual ref; this is not supported in +# reftable. +test_expect_success REFFILES 'reflog expire operates on symref not referrent' ' git branch --create-reflog the_symref && git branch --create-reflog referrent && git update-ref referrent HEAD && From 2cf9f0fca1ad0fedb88f63f59b311b4d80b28f0e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:34 +0000 Subject: [PATCH 09/11] t7064: use update-ref -d to remove upstream branch The previous code tested this by writing $ZERO_OID explicitly in the packed-refs file. This is a type of corruption that doesn't reflect realistic use-cases. In addition, even the ref-store test-tool refuses to write invalid OIDs. (update-ref interprets $ZERO_OID is deleting the ref). Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t7064-wtstatus-pv2.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh index 4613882caf..eeb0534163 100755 --- a/t/t7064-wtstatus-pv2.sh +++ b/t/t7064-wtstatus-pv2.sh @@ -373,10 +373,7 @@ test_expect_success 'verify upstream fields in branch header' ' ## Test upstream-gone case. Fake this by pointing ## origin/initial-branch at a non-existing commit. - OLD=$(git rev-parse origin/initial-branch) && - NEW=$ZERO_OID && - mv .git/packed-refs .git/old-packed-refs && - sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs && + git update-ref -d refs/remotes/origin/initial-branch && HUF=$(git rev-parse HEAD) && From f95661b74088f019847ee8408c8ce82012089e2e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:35 +0000 Subject: [PATCH 10/11] t6500: use "ls -1" to snapshot ref database state By doing ls -1 .git/{reftable,refs/heads}, we can capture changes to both reftable and packed/loose ref storage. This relies on the fact that git-pack-refs (which we're looking for here) changes the number (loose/packed storage) and/or names (reftable) files used for ref storage. Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t6500-gc.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index 10c7ae7f09..c2021267f2 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -241,7 +241,7 @@ test_expect_success 'background auto gc respects lock for all operations' ' # create a ref whose loose presence we can use to detect a pack-refs run git update-ref refs/heads/should-be-loose HEAD && - test_path_is_file .git/refs/heads/should-be-loose && + (ls -1 .git/refs/heads .git/reftable >expect || true) && # now fake a concurrent gc that holds the lock; we can use our # shell pid so that it looks valid. @@ -258,7 +258,8 @@ test_expect_success 'background auto gc respects lock for all operations' ' # our gc should exit zero without doing anything run_and_wait_for_auto_gc && - test_path_is_file .git/refs/heads/should-be-loose + (ls -1 .git/refs/heads .git/reftable >actual || true) && + test_cmp expect actual ' # DO NOT leave a detached auto gc process running near the end of the From 977f8acefdbb5a7a39af52c82d21a9964f6ff7b0 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 2 Aug 2021 16:53:36 +0000 Subject: [PATCH 11/11] t6001: avoid direct file system access Signed-off-by: Han-Wen Nienhuys Signed-off-by: Junio C Hamano --- t/t6001-rev-list-graft.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t6001-rev-list-graft.sh b/t/t6001-rev-list-graft.sh index 90d93f77fa..7294147334 100755 --- a/t/t6001-rev-list-graft.sh +++ b/t/t6001-rev-list-graft.sh @@ -23,7 +23,8 @@ test_expect_success setup ' git commit -a -m "Third in one history." && A2=$(git rev-parse --verify HEAD) && - rm -f .git/refs/heads/main .git/index && + git update-ref -d refs/heads/main && + rm -f .git/index && echo >fileA fileA again && echo >subdir/fileB fileB again &&