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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Dec 5, 2017 at 16:58 UTC 43f25158ca0ae31b663e37f6b538daf735df10a3
2 files changed +32
builtin/fsck.c
+8
@@ -434,6 +434,14 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
434
435 obj = parse_object(oid);
436 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 + }
445 error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
446 errors_found |= ERROR_REACHABLE;
447 /* We'll continue with the rest despite the error.. */
t/t0410-partial-clone.sh
+24
@@ -13,6 +13,14 @@ pack_as_from_promisor () {
13 >repo/.git/objects/pack/pack-$HASH.promisor
14 }
15
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 +
24 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
25 test_create_repo repo &&
26 test_commit -C repo my_commit &&
@@ -78,4 +86,20 @@ test_expect_success 'missing reflog object alone fails fsck, even with extension
86 test_must_fail git -C repo fsck
87 '
88
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 +
105 test_done