Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -5135,8 +5135,16 @@ static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
.source_infop = &source_info,
};

if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info,
OBJECT_INFO_SKIP_FETCH_OBJECT)) {
/*
* This is the best-effort pass that repacks local links from an
* incoming promisor pack. A missing object cannot be packed, so
* skip it. If it was not promised, its data was already absent;
* later access still needs a remote to provide it.
*/
return 0;
}
return source_info.source->type != ODB_SOURCE_PACKED || !source_info.u.packed.pack->pack_promisor;
}

Expand Down
55 changes: 55 additions & 0 deletions t/t5616-partial-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,61 @@ test_expect_success 'merge does not lazy-fetch locally written objects' '
done &&
test_cmp server/only-in-C client/only-in-C
'
for opt in --unshallow --deepen=1
do
test_expect_success "filtered fetch $opt of a moved ref repacks local links" '
test_when_finished "rm -rf source target" &&

git init source &&
test_commit_bulk -C source 4 &&
git -C source config uploadpack.allowFilter true &&
git -C source config uploadpack.allowAnySHA1InWant true &&
COMMIT=$(git -C source rev-parse main~1) &&

git init target &&
git -C target remote add origin "file://$(pwd)/source" &&
git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&

# The fetched pack has the new tip whose parent is the local shallow
# tip, so index-pack repacks it into a promisor pack. That process
# inherits the shallow file and walks into promisor commits whose
# trees do not exist.
git -C target fetch --no-tags --filter=tree:0 "$opt" origin \
+refs/heads/main:refs/remotes/origin/main &&
git -C target rev-parse --verify refs/remotes/origin/main >actual &&
git -C source rev-parse --verify refs/heads/main >expect &&
test_cmp expect actual &&
git -C target fsck
'
done

test_expect_success 'repacking local links tolerates missing trees of promisor commits' '
test_when_finished "rm -rf source target" &&

git init source &&
test_commit_bulk -C source 4 &&
git -C source config uploadpack.allowFilter true &&
git -C source config uploadpack.allowAnySHA1InWant true &&
COMMIT=$(git -C source rev-parse main~1) &&

# Fetch a single commit as a non-promisor object, then unshallow it
# with a filter that omits trees. The commits below the former
# shallow boundary are now promisor objects whose trees are missing.
git init target &&
git -C target remote add origin "file://$(pwd)/source" &&
git -C target fetch --no-tags --depth=1 origin "+$COMMIT:refs/remotes/origin/main" &&
git -C target fetch --no-tags --filter=tree:0 --unshallow origin \
"+$COMMIT:refs/remotes/origin/main" &&
test_path_is_missing target/.git/shallow &&

# Fetching a descendant of the local non-promisor commit causes
# index-pack to repack that commit into a promisor pack. The revision
# walk must not die when it reaches the missing trees of promisor commits.
git -C target fetch --no-tags --filter=tree:0 origin \
+refs/heads/main:refs/remotes/origin/main &&
git -C target rev-parse --verify refs/remotes/origin/main &&
git -C target fsck
'

. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
Expand Down
Loading