]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t5329-pack-objects-cruft.sh
builtin/gc.c: conditionally avoid pruning objects via loose
[thirdparty/git.git] / t / t5329-pack-objects-cruft.sh
index 8de87afce21a654026622ff93d2c9f4f735c3450..70a6a9553c71ce901d6d772b51ff9562f47bce1a 100755 (executable)
@@ -429,6 +429,43 @@ test_expect_success 'loose objects mtimes upsert others' '
        )
 '
 
+test_expect_success 'expiring cruft objects with git gc' '
+       git init repo &&
+       test_when_finished "rm -fr repo" &&
+       (
+               cd repo &&
+
+               test_commit reachable &&
+               git branch -M main &&
+               git checkout --orphan other &&
+               test_commit unreachable &&
+
+               git checkout main &&
+               git branch -D other &&
+               git tag -d unreachable &&
+               # objects are not cruft if they are contained in the reflogs
+               git reflog expire --all --expire=all &&
+
+               git rev-list --objects --all --no-object-names >reachable.raw &&
+               git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
+               sort <reachable.raw >reachable &&
+               comm -13 reachable objects >unreachable &&
+
+               git repack --cruft -d &&
+
+               mtimes=$(ls .git/objects/pack/pack-*.mtimes) &&
+               test_path_is_file $mtimes &&
+
+               git gc --cruft --prune=now &&
+
+               git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
+
+               comm -23 unreachable objects >removed &&
+               test_cmp unreachable removed &&
+               test_path_is_missing $mtimes
+       )
+'
+
 test_expect_success 'cruft packs are not included in geometric repack' '
        git init repo &&
        test_when_finished "rm -fr repo" &&