diff options
| -rw-r--r-- | builtin/repack.c | 3 | ||||
| -rwxr-xr-x | t/t7700-repack.sh | 36 |
2 files changed, 38 insertions, 1 deletions
diff --git a/builtin/repack.c b/builtin/repack.c index 51698e3c68..724e09536e 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -125,6 +125,9 @@ static void collect_pack_filenames(struct string_list *fname_nonkept_list, strbuf_add(&buf, e->d_name, len); strbuf_addstr(&buf, ".pack"); + if (!file_exists(mkpath("%s/%s", packdir, buf.buf))) + continue; + for (i = 0; i < extra_keep->nr; i++) if (!fspathcmp(buf.buf, extra_keep->items[i].string)) break; diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index af79266c58..27b66807cd 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -213,7 +213,7 @@ test_expect_success 'repack --keep-pack' ' test_create_repo keep-pack && ( cd keep-pack && - # avoid producing difference packs to delta/base choices + # avoid producing different packs due to delta/base choices git config pack.window 0 && P1=$(commit_and_pack 1) && P2=$(commit_and_pack 2) && @@ -239,6 +239,10 @@ test_expect_success 'repack --keep-pack' ' mv "$from" "$to" || return 1 done && + # A .idx file without a .pack should not stop us from + # repacking what we can. + touch .git/objects/pack/pack-does-not-exist.idx && + git repack --cruft -d --keep-pack $P1 --keep-pack $P4 && ls .git/objects/pack/*.pack >newer-counts && @@ -247,6 +251,36 @@ test_expect_success 'repack --keep-pack' ' ) ' +test_expect_success 'repacking fails when missing .pack actually means missing objects' ' + test_create_repo idx-without-pack && + ( + cd idx-without-pack && + + # Avoid producing different packs due to delta/base choices + git config pack.window 0 && + P1=$(commit_and_pack 1) && + P2=$(commit_and_pack 2) && + P3=$(commit_and_pack 3) && + P4=$(commit_and_pack 4) && + ls .git/objects/pack/*.pack >old-counts && + test_line_count = 4 old-counts && + + # Remove one .pack file + rm .git/objects/pack/$P2 && + + ls .git/objects/pack/*.pack >before-pack-dir && + + test_must_fail git fsck && + test_must_fail git repack --cruft -d 2>err && + grep "bad object" err && + + # Before failing, the repack did not modify the + # pack directory. + ls .git/objects/pack/*.pack >after-pack-dir && + test_cmp before-pack-dir after-pack-dir + ) +' + test_expect_success 'bitmaps are created by default in bare repos' ' git clone --bare .git bare.git && rm -f bare.git/objects/pack/*.bitmap && |
