3ddb3b98fe5001c722c5d21a0f48694ffb81aee5
1#!/bin/sh
2
3test_description='partial clone'
4
5. ./test-lib.sh
6
7delete_object () {
8 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
9}
10
11pack_as_from_promisor () {
12 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
13 >repo/.git/objects/pack/pack-$HASH.promisor
14}
15
16test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
17 test_create_repo repo &&
18 test_commit -C repo my_commit &&
19
20 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
21 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
22
23 # Reference $A only from reflog, and delete it
24 git -C repo branch my_branch "$A" &&
25 git -C repo branch -f my_branch my_commit &&
26 delete_object repo "$A" &&
27
28 # State that we got $C, which refers to $A, from promisor
29 printf "$C\n" | pack_as_from_promisor &&
30
31 # Normally, it fails
32 test_must_fail git -C repo fsck &&
33
34 # But with the extension, it succeeds
35 git -C repo config core.repositoryformatversion 1 &&
36 git -C repo config extensions.partialclone "arbitrary string" &&
37 git -C repo fsck
38'
39
40test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
41 rm -rf repo &&
42 test_create_repo repo &&
43 test_commit -C repo my_commit &&
44
45 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
46 git -C repo tag -a -m d my_tag_name $A &&
47 T=$(git -C repo rev-parse my_tag_name) &&
48 git -C repo tag -d my_tag_name &&
49
50 # Reference $A only from reflog, and delete it
51 git -C repo branch my_branch "$A" &&
52 git -C repo branch -f my_branch my_commit &&
53 delete_object repo "$A" &&
54
55 # State that we got $T, which refers to $A, from promisor
56 printf "$T\n" | pack_as_from_promisor &&
57
58 git -C repo config core.repositoryformatversion 1 &&
59 git -C repo config extensions.partialclone "arbitrary string" &&
60 git -C repo fsck
61'
62
63test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
64 rm -rf repo &&
65 test_create_repo repo &&
66 test_commit -C repo my_commit &&
67
68 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
69 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
70
71 # Reference $A only from reflog, and delete it
72 git -C repo branch my_branch "$A" &&
73 git -C repo branch -f my_branch my_commit &&
74 delete_object repo "$A" &&
75
76 git -C repo config core.repositoryformatversion 1 &&
77 git -C repo config extensions.partialclone "arbitrary string" &&
78 test_must_fail git -C repo fsck
79'
80
81test_done