Merge branch 'ps/repack-keep-unreachable-in-unpacked-repo'

"git repack --keep-unreachable" to send unreachable objects to the
main pack "git repack -ad" produces did not work when there is no
existing packs, which has been corrected.

* ps/repack-keep-unreachable-in-unpacked-repo:
  builtin/repack: fix `--keep-unreachable` when there are no packs
This commit is contained in:
Junio C Hamano
2025-02-12 10:08:51 -08:00
2 changed files with 20 additions and 1 deletions

View File

@ -1377,9 +1377,12 @@ int cmd_repack(int argc,
"--unpack-unreachable");
} else if (keep_unreachable) {
strvec_push(&cmd.args, "--keep-unreachable");
strvec_push(&cmd.args, "--pack-loose-unreachable");
}
}
if (keep_unreachable && delete_redundant &&
!(pack_everything & PACK_CRUFT))
strvec_push(&cmd.args, "--pack-loose-unreachable");
} else if (geometry.split_factor) {
strvec_push(&cmd.args, "--stdin-packs");
strvec_push(&cmd.args, "--unpacked");

View File

@ -195,4 +195,20 @@ test_expect_success 'repack -k packs unreachable loose objects' '
git cat-file -p $sha1
'
test_expect_success 'repack -k packs unreachable loose objects without existing packfiles' '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
oid=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
test_path_is_file $objpath &&
git repack -ad --keep-unreachable &&
test_path_is_missing $objpath &&
git cat-file -p $oid
)
'
test_done