Jonathan Tan <jonathantanmy@xxxxxxxxxx> writes: > Teach fsck to not treat refs with missing targets as an error when > extensions.lazyobject is set. > > For the purposes of warning about no default refs, such refs are still > treated as legitimate refs. > > Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> > --- > builtin/fsck.c | 8 ++++++++ > t/t0410-lazy-object.sh | 20 ++++++++++++++++++++ > 2 files changed, 28 insertions(+) > > diff --git a/builtin/fsck.c b/builtin/fsck.c > index 1cfb8d98c..e29ff760b 100644 > --- a/builtin/fsck.c > +++ b/builtin/fsck.c > @@ -438,6 +438,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, > > obj = parse_object(oid); > if (!obj) { > + if (repository_format_lazy_object) { > + /* > + * Increment default_refs anyway, because this is a > + * valid ref. > + */ > + default_refs++; > + return 0; > + } > error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid)); > errors_found |= ERROR_REACHABLE; At this point, do we know (or can we tell) if this is a missing object or a file exists as a loose object but is corrupt? If we could, it would be nice to do this only for the former to avoid sweeping a real corruption that is unrelated to the lazy fetch under the rug. > +test_expect_success 'fsck fails on lazy object pointed to by ref' ' > + rm -rf repo && > + test_create_repo repo && > + test_commit -C repo 1 && > + > + A=$(git -C repo commit-tree -m a HEAD^{tree}) && > + > + # Reference $A only from ref, and delete it > + git -C repo branch mybranch "$A" && > + delete_object repo "$A" && > + > + test_must_fail git -C repo fsck > +' And a new test that uses a helper different from delete_object (perhaps call it corrupt_object?) can be used to make sure that we complain in that case here. > +test_expect_success '...but succeeds if lazyobject is set' ' > + git -C repo config core.repositoryformatversion 1 && > + git -C repo config extensions.lazyobject "arbitrary string" && > + git -C repo fsck > +' > + > test_done