Skip to content

Commit 43f2515

Browse files
jonathantanmygitster
authored andcommitted
fsck: support refs pointing to promisor objects
Teach fsck to not treat refs referring to missing promisor objects as an error when extensions.partialclone is set. For the purposes of warning about no default refs, such refs are still treated as legitimate refs. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 498f1f6 commit 43f2515

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

builtin/fsck.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
434434

435435
obj = parse_object(oid);
436436
if (!obj) {
437+
if (is_promisor_object(oid)) {
438+
/*
439+
* Increment default_refs anyway, because this is a
440+
* valid ref.
441+
*/
442+
default_refs++;
443+
return 0;
444+
}
437445
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
438446
errors_found |= ERROR_REACHABLE;
439447
/* We'll continue with the rest despite the error.. */

t/t0410-partial-clone.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ pack_as_from_promisor () {
1313
>repo/.git/objects/pack/pack-$HASH.promisor
1414
}
1515

16+
promise_and_delete () {
17+
HASH=$(git -C repo rev-parse "$1") &&
18+
git -C repo tag -a -m message my_annotated_tag "$HASH" &&
19+
git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
20+
git -C repo tag -d my_annotated_tag &&
21+
delete_object repo "$HASH"
22+
}
23+
1624
test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
1725
test_create_repo repo &&
1826
test_commit -C repo my_commit &&
@@ -78,4 +86,20 @@ test_expect_success 'missing reflog object alone fails fsck, even with extension
7886
test_must_fail git -C repo fsck
7987
'
8088

89+
test_expect_success 'missing ref object, but promised, passes fsck' '
90+
rm -rf repo &&
91+
test_create_repo repo &&
92+
test_commit -C repo my_commit &&
93+
94+
A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
95+
96+
# Reference $A only from ref
97+
git -C repo branch my_branch "$A" &&
98+
promise_and_delete "$A" &&
99+
100+
git -C repo config core.repositoryformatversion 1 &&
101+
git -C repo config extensions.partialclone "arbitrary string" &&
102+
git -C repo fsck
103+
'
104+
81105
test_done

0 commit comments

Comments
 (0)