]>
Commit | Line | Data |
---|---|---|
9901164d JX |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2021 Jiang Xin | |
4 | # | |
5 | ||
6 | test_description='Test git-bundle' | |
7 | ||
8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
10 | ||
11 | . ./test-lib.sh | |
e8a8e7ff | 12 | . "$TEST_DIRECTORY"/lib-bundle.sh |
8b95521e | 13 | . "$TEST_DIRECTORY"/lib-terminal.sh |
9901164d | 14 | |
891cb09d ÆAB |
15 | for cmd in create verify list-heads unbundle |
16 | do | |
17 | test_expect_success "usage: git bundle $cmd needs an argument" ' | |
18 | test_expect_code 129 git bundle $cmd | |
19 | ' | |
20 | done | |
21 | ||
9901164d JX |
22 | # Create a commit or tag and set the variable with the object ID. |
23 | test_commit_setvar () { | |
24 | notick= | |
25 | signoff= | |
26 | indir= | |
27 | merge= | |
28 | tag= | |
29 | var= | |
30 | ||
31 | while test $# != 0 | |
32 | do | |
33 | case "$1" in | |
34 | --merge) | |
35 | merge=t | |
36 | ;; | |
37 | --tag) | |
38 | tag=t | |
39 | ;; | |
40 | --notick) | |
41 | notick=t | |
42 | ;; | |
43 | --signoff) | |
44 | signoff="$1" | |
45 | ;; | |
46 | -C) | |
47 | shift | |
48 | indir="$1" | |
49 | ;; | |
50 | -*) | |
51 | echo >&2 "error: unknown option $1" | |
52 | return 1 | |
53 | ;; | |
54 | *) | |
55 | break | |
56 | ;; | |
57 | esac | |
58 | shift | |
59 | done | |
60 | if test $# -lt 2 | |
61 | then | |
62 | echo >&2 "error: test_commit_setvar must have at least 2 arguments" | |
63 | return 1 | |
64 | fi | |
65 | var=$1 | |
66 | shift | |
67 | indir=${indir:+"$indir"/} | |
68 | if test -z "$notick" | |
69 | then | |
70 | test_tick | |
71 | fi && | |
72 | if test -n "$merge" | |
73 | then | |
74 | git ${indir:+ -C "$indir"} merge --no-edit --no-ff \ | |
75 | ${2:+-m "$2"} "$1" && | |
76 | oid=$(git ${indir:+ -C "$indir"} rev-parse HEAD) | |
77 | elif test -n "$tag" | |
78 | then | |
79 | git ${indir:+ -C "$indir"} tag -m "$1" "$1" "${2:-HEAD}" && | |
80 | oid=$(git ${indir:+ -C "$indir"} rev-parse "$1") | |
81 | else | |
82 | file=${2:-"$1.t"} && | |
83 | echo "${3-$1}" >"$indir$file" && | |
84 | git ${indir:+ -C "$indir"} add "$file" && | |
85 | git ${indir:+ -C "$indir"} commit $signoff -m "$1" && | |
86 | oid=$(git ${indir:+ -C "$indir"} rev-parse HEAD) | |
87 | fi && | |
88 | eval $var=$oid | |
89 | } | |
90 | ||
eb87c6f5 JX |
91 | get_abbrev_oid () { |
92 | oid=$1 && | |
93 | suffix=${oid#???????} && | |
94 | oid=${oid%$suffix} && | |
95 | if test -n "$oid" | |
96 | then | |
97 | echo "$oid" | |
98 | else | |
99 | echo "undefined-oid" | |
100 | fi | |
101 | } | |
102 | ||
9901164d JX |
103 | # Format the output of git commands to make a user-friendly and stable |
104 | # text. We can easily prepare the expect text without having to worry | |
2bafb3d7 | 105 | # about future changes of the commit ID. |
9901164d JX |
106 | make_user_friendly_and_stable_output () { |
107 | sed \ | |
eb87c6f5 JX |
108 | -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \ |
109 | -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \ | |
110 | -e "s/$(get_abbrev_oid $C)[0-9a-f]*/<COMMIT-C>/g" \ | |
111 | -e "s/$(get_abbrev_oid $D)[0-9a-f]*/<COMMIT-D>/g" \ | |
112 | -e "s/$(get_abbrev_oid $E)[0-9a-f]*/<COMMIT-E>/g" \ | |
113 | -e "s/$(get_abbrev_oid $F)[0-9a-f]*/<COMMIT-F>/g" \ | |
114 | -e "s/$(get_abbrev_oid $G)[0-9a-f]*/<COMMIT-G>/g" \ | |
115 | -e "s/$(get_abbrev_oid $H)[0-9a-f]*/<COMMIT-H>/g" \ | |
116 | -e "s/$(get_abbrev_oid $I)[0-9a-f]*/<COMMIT-I>/g" \ | |
117 | -e "s/$(get_abbrev_oid $J)[0-9a-f]*/<COMMIT-J>/g" \ | |
118 | -e "s/$(get_abbrev_oid $K)[0-9a-f]*/<COMMIT-K>/g" \ | |
119 | -e "s/$(get_abbrev_oid $L)[0-9a-f]*/<COMMIT-L>/g" \ | |
120 | -e "s/$(get_abbrev_oid $M)[0-9a-f]*/<COMMIT-M>/g" \ | |
121 | -e "s/$(get_abbrev_oid $N)[0-9a-f]*/<COMMIT-N>/g" \ | |
122 | -e "s/$(get_abbrev_oid $O)[0-9a-f]*/<COMMIT-O>/g" \ | |
123 | -e "s/$(get_abbrev_oid $P)[0-9a-f]*/<COMMIT-P>/g" \ | |
124 | -e "s/$(get_abbrev_oid $TAG1)[0-9a-f]*/<TAG-1>/g" \ | |
125 | -e "s/$(get_abbrev_oid $TAG2)[0-9a-f]*/<TAG-2>/g" \ | |
7cc11473 | 126 | -e "s/$(get_abbrev_oid $TAG3)[0-9a-f]*/<TAG-3>/g" |
2bafb3d7 JX |
127 | } |
128 | ||
129 | format_and_save_expect () { | |
130 | sed -e 's/Z$//' >expect | |
9901164d JX |
131 | } |
132 | ||
8ba221e2 DS |
133 | HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH" |
134 | ||
9901164d JX |
135 | # (C) (D, pull/1/head, topic/1) |
136 | # o --- o | |
137 | # / \ (L) | |
138 | # / \ o (H, topic/2) (M, tag:v2) | |
139 | # / (F) \ / (N, tag:v3) | |
140 | # / o --------- o (G, pull/2/head) o --- o --- o (release) | |
141 | # / / \ \ / \ | |
142 | # o --- o --- o -------- o -- o ------------------ o ------- o --- o (main) | |
143 | # (A) (B) (E, tag:v1) (I) (J) (K) (O) (P) | |
144 | # | |
145 | test_expect_success 'setup' ' | |
146 | # Try to make a stable fixed width for abbreviated commit ID, | |
147 | # this fixed-width oid will be replaced with "<OID>". | |
148 | git config core.abbrev 7 && | |
149 | ||
150 | # branch main: commit A & B | |
151 | test_commit_setvar A "Commit A" main.txt && | |
152 | test_commit_setvar B "Commit B" main.txt && | |
153 | ||
154 | # branch topic/1: commit C & D, refs/pull/1/head | |
155 | git checkout -b topic/1 && | |
156 | test_commit_setvar C "Commit C" topic-1.txt && | |
157 | test_commit_setvar D "Commit D" topic-1.txt && | |
158 | git update-ref refs/pull/1/head HEAD && | |
159 | ||
160 | # branch topic/1: commit E, tag v1 | |
161 | git checkout main && | |
162 | test_commit_setvar E "Commit E" main.txt && | |
163 | test_commit_setvar --tag TAG1 v1 && | |
164 | ||
165 | # branch topic/2: commit F & G, refs/pull/2/head | |
166 | git checkout -b topic/2 && | |
167 | test_commit_setvar F "Commit F" topic-2.txt && | |
168 | test_commit_setvar G "Commit G" topic-2.txt && | |
169 | git update-ref refs/pull/2/head HEAD && | |
170 | test_commit_setvar H "Commit H" topic-2.txt && | |
171 | ||
172 | # branch main: merge commit I & J | |
173 | git checkout main && | |
174 | test_commit_setvar --merge I topic/1 "Merge commit I" && | |
175 | test_commit_setvar --merge J refs/pull/2/head "Merge commit J" && | |
176 | ||
177 | # branch main: commit K | |
178 | git checkout main && | |
179 | test_commit_setvar K "Commit K" main.txt && | |
180 | ||
181 | # branch release: | |
182 | git checkout -b release && | |
183 | test_commit_setvar L "Commit L" release.txt && | |
184 | test_commit_setvar M "Commit M" release.txt && | |
185 | test_commit_setvar --tag TAG2 v2 && | |
186 | test_commit_setvar N "Commit N" release.txt && | |
187 | test_commit_setvar --tag TAG3 v3 && | |
188 | ||
189 | # branch main: merge commit O, commit P | |
190 | git checkout main && | |
191 | test_commit_setvar --merge O tags/v2 "Merge commit O" && | |
192 | test_commit_setvar P "Commit P" main.txt | |
193 | ' | |
194 | ||
ce1d6d9f | 195 | test_expect_success 'create bundle from special rev: main^!' ' |
9901164d JX |
196 | git bundle create special-rev.bdl "main^!" && |
197 | ||
198 | git bundle list-heads special-rev.bdl | | |
199 | make_user_friendly_and_stable_output >actual && | |
200 | cat >expect <<-\EOF && | |
201 | <COMMIT-P> refs/heads/main | |
202 | EOF | |
1108cea7 | 203 | test_cmp expect actual && |
9901164d JX |
204 | |
205 | git bundle verify special-rev.bdl | | |
206 | make_user_friendly_and_stable_output >actual && | |
8ba221e2 | 207 | format_and_save_expect <<-EOF && |
9901164d JX |
208 | The bundle contains this ref: |
209 | <COMMIT-P> refs/heads/main | |
210 | The bundle requires this ref: | |
2bafb3d7 | 211 | <COMMIT-O> Z |
8ba221e2 | 212 | $HASH_MESSAGE |
9901164d | 213 | EOF |
1108cea7 | 214 | test_cmp expect actual && |
9901164d JX |
215 | |
216 | test_bundle_object_count special-rev.bdl 3 | |
217 | ' | |
218 | ||
219 | test_expect_success 'create bundle with --max-count option' ' | |
220 | git bundle create max-count.bdl --max-count 1 \ | |
221 | main \ | |
222 | "^release" \ | |
223 | refs/tags/v1 \ | |
224 | refs/pull/1/head \ | |
225 | refs/pull/2/head && | |
226 | ||
227 | git bundle verify max-count.bdl | | |
228 | make_user_friendly_and_stable_output >actual && | |
8ba221e2 | 229 | format_and_save_expect <<-EOF && |
9901164d JX |
230 | The bundle contains these 2 refs: |
231 | <COMMIT-P> refs/heads/main | |
232 | <TAG-1> refs/tags/v1 | |
233 | The bundle requires this ref: | |
2bafb3d7 | 234 | <COMMIT-O> Z |
8ba221e2 | 235 | $HASH_MESSAGE |
9901164d | 236 | EOF |
1108cea7 | 237 | test_cmp expect actual && |
9901164d JX |
238 | |
239 | test_bundle_object_count max-count.bdl 4 | |
240 | ' | |
241 | ||
242 | test_expect_success 'create bundle with --since option' ' | |
243 | git log -1 --pretty="%ad" $M >actual && | |
244 | cat >expect <<-\EOF && | |
245 | Thu Apr 7 15:26:13 2005 -0700 | |
246 | EOF | |
247 | test_cmp expect actual && | |
248 | ||
249 | git bundle create since.bdl \ | |
250 | --since "Thu Apr 7 15:27:00 2005 -0700" \ | |
251 | --all && | |
252 | ||
253 | git bundle verify since.bdl | | |
254 | make_user_friendly_and_stable_output >actual && | |
8ba221e2 | 255 | format_and_save_expect <<-EOF && |
9901164d JX |
256 | The bundle contains these 5 refs: |
257 | <COMMIT-P> refs/heads/main | |
258 | <COMMIT-N> refs/heads/release | |
259 | <TAG-2> refs/tags/v2 | |
260 | <TAG-3> refs/tags/v3 | |
261 | <COMMIT-P> HEAD | |
262 | The bundle requires these 2 refs: | |
2bafb3d7 JX |
263 | <COMMIT-M> Z |
264 | <COMMIT-K> Z | |
8ba221e2 | 265 | $HASH_MESSAGE |
9901164d | 266 | EOF |
1108cea7 | 267 | test_cmp expect actual && |
9901164d JX |
268 | |
269 | test_bundle_object_count --thin since.bdl 13 | |
270 | ' | |
271 | ||
272 | test_expect_success 'create bundle 1 - no prerequisites' ' | |
5bb0fd2c | 273 | # create bundle from args |
9901164d JX |
274 | git bundle create 1.bdl topic/1 topic/2 && |
275 | ||
5bb0fd2c JX |
276 | # create bundle from stdin |
277 | cat >input <<-\EOF && | |
278 | topic/1 | |
279 | topic/2 | |
280 | EOF | |
281 | git bundle create stdin-1.bdl --stdin <input && | |
282 | ||
8ba221e2 | 283 | format_and_save_expect <<-EOF && |
9901164d JX |
284 | The bundle contains these 2 refs: |
285 | <COMMIT-D> refs/heads/topic/1 | |
286 | <COMMIT-H> refs/heads/topic/2 | |
287 | The bundle records a complete history. | |
8ba221e2 | 288 | $HASH_MESSAGE |
9901164d JX |
289 | EOF |
290 | ||
291 | # verify bundle, which has no prerequisites | |
292 | git bundle verify 1.bdl | | |
293 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 294 | test_cmp expect actual && |
9901164d | 295 | |
5bb0fd2c JX |
296 | git bundle verify stdin-1.bdl | |
297 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 298 | test_cmp expect actual && |
5bb0fd2c JX |
299 | |
300 | test_bundle_object_count 1.bdl 24 && | |
301 | test_bundle_object_count stdin-1.bdl 24 | |
9901164d JX |
302 | ' |
303 | ||
304 | test_expect_success 'create bundle 2 - has prerequisites' ' | |
5bb0fd2c | 305 | # create bundle from args |
9901164d JX |
306 | git bundle create 2.bdl \ |
307 | --ignore-missing \ | |
308 | ^topic/deleted \ | |
309 | ^$D \ | |
310 | ^topic/2 \ | |
311 | release && | |
312 | ||
5bb0fd2c JX |
313 | # create bundle from stdin |
314 | # input has a non-exist reference: "topic/deleted" | |
315 | cat >input <<-EOF && | |
316 | ^topic/deleted | |
317 | ^$D | |
318 | ^topic/2 | |
319 | EOF | |
320 | git bundle create stdin-2.bdl \ | |
321 | --ignore-missing \ | |
322 | --stdin \ | |
323 | release <input && | |
324 | ||
8ba221e2 | 325 | format_and_save_expect <<-EOF && |
9901164d JX |
326 | The bundle contains this ref: |
327 | <COMMIT-N> refs/heads/release | |
328 | The bundle requires these 3 refs: | |
2bafb3d7 JX |
329 | <COMMIT-D> Z |
330 | <COMMIT-E> Z | |
331 | <COMMIT-G> Z | |
8ba221e2 | 332 | $HASH_MESSAGE |
9901164d JX |
333 | EOF |
334 | ||
335 | git bundle verify 2.bdl | | |
336 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 337 | test_cmp expect actual && |
9901164d | 338 | |
5bb0fd2c JX |
339 | git bundle verify stdin-2.bdl | |
340 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 341 | test_cmp expect actual && |
5bb0fd2c JX |
342 | |
343 | test_bundle_object_count 2.bdl 16 && | |
344 | test_bundle_object_count stdin-2.bdl 16 | |
9901164d JX |
345 | ' |
346 | ||
347 | test_expect_success 'fail to verify bundle without prerequisites' ' | |
348 | git init --bare test1.git && | |
349 | ||
2bafb3d7 | 350 | format_and_save_expect <<-\EOF && |
9901164d | 351 | error: Repository lacks these prerequisite commits: |
2bafb3d7 JX |
352 | error: <COMMIT-D> Z |
353 | error: <COMMIT-E> Z | |
354 | error: <COMMIT-G> Z | |
9901164d JX |
355 | EOF |
356 | ||
357 | test_must_fail git -C test1.git bundle verify ../2.bdl 2>&1 | | |
358 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 359 | test_cmp expect actual && |
5bb0fd2c JX |
360 | |
361 | test_must_fail git -C test1.git bundle verify ../stdin-2.bdl 2>&1 | | |
362 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 363 | test_cmp expect actual |
9901164d JX |
364 | ' |
365 | ||
366 | test_expect_success 'create bundle 3 - two refs, same object' ' | |
5bb0fd2c | 367 | # create bundle from args |
9901164d JX |
368 | git bundle create --version=3 3.bdl \ |
369 | ^release \ | |
370 | ^topic/1 \ | |
371 | ^topic/2 \ | |
372 | main \ | |
373 | HEAD && | |
374 | ||
5bb0fd2c JX |
375 | # create bundle from stdin |
376 | cat >input <<-\EOF && | |
377 | ^release | |
378 | ^topic/1 | |
379 | ^topic/2 | |
380 | EOF | |
381 | git bundle create --version=3 stdin-3.bdl \ | |
382 | --stdin \ | |
383 | main HEAD <input && | |
384 | ||
8ba221e2 | 385 | format_and_save_expect <<-EOF && |
9901164d JX |
386 | The bundle contains these 2 refs: |
387 | <COMMIT-P> refs/heads/main | |
388 | <COMMIT-P> HEAD | |
389 | The bundle requires these 2 refs: | |
2bafb3d7 JX |
390 | <COMMIT-M> Z |
391 | <COMMIT-K> Z | |
8ba221e2 | 392 | $HASH_MESSAGE |
9901164d JX |
393 | EOF |
394 | ||
395 | git bundle verify 3.bdl | | |
396 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 397 | test_cmp expect actual && |
9901164d | 398 | |
5bb0fd2c JX |
399 | git bundle verify stdin-3.bdl | |
400 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 401 | test_cmp expect actual && |
5bb0fd2c JX |
402 | |
403 | test_bundle_object_count 3.bdl 4 && | |
404 | test_bundle_object_count stdin-3.bdl 4 | |
9901164d JX |
405 | ' |
406 | ||
407 | test_expect_success 'create bundle 4 - with tags' ' | |
5bb0fd2c | 408 | # create bundle from args |
9901164d JX |
409 | git bundle create 4.bdl \ |
410 | ^main \ | |
411 | ^release \ | |
412 | ^topic/1 \ | |
413 | ^topic/2 \ | |
414 | --all && | |
415 | ||
5bb0fd2c JX |
416 | # create bundle from stdin |
417 | cat >input <<-\EOF && | |
418 | ^main | |
419 | ^release | |
420 | ^topic/1 | |
421 | ^topic/2 | |
422 | EOF | |
423 | git bundle create stdin-4.bdl \ | |
424 | --ignore-missing \ | |
425 | --stdin \ | |
426 | --all <input && | |
427 | ||
8ba221e2 | 428 | cat >expect <<-EOF && |
9901164d JX |
429 | The bundle contains these 3 refs: |
430 | <TAG-1> refs/tags/v1 | |
431 | <TAG-2> refs/tags/v2 | |
432 | <TAG-3> refs/tags/v3 | |
433 | The bundle records a complete history. | |
8ba221e2 | 434 | $HASH_MESSAGE |
9901164d JX |
435 | EOF |
436 | ||
437 | git bundle verify 4.bdl | | |
438 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 439 | test_cmp expect actual && |
9901164d | 440 | |
5bb0fd2c JX |
441 | git bundle verify stdin-4.bdl | |
442 | make_user_friendly_and_stable_output >actual && | |
1108cea7 | 443 | test_cmp expect actual && |
5bb0fd2c JX |
444 | |
445 | test_bundle_object_count 4.bdl 3 && | |
446 | test_bundle_object_count stdin-4.bdl 3 | |
9901164d JX |
447 | ' |
448 | ||
449 | test_expect_success 'clone from bundle' ' | |
450 | git clone --mirror 1.bdl mirror.git && | |
451 | git -C mirror.git show-ref | | |
452 | make_user_friendly_and_stable_output >actual && | |
453 | cat >expect <<-\EOF && | |
454 | <COMMIT-D> refs/heads/topic/1 | |
455 | <COMMIT-H> refs/heads/topic/2 | |
456 | EOF | |
457 | test_cmp expect actual && | |
458 | ||
459 | git -C mirror.git fetch ../2.bdl "+refs/*:refs/*" && | |
460 | git -C mirror.git show-ref | | |
461 | make_user_friendly_and_stable_output >actual && | |
462 | cat >expect <<-\EOF && | |
463 | <COMMIT-N> refs/heads/release | |
464 | <COMMIT-D> refs/heads/topic/1 | |
465 | <COMMIT-H> refs/heads/topic/2 | |
466 | EOF | |
467 | test_cmp expect actual && | |
468 | ||
469 | git -C mirror.git fetch ../3.bdl "+refs/*:refs/*" && | |
470 | git -C mirror.git show-ref | | |
471 | make_user_friendly_and_stable_output >actual && | |
472 | cat >expect <<-\EOF && | |
473 | <COMMIT-P> refs/heads/main | |
474 | <COMMIT-N> refs/heads/release | |
475 | <COMMIT-D> refs/heads/topic/1 | |
476 | <COMMIT-H> refs/heads/topic/2 | |
477 | EOF | |
478 | test_cmp expect actual && | |
479 | ||
480 | git -C mirror.git fetch ../4.bdl "+refs/*:refs/*" && | |
481 | git -C mirror.git show-ref | | |
482 | make_user_friendly_and_stable_output >actual && | |
483 | cat >expect <<-\EOF && | |
484 | <COMMIT-P> refs/heads/main | |
485 | <COMMIT-N> refs/heads/release | |
486 | <COMMIT-D> refs/heads/topic/1 | |
487 | <COMMIT-H> refs/heads/topic/2 | |
488 | <TAG-1> refs/tags/v1 | |
489 | <TAG-2> refs/tags/v2 | |
490 | <TAG-3> refs/tags/v3 | |
491 | EOF | |
492 | test_cmp expect actual | |
493 | ' | |
494 | ||
4f33a634 ÆAB |
495 | test_expect_success 'unfiltered bundle with --objects' ' |
496 | git bundle create all-objects.bdl \ | |
497 | --all --objects && | |
498 | git bundle create all.bdl \ | |
499 | --all && | |
500 | ||
501 | # Compare the headers of these files. | |
502 | sed -n -e "/^$/q" -e "p" all.bdl >expect && | |
503 | sed -n -e "/^$/q" -e "p" all-objects.bdl >actual && | |
504 | test_cmp expect actual | |
505 | ' | |
506 | ||
f18b512b DS |
507 | for filter in "blob:none" "tree:0" "tree:1" "blob:limit=100" |
508 | do | |
509 | test_expect_success "filtered bundle: $filter" ' | |
510 | test_when_finished rm -rf .git/objects/pack cloned unbundled && | |
511 | git bundle create partial.bdl \ | |
512 | --all \ | |
513 | --filter=$filter && | |
514 | ||
515 | git bundle verify partial.bdl >unfiltered && | |
516 | make_user_friendly_and_stable_output <unfiltered >actual && | |
517 | ||
518 | cat >expect <<-EOF && | |
519 | The bundle contains these 10 refs: | |
520 | <COMMIT-P> refs/heads/main | |
521 | <COMMIT-N> refs/heads/release | |
522 | <COMMIT-D> refs/heads/topic/1 | |
523 | <COMMIT-H> refs/heads/topic/2 | |
524 | <COMMIT-D> refs/pull/1/head | |
525 | <COMMIT-G> refs/pull/2/head | |
526 | <TAG-1> refs/tags/v1 | |
527 | <TAG-2> refs/tags/v2 | |
528 | <TAG-3> refs/tags/v3 | |
529 | <COMMIT-P> HEAD | |
f18b512b | 530 | The bundle records a complete history. |
8ba221e2 | 531 | $HASH_MESSAGE |
017303eb | 532 | The bundle uses this filter: $filter |
f18b512b DS |
533 | EOF |
534 | test_cmp expect actual && | |
535 | ||
536 | test_config uploadpack.allowfilter 1 && | |
537 | test_config uploadpack.allowanysha1inwant 1 && | |
538 | git clone --no-local --filter=$filter --bare "file://$(pwd)" cloned && | |
539 | ||
540 | git init unbundled && | |
541 | git -C unbundled bundle unbundle ../partial.bdl >ref-list.txt && | |
4f39eb03 DS |
542 | ls unbundled/.git/objects/pack/pack-*.promisor >promisor && |
543 | test_line_count = 1 promisor && | |
f18b512b DS |
544 | |
545 | # Count the same number of reachable objects. | |
546 | reflist=$(git for-each-ref --format="%(objectname)") && | |
547 | git rev-list --objects --filter=$filter --missing=allow-any \ | |
548 | $reflist >expect && | |
549 | for repo in cloned unbundled | |
550 | do | |
551 | git -C $repo rev-list --objects --missing=allow-any \ | |
552 | $reflist >actual && | |
553 | test_cmp expect actual || return 1 | |
554 | done | |
555 | ' | |
556 | done | |
557 | ||
86fdd94d DS |
558 | # NEEDSWORK: 'git clone --bare' should be able to clone from a filtered |
559 | # bundle, but that requires a change to promisor/filter config options. | |
560 | # For now, we fail gracefully with a helpful error. This behavior can be | |
561 | # changed in the future to succeed as much as possible. | |
562 | test_expect_success 'cloning from filtered bundle has useful error' ' | |
563 | git bundle create partial.bdl \ | |
564 | --all \ | |
565 | --filter=blob:none && | |
566 | test_must_fail git clone --bare partial.bdl partial 2>err && | |
567 | grep "cannot clone from filtered bundle" err | |
568 | ' | |
569 | ||
e72171f0 DS |
570 | test_expect_success 'verify catches unreachable, broken prerequisites' ' |
571 | test_when_finished rm -rf clone-from clone-to && | |
572 | git init clone-from && | |
573 | ( | |
574 | cd clone-from && | |
575 | git checkout -b base && | |
576 | test_commit A && | |
577 | git checkout -b tip && | |
578 | git commit --allow-empty -m "will drop by shallow" && | |
579 | git commit --allow-empty -m "will keep by shallow" && | |
580 | git commit --allow-empty -m "for bundle, not clone" && | |
581 | git bundle create tip.bundle tip~1..tip && | |
582 | git reset --hard HEAD~1 && | |
583 | git checkout base | |
584 | ) && | |
585 | BAD_OID=$(git -C clone-from rev-parse tip~1) && | |
586 | TIP_OID=$(git -C clone-from rev-parse tip) && | |
587 | git clone --depth=1 --no-single-branch \ | |
588 | "file://$(pwd)/clone-from" clone-to && | |
589 | ( | |
590 | cd clone-to && | |
591 | ||
592 | # Set up broken history by removing shallow markers | |
593 | git update-ref -d refs/remotes/origin/tip && | |
594 | rm .git/shallow && | |
595 | ||
596 | # Verify should fail | |
597 | test_must_fail git bundle verify \ | |
598 | ../clone-from/tip.bundle 2>err && | |
d9fd674c DS |
599 | grep "some prerequisite commits .* are not connected" err && |
600 | test_line_count = 1 err && | |
e72171f0 DS |
601 | |
602 | # Unbundling should fail | |
603 | test_must_fail git bundle unbundle \ | |
604 | ../clone-from/tip.bundle 2>err && | |
d9fd674c DS |
605 | grep "some prerequisite commits .* are not connected" err && |
606 | test_line_count = 1 err | |
e72171f0 DS |
607 | ) |
608 | ' | |
609 | ||
8b95521e JK |
610 | test_expect_success 'bundle progress includes write phase' ' |
611 | GIT_PROGRESS_DELAY=0 \ | |
612 | git bundle create --progress out.bundle --all 2>err && | |
613 | grep 'Writing' err | |
614 | ' | |
615 | ||
616 | test_expect_success TTY 'create --quiet disables all bundle progress' ' | |
617 | test_terminal env GIT_PROGRESS_DELAY=0 \ | |
618 | git bundle create --quiet out.bundle --all 2>err && | |
619 | test_must_be_empty err | |
620 | ' | |
621 | ||
d089a064 RS |
622 | test_expect_success 'bundle progress with --no-quiet' ' |
623 | GIT_PROGRESS_DELAY=0 \ | |
624 | git bundle create --no-quiet out.bundle --all 2>err && | |
625 | grep "%" err | |
626 | ' | |
627 | ||
bf8b1e04 JK |
628 | test_expect_success 'read bundle over stdin' ' |
629 | git bundle create some.bundle HEAD && | |
630 | ||
631 | git bundle verify - <some.bundle 2>err && | |
632 | grep "<stdin> is okay" err && | |
633 | ||
634 | git bundle list-heads some.bundle >expect && | |
635 | git bundle list-heads - <some.bundle >actual && | |
636 | test_cmp expect actual && | |
637 | ||
638 | git bundle unbundle some.bundle >expect && | |
639 | git bundle unbundle - <some.bundle >actual && | |
640 | test_cmp expect actual | |
641 | ' | |
642 | ||
a8bfa99d JH |
643 | test_expect_success 'send a bundle to standard output' ' |
644 | git bundle create - --all HEAD >bundle-one && | |
645 | mkdir -p down && | |
646 | git -C down bundle create - --all HEAD >bundle-two && | |
647 | git bundle verify bundle-one && | |
648 | git bundle verify bundle-two && | |
649 | git ls-remote bundle-one >expect && | |
650 | git ls-remote bundle-two >actual && | |
651 | test_cmp expect actual | |
652 | ' | |
653 | ||
9901164d | 654 | test_done |