t5304: use "reflog expire --all" to clear the reflog
This test checks that unreachable objects are really removed. For the test to work, it has to ensure that no reflog retain any reachable objects. Previously, it did this by manipulating the file system to remove reflog in the first test, and relying on git not updating the reflog if the relevant logfile doesn't exist in follow-up tests. Now, explicitly clear the reflog using 'reflog expire'. This reduces the dependency between test functions. It also is more amenable to use with reftable, which has no concept of (non)-existence of a reflog Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Han-Wen Nienhuys committed
May 31, 2021 at 16:56 UTC
d491f5ea07e5bb85be75060d3939894892f9478a
1 file changed
+4
-5
t/t5304-prune.sh
+4
-5
@@ -81,12 +81,12 @@ test_expect_success 'prune: prune nonsense parameters' '
81
82
test_expect_success 'prune: prune unreachable heads' '
83
git config core.logAllRefUpdates false &&
84
- mv .git/logs .git/logs.old &&
85
- : > file2 &&
84
+ >file2 &&
85
git add file2 &&
86
git commit -m temporary &&
87
tmp_head=$(git rev-list -1 HEAD) &&
88
git reset HEAD^ &&
89
+ git reflog expire --all &&
90
git prune &&
91
test_must_fail git reset $tmp_head --
92
'
@@ -94,9 +94,7 @@ test_expect_success 'prune: prune unreachable heads' '
94
test_expect_success 'prune: do not prune detached HEAD with no reflog' '
95
git checkout --detach --quiet &&
96
git commit --allow-empty -m "detached commit" &&
97
- # verify that there is no reflogs
98
- # (should be removed and disabled by previous test)
99
- test_path_is_missing .git/logs &&
97
+ git reflog expire --all &&
98
git prune -n >prune_actual &&
99
test_must_be_empty prune_actual
100
'
@@ -104,6 +102,7 @@ test_expect_success 'prune: do not prune detached HEAD with no reflog' '
102
test_expect_success 'prune: prune former HEAD after checking out branch' '
103
head_oid=$(git rev-parse HEAD) &&
104
git checkout --quiet main &&
105
+ git reflog expire --all &&
106
git prune -v >prune_actual &&
107
grep "$head_oid" prune_actual
108
'