During fsck, an empty "packed-refs" gives an error; this is unwarranted. We should just skip checking the content of "packed-refs" just like the runtime code paths such as "create_snapshot" which simply returns the "snapshot" without checking the content of "packed-refs". Signed-off-by: shejialuo <shejialuo@xxxxxxxxx> --- refs/packed-backend.c | 3 +++ t/t0602-reffiles-fsck.sh | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 3ad1ed0787..0dd6c6677b 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -2103,6 +2103,9 @@ static int packed_fsck(struct ref_store *ref_store, goto cleanup; } + if (!st.st_size) + goto cleanup; + if (strbuf_read(&packed_ref_content, fd, 0) < 0) { ret = error_errno(_("unable to read '%s'"), refs->path); goto cleanup; diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh index 9d1dc2144c..e04967581c 100755 --- a/t/t0602-reffiles-fsck.sh +++ b/t/t0602-reffiles-fsck.sh @@ -647,6 +647,19 @@ test_expect_success SYMLINKS 'the filetype of packed-refs should be checked' ' ) ' +test_expect_success 'empty packed-refs should not be reported' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit default && + + >.git/packed-refs && + git refs verify 2>err && + test_must_be_empty err + ) +' + test_expect_success 'packed-refs header should be checked' ' test_when_finished "rm -rf repo" && git init repo && -- 2.49.0