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