]>
Commit | Line | Data |
---|---|---|
35a7ae95 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git partial clone' | |
4 | ||
95cf2c01 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
35a7ae95 JH |
8 | . ./test-lib.sh |
9 | ||
10 | # create a normal "src" repo where we can later create new commits. | |
11 | # expect_1.oids will contain a list of the OIDs of all blobs. | |
12 | test_expect_success 'setup normal src repo' ' | |
13 | echo "{print \$1}" >print_1.awk && | |
14 | echo "{print \$2}" >print_2.awk && | |
15 | ||
16 | git init src && | |
17 | for n in 1 2 3 4 | |
18 | do | |
19 | echo "This is file: $n" > src/file.$n.txt | |
20 | git -C src add file.$n.txt | |
21 | git -C src commit -m "file $n" | |
22 | git -C src ls-files -s file.$n.txt >>temp | |
23 | done && | |
24 | awk -f print_2.awk <temp | sort >expect_1.oids && | |
25 | test_line_count = 4 expect_1.oids | |
26 | ' | |
27 | ||
28 | # bare clone "src" giving "srv.bare" for use as our server. | |
29 | test_expect_success 'setup bare clone for server' ' | |
30 | git clone --bare "file://$(pwd)/src" srv.bare && | |
31 | git -C srv.bare config --local uploadpack.allowfilter 1 && | |
32 | git -C srv.bare config --local uploadpack.allowanysha1inwant 1 | |
33 | ' | |
34 | ||
35 | # do basic partial clone from "srv.bare" | |
36 | # confirm we are missing all of the known blobs. | |
37 | # confirm partial clone was registered in the local config. | |
38 | test_expect_success 'do partial clone 1' ' | |
39 | git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 && | |
bdbc17e8 | 40 | |
8d6ba495 | 41 | git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs && |
61de0ff6 | 42 | awk -f print_1.awk revs | |
bdbc17e8 MD |
43 | sed "s/?//" | |
44 | sort >observed.oids && | |
45 | ||
35a7ae95 JH |
46 | test_cmp expect_1.oids observed.oids && |
47 | test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" && | |
b14ed5ad | 48 | test "$(git -C pc1 config --local remote.origin.promisor)" = "true" && |
fa3d1b63 | 49 | test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none" |
35a7ae95 JH |
50 | ' |
51 | ||
5374a290 JT |
52 | test_expect_success 'verify that .promisor file contains refs fetched' ' |
53 | ls pc1/.git/objects/pack/pack-*.promisor >promisorlist && | |
54 | test_line_count = 1 promisorlist && | |
6c28bef2 | 55 | git -C srv.bare rev-parse --verify HEAD >headhash && |
5374a290 | 56 | grep "$(cat headhash) HEAD" $(cat promisorlist) && |
95cf2c01 | 57 | grep "$(cat headhash) refs/heads/main" $(cat promisorlist) |
5374a290 JT |
58 | ' |
59 | ||
95cf2c01 | 60 | # checkout main to force dynamic object fetch of blobs at HEAD. |
35a7ae95 | 61 | test_expect_success 'verify checkout with dynamic object fetch' ' |
8d6ba495 | 62 | git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed && |
35a7ae95 | 63 | test_line_count = 4 observed && |
95cf2c01 | 64 | git -C pc1 checkout main && |
8d6ba495 | 65 | git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed && |
35a7ae95 JH |
66 | test_line_count = 0 observed |
67 | ' | |
68 | ||
69 | # create new commits in "src" repo to establish a blame history on file.1.txt | |
70 | # and push to "srv.bare". | |
71 | test_expect_success 'push new commits to server' ' | |
72 | git -C src remote add srv "file://$(pwd)/srv.bare" && | |
73 | for x in a b c d e | |
74 | do | |
aa57b871 | 75 | echo "Mod file.1.txt $x" >>src/file.1.txt |
35a7ae95 JH |
76 | git -C src add file.1.txt |
77 | git -C src commit -m "mod $x" | |
78 | done && | |
95cf2c01 JS |
79 | git -C src blame main -- file.1.txt >expect.blame && |
80 | git -C src push -u srv main | |
35a7ae95 JH |
81 | ' |
82 | ||
83 | # (partial) fetch in the partial clone repo from the promisor remote. | |
84 | # verify that fetch inherited the filter-spec from the config and DOES NOT | |
85 | # have the new blobs. | |
86 | test_expect_success 'partial fetch inherits filter settings' ' | |
87 | git -C pc1 fetch origin && | |
8d6ba495 | 88 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 89 | main..origin/main >observed && |
35a7ae95 JH |
90 | test_line_count = 5 observed |
91 | ' | |
92 | ||
93 | # force dynamic object fetch using diff. | |
95cf2c01 | 94 | # we should only get 1 new blob (for the file in origin/main). |
35a7ae95 | 95 | test_expect_success 'verify diff causes dynamic object fetch' ' |
95cf2c01 | 96 | git -C pc1 diff main..origin/main -- file.1.txt && |
8d6ba495 | 97 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 98 | main..origin/main >observed && |
35a7ae95 JH |
99 | test_line_count = 4 observed |
100 | ' | |
101 | ||
102 | # force full dynamic object fetch of the file's history using blame. | |
103 | # we should get the intermediate blobs for the file. | |
104 | test_expect_success 'verify blame causes dynamic object fetch' ' | |
95cf2c01 | 105 | git -C pc1 blame origin/main -- file.1.txt >observed.blame && |
35a7ae95 | 106 | test_cmp expect.blame observed.blame && |
8d6ba495 | 107 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 108 | main..origin/main >observed && |
35a7ae95 JH |
109 | test_line_count = 0 observed |
110 | ' | |
111 | ||
aa57b871 JH |
112 | # create new commits in "src" repo to establish a history on file.2.txt |
113 | # and push to "srv.bare". | |
114 | test_expect_success 'push new commits to server for file.2.txt' ' | |
115 | for x in a b c d e f | |
116 | do | |
117 | echo "Mod file.2.txt $x" >>src/file.2.txt | |
118 | git -C src add file.2.txt | |
119 | git -C src commit -m "mod $x" | |
120 | done && | |
95cf2c01 | 121 | git -C src push -u srv main |
aa57b871 JH |
122 | ' |
123 | ||
3aa6694f | 124 | # Do FULL fetch by disabling inherited filter-spec using --no-filter. |
aa57b871 JH |
125 | # Verify we have all the new blobs. |
126 | test_expect_success 'override inherited filter-spec using --no-filter' ' | |
127 | git -C pc1 fetch --no-filter origin && | |
8d6ba495 | 128 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 129 | main..origin/main >observed && |
aa57b871 JH |
130 | test_line_count = 0 observed |
131 | ' | |
132 | ||
3aa6694f JH |
133 | # create new commits in "src" repo to establish a history on file.3.txt |
134 | # and push to "srv.bare". | |
135 | test_expect_success 'push new commits to server for file.3.txt' ' | |
136 | for x in a b c d e f | |
137 | do | |
138 | echo "Mod file.3.txt $x" >>src/file.3.txt | |
139 | git -C src add file.3.txt | |
140 | git -C src commit -m "mod $x" | |
141 | done && | |
95cf2c01 | 142 | git -C src push -u srv main |
3aa6694f JH |
143 | ' |
144 | ||
145 | # Do a partial fetch and then try to manually fetch the missing objects. | |
146 | # This can be used as the basis of a pre-command hook to bulk fetch objects | |
147 | # perhaps combined with a command in dry-run mode. | |
148 | test_expect_success 'manual prefetch of missing objects' ' | |
149 | git -C pc1 fetch --filter=blob:none origin && | |
bdbc17e8 | 150 | |
8d6ba495 | 151 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 152 | main..origin/main >revs && |
61de0ff6 | 153 | awk -f print_1.awk revs | |
bdbc17e8 MD |
154 | sed "s/?//" | |
155 | sort >observed.oids && | |
156 | ||
3aa6694f JH |
157 | test_line_count = 6 observed.oids && |
158 | git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids && | |
bdbc17e8 | 159 | |
8d6ba495 | 160 | git -C pc1 rev-list --quiet --objects --missing=print \ |
95cf2c01 | 161 | main..origin/main >revs && |
61de0ff6 | 162 | awk -f print_1.awk revs | |
bdbc17e8 MD |
163 | sed "s/?//" | |
164 | sort >observed.oids && | |
165 | ||
3aa6694f JH |
166 | test_line_count = 0 observed.oids |
167 | ' | |
168 | ||
1b03df5f JT |
169 | test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' ' |
170 | test_create_repo submodule && | |
171 | test_commit -C submodule mycommit && | |
172 | ||
173 | test_create_repo src_with_sub && | |
174 | test_config -C src_with_sub uploadpack.allowfilter 1 && | |
175 | test_config -C src_with_sub uploadpack.allowanysha1inwant 1 && | |
176 | ||
177 | git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub && | |
178 | git -C src_with_sub commit -m "commit with submodule" && | |
179 | ||
180 | git -c transfer.fsckobjects=1 \ | |
181 | clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst && | |
182 | test_when_finished rm -rf dst | |
183 | ' | |
184 | ||
98a2ea46 JT |
185 | test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' ' |
186 | git init src && | |
187 | test_commit -C src x && | |
188 | test_config -C src uploadpack.allowfilter 1 && | |
189 | test_config -C src uploadpack.allowanysha1inwant 1 && | |
190 | ||
191 | GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \ | |
192 | clone --filter="blob:none" "file://$(pwd)/src" dst && | |
193 | grep "git index-pack.*--fsck-objects" trace | |
194 | ' | |
195 | ||
bc5975d2 MD |
196 | test_expect_success 'use fsck before and after manually fetching a missing subtree' ' |
197 | # push new commit so server has a subtree | |
198 | mkdir src/dir && | |
199 | echo "in dir" >src/dir/file.txt && | |
200 | git -C src add dir/file.txt && | |
201 | git -C src commit -m "file in dir" && | |
95cf2c01 | 202 | git -C src push -u srv main && |
bc5975d2 MD |
203 | SUBTREE=$(git -C src rev-parse HEAD:dir) && |
204 | ||
205 | rm -rf dst && | |
206 | git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst && | |
207 | git -C dst fsck && | |
208 | ||
209 | # Make sure we only have commits, and all trees and blobs are missing. | |
95cf2c01 | 210 | git -C dst rev-list --missing=allow-any --objects main \ |
bc5975d2 MD |
211 | >fetched_objects && |
212 | awk -f print_1.awk fetched_objects | | |
213 | xargs -n1 git -C dst cat-file -t >fetched_types && | |
214 | ||
215 | sort -u fetched_types >unique_types.observed && | |
216 | echo commit >unique_types.expected && | |
217 | test_cmp unique_types.expected unique_types.observed && | |
218 | ||
219 | # Auto-fetch a tree with cat-file. | |
220 | git -C dst cat-file -p $SUBTREE >tree_contents && | |
221 | grep file.txt tree_contents && | |
222 | ||
223 | # fsck still works after an auto-fetch of a tree. | |
224 | git -C dst fsck && | |
225 | ||
226 | # Auto-fetch all remaining trees and blobs with --missing=error | |
95cf2c01 | 227 | git -C dst rev-list --missing=error --objects main >fetched_objects && |
bc5975d2 MD |
228 | test_line_count = 70 fetched_objects && |
229 | ||
230 | awk -f print_1.awk fetched_objects | | |
231 | xargs -n1 git -C dst cat-file -t >fetched_types && | |
232 | ||
233 | sort -u fetched_types >unique_types.observed && | |
d9e6d094 | 234 | test_write_lines blob commit tree >unique_types.expected && |
bc5975d2 MD |
235 | test_cmp unique_types.expected unique_types.observed |
236 | ' | |
237 | ||
489fc9ee MD |
238 | test_expect_success 'implicitly construct combine: filter with repeated flags' ' |
239 | GIT_TRACE=$(pwd)/trace git clone --bare \ | |
240 | --filter=blob:none --filter=tree:1 \ | |
241 | "file://$(pwd)/srv.bare" pc2 && | |
242 | grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \ | |
243 | trace && | |
244 | git -C pc2 rev-list --objects --missing=allow-any HEAD >objects && | |
245 | ||
246 | # We should have gotten some root trees. | |
247 | grep " $" objects && | |
248 | # Should not have gotten any non-root trees or blobs. | |
249 | ! grep " ." objects && | |
250 | ||
251 | xargs -n 1 git -C pc2 cat-file -t <objects >types && | |
252 | sort -u types >unique_types.actual && | |
253 | test_write_lines commit tree >unique_types.expected && | |
254 | test_cmp unique_types.expected unique_types.actual | |
255 | ' | |
256 | ||
6dd3456a TB |
257 | test_expect_success 'upload-pack fails banned object filters' ' |
258 | test_config -C srv.bare uploadpackfilter.blob:none.allow false && | |
259 | test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \ | |
260 | "file://$(pwd)/srv.bare" pc3 2>err && | |
6cc275ea | 261 | test_i18ngrep "filter '\''blob:none'\'' not supported" err |
6dd3456a TB |
262 | ' |
263 | ||
264 | test_expect_success 'upload-pack fails banned combine object filters' ' | |
265 | test_config -C srv.bare uploadpackfilter.allow false && | |
266 | test_config -C srv.bare uploadpackfilter.combine.allow true && | |
267 | test_config -C srv.bare uploadpackfilter.tree.allow true && | |
268 | test_config -C srv.bare uploadpackfilter.blob:none.allow false && | |
269 | test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \ | |
270 | --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err && | |
6cc275ea | 271 | test_i18ngrep "filter '\''blob:none'\'' not supported" err |
6dd3456a TB |
272 | ' |
273 | ||
274 | test_expect_success 'upload-pack fails banned object filters with fallback' ' | |
275 | test_config -C srv.bare uploadpackfilter.allow false && | |
276 | test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \ | |
277 | "file://$(pwd)/srv.bare" pc3 2>err && | |
6cc275ea | 278 | test_i18ngrep "filter '\''blob:none'\'' not supported" err |
6dd3456a TB |
279 | ' |
280 | ||
5b01a4e8 TB |
281 | test_expect_success 'upload-pack limits tree depth filters' ' |
282 | test_config -C srv.bare uploadpackfilter.allow false && | |
283 | test_config -C srv.bare uploadpackfilter.tree.allow true && | |
284 | test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 && | |
285 | test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \ | |
286 | "file://$(pwd)/srv.bare" pc3 2>err && | |
6cc275ea | 287 | test_i18ngrep "tree filter allows max depth 0, but got 1" err |
5b01a4e8 TB |
288 | ' |
289 | ||
a0c9016a JT |
290 | test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' ' |
291 | rm -rf src dst && | |
292 | git init src && | |
293 | test_commit -C src x && | |
294 | test_config -C src uploadpack.allowfilter 1 && | |
295 | test_config -C src uploadpack.allowanysha1inwant 1 && | |
296 | ||
297 | # Create a tag pointing to a blob. | |
298 | BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) && | |
299 | git -C src tag myblob "$BLOB" && | |
300 | ||
301 | git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err && | |
302 | ! grep "does not point to a valid object" err && | |
303 | git -C dst fsck | |
304 | ' | |
305 | ||
35f9e3e5 JT |
306 | test_expect_success 'fetch what is specified on CLI even if already promised' ' |
307 | rm -rf src dst.git && | |
308 | git init src && | |
309 | test_commit -C src foo && | |
310 | test_config -C src uploadpack.allowfilter 1 && | |
311 | test_config -C src uploadpack.allowanysha1inwant 1 && | |
312 | ||
313 | git hash-object --stdin <src/foo.t >blob && | |
314 | ||
315 | git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git && | |
316 | git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before && | |
317 | grep "?$(cat blob)" missing_before && | |
318 | git -C dst.git fetch origin $(cat blob) && | |
319 | git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after && | |
320 | ! grep "?$(cat blob)" missing_after | |
321 | ' | |
322 | ||
72de5895 JS |
323 | test_expect_success 'setup src repo for sparse filter' ' |
324 | git init sparse-src && | |
325 | git -C sparse-src config --local uploadpack.allowfilter 1 && | |
326 | git -C sparse-src config --local uploadpack.allowanysha1inwant 1 && | |
327 | test_commit -C sparse-src one && | |
328 | test_commit -C sparse-src two && | |
329 | echo /one.t >sparse-src/only-one && | |
330 | git -C sparse-src add . && | |
331 | git -C sparse-src commit -m "add sparse checkout files" | |
332 | ' | |
333 | ||
4c96a775 | 334 | test_expect_success 'partial clone with sparse filter succeeds' ' |
72de5895 JS |
335 | rm -rf dst.git && |
336 | git clone --no-local --bare \ | |
95cf2c01 | 337 | --filter=sparse:oid=main:only-one \ |
72de5895 JS |
338 | sparse-src dst.git && |
339 | ( | |
340 | cd dst.git && | |
341 | git rev-list --objects --missing=print HEAD >out && | |
342 | grep "^$(git rev-parse HEAD:one.t)" out && | |
343 | grep "^?$(git rev-parse HEAD:two.t)" out | |
344 | ) | |
345 | ' | |
346 | ||
4c96a775 | 347 | test_expect_success 'partial clone with unresolvable sparse filter fails cleanly' ' |
72de5895 JS |
348 | rm -rf dst.git && |
349 | test_must_fail git clone --no-local --bare \ | |
95cf2c01 | 350 | --filter=sparse:oid=main:no-such-name \ |
72de5895 | 351 | sparse-src dst.git 2>err && |
95cf2c01 | 352 | test_i18ngrep "unable to access sparse blob in .main:no-such-name" err && |
72de5895 | 353 | test_must_fail git clone --no-local --bare \ |
95cf2c01 | 354 | --filter=sparse:oid=main \ |
72de5895 | 355 | sparse-src dst.git 2>err && |
cf34337f | 356 | test_i18ngrep "unable to parse sparse filter data in" err |
72de5895 JS |
357 | ' |
358 | ||
6462d5eb JT |
359 | setup_triangle () { |
360 | rm -rf big-blob.txt server client promisor-remote && | |
361 | ||
362 | printf "line %d\n" $(test_seq 1 100) >big-blob.txt && | |
363 | ||
b54128bb | 364 | # Create a server with 2 commits: a commit with a big tree and a child |
6462d5eb JT |
365 | # commit with an incremental change. Also, create a partial clone |
366 | # client that only contains the first commit. | |
367 | git init server && | |
368 | git -C server config --local uploadpack.allowfilter 1 && | |
b54128bb JT |
369 | for i in $(test_seq 1 100) |
370 | do | |
371 | echo "make the tree big" >server/file$i && | |
372 | git -C server add file$i | |
373 | done && | |
6462d5eb JT |
374 | git -C server commit -m "initial" && |
375 | git clone --bare --filter=tree:0 "file://$(pwd)/server" client && | |
b54128bb JT |
376 | echo another line >>server/file1 && |
377 | git -C server commit -am "incremental change" && | |
6462d5eb | 378 | |
b54128bb JT |
379 | # Create a promisor remote that only contains the tree and blob from |
380 | # the first commit. | |
6462d5eb | 381 | git init promisor-remote && |
b54128bb JT |
382 | git -C server config --local uploadpack.allowanysha1inwant 1 && |
383 | TREE_HASH=$(git -C server rev-parse HEAD~1^{tree}) && | |
384 | git -C promisor-remote fetch --keep "file://$(pwd)/server" "$TREE_HASH" && | |
385 | git -C promisor-remote count-objects -v >object-count && | |
386 | test_i18ngrep "count: 0" object-count && | |
387 | test_i18ngrep "in-pack: 2" object-count && | |
388 | ||
389 | # Set it as the promisor remote of client. Thus, whenever | |
390 | # the client lazy fetches, the lazy fetch will succeed only if it is | |
391 | # for this tree or blob. | |
6462d5eb JT |
392 | test_commit -C promisor-remote one && # so that ref advertisement is not empty |
393 | git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 && | |
6462d5eb JT |
394 | git -C client remote set-url origin "file://$(pwd)/promisor-remote" |
395 | } | |
396 | ||
397 | # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only | |
398 | # test that "fetch" avoid fetching trees and blobs, but not commits or | |
399 | # tags. Revisit this if Git is ever taught to support partial clones | |
400 | # with commits and/or tags filtered out. | |
401 | ||
402 | test_expect_success 'fetch lazy-fetches only to resolve deltas' ' | |
403 | setup_triangle && | |
404 | ||
405 | # Exercise to make sure it works. Git will not fetch anything from the | |
b54128bb | 406 | # promisor remote other than for the big tree (because it needs to |
6462d5eb JT |
407 | # resolve the delta). |
408 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client \ | |
95cf2c01 | 409 | fetch "file://$(pwd)/server" main && |
6462d5eb JT |
410 | |
411 | # Verify the assumption that the client needed to fetch the delta base | |
412 | # to resolve the delta. | |
b54128bb | 413 | git -C server rev-parse HEAD~1^{tree} >hash && |
6462d5eb JT |
414 | grep "want $(cat hash)" trace |
415 | ' | |
416 | ||
417 | test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' ' | |
418 | setup_triangle && | |
419 | ||
420 | git -C server config --local protocol.version 2 && | |
421 | git -C client config --local protocol.version 2 && | |
422 | git -C promisor-remote config --local protocol.version 2 && | |
423 | ||
424 | # Exercise to make sure it works. Git will not fetch anything from the | |
425 | # promisor remote other than for the big blob (because it needs to | |
426 | # resolve the delta). | |
427 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client \ | |
95cf2c01 | 428 | fetch "file://$(pwd)/server" main && |
6462d5eb JT |
429 | |
430 | # Verify that protocol version 2 was used. | |
431 | grep "fetch< version 2" trace && | |
432 | ||
433 | # Verify the assumption that the client needed to fetch the delta base | |
434 | # to resolve the delta. | |
b54128bb | 435 | git -C server rev-parse HEAD~1^{tree} >hash && |
6462d5eb JT |
436 | grep "want $(cat hash)" trace |
437 | ' | |
438 | ||
5c3b801d JT |
439 | test_expect_success 'fetch does not lazy-fetch missing targets of its refs' ' |
440 | rm -rf server client trace && | |
441 | ||
442 | test_create_repo server && | |
443 | test_config -C server uploadpack.allowfilter 1 && | |
444 | test_config -C server uploadpack.allowanysha1inwant 1 && | |
445 | test_commit -C server foo && | |
446 | ||
447 | git clone --filter=blob:none "file://$(pwd)/server" client && | |
448 | # Make all refs point to nothing by deleting all objects. | |
449 | rm client/.git/objects/pack/* && | |
450 | ||
451 | test_commit -C server bar && | |
452 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \ | |
453 | --no-tags --recurse-submodules=no \ | |
454 | origin refs/tags/bar && | |
455 | FOO_HASH=$(git -C server rev-parse foo) && | |
456 | ! grep "want $FOO_HASH" trace | |
457 | ' | |
458 | ||
08450ef7 CC |
459 | # The following two tests must be in this order. It is important that |
460 | # the srv.bare repository did not have tags during clone, but has tags | |
d0badf87 DS |
461 | # in the fetch. |
462 | ||
08450ef7 | 463 | test_expect_success 'verify fetch succeeds when asking for new tags' ' |
d0badf87 DS |
464 | git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test && |
465 | for i in I J K | |
466 | do | |
467 | test_commit -C src $i && | |
468 | git -C src branch $i || return 1 | |
469 | done && | |
470 | git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* && | |
471 | git -C tag-test -c protocol.version=2 fetch --tags origin | |
472 | ' | |
473 | ||
3e96c668 | 474 | test_expect_success 'verify fetch downloads only one pack when updating refs' ' |
d0badf87 DS |
475 | git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test && |
476 | ls pack-test/.git/objects/pack/*pack >pack-list && | |
477 | test_line_count = 2 pack-list && | |
478 | for i in A B C | |
479 | do | |
480 | test_commit -C src $i && | |
481 | git -C src branch $i || return 1 | |
482 | done && | |
483 | git -C srv.bare fetch origin +refs/heads/*:refs/heads/* && | |
484 | git -C pack-test fetch origin && | |
485 | ls pack-test/.git/objects/pack/*pack >pack-list && | |
486 | test_line_count = 3 pack-list | |
487 | ' | |
488 | ||
167a575e JK |
489 | test_expect_success 'single-branch tag following respects partial clone' ' |
490 | git clone --single-branch -b B --filter=blob:none \ | |
491 | "file://$(pwd)/srv.bare" single && | |
492 | git -C single rev-parse --verify refs/tags/B && | |
493 | git -C single rev-parse --verify refs/tags/A && | |
494 | test_must_fail git -C single rev-parse --verify refs/tags/C | |
495 | ' | |
496 | ||
77aa0941 JT |
497 | test_expect_success 'fetch from a partial clone, protocol v0' ' |
498 | rm -rf server client trace && | |
499 | ||
500 | # Pretend that the server is a partial clone | |
501 | git init server && | |
502 | git -C server remote add a_remote "file://$(pwd)/" && | |
503 | test_config -C server core.repositoryformatversion 1 && | |
504 | test_config -C server extensions.partialclone a_remote && | |
505 | test_config -C server protocol.version 0 && | |
506 | test_commit -C server foo && | |
507 | ||
508 | # Fetch from the server | |
509 | git init client && | |
510 | test_config -C client protocol.version 0 && | |
511 | test_commit -C client bar && | |
512 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" && | |
513 | ! grep "version 2" trace | |
514 | ' | |
515 | ||
516 | test_expect_success 'fetch from a partial clone, protocol v2' ' | |
517 | rm -rf server client trace && | |
518 | ||
519 | # Pretend that the server is a partial clone | |
520 | git init server && | |
521 | git -C server remote add a_remote "file://$(pwd)/" && | |
522 | test_config -C server core.repositoryformatversion 1 && | |
523 | test_config -C server extensions.partialclone a_remote && | |
524 | test_config -C server protocol.version 2 && | |
525 | test_commit -C server foo && | |
526 | ||
527 | # Fetch from the server | |
528 | git init client && | |
529 | test_config -C client protocol.version 2 && | |
530 | test_commit -C client bar && | |
531 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" && | |
532 | grep "version 2" trace | |
533 | ' | |
534 | ||
a7e67c11 JT |
535 | . "$TEST_DIRECTORY"/lib-httpd.sh |
536 | start_httpd | |
537 | ||
385d1bfd JT |
538 | # Converts bytes into their hexadecimal representation. For example, |
539 | # "printf 'ab\r\n' | hex_unpack" results in '61620d0a'. | |
540 | hex_unpack () { | |
541 | perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' | |
542 | } | |
543 | ||
544 | # Inserts $1 at the start of the string and every 2 characters thereafter. | |
545 | intersperse () { | |
546 | sed 's/\(..\)/'$1'\1/g' | |
547 | } | |
548 | ||
eafff6e4 | 549 | # Create a one-time-perl command to replace the existing packfile with $1. |
385d1bfd JT |
550 | replace_packfile () { |
551 | # The protocol requires that the packfile be sent in sideband 1, hence | |
552 | # the extra \x01 byte at the beginning. | |
eafff6e4 JS |
553 | cp $1 "$HTTPD_ROOT_PATH/one-time-pack" && |
554 | echo 'if (/packfile/) { | |
555 | print; | |
556 | my $length = -s "one-time-pack"; | |
557 | printf "%04x\x01", $length + 5; | |
558 | print `cat one-time-pack` . "0000"; | |
559 | last | |
560 | }' >"$HTTPD_ROOT_PATH/one-time-perl" | |
a7e67c11 JT |
561 | } |
562 | ||
563 | test_expect_success 'upon cloning, check that all refs point to objects' ' | |
564 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && | |
565 | rm -rf "$SERVER" repo && | |
566 | test_create_repo "$SERVER" && | |
567 | test_commit -C "$SERVER" foo && | |
568 | test_config -C "$SERVER" uploadpack.allowfilter 1 && | |
569 | test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 && | |
570 | ||
571 | # Create a tag pointing to a blob. | |
572 | BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) && | |
573 | git -C "$SERVER" tag myblob "$BLOB" && | |
574 | ||
575 | # Craft a packfile not including that blob. | |
576 | git -C "$SERVER" rev-parse HEAD | | |
bdbc17e8 | 577 | git -C "$SERVER" pack-objects --stdout >incomplete.pack && |
a7e67c11 JT |
578 | |
579 | # Replace the existing packfile with the crafted one. The protocol | |
580 | # requires that the packfile be sent in sideband 1, hence the extra | |
581 | # \x01 byte at the beginning. | |
385d1bfd | 582 | replace_packfile incomplete.pack && |
a7e67c11 | 583 | |
eafff6e4 | 584 | # Use protocol v2 because the perl command looks for the "packfile" |
a7e67c11 JT |
585 | # section header. |
586 | test_config -C "$SERVER" protocol.version 2 && | |
587 | test_must_fail git -c protocol.version=2 clone \ | |
eafff6e4 | 588 | --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err && |
a7e67c11 | 589 | |
3813a89f | 590 | test_i18ngrep "did not send all necessary objects" err && |
a7e67c11 | 591 | |
eafff6e4 JS |
592 | # Ensure that the one-time-perl script was used. |
593 | ! test -e "$HTTPD_ROOT_PATH/one-time-perl" | |
a7e67c11 JT |
594 | ' |
595 | ||
dc0a13f6 JT |
596 | test_expect_success 'when partial cloning, tolerate server not sending target of tag' ' |
597 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && | |
598 | rm -rf "$SERVER" repo && | |
599 | test_create_repo "$SERVER" && | |
600 | test_commit -C "$SERVER" foo && | |
601 | test_config -C "$SERVER" uploadpack.allowfilter 1 && | |
602 | test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 && | |
603 | ||
604 | # Create an annotated tag pointing to a blob. | |
605 | BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) && | |
606 | git -C "$SERVER" tag -m message -a myblob "$BLOB" && | |
607 | ||
608 | # Craft a packfile including the tag, but not the blob it points to. | |
8c4cc326 JT |
609 | # Also, omit objects referenced from HEAD in order to force a second |
610 | # fetch (to fetch missing objects) upon the automatic checkout that | |
611 | # happens after a clone. | |
612 | printf "%s\n%s\n--not\n%s\n%s\n" \ | |
dc0a13f6 JT |
613 | $(git -C "$SERVER" rev-parse HEAD) \ |
614 | $(git -C "$SERVER" rev-parse myblob) \ | |
8c4cc326 | 615 | $(git -C "$SERVER" rev-parse HEAD^{tree}) \ |
dc0a13f6 JT |
616 | $(git -C "$SERVER" rev-parse myblob^{blob}) | |
617 | git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack && | |
618 | ||
619 | # Replace the existing packfile with the crafted one. The protocol | |
620 | # requires that the packfile be sent in sideband 1, hence the extra | |
621 | # \x01 byte at the beginning. | |
385d1bfd | 622 | replace_packfile incomplete.pack && |
dc0a13f6 | 623 | |
eafff6e4 | 624 | # Use protocol v2 because the perl command looks for the "packfile" |
dc0a13f6 JT |
625 | # section header. |
626 | test_config -C "$SERVER" protocol.version 2 && | |
627 | ||
628 | # Exercise to make sure it works. | |
629 | git -c protocol.version=2 clone \ | |
eafff6e4 | 630 | --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err && |
8c4cc326 | 631 | ! grep "missing object referenced by" err && |
dc0a13f6 | 632 | |
eafff6e4 JS |
633 | # Ensure that the one-time-perl script was used. |
634 | ! test -e "$HTTPD_ROOT_PATH/one-time-perl" | |
dc0a13f6 JT |
635 | ' |
636 | ||
8a30a1ef JT |
637 | test_expect_success 'tolerate server sending REF_DELTA against missing promisor objects' ' |
638 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && | |
639 | rm -rf "$SERVER" repo && | |
640 | test_create_repo "$SERVER" && | |
641 | test_config -C "$SERVER" uploadpack.allowfilter 1 && | |
642 | test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 && | |
643 | ||
810e1932 | 644 | # Create a commit with 2 blobs to be used as delta bases. |
8a30a1ef JT |
645 | for i in $(test_seq 10) |
646 | do | |
810e1932 JT |
647 | echo "this is a line" >>"$SERVER/foo.txt" && |
648 | echo "this is another line" >>"$SERVER/have.txt" | |
8a30a1ef | 649 | done && |
810e1932 | 650 | git -C "$SERVER" add foo.txt have.txt && |
8a30a1ef | 651 | git -C "$SERVER" commit -m bar && |
810e1932 JT |
652 | git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing && |
653 | git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have && | |
8a30a1ef | 654 | |
810e1932 | 655 | # Clone. The client has deltabase_have but not deltabase_missing. |
8a30a1ef | 656 | git -c protocol.version=2 clone --no-checkout \ |
eafff6e4 | 657 | --filter=blob:none $HTTPD_URL/one_time_perl/server repo && |
810e1932 | 658 | git -C repo hash-object -w -- "$SERVER/have.txt" && |
8a30a1ef | 659 | |
810e1932 JT |
660 | # Sanity check to ensure that the client does not have |
661 | # deltabase_missing. | |
5718c53d | 662 | git -C repo rev-list --objects --ignore-missing \ |
810e1932 | 663 | -- $(cat deltabase_missing) >objlist && |
8a30a1ef JT |
664 | test_line_count = 0 objlist && |
665 | ||
666 | # Another commit. This commit will be fetched by the client. | |
667 | echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" && | |
810e1932 JT |
668 | echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" && |
669 | git -C "$SERVER" add foo.txt have.txt && | |
8a30a1ef JT |
670 | git -C "$SERVER" commit -m baz && |
671 | ||
672 | # Pack a thin pack containing, among other things, HEAD:foo.txt | |
810e1932 JT |
673 | # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against |
674 | # HEAD^:have.txt. | |
8a30a1ef JT |
675 | printf "%s\n--not\n%s\n" \ |
676 | $(git -C "$SERVER" rev-parse HEAD) \ | |
677 | $(git -C "$SERVER" rev-parse HEAD^) | | |
678 | git -C "$SERVER" pack-objects --thin --stdout >thin.pack && | |
679 | ||
680 | # Ensure that the pack contains one delta against HEAD^:foo.txt. Since | |
681 | # the delta contains at least 26 novel characters, the size cannot be | |
682 | # contained in 4 bits, so the object header will take up 2 bytes. The | |
683 | # most significant nybble of the first byte is 0b1111 (0b1 to indicate | |
684 | # that the header continues, and 0b111 to indicate REF_DELTA), followed | |
685 | # by any 3 nybbles, then the OID of the delta base. | |
810e1932 JT |
686 | printf "f.,..%s" $(intersperse "," <deltabase_missing) >want && |
687 | hex_unpack <thin.pack | intersperse "," >have && | |
688 | grep $(cat want) have && | |
689 | ||
690 | # Ensure that the pack contains one delta against HEAD^:have.txt, | |
691 | # similar to the above. | |
692 | printf "f.,..%s" $(intersperse "," <deltabase_have) >want && | |
8a30a1ef JT |
693 | hex_unpack <thin.pack | intersperse "," >have && |
694 | grep $(cat want) have && | |
695 | ||
696 | replace_packfile thin.pack && | |
697 | ||
eafff6e4 | 698 | # Use protocol v2 because the perl command looks for the "packfile" |
8a30a1ef JT |
699 | # section header. |
700 | test_config -C "$SERVER" protocol.version 2 && | |
701 | ||
702 | # Fetch the thin pack and ensure that index-pack is able to handle the | |
703 | # REF_DELTA object with a missing promisor delta base. | |
810e1932 JT |
704 | GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch && |
705 | ||
706 | # Ensure that the missing delta base was directly fetched, but not the | |
707 | # one that the client has. | |
708 | grep "want $(cat deltabase_missing)" trace && | |
709 | ! grep "want $(cat deltabase_have)" trace && | |
8a30a1ef | 710 | |
eafff6e4 JS |
711 | # Ensure that the one-time-perl script was used. |
712 | ! test -e "$HTTPD_ROOT_PATH/one-time-perl" | |
8a30a1ef JT |
713 | ' |
714 | ||
decfe05b SG |
715 | # DO NOT add non-httpd-specific tests here, because the last part of this |
716 | # test script is only executed when httpd is available and enabled. | |
717 | ||
35a7ae95 | 718 | test_done |