[PATCH v3 1/6] unpack-objects: distinguish missing objects from type mismatches
- From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Sep 6, 2026, 07:24 UTC
- Message-ID
- <6056689be039696d03dc67b8365300449b08676d.1788679500.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2208.v3.git.1788679500.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
With receive.fsckObjects enabled, an incomplete pushed pack reports "object of unexpected type" when the expected object is simply absent. That suggests corruption rather than identifying the missing object.
Use the same diagnostics as index-pack: report "did not receive expected object" when lookup fails, and reserve the type-mismatch message for an object that exists with the wrong type.
Signed-off-by: Elijah Newren <newren@gmail.com> --- builtin/unpack-objects.c | 9 +++++++-- t/t5504-fetch-receive-strict.sh | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 351948724a..ceefeb5a49 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -233,8 +233,13 @@ static int check_object(struct object *obj, enum object_type type, if (!(obj->flags & FLAG_OPEN)) { size_t size; int type = odb_read_object_info(the_repository->objects, &obj->oid, &size); - if (type != obj->type || type <= 0) - die("object of unexpected type"); + if (type <= 0) + die(_("did not receive expected object %s"), + oid_to_hex(&obj->oid)); + if (type != obj->type) + die(_("object %s: expected type %s, found %s"), + oid_to_hex(&obj->oid), + type_name(obj->type), type_name(type)); obj->flags |= FLAG_WRITTEN; return 0; } diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index 75b2b87999..0848e2da4a 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -105,8 +105,11 @@ test_expect_success 'push with receive.fsckobjects' ' To dst ! refs/heads/main:refs/heads/test [remote rejected] (unpacker error) EOF - test_must_fail git push --porcelain dst main:refs/heads/test >act && - test_cmp exp act + test_must_fail git push --porcelain dst main:refs/heads/test >act 2>err && + test_cmp exp act && + missing_oid=$(sed -e s%/%% S) && + test_grep "did not receive expected object $missing_oid" err && + test_grep ! "object of unexpected type" err ' test_expect_success 'push with transfer.fsckobjects' '
-- gitgitgadget