diff --git a/builtin/repack.c b/builtin/repack.c index e472586ed5..75e3752353 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -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"); diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh index 5715f4d69a..5559d4ccb4 100755 --- a/t/t7701-repack-unpack-unreachable.sh +++ b/t/t7701-repack-unpack-unreachable.sh @@ -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