]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0410-partial-clone.sh
sha1_file: support lazily fetching missing objects
[thirdparty/git.git] / t / t0410-partial-clone.sh
CommitLineData
498f1f61
JT
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
43f25158
JT
16promise_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
498f1f61
JT
24test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
25 test_create_repo repo &&
26 test_commit -C repo my_commit &&
27
28 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
29 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
30
31 # Reference $A only from reflog, and delete it
32 git -C repo branch my_branch "$A" &&
33 git -C repo branch -f my_branch my_commit &&
34 delete_object repo "$A" &&
35
36 # State that we got $C, which refers to $A, from promisor
37 printf "$C\n" | pack_as_from_promisor &&
38
39 # Normally, it fails
40 test_must_fail git -C repo fsck &&
41
42 # But with the extension, it succeeds
43 git -C repo config core.repositoryformatversion 1 &&
44 git -C repo config extensions.partialclone "arbitrary string" &&
45 git -C repo fsck
46'
47
48test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
49 rm -rf repo &&
50 test_create_repo repo &&
51 test_commit -C repo my_commit &&
52
53 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
54 git -C repo tag -a -m d my_tag_name $A &&
55 T=$(git -C repo rev-parse my_tag_name) &&
56 git -C repo tag -d my_tag_name &&
57
58 # Reference $A only from reflog, and delete it
59 git -C repo branch my_branch "$A" &&
60 git -C repo branch -f my_branch my_commit &&
61 delete_object repo "$A" &&
62
63 # State that we got $T, which refers to $A, from promisor
64 printf "$T\n" | pack_as_from_promisor &&
65
66 git -C repo config core.repositoryformatversion 1 &&
67 git -C repo config extensions.partialclone "arbitrary string" &&
68 git -C repo fsck
69'
70
71test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
72 rm -rf repo &&
73 test_create_repo repo &&
74 test_commit -C repo my_commit &&
75
76 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
77 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
78
79 # Reference $A only from reflog, and delete it
80 git -C repo branch my_branch "$A" &&
81 git -C repo branch -f my_branch my_commit &&
82 delete_object repo "$A" &&
83
84 git -C repo config core.repositoryformatversion 1 &&
85 git -C repo config extensions.partialclone "arbitrary string" &&
86 test_must_fail git -C repo fsck
87'
88
43f25158
JT
89test_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
caba7fc3
JT
105test_expect_success 'missing object, but promised, passes fsck' '
106 rm -rf repo &&
107 test_create_repo repo &&
108 test_commit -C repo 1 &&
109 test_commit -C repo 2 &&
110 test_commit -C repo 3 &&
111 git -C repo tag -a annotated_tag -m "annotated tag" &&
112
113 C=$(git -C repo rev-parse 1) &&
114 T=$(git -C repo rev-parse 2^{tree}) &&
115 B=$(git hash-object repo/3.t) &&
116 AT=$(git -C repo rev-parse annotated_tag) &&
117
118 promise_and_delete "$C" &&
119 promise_and_delete "$T" &&
120 promise_and_delete "$B" &&
121 promise_and_delete "$AT" &&
122
123 git -C repo config core.repositoryformatversion 1 &&
124 git -C repo config extensions.partialclone "arbitrary string" &&
125 git -C repo fsck
126'
127
096c9b8b
JT
128test_expect_success 'missing CLI object, but promised, passes fsck' '
129 rm -rf repo &&
130 test_create_repo repo &&
131 test_commit -C repo my_commit &&
132
133 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
134 promise_and_delete "$A" &&
135
136 git -C repo config core.repositoryformatversion 1 &&
137 git -C repo config extensions.partialclone "arbitrary string" &&
138 git -C repo fsck "$A"
139'
140
8b4c0103
JT
141test_expect_success 'fetching of missing objects' '
142 rm -rf repo &&
143 test_create_repo server &&
144 test_commit -C server foo &&
145 git -C server repack -a -d --write-bitmap-index &&
146
147 git clone "file://$(pwd)/server" repo &&
148 HASH=$(git -C repo rev-parse foo) &&
149 rm -rf repo/.git/objects/* &&
150
151 git -C repo config core.repositoryformatversion 1 &&
152 git -C repo config extensions.partialclone "origin" &&
153 git -C repo cat-file -p "$HASH" &&
154
155 # Ensure that the .promisor file is written, and check that its
156 # associated packfile contains the object
157 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
158 test_line_count = 1 promisorlist &&
159 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
160 git verify-pack --verbose "$IDX" | grep "$HASH"
161'
162
163LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root
164. "$TEST_DIRECTORY"/lib-httpd.sh
165start_httpd
166
167test_expect_success 'fetching of missing objects from an HTTP server' '
168 rm -rf repo &&
169 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
170 test_create_repo "$SERVER" &&
171 test_commit -C "$SERVER" foo &&
172 git -C "$SERVER" repack -a -d --write-bitmap-index &&
173
174 git clone $HTTPD_URL/smart/server repo &&
175 HASH=$(git -C repo rev-parse foo) &&
176 rm -rf repo/.git/objects/* &&
177
178 git -C repo config core.repositoryformatversion 1 &&
179 git -C repo config extensions.partialclone "origin" &&
180 git -C repo cat-file -p "$HASH" &&
181
182 # Ensure that the .promisor file is written, and check that its
183 # associated packfile contains the object
184 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
185 test_line_count = 1 promisorlist &&
186 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
187 git verify-pack --verbose "$IDX" | grep "$HASH"
188'
189
190stop_httpd
191
498f1f61 192test_done