]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9300-fast-import.sh
Merge branch 'jt/reftable-geometric-compaction'
[thirdparty/git.git] / t / t9300-fast-import.sh
CommitLineData
50aee995
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
eaa2a6fc 6test_description='test git fast-import utility'
a881baa2 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
50aee995 10. ./test-lib.sh
ebd73f50 11. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
50aee995 12
05880b02
JS
13verify_packs () {
14 for p in .git/objects/pack/*.pack
15 do
16 git verify-pack "$@" "$p" || return
17 done
18}
19
8232dc42
SP
20file2_data='file2
21second line of EOF'
22
23file3_data='EOF
24in 3rd file
25 END'
26
27file4_data=abcd
28file4_len=4
29
b715cfbb
SP
30file5_data='an inline file.
31 we should see it later.'
32
33file6_data='#!/bin/sh
34echo "$@"'
35
50aee995
SP
36###
37### series A
38###
39
85c62395 40test_expect_success 'empty stream succeeds' '
d9545c7f 41 git config fastimport.unpackLimit 0 &&
85c62395
DB
42 git fast-import </dev/null
43'
44
b7090430
JK
45test_expect_success 'truncated stream complains' '
46 echo "tag foo" | test_must_fail git fast-import
47'
48
d67824fe 49test_expect_success 'A: create pack from stdin' '
68297e0f
JS
50 test_tick &&
51 cat >input <<-INPUT_END &&
52 blob
53 mark :2
54 data <<EOF
55 $file2_data
56 EOF
57
58 blob
59 mark :3
60 data <<END
61 $file3_data
62 END
63
64 blob
65 mark :4
66 data $file4_len
67 $file4_data
a881baa2 68 commit refs/heads/main
68297e0f
JS
69 mark :5
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
71 data <<COMMIT
72 initial
73 COMMIT
74
75 M 644 :2 file2
76 M 644 :3 file3
77 M 755 :4 file4
78
79 tag series-A
80 from :5
81 data <<EOF
82 An annotated tag without a tagger
83 EOF
84
85 tag series-A-blob
86 from :3
87 data <<EOF
88 An annotated tag that annotates a blob.
89 EOF
90
3164e6bd
EN
91 tag to-be-deleted
92 from :3
93 data <<EOF
94 Another annotated tag that annotates a blob.
95 EOF
96
97 reset refs/tags/to-be-deleted
287bb3ab 98 from $ZERO_OID
3164e6bd 99
f73b2aba
EN
100 tag nested
101 mark :6
102 from :4
103 data <<EOF
104 Tag of our lovely commit
105 EOF
106
107 reset refs/tags/nested
287bb3ab 108 from $ZERO_OID
f73b2aba
EN
109
110 tag nested
111 mark :7
112 from :6
113 data <<EOF
114 Tag of tag of our lovely commit
115 EOF
116
b8f50e5b
EN
117 alias
118 mark :8
119 to :5
120
68297e0f 121 INPUT_END
d67824fe 122 git fast-import --export-marks=marks.out <input &&
a881baa2 123 git whatchanged main
d67824fe 124'
05880b02
JS
125
126test_expect_success 'A: verify pack' '
127 verify_packs
128'
50aee995 129
d67824fe 130test_expect_success 'A: verify commit' '
68297e0f
JS
131 cat >expect <<-EOF &&
132 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
134
135 initial
136 EOF
a881baa2 137 git cat-file commit main | sed 1d >actual &&
d67824fe
JS
138 test_cmp expect actual
139'
50aee995 140
d67824fe 141test_expect_success 'A: verify tree' '
68297e0f
JS
142 cat >expect <<-EOF &&
143 100644 blob file2
144 100644 blob file3
145 100755 blob file4
146 EOF
a881baa2 147 git cat-file -p main^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
d67824fe
JS
148 test_cmp expect actual
149'
50aee995 150
d67824fe 151test_expect_success 'A: verify file2' '
68297e0f 152 echo "$file2_data" >expect &&
a881baa2 153 git cat-file blob main:file2 >actual &&
ec2c10be 154 test_cmp expect actual
d67824fe 155'
50aee995 156
d67824fe 157test_expect_success 'A: verify file3' '
68297e0f 158 echo "$file3_data" >expect &&
a881baa2 159 git cat-file blob main:file3 >actual &&
ec2c10be 160 test_cmp expect actual
d67824fe 161'
50aee995 162
d67824fe 163test_expect_success 'A: verify file4' '
68297e0f 164 printf "$file4_data" >expect &&
a881baa2 165 git cat-file blob main:file4 >actual &&
ec2c10be 166 test_cmp expect actual
d67824fe 167'
50aee995 168
88fbf67b 169test_expect_success 'A: verify tag/series-A' '
68297e0f 170 cat >expect <<-EOF &&
a881baa2 171 object $(git rev-parse refs/heads/main)
68297e0f
JS
172 type commit
173 tag series-A
174
175 An annotated tag without a tagger
176 EOF
88fbf67b
JH
177 git cat-file tag tags/series-A >actual &&
178 test_cmp expect actual
179'
180
2efe38e7 181test_expect_success 'A: verify tag/series-A-blob' '
68297e0f 182 cat >expect <<-EOF &&
a881baa2 183 object $(git rev-parse refs/heads/main:file3)
68297e0f
JS
184 type blob
185 tag series-A-blob
186
187 An annotated tag that annotates a blob.
188 EOF
2efe38e7
DI
189 git cat-file tag tags/series-A-blob >actual &&
190 test_cmp expect actual
191'
192
3164e6bd
EN
193test_expect_success 'A: verify tag deletion is successful' '
194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted
195'
196
d67824fe 197test_expect_success 'A: verify marks output' '
68297e0f 198 cat >expect <<-EOF &&
a881baa2
JS
199 :2 $(git rev-parse --verify main:file2)
200 :3 $(git rev-parse --verify main:file3)
201 :4 $(git rev-parse --verify main:file4)
202 :5 $(git rev-parse --verify main^0)
f73b2aba
EN
203 :6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
204 :7 $(git rev-parse --verify nested)
a881baa2 205 :8 $(git rev-parse --verify main^0)
68297e0f 206 EOF
d67824fe
JS
207 test_cmp expect marks.out
208'
50aee995 209
d67824fe
JS
210test_expect_success 'A: verify marks import' '
211 git fast-import \
e8438420
SP
212 --import-marks=marks.out \
213 --export-marks=marks.new \
214 </dev/null &&
d67824fe
JS
215 test_cmp expect marks.new
216'
e8438420 217
d67824fe 218test_expect_success 'A: tag blob by sha1' '
68297e0f
JS
219 test_tick &&
220 new_blob=$(echo testing | git hash-object --stdin) &&
221 cat >input <<-INPUT_END &&
222 tag series-A-blob-2
a881baa2 223 from $(git rev-parse refs/heads/main:file3)
68297e0f
JS
224 data <<EOF
225 Tag blob by sha1.
226 EOF
227
228 blob
229 mark :6
230 data <<EOF
231 testing
232 EOF
233
234 commit refs/heads/new_blob
235 committer <> 0 +0000
236 data 0
237 M 644 :6 new_blob
238 #pretend we got sha1 from fast-import
239 ls "new_blob"
240
241 tag series-A-blob-3
242 from $new_blob
243 data <<EOF
244 Tag new_blob.
245 EOF
246 INPUT_END
247
248 cat >expect <<-EOF &&
a881baa2 249 object $(git rev-parse refs/heads/main:file3)
68297e0f
JS
250 type blob
251 tag series-A-blob-2
252
253 Tag blob by sha1.
254 object $new_blob
255 type blob
256 tag series-A-blob-3
257
258 Tag new_blob.
259 EOF
260
d67824fe 261 git fast-import <input &&
2efe38e7 262 git cat-file tag tags/series-A-blob-2 >actual &&
6c447f63 263 git cat-file tag tags/series-A-blob-3 >>actual &&
d67824fe
JS
264 test_cmp expect actual
265'
2efe38e7 266
68297e0f
JS
267test_expect_success 'A: verify marks import does not crash' '
268 test_tick &&
269 cat >input <<-INPUT_END &&
270 commit refs/heads/verify--import-marks
271 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
272 data <<COMMIT
273 recreate from :5
274 COMMIT
275
276 from :5
277 M 755 :2 copy-of-file2
aac65ed1 278
68297e0f 279 INPUT_END
aac65ed1 280
d67824fe
JS
281 git fast-import --import-marks=marks.out <input &&
282 git whatchanged verify--import-marks
283'
05880b02
JS
284
285test_expect_success 'A: verify pack' '
286 verify_packs
287'
288
d67824fe 289test_expect_success 'A: verify diff' '
a881baa2 290 copy=$(git rev-parse --verify main:file2) &&
68297e0f 291 cat >expect <<-EOF &&
287bb3ab 292 :000000 100755 $ZERO_OID $copy A copy-of-file2
68297e0f 293 EOF
a881baa2 294 git diff-tree -M -r main verify--import-marks >actual &&
d67824fe 295 compare_diff_raw expect actual &&
a881baa2 296 test $(git rev-parse --verify main:file2) \
80a6b3f0 297 = $(git rev-parse --verify verify--import-marks:copy-of-file2)
d67824fe 298'
aac65ed1 299
7e7db5e4 300test_expect_success 'A: export marks with large values' '
68297e0f
JS
301 test_tick &&
302 mt=$(git hash-object --stdin < /dev/null) &&
303 >input.blob &&
304 >marks.exp &&
305 >tree.exp &&
306
307 cat >input.commit <<-EOF &&
308 commit refs/heads/verify--dump-marks
309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
310 data <<COMMIT
311 test the sparse array dumping routines with exponentially growing marks
312 COMMIT
313 EOF
314
315 i=0 l=4 m=6 n=7 &&
316 while test "$i" -lt 27
317 do
318 cat >>input.blob <<-EOF &&
319 blob
320 mark :$l
321 data 0
322 blob
323 mark :$m
324 data 0
325 blob
326 mark :$n
327 data 0
328 EOF
329 echo "M 100644 :$l l$i" >>input.commit &&
330 echo "M 100644 :$m m$i" >>input.commit &&
331 echo "M 100644 :$n n$i" >>input.commit &&
332
333 echo ":$l $mt" >>marks.exp &&
334 echo ":$m $mt" >>marks.exp &&
335 echo ":$n $mt" >>marks.exp &&
336
337 printf "100644 blob $mt\tl$i\n" >>tree.exp &&
338 printf "100644 blob $mt\tm$i\n" >>tree.exp &&
339 printf "100644 blob $mt\tn$i\n" >>tree.exp &&
340
341 l=$(($l + $l)) &&
342 m=$(($m + $m)) &&
343 n=$(($l + $n)) &&
344
345 i=$((1 + $i)) || return 1
346 done &&
347
348 sort tree.exp > tree.exp_s &&
349
7e7db5e4
RH
350 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
351 git ls-tree refs/heads/verify--dump-marks >tree.out &&
352 test_cmp tree.exp_s tree.out &&
d67824fe
JS
353 test_cmp marks.exp marks.large
354'
7e7db5e4 355
50aee995
SP
356###
357### series B
358###
359
68297e0f
JS
360test_expect_success 'B: fail on invalid blob sha1' '
361 test_tick &&
362 cat >input <<-INPUT_END &&
363 commit refs/heads/branch
364 mark :1
365 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
366 data <<COMMIT
367 corrupt
368 COMMIT
369
a881baa2 370 from refs/heads/main
287bb3ab 371 M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
50aee995 372
68297e0f 373 INPUT_END
50aee995 374
93e911f5 375 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
d67824fe 376 test_must_fail git fast-import <input
41ac414e 377'
50aee995 378
68297e0f
JS
379test_expect_success 'B: accept branch name "TEMP_TAG"' '
380 cat >input <<-INPUT_END &&
381 commit TEMP_TAG
382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
383 data <<COMMIT
384 tag base
385 COMMIT
386
a881baa2 387 from refs/heads/main
ea08a6fd 388
68297e0f 389 INPUT_END
ea08a6fd 390
c58100ab 391 test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" &&
d67824fe 392 git fast-import <input &&
62038c81 393 test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
a881baa2 394 test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
d67824fe 395'
4cedb78c 396
4cedb78c 397test_expect_success 'B: accept empty committer' '
68297e0f
JS
398 cat >input <<-INPUT_END &&
399 commit refs/heads/empty-committer-1
400 committer <> $GIT_COMMITTER_DATE
401 data <<COMMIT
402 empty commit
403 COMMIT
404 INPUT_END
405
93e911f5 406 test_when_finished "git update-ref -d refs/heads/empty-committer-1
c58100ab 407 git gc --prune=now" &&
4cedb78c
DI
408 git fast-import <input &&
409 out=$(git fsck) &&
410 echo "$out" &&
411 test -z "$out"
412'
4cedb78c 413
d42a2fb7
EN
414test_expect_success 'B: reject invalid timezone' '
415 cat >input <<-INPUT_END &&
416 commit refs/heads/invalid-timezone
417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
418 data <<COMMIT
419 empty commit
420 COMMIT
421 INPUT_END
422
423 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
424 test_must_fail git fast-import <input
425'
426
427test_expect_success 'B: accept invalid timezone with raw-permissive' '
428 cat >input <<-INPUT_END &&
429 commit refs/heads/invalid-timezone
430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
431 data <<COMMIT
432 empty commit
433 COMMIT
434 INPUT_END
435
436 git init invalid-timezone &&
437 git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
438 git -C invalid-timezone cat-file -p invalid-timezone >out &&
439 grep "1234567890 [+]051800" out
440'
441
17fb0072 442test_expect_success 'B: accept and fixup committer with no name' '
68297e0f
JS
443 cat >input <<-INPUT_END &&
444 commit refs/heads/empty-committer-2
445 committer <a@b.com> $GIT_COMMITTER_DATE
446 data <<COMMIT
447 empty commit
448 COMMIT
449 INPUT_END
450
93e911f5 451 test_when_finished "git update-ref -d refs/heads/empty-committer-2
c58100ab 452 git gc --prune=now" &&
4cedb78c
DI
453 git fast-import <input &&
454 out=$(git fsck) &&
455 echo "$out" &&
456 test -z "$out"
457'
4cedb78c 458
4b4963c0 459test_expect_success 'B: fail on invalid committer (1)' '
68297e0f
JS
460 cat >input <<-INPUT_END &&
461 commit refs/heads/invalid-committer
462 committer Name email> $GIT_COMMITTER_DATE
463 data <<COMMIT
464 empty commit
465 COMMIT
466 INPUT_END
467
93e911f5 468 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
4cedb78c
DI
469 test_must_fail git fast-import <input
470'
4cedb78c 471
4b4963c0 472test_expect_success 'B: fail on invalid committer (2)' '
68297e0f
JS
473 cat >input <<-INPUT_END &&
474 commit refs/heads/invalid-committer
475 committer Name <e<mail> $GIT_COMMITTER_DATE
476 data <<COMMIT
477 empty commit
478 COMMIT
479 INPUT_END
480
93e911f5 481 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
4cedb78c
DI
482 test_must_fail git fast-import <input
483'
4cedb78c 484
4b4963c0 485test_expect_success 'B: fail on invalid committer (3)' '
68297e0f
JS
486 cat >input <<-INPUT_END &&
487 commit refs/heads/invalid-committer
488 committer Name <email>> $GIT_COMMITTER_DATE
489 data <<COMMIT
490 empty commit
491 COMMIT
492 INPUT_END
493
93e911f5 494 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
4cedb78c
DI
495 test_must_fail git fast-import <input
496'
4cedb78c 497
4b4963c0 498test_expect_success 'B: fail on invalid committer (4)' '
68297e0f
JS
499 cat >input <<-INPUT_END &&
500 commit refs/heads/invalid-committer
501 committer Name <email $GIT_COMMITTER_DATE
502 data <<COMMIT
503 empty commit
504 COMMIT
505 INPUT_END
506
93e911f5 507 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
4cedb78c
DI
508 test_must_fail git fast-import <input
509'
4cedb78c 510
4b4963c0 511test_expect_success 'B: fail on invalid committer (5)' '
68297e0f
JS
512 cat >input <<-INPUT_END &&
513 commit refs/heads/invalid-committer
514 committer Name<email> $GIT_COMMITTER_DATE
515 data <<COMMIT
516 empty commit
517 COMMIT
518 INPUT_END
519
93e911f5 520 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
4cedb78c
DI
521 test_must_fail git fast-import <input
522'
4cedb78c 523
50aee995
SP
524###
525### series C
526###
527
d67824fe 528test_expect_success 'C: incremental import create pack from stdin' '
80a6b3f0 529 newf=$(echo hi newf | git hash-object -w --stdin) &&
a881baa2
JS
530 oldf=$(git rev-parse --verify main:file2) &&
531 thrf=$(git rev-parse --verify main:file3) &&
68297e0f
JS
532 test_tick &&
533 cat >input <<-INPUT_END &&
534 commit refs/heads/branch
535 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
536 data <<COMMIT
537 second
538 COMMIT
539
a881baa2 540 from refs/heads/main
68297e0f
JS
541 M 644 $oldf file2/oldf
542 M 755 $newf file2/newf
543 D file3
544
545 INPUT_END
546
d67824fe
JS
547 git fast-import <input &&
548 git whatchanged branch
549'
05880b02
JS
550
551test_expect_success 'C: verify pack' '
552 verify_packs
553'
554
d67824fe 555test_expect_success 'C: validate reuse existing blob' '
80a6b3f0
EP
556 test $newf = $(git rev-parse --verify branch:file2/newf) &&
557 test $oldf = $(git rev-parse --verify branch:file2/oldf)
d67824fe 558'
50aee995 559
d67824fe 560test_expect_success 'C: verify commit' '
68297e0f 561 cat >expect <<-EOF &&
a881baa2 562 parent $(git rev-parse --verify main^0)
68297e0f
JS
563 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
565
566 second
567 EOF
568
d67824fe
JS
569 git cat-file commit branch | sed 1d >actual &&
570 test_cmp expect actual
571'
50aee995 572
d67824fe 573test_expect_success 'C: validate rename result' '
22f18244 574 zero=$ZERO_OID &&
68297e0f 575 cat >expect <<-EOF &&
22f18244 576 :000000 100755 $zero $newf A file2/newf
577 :100644 100644 $oldf $oldf R100 file2 file2/oldf
578 :100644 000000 $thrf $zero D file3
68297e0f 579 EOF
a881baa2 580 git diff-tree -M -r main branch >actual &&
d67824fe
JS
581 compare_diff_raw expect actual
582'
50aee995 583
b715cfbb
SP
584###
585### series D
586###
587
d67824fe 588test_expect_success 'D: inline data in commit' '
68297e0f
JS
589 test_tick &&
590 cat >input <<-INPUT_END &&
591 commit refs/heads/branch
592 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
593 data <<COMMIT
594 third
595 COMMIT
596
597 from refs/heads/branch^0
598 M 644 inline newdir/interesting
599 data <<EOF
600 $file5_data
601 EOF
602
603 M 755 inline newdir/exec.sh
604 data <<EOF
605 $file6_data
606 EOF
607
608 INPUT_END
609
d67824fe
JS
610 git fast-import <input &&
611 git whatchanged branch
612'
05880b02
JS
613
614test_expect_success 'D: verify pack' '
615 verify_packs
616'
b715cfbb 617
d67824fe 618test_expect_success 'D: validate new files added' '
22f18244 619 f5id=$(echo "$file5_data" | git hash-object --stdin) &&
620 f6id=$(echo "$file6_data" | git hash-object --stdin) &&
68297e0f 621 cat >expect <<-EOF &&
287bb3ab 622 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh
623 :000000 100644 $ZERO_OID $f5id A newdir/interesting
68297e0f
JS
624 EOF
625 git diff-tree -M -r branch^ branch >actual &&
d67824fe
JS
626 compare_diff_raw expect actual
627'
b715cfbb 628
d67824fe 629test_expect_success 'D: verify file5' '
68297e0f 630 echo "$file5_data" >expect &&
d67824fe
JS
631 git cat-file blob branch:newdir/interesting >actual &&
632 test_cmp expect actual
633'
b715cfbb 634
d67824fe 635test_expect_success 'D: verify file6' '
68297e0f 636 echo "$file6_data" >expect &&
d67824fe
JS
637 git cat-file blob branch:newdir/exec.sh >actual &&
638 test_cmp expect actual
639'
b715cfbb 640
63e0c8b3
SP
641###
642### series E
643###
644
68297e0f
JS
645test_expect_success 'E: rfc2822 date, --date-format=raw' '
646 cat >input <<-INPUT_END &&
647 commit refs/heads/branch
648 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
649 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
650 data <<COMMIT
651 RFC 2822 type date
652 COMMIT
653
654 from refs/heads/branch^0
63e0c8b3 655
68297e0f 656 INPUT_END
63e0c8b3 657
d67824fe
JS
658 test_must_fail git fast-import --date-format=raw <input
659'
660test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
661 git fast-import --date-format=rfc2822 <input
41ac414e 662'
05880b02
JS
663
664test_expect_success 'E: verify pack' '
665 verify_packs
666'
63e0c8b3 667
d67824fe 668test_expect_success 'E: verify commit' '
68297e0f
JS
669 cat >expect <<-EOF &&
670 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
672
673 RFC 2822 type date
674 EOF
d67824fe
JS
675 git cat-file commit branch | sed 1,2d >actual &&
676 test_cmp expect actual
677'
63e0c8b3 678
7073e69e
SP
679###
680### series F
681###
682
68297e0f 683test_expect_success 'F: non-fast-forward update skips' '
80a6b3f0 684 old_branch=$(git rev-parse --verify branch^0) &&
68297e0f
JS
685 test_tick &&
686 cat >input <<-INPUT_END &&
687 commit refs/heads/branch
688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
689 data <<COMMIT
690 losing things already?
691 COMMIT
7073e69e 692
68297e0f 693 from refs/heads/branch~1
7073e69e 694
68297e0f
JS
695 reset refs/heads/other
696 from refs/heads/branch
697
698 INPUT_END
7073e69e 699
b08d82f0
JS
700 test_must_fail git fast-import <input &&
701 # branch must remain unaffected
80a6b3f0 702 test $old_branch = $(git rev-parse --verify branch^0)
d67824fe 703'
05880b02
JS
704
705test_expect_success 'F: verify pack' '
706 verify_packs
707'
7073e69e 708
d67824fe 709test_expect_success 'F: verify other commit' '
68297e0f 710 cat >expect <<-EOF &&
80a6b3f0
EP
711 tree $(git rev-parse branch~1^{tree})
712 parent $(git rev-parse branch~1)
68297e0f
JS
713 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
715
716 losing things already?
717 EOF
d67824fe
JS
718 git cat-file commit other >actual &&
719 test_cmp expect actual
720'
7073e69e
SP
721
722###
723### series G
724###
725
68297e0f 726test_expect_success 'G: non-fast-forward update forced' '
80a6b3f0 727 old_branch=$(git rev-parse --verify branch^0) &&
68297e0f
JS
728 test_tick &&
729 cat >input <<-INPUT_END &&
730 commit refs/heads/branch
731 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
732 data <<COMMIT
733 losing things already?
734 COMMIT
7073e69e 735
68297e0f 736 from refs/heads/branch~1
7073e69e 737
68297e0f 738 INPUT_END
d67824fe
JS
739 git fast-import --force <input
740'
05880b02
JS
741
742test_expect_success 'G: verify pack' '
743 verify_packs
744'
745
d67824fe 746test_expect_success 'G: branch changed, but logged' '
80a6b3f0
EP
747 test $old_branch != $(git rev-parse --verify branch^0) &&
748 test $old_branch = $(git rev-parse --verify branch@{1})
d67824fe 749'
7073e69e 750
825769a8
SP
751###
752### series H
753###
754
d67824fe 755test_expect_success 'H: deletall, add 1' '
68297e0f
JS
756 test_tick &&
757 cat >input <<-INPUT_END &&
758 commit refs/heads/H
759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
760 data <<COMMIT
761 third
762 COMMIT
763
764 from refs/heads/branch^0
765 M 644 inline i-will-die
766 data <<EOF
767 this file will never exist.
768 EOF
769
770 deleteall
771 M 644 inline h/e/l/lo
772 data <<EOF
773 $file5_data
774 EOF
775
776 INPUT_END
d67824fe
JS
777 git fast-import <input &&
778 git whatchanged H
779'
05880b02
JS
780
781test_expect_success 'H: verify pack' '
782 verify_packs
783'
825769a8 784
d67824fe 785test_expect_success 'H: validate old files removed, new files added' '
22f18244 786 f4id=$(git rev-parse HEAD:file4) &&
68297e0f 787 cat >expect <<-EOF &&
22f18244 788 :100755 000000 $newf $zero D file2/newf
789 :100644 000000 $oldf $zero D file2/oldf
790 :100755 000000 $f4id $zero D file4
791 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo
792 :100755 000000 $f6id $zero D newdir/exec.sh
68297e0f
JS
793 EOF
794 git diff-tree -M -r H^ H >actual &&
d67824fe
JS
795 compare_diff_raw expect actual
796'
825769a8 797
d67824fe 798test_expect_success 'H: verify file' '
68297e0f 799 echo "$file5_data" >expect &&
d67824fe
JS
800 git cat-file blob H:h/e/l/lo >actual &&
801 test_cmp expect actual
802'
825769a8 803
bdf1c06d
SP
804###
805### series I
806###
807
68297e0f
JS
808test_expect_success 'I: export-pack-edges' '
809 cat >input <<-INPUT_END &&
810 commit refs/heads/export-boundary
811 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
812 data <<COMMIT
813 we have a border. its only 40 characters wide.
814 COMMIT
bdf1c06d 815
68297e0f 816 from refs/heads/branch
bdf1c06d 817
68297e0f 818 INPUT_END
d67824fe
JS
819 git fast-import --export-pack-edges=edges.list <input
820'
bdf1c06d 821
d67824fe 822test_expect_success 'I: verify edge list' '
68297e0f 823 cat >expect <<-EOF &&
80a6b3f0 824 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
68297e0f 825 EOF
d67824fe
JS
826 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
827 test_cmp expect actual
828'
bdf1c06d 829
ea5e370a
SP
830###
831### series J
832###
833
68297e0f
JS
834test_expect_success 'J: reset existing branch creates empty commit' '
835 cat >input <<-INPUT_END &&
836 commit refs/heads/J
837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
838 data <<COMMIT
839 create J
840 COMMIT
ea5e370a 841
68297e0f 842 from refs/heads/branch
ea5e370a 843
68297e0f 844 reset refs/heads/J
ea5e370a 845
68297e0f
JS
846 commit refs/heads/J
847 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
848 data <<COMMIT
849 initialize J
850 COMMIT
ea5e370a 851
68297e0f 852 INPUT_END
d67824fe
JS
853 git fast-import <input
854'
855test_expect_success 'J: branch has 1 commit, empty tree' '
80a6b3f0
EP
856 test 1 = $(git rev-list J | wc -l) &&
857 test 0 = $(git ls-tree J | wc -l)
d67824fe 858'
ea5e370a 859
d67824fe 860test_expect_success 'J: tag must fail on empty branch' '
68297e0f
JS
861 cat >input <<-INPUT_END &&
862 reset refs/heads/J2
863
864 tag wrong_tag
865 from refs/heads/J2
866 data <<EOF
867 Tag branch that was reset.
868 EOF
869 INPUT_END
d67824fe
JS
870 test_must_fail git fast-import <input
871'
68297e0f 872
ea5e370a
SP
873###
874### series K
875###
876
68297e0f
JS
877test_expect_success 'K: reinit branch with from' '
878 cat >input <<-INPUT_END &&
879 commit refs/heads/K
880 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
881 data <<COMMIT
882 create K
883 COMMIT
ea5e370a 884
68297e0f 885 from refs/heads/branch
ea5e370a 886
68297e0f
JS
887 commit refs/heads/K
888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
889 data <<COMMIT
890 redo K
891 COMMIT
ea5e370a 892
68297e0f 893 from refs/heads/branch^1
ea5e370a 894
68297e0f 895 INPUT_END
d67824fe
JS
896 git fast-import <input
897'
898test_expect_success 'K: verify K^1 = branch^1' '
80a6b3f0
EP
899 test $(git rev-parse --verify branch^1) \
900 = $(git rev-parse --verify K^1)
d67824fe 901'
ea5e370a 902
e7411303
JK
903###
904### series L
905###
906
68297e0f
JS
907test_expect_success 'L: verify internal tree sorting' '
908 cat >input <<-INPUT_END &&
909 blob
910 mark :1
911 data <<EOF
912 some data
913 EOF
914
915 blob
916 mark :2
917 data <<EOF
918 other data
919 EOF
920
921 commit refs/heads/L
922 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
923 data <<COMMIT
924 create L
925 COMMIT
926
927 M 644 :1 b.
928 M 644 :1 b/other
929 M 644 :1 ba
930
931 commit refs/heads/L
932 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
933 data <<COMMIT
934 update L
935 COMMIT
936
937 M 644 :2 b.
938 M 644 :2 b/other
939 M 644 :2 ba
940 INPUT_END
941
942 cat >expect <<-EXPECT_END &&
22f18244 943 :100644 100644 M b.
944 :040000 040000 M b
945 :100644 100644 M ba
68297e0f
JS
946 EXPECT_END
947
948 git fast-import <input &&
a2cd709d 949 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
22f18244 950 cut -d" " -f1,2,5 output >actual &&
951 test_cmp expect actual
68297e0f
JS
952'
953
954test_expect_success 'L: nested tree copy does not corrupt deltas' '
955 cat >input <<-INPUT_END &&
956 blob
957 mark :1
958 data <<EOF
959 the data
960 EOF
961
962 commit refs/heads/L2
963 committer C O Mitter <committer@example.com> 1112912473 -0700
964 data <<COMMIT
965 init L2
966 COMMIT
967 M 644 :1 a/b/c
968 M 644 :1 a/b/d
969 M 644 :1 a/e/f
e7411303 970
68297e0f
JS
971 commit refs/heads/L2
972 committer C O Mitter <committer@example.com> 1112912473 -0700
973 data <<COMMIT
974 update L2
975 COMMIT
976 C a g
977 C a/e g/b
978 M 644 :1 g/b/h
979 INPUT_END
e7411303 980
68297e0f
JS
981 cat >expect <<-\EOF &&
982 g/b/f
983 g/b/h
984 EOF
9a0edb79 985
93e911f5 986 test_when_finished "git update-ref -d refs/heads/L2" &&
d67824fe 987 git fast-import <input &&
9a0edb79 988 git ls-tree L2 g/b/ >tmp &&
af7dd8bd 989 cut -f 2 <tmp >actual &&
9a0edb79 990 test_cmp expect actual &&
80a6b3f0 991 git fsck $(git rev-parse L2)
d67824fe 992'
9a0edb79 993
f39a946a
SP
994###
995### series M
996###
997
68297e0f
JS
998test_expect_success 'M: rename file in same subdirectory' '
999 test_tick &&
1000 cat >input <<-INPUT_END &&
1001 commit refs/heads/M1
1002 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1003 data <<COMMIT
1004 file rename
1005 COMMIT
f39a946a 1006
68297e0f
JS
1007 from refs/heads/branch^0
1008 R file2/newf file2/n.e.w.f
f39a946a 1009
68297e0f 1010 INPUT_END
f39a946a 1011
68297e0f 1012 cat >expect <<-EOF &&
22f18244 1013 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f
68297e0f 1014 EOF
d67824fe
JS
1015 git fast-import <input &&
1016 git diff-tree -M -r M1^ M1 >actual &&
1017 compare_diff_raw expect actual
1018'
f39a946a 1019
68297e0f
JS
1020test_expect_success 'M: rename file to new subdirectory' '
1021 cat >input <<-INPUT_END &&
1022 commit refs/heads/M2
1023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1024 data <<COMMIT
1025 file rename
1026 COMMIT
f39a946a 1027
68297e0f
JS
1028 from refs/heads/branch^0
1029 R file2/newf i/am/new/to/you
f39a946a 1030
68297e0f 1031 INPUT_END
f39a946a 1032
68297e0f 1033 cat >expect <<-EOF &&
22f18244 1034 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you
68297e0f 1035 EOF
d67824fe
JS
1036 git fast-import <input &&
1037 git diff-tree -M -r M2^ M2 >actual &&
1038 compare_diff_raw expect actual
1039'
f39a946a 1040
68297e0f
JS
1041test_expect_success 'M: rename subdirectory to new subdirectory' '
1042 cat >input <<-INPUT_END &&
1043 commit refs/heads/M3
1044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1045 data <<COMMIT
1046 file rename
1047 COMMIT
f39a946a 1048
68297e0f
JS
1049 from refs/heads/M2^0
1050 R i other/sub
f39a946a 1051
68297e0f 1052 INPUT_END
f39a946a 1053
68297e0f 1054 cat >expect <<-EOF &&
22f18244 1055 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you
68297e0f 1056 EOF
d67824fe
JS
1057 git fast-import <input &&
1058 git diff-tree -M -r M3^ M3 >actual &&
1059 compare_diff_raw expect actual
1060'
f39a946a 1061
68297e0f
JS
1062test_expect_success 'M: rename root to subdirectory' '
1063 cat >input <<-INPUT_END &&
1064 commit refs/heads/M4
1065 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1066 data <<COMMIT
1067 rename root
1068 COMMIT
aca70610 1069
68297e0f
JS
1070 from refs/heads/M2^0
1071 R "" sub
aca70610 1072
68297e0f 1073 INPUT_END
aca70610 1074
68297e0f 1075 cat >expect <<-EOF &&
22f18244 1076 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1077 :100755 100755 $f4id $f4id R100 file4 sub/file4
1078 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1079 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1080 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
68297e0f 1081 EOF
d67824fe
JS
1082 git fast-import <input &&
1083 git diff-tree -M -r M4^ M4 >actual &&
d67824fe
JS
1084 compare_diff_raw expect actual
1085'
aca70610 1086
b6f3481b
SP
1087###
1088### series N
1089###
1090
68297e0f
JS
1091test_expect_success 'N: copy file in same subdirectory' '
1092 test_tick &&
1093 cat >input <<-INPUT_END &&
1094 commit refs/heads/N1
1095 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1096 data <<COMMIT
1097 file copy
1098 COMMIT
b6f3481b 1099
68297e0f
JS
1100 from refs/heads/branch^0
1101 C file2/newf file2/n.e.w.f
b6f3481b 1102
68297e0f 1103 INPUT_END
b6f3481b 1104
68297e0f 1105 cat >expect <<-EOF &&
22f18244 1106 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
68297e0f 1107 EOF
d67824fe
JS
1108 git fast-import <input &&
1109 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1110 compare_diff_raw expect actual
1111'
b6f3481b 1112
68297e0f
JS
1113test_expect_success 'N: copy then modify subdirectory' '
1114 cat >input <<-INPUT_END &&
1115 commit refs/heads/N2
1116 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1117 data <<COMMIT
1118 clean directory copy
1119 COMMIT
b6f3481b 1120
68297e0f
JS
1121 from refs/heads/branch^0
1122 C file2 file3
b6f3481b 1123
68297e0f
JS
1124 commit refs/heads/N2
1125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1126 data <<COMMIT
1127 modify directory copy
1128 COMMIT
b6f3481b 1129
68297e0f
JS
1130 M 644 inline file3/file5
1131 data <<EOF
1132 $file5_data
1133 EOF
b6f3481b 1134
68297e0f 1135 INPUT_END
b6f3481b 1136
68297e0f 1137 cat >expect <<-EOF &&
22f18244 1138 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1139 :100755 100755 $newf $newf C100 file2/newf file3/newf
1140 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
68297e0f 1141 EOF
d67824fe
JS
1142 git fast-import <input &&
1143 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1144 compare_diff_raw expect actual
1145'
b6f3481b 1146
68297e0f
JS
1147test_expect_success 'N: copy dirty subdirectory' '
1148 cat >input <<-INPUT_END &&
1149 commit refs/heads/N3
1150 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1151 data <<COMMIT
1152 dirty directory copy
1153 COMMIT
b6f3481b 1154
68297e0f
JS
1155 from refs/heads/branch^0
1156 M 644 inline file2/file5
1157 data <<EOF
1158 $file5_data
1159 EOF
b6f3481b 1160
68297e0f
JS
1161 C file2 file3
1162 D file2/file5
b6f3481b 1163
68297e0f 1164 INPUT_END
b6f3481b 1165
d67824fe 1166 git fast-import <input &&
80a6b3f0 1167 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
d67824fe 1168'
b6f3481b 1169
d67824fe 1170test_expect_success 'N: copy directory by id' '
22f18244 1171 cat >expect <<-EOF &&
1172 :100755 100755 $newf $newf C100 file2/newf file3/newf
1173 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
334fba65 1174 EOF
d67824fe
JS
1175 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1176 cat >input <<-INPUT_END &&
334fba65
JN
1177 commit refs/heads/N4
1178 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1179 data <<COMMIT
1180 copy by tree hash
1181 COMMIT
1182
1183 from refs/heads/branch^0
1184 M 040000 $subdir file3
1185 INPUT_END
d67824fe
JS
1186 git fast-import <input &&
1187 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1188 compare_diff_raw expect actual
1189'
334fba65 1190
8dc6a373 1191test_expect_success PIPE 'N: read and copy directory' '
22f18244 1192 cat >expect <<-EOF &&
1193 :100755 100755 $newf $newf C100 file2/newf file3/newf
1194 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
8dc6a373
DB
1195 EOF
1196 git update-ref -d refs/heads/N4 &&
1197 rm -f backflow &&
1198 mkfifo backflow &&
1199 (
1200 exec <backflow &&
1201 cat <<-EOF &&
1202 commit refs/heads/N4
1203 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1204 data <<COMMIT
1205 copy by tree hash, part 2
1206 COMMIT
1207
1208 from refs/heads/branch^0
1209 ls "file2"
1210 EOF
1211 read mode type tree filename &&
1212 echo "M 040000 $tree file3"
1213 ) |
1214 git fast-import --cat-blob-fd=3 3>backflow &&
1215 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1216 compare_diff_raw expect actual
1217'
1218
1219test_expect_success PIPE 'N: empty directory reads as missing' '
1220 cat <<-\EOF >expect &&
1221 OBJNAME
1222 :000000 100644 OBJNAME OBJNAME A unrelated
1223 EOF
1224 echo "missing src" >expect.response &&
1225 git update-ref -d refs/heads/read-empty &&
1226 rm -f backflow &&
1227 mkfifo backflow &&
1228 (
1229 exec <backflow &&
1230 cat <<-EOF &&
1231 commit refs/heads/read-empty
1232 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1233 data <<COMMIT
1234 read "empty" (missing) directory
1235 COMMIT
1236
1237 M 100644 inline src/greeting
1238 data <<BLOB
1239 hello
1240 BLOB
1241 C src/greeting dst1/non-greeting
1242 C src/greeting unrelated
1243 # leave behind "empty" src directory
1244 D src/greeting
1245 ls "src"
1246 EOF
1247 read -r line &&
1248 printf "%s\n" "$line" >response &&
1249 cat <<-\EOF
1250 D dst1
1251 D dst2
1252 EOF
1253 ) |
1254 git fast-import --cat-blob-fd=3 3>backflow &&
1255 test_cmp expect.response response &&
1256 git rev-list read-empty |
1257 git diff-tree -r --root --stdin |
2ece6ad2 1258 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
8dc6a373
DB
1259 test_cmp expect actual
1260'
1261
d67824fe 1262test_expect_success 'N: copy root directory by tree hash' '
22f18244 1263 cat >expect <<-EOF &&
1264 :100755 000000 $newf $zero D file3/newf
1265 :100644 000000 $oldf $zero D file3/oldf
2794ad52 1266 EOF
d67824fe
JS
1267 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1268 cat >input <<-INPUT_END &&
2794ad52
DB
1269 commit refs/heads/N6
1270 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1271 data <<COMMIT
1272 copy root directory by tree hash
1273 COMMIT
1274
1275 from refs/heads/branch^0
1276 M 040000 $root ""
1277 INPUT_END
d67824fe
JS
1278 git fast-import <input &&
1279 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1280 compare_diff_raw expect actual
1281'
2794ad52 1282
d67824fe 1283test_expect_success 'N: copy root by path' '
22f18244 1284 cat >expect <<-EOF &&
1285 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1286 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1287 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1288 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1289 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
aca70610 1290 EOF
d67824fe 1291 cat >input <<-INPUT_END &&
aca70610
JK
1292 commit refs/heads/N-copy-root-path
1293 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1294 data <<COMMIT
1295 copy root directory by (empty) path
1296 COMMIT
1297
1298 from refs/heads/branch^0
1299 C "" oldroot
1300 INPUT_END
d67824fe
JS
1301 git fast-import <input &&
1302 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1303 compare_diff_raw expect actual
1304'
aca70610 1305
d67824fe
JS
1306test_expect_success 'N: delete directory by copying' '
1307 cat >expect <<-\EOF &&
8fe533f6
JN
1308 OBJID
1309 :100644 000000 OBJID OBJID D foo/bar/qux
1310 OBJID
1311 :000000 100644 OBJID OBJID A foo/bar/baz
1312 :000000 100644 OBJID OBJID A foo/bar/qux
1313 EOF
d67824fe
JS
1314 empty_tree=$(git mktree </dev/null) &&
1315 cat >input <<-INPUT_END &&
8fe533f6
JN
1316 commit refs/heads/N-delete
1317 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1318 data <<COMMIT
1319 collect data to be deleted
1320 COMMIT
1321
1322 deleteall
1323 M 100644 inline foo/bar/baz
1324 data <<DATA_END
1325 hello
1326 DATA_END
1327 C "foo/bar/baz" "foo/bar/qux"
1328 C "foo/bar/baz" "foo/bar/quux/1"
1329 C "foo/bar/baz" "foo/bar/quuux"
1330 M 040000 $empty_tree foo/bar/quux
1331 M 040000 $empty_tree foo/bar/quuux
1332
1333 commit refs/heads/N-delete
1334 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1335 data <<COMMIT
1336 delete subdirectory
1337 COMMIT
1338
1339 M 040000 $empty_tree foo/bar/qux
1340 INPUT_END
d67824fe
JS
1341 git fast-import <input &&
1342 git rev-list N-delete |
8fe533f6 1343 git diff-tree -r --stdin --root --always |
2ece6ad2 1344 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
d67824fe
JS
1345 test_cmp expect actual
1346'
8fe533f6 1347
d67824fe 1348test_expect_success 'N: modify copied tree' '
22f18244 1349 cat >expect <<-EOF &&
1350 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1351 :100755 100755 $newf $newf C100 file2/newf file3/newf
1352 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
334fba65 1353 EOF
d67824fe
JS
1354 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1355 cat >input <<-INPUT_END &&
334fba65
JN
1356 commit refs/heads/N5
1357 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1358 data <<COMMIT
1359 copy by tree hash
1360 COMMIT
1361
1362 from refs/heads/branch^0
1363 M 040000 $subdir file3
1364
1365 commit refs/heads/N5
1366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1367 data <<COMMIT
1368 modify directory copy
1369 COMMIT
1370
1371 M 644 inline file3/file5
1372 data <<EOF
1373 $file5_data
1374 EOF
1375 INPUT_END
d67824fe
JS
1376 git fast-import <input &&
1377 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1378 compare_diff_raw expect actual
1379'
1380
1381test_expect_success 'N: reject foo/ syntax' '
1382 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1383 test_must_fail git fast-import <<-INPUT_END
34215783
JN
1384 commit refs/heads/N5B
1385 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1386 data <<COMMIT
1387 copy with invalid syntax
1388 COMMIT
1389
1390 from refs/heads/branch^0
1391 M 040000 $subdir file3/
d67824fe
JS
1392 INPUT_END
1393'
34215783 1394
d67824fe
JS
1395test_expect_success 'N: reject foo/ syntax in copy source' '
1396 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1397 commit refs/heads/N5C
1398 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1399 data <<COMMIT
1400 copy with invalid syntax
1401 COMMIT
1402
1403 from refs/heads/branch^0
1404 C file2/ file3
d67824fe
JS
1405 INPUT_END
1406'
178e1dea 1407
d67824fe
JS
1408test_expect_success 'N: reject foo/ syntax in rename source' '
1409 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1410 commit refs/heads/N5D
1411 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1412 data <<COMMIT
1413 rename with invalid syntax
1414 COMMIT
1415
1416 from refs/heads/branch^0
1417 R file2/ file3
d67824fe
JS
1418 INPUT_END
1419'
178e1dea 1420
d67824fe
JS
1421test_expect_success 'N: reject foo/ syntax in ls argument' '
1422 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1423 commit refs/heads/N5E
1424 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1425 data <<COMMIT
1426 copy with invalid syntax
1427 COMMIT
1428
1429 from refs/heads/branch^0
1430 ls "file2/"
d67824fe
JS
1431 INPUT_END
1432'
178e1dea 1433
d67824fe
JS
1434test_expect_success 'N: copy to root by id and modify' '
1435 echo "hello, world" >expect.foo &&
1436 echo hello >expect.bar &&
1437 git fast-import <<-SETUP_END &&
5edde510
JN
1438 commit refs/heads/N7
1439 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1440 data <<COMMIT
1441 hello, tree
1442 COMMIT
1443
1444 deleteall
1445 M 644 inline foo/bar
1446 data <<EOF
1447 hello
1448 EOF
1449 SETUP_END
1450
d67824fe
JS
1451 tree=$(git rev-parse --verify N7:) &&
1452 git fast-import <<-INPUT_END &&
5edde510
JN
1453 commit refs/heads/N8
1454 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1455 data <<COMMIT
1456 copy to root by id and modify
1457 COMMIT
1458
1459 M 040000 $tree ""
1460 M 644 inline foo/foo
1461 data <<EOF
1462 hello, world
1463 EOF
1464 INPUT_END
d67824fe
JS
1465 git show N8:foo/foo >actual.foo &&
1466 git show N8:foo/bar >actual.bar &&
1467 test_cmp expect.foo actual.foo &&
1468 test_cmp expect.bar actual.bar
1469'
1470
1471test_expect_success 'N: extract subtree' '
1472 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1473 cat >input <<-INPUT_END &&
34215783
JN
1474 commit refs/heads/N9
1475 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1476 data <<COMMIT
1477 extract subtree branch:newdir
1478 COMMIT
1479
1480 M 040000 $branch ""
971728c8 1481 C "newdir" ""
34215783 1482 INPUT_END
d67824fe
JS
1483 git fast-import <input &&
1484 git diff --exit-code branch:newdir N9
1485'
1486
1487test_expect_success 'N: modify subtree, extract it, and modify again' '
1488 echo hello >expect.baz &&
1489 echo hello, world >expect.qux &&
1490 git fast-import <<-SETUP_END &&
971728c8
JN
1491 commit refs/heads/N10
1492 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1493 data <<COMMIT
1494 hello, tree
1495 COMMIT
1496
1497 deleteall
1498 M 644 inline foo/bar/baz
1499 data <<EOF
1500 hello
1501 EOF
1502 SETUP_END
1503
d67824fe
JS
1504 tree=$(git rev-parse --verify N10:) &&
1505 git fast-import <<-INPUT_END &&
971728c8
JN
1506 commit refs/heads/N11
1507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1508 data <<COMMIT
1509 copy to root by id and modify
1510 COMMIT
1511
1512 M 040000 $tree ""
1513 M 100644 inline foo/bar/qux
1514 data <<EOF
1515 hello, world
1516 EOF
1517 R "foo" ""
1518 C "bar/qux" "bar/quux"
1519 INPUT_END
d67824fe
JS
1520 git show N11:bar/baz >actual.baz &&
1521 git show N11:bar/qux >actual.qux &&
1522 git show N11:bar/quux >actual.quux &&
1523 test_cmp expect.baz actual.baz &&
1524 test_cmp expect.qux actual.qux &&
1525 test_cmp expect.qux actual.quux'
971728c8 1526
401d53fa
SP
1527###
1528### series O
1529###
1530
68297e0f
JS
1531test_expect_success 'O: comments are all skipped' '
1532 cat >input <<-INPUT_END &&
1533 #we will
1534 commit refs/heads/O1
1535 # -- ignore all of this text
1536 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
68297e0f
JS
1537 data <<COMMIT
1538 dirty directory copy
1539 COMMIT
1540
1541 # do not forget the import blank line!
1542 #
1543 # yes, we started from our usual base of branch^0.
1544 # i like branch^0.
1545 from refs/heads/branch^0
1546 # and we need to reuse file2/file5 from N3 above.
1547 M 644 inline file2/file5
1548 # otherwise the tree will be different
1549 data <<EOF
1550 $file5_data
1551 EOF
401d53fa 1552
68297e0f
JS
1553 # do not forget to copy file2 to file3
1554 C file2 file3
1555 #
1556 # or to delete file5 from file2.
1557 D file2/file5
1558 # are we done yet?
1559
1560 INPUT_END
401d53fa 1561
d67824fe 1562 git fast-import <input &&
80a6b3f0 1563 test $(git rev-parse N3) = $(git rev-parse O1)
d67824fe 1564'
401d53fa 1565
68297e0f
JS
1566test_expect_success 'O: blank lines not necessary after data commands' '
1567 cat >input <<-INPUT_END &&
1568 commit refs/heads/O2
1569 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1570 data <<COMMIT
1571 dirty directory copy
1572 COMMIT
1573 from refs/heads/branch^0
1574 M 644 inline file2/file5
1575 data <<EOF
1576 $file5_data
1577 EOF
1578 C file2 file3
1579 D file2/file5
2c570cde 1580
68297e0f 1581 INPUT_END
2c570cde 1582
d67824fe 1583 git fast-import <input &&
80a6b3f0 1584 test $(git rev-parse N3) = $(git rev-parse O2)
d67824fe 1585'
2c570cde 1586
d67824fe
JS
1587test_expect_success 'O: repack before next test' '
1588 git repack -a -d
1589'
1fdb649c 1590
d67824fe 1591test_expect_success 'O: blank lines not necessary after other commands' '
68297e0f
JS
1592 cat >input <<-INPUT_END &&
1593 commit refs/heads/O3
1594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1595 data <<COMMIT
1596 zstring
1597 COMMIT
1598 commit refs/heads/O3
1599 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1600 data <<COMMIT
1601 zof
1602 COMMIT
1603 checkpoint
1604 commit refs/heads/O3
1605 mark :5
1606 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1607 data <<COMMIT
1608 zempty
1609 COMMIT
1610 checkpoint
1611 commit refs/heads/O3
1612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1613 data <<COMMIT
1614 zcommits
1615 COMMIT
1616 reset refs/tags/O3-2nd
1617 from :5
1618 reset refs/tags/O3-3rd
1619 from :5
1620 INPUT_END
1621
1622 cat >expect <<-INPUT_END &&
1623 string
1624 of
1625 empty
1626 commits
1627 INPUT_END
1628
d67824fe 1629 git fast-import <input &&
35a8a354
TB
1630 ls -la .git/objects/pack/pack-*.pack >packlist &&
1631 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1632 test_line_count = 4 idxlist &&
1633 test_line_count = 4 packlist &&
80a6b3f0 1634 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
d67824fe
JS
1635 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1636 test_cmp expect actual
1637'
1fdb649c 1638
d67824fe 1639test_expect_success 'O: progress outputs as requested by input' '
68297e0f
JS
1640 cat >input <<-INPUT_END &&
1641 commit refs/heads/O4
1642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1643 data <<COMMIT
1644 zstring
1645 COMMIT
1646 commit refs/heads/O4
1647 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1648 data <<COMMIT
1649 zof
1650 COMMIT
1651 progress Two commits down, 2 to go!
1652 commit refs/heads/O4
1653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1654 data <<COMMIT
1655 zempty
1656 COMMIT
1657 progress Three commits down, 1 to go!
1658 commit refs/heads/O4
1659 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1660 data <<COMMIT
1661 zcommits
1662 COMMIT
1663 progress done!
1664 INPUT_END
d67824fe
JS
1665 git fast-import <input >actual &&
1666 grep "progress " <input >expect &&
1667 test_cmp expect actual
1668'
ac053c02 1669
68297e0f
JS
1670###
1671### series P (gitlinks)
1672###
1673
1674test_expect_success 'P: superproject & submodule mix' '
1675 cat >input <<-INPUT_END &&
1676 blob
1677 mark :1
1678 data 10
1679 test file
1680
1681 reset refs/heads/sub
1682 commit refs/heads/sub
1683 mark :2
1684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1685 data 12
1686 sub_initial
1687 M 100644 :1 file
1688
1689 blob
1690 mark :3
1691 data <<DATAEND
1692 [submodule "sub"]
1693 path = sub
80a6b3f0 1694 url = "$(pwd)/sub"
68297e0f
JS
1695 DATAEND
1696
1697 commit refs/heads/subuse1
1698 mark :4
1699 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1700 data 8
1701 initial
a881baa2 1702 from refs/heads/main
68297e0f
JS
1703 M 100644 :3 .gitmodules
1704 M 160000 :2 sub
1705
1706 blob
1707 mark :5
1708 data 20
1709 test file
1710 more data
1711
1712 commit refs/heads/sub
1713 mark :6
1714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1715 data 11
1716 sub_second
1717 from :2
1718 M 100644 :5 file
1719
1720 commit refs/heads/subuse1
1721 mark :7
1722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1723 data 7
1724 second
1725 from :4
1726 M 160000 :6 sub
1727
1728 INPUT_END
1729
1730 git fast-import <input &&
1731 git checkout subuse1 &&
1732 rm -rf sub &&
1733 mkdir sub &&
1734 (
1735 cd sub &&
1736 git init &&
a881baa2
JS
1737 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1738 git checkout main
68297e0f
JS
1739 ) &&
1740 git submodule init &&
1741 git submodule update
1742'
1743
1744test_expect_success 'P: verbatim SHA gitlinks' '
1745 SUBLAST=$(git rev-parse --verify sub) &&
1746 SUBPREV=$(git rev-parse --verify sub^) &&
1747
1748 cat >input <<-INPUT_END &&
1749 blob
1750 mark :1
1751 data <<DATAEND
1752 [submodule "sub"]
1753 path = sub
80a6b3f0 1754 url = "$(pwd)/sub"
68297e0f
JS
1755 DATAEND
1756
1757 commit refs/heads/subuse2
1758 mark :2
1759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1760 data 8
1761 initial
a881baa2 1762 from refs/heads/main
68297e0f
JS
1763 M 100644 :1 .gitmodules
1764 M 160000 $SUBPREV sub
1765
1766 commit refs/heads/subuse2
1767 mark :3
1768 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1769 data 7
1770 second
1771 from :2
1772 M 160000 $SUBLAST sub
1773
1774 INPUT_END
1775
1776 git branch -D sub &&
c58100ab 1777 git gc --prune=now &&
68297e0f
JS
1778 git fast-import <input &&
1779 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1780'
1781
1782test_expect_success 'P: fail on inline gitlink' '
1783 test_tick &&
1784 cat >input <<-INPUT_END &&
1785 commit refs/heads/subuse3
1786 mark :1
1787 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1788 data <<COMMIT
1789 corrupt
1790 COMMIT
1791
1792 from refs/heads/subuse2
1793 M 160000 inline sub
1794 data <<DATA
1795 $SUBPREV
1796 DATA
1797
1798 INPUT_END
1799
1800 test_must_fail git fast-import <input
1801'
1802
1803test_expect_success 'P: fail on blob mark in gitlink' '
1804 test_tick &&
1805 cat >input <<-INPUT_END &&
1806 blob
1807 mark :1
1808 data <<DATA
1809 $SUBPREV
1810 DATA
1811
1812 commit refs/heads/subuse3
1813 mark :2
1814 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1815 data <<COMMIT
1816 corrupt
1817 COMMIT
1818
1819 from refs/heads/subuse2
1820 M 160000 :1 sub
1821
1822 INPUT_END
1823
1824 test_must_fail git fast-import <input
1825'
1826
1827###
1828### series Q (notes)
1829###
1830
1831test_expect_success 'Q: commit notes' '
1832 note1_data="The first note for the first commit" &&
1833 note2_data="The first note for the second commit" &&
1834 note3_data="The first note for the third commit" &&
1835 note1b_data="The second note for the first commit" &&
1836 note1c_data="The third note for the first commit" &&
1837 note2b_data="The second note for the second commit" &&
1838
1839 test_tick &&
1840 cat >input <<-INPUT_END &&
1841 blob
1842 mark :2
1843 data <<EOF
1844 $file2_data
1845 EOF
1846
1847 commit refs/heads/notes-test
1848 mark :3
1849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1850 data <<COMMIT
1851 first (:3)
1852 COMMIT
1853
1854 M 644 :2 file2
03db4525 1855
68297e0f
JS
1856 blob
1857 mark :4
1858 data $file4_len
1859 $file4_data
1860 commit refs/heads/notes-test
1861 mark :5
1862 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1863 data <<COMMIT
1864 second (:5)
1865 COMMIT
03db4525 1866
68297e0f 1867 M 644 :4 file4
03db4525 1868
68297e0f
JS
1869 commit refs/heads/notes-test
1870 mark :6
1871 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1872 data <<COMMIT
1873 third (:6)
1874 COMMIT
03db4525 1875
68297e0f
JS
1876 M 644 inline file5
1877 data <<EOF
1878 $file5_data
1879 EOF
03db4525 1880
68297e0f
JS
1881 M 755 inline file6
1882 data <<EOF
1883 $file6_data
1884 EOF
03db4525 1885
68297e0f
JS
1886 blob
1887 mark :7
1888 data <<EOF
1889 $note1_data
1890 EOF
03db4525 1891
68297e0f
JS
1892 blob
1893 mark :8
1894 data <<EOF
1895 $note2_data
1896 EOF
03db4525 1897
68297e0f
JS
1898 commit refs/notes/foobar
1899 mark :9
1900 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1901 data <<COMMIT
1902 notes (:9)
1903 COMMIT
03db4525 1904
68297e0f
JS
1905 N :7 :3
1906 N :8 :5
1907 N inline :6
1908 data <<EOF
1909 $note3_data
1910 EOF
03db4525 1911
68297e0f
JS
1912 commit refs/notes/foobar
1913 mark :10
1914 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1915 data <<COMMIT
1916 notes (:10)
1917 COMMIT
03db4525 1918
68297e0f
JS
1919 N inline :3
1920 data <<EOF
1921 $note1b_data
1922 EOF
03db4525 1923
68297e0f
JS
1924 commit refs/notes/foobar2
1925 mark :11
1926 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1927 data <<COMMIT
1928 notes (:11)
1929 COMMIT
03db4525 1930
68297e0f
JS
1931 N inline :3
1932 data <<EOF
1933 $note1c_data
1934 EOF
03db4525 1935
68297e0f
JS
1936 commit refs/notes/foobar
1937 mark :12
1938 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1939 data <<COMMIT
1940 notes (:12)
1941 COMMIT
1942
1943 deleteall
1944 N inline :5
1945 data <<EOF
1946 $note2b_data
1947 EOF
a8dd2e7d 1948
68297e0f 1949 INPUT_END
2a113aee 1950
d67824fe
JS
1951 git fast-import <input &&
1952 git whatchanged notes-test
1953'
05880b02
JS
1954
1955test_expect_success 'Q: verify pack' '
1956 verify_packs
1957'
a8dd2e7d 1958
68297e0f
JS
1959test_expect_success 'Q: verify first commit' '
1960 commit1=$(git rev-parse notes-test~2) &&
1961 commit2=$(git rev-parse notes-test^) &&
1962 commit3=$(git rev-parse notes-test) &&
a8dd2e7d 1963
68297e0f
JS
1964 cat >expect <<-EOF &&
1965 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1966 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
a8dd2e7d 1967
68297e0f
JS
1968 first (:3)
1969 EOF
d67824fe
JS
1970 git cat-file commit notes-test~2 | sed 1d >actual &&
1971 test_cmp expect actual
1972'
a8dd2e7d 1973
d67824fe 1974test_expect_success 'Q: verify second commit' '
68297e0f
JS
1975 cat >expect <<-EOF &&
1976 parent $commit1
1977 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1978 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1979
1980 second (:5)
1981 EOF
d67824fe
JS
1982 git cat-file commit notes-test^ | sed 1d >actual &&
1983 test_cmp expect actual
1984'
a8dd2e7d 1985
d67824fe 1986test_expect_success 'Q: verify third commit' '
68297e0f
JS
1987 cat >expect <<-EOF &&
1988 parent $commit2
1989 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1990 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1991
1992 third (:6)
1993 EOF
d67824fe
JS
1994 git cat-file commit notes-test | sed 1d >actual &&
1995 test_cmp expect actual
1996'
a8dd2e7d 1997
d67824fe 1998test_expect_success 'Q: verify first notes commit' '
68297e0f
JS
1999 cat >expect <<-EOF &&
2000 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2001 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2002
2003 notes (:9)
2004 EOF
d67824fe
JS
2005 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2006 test_cmp expect actual
2007'
a8dd2e7d 2008
d67824fe 2009test_expect_success 'Q: verify first notes tree' '
af7dd8bd 2010 sort >expect <<-EOF &&
68297e0f
JS
2011 100644 blob $commit1
2012 100644 blob $commit2
2013 100644 blob $commit3
2014 EOF
d67824fe
JS
2015 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2016 test_cmp expect actual
2017'
a8dd2e7d 2018
d67824fe 2019test_expect_success 'Q: verify first note for first commit' '
68297e0f 2020 echo "$note1_data" >expect &&
ec2c10be
JS
2021 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2022 test_cmp expect actual
d67824fe 2023'
a8dd2e7d 2024
d67824fe 2025test_expect_success 'Q: verify first note for second commit' '
68297e0f 2026 echo "$note2_data" >expect &&
ec2c10be
JS
2027 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2028 test_cmp expect actual
d67824fe 2029'
2a113aee 2030
d67824fe 2031test_expect_success 'Q: verify first note for third commit' '
68297e0f 2032 echo "$note3_data" >expect &&
ec2c10be
JS
2033 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2034 test_cmp expect actual
d67824fe 2035'
2a113aee 2036
d67824fe 2037test_expect_success 'Q: verify second notes commit' '
68297e0f 2038 cat >expect <<-EOF &&
80a6b3f0 2039 parent $(git rev-parse --verify refs/notes/foobar~2)
68297e0f
JS
2040 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2041 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2042
2043 notes (:10)
2044 EOF
d67824fe
JS
2045 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2046 test_cmp expect actual
2047'
2a113aee 2048
d67824fe 2049test_expect_success 'Q: verify second notes tree' '
af7dd8bd 2050 sort >expect <<-EOF &&
68297e0f
JS
2051 100644 blob $commit1
2052 100644 blob $commit2
2053 100644 blob $commit3
2054 EOF
d67824fe
JS
2055 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2056 test_cmp expect actual
2057'
2a113aee 2058
d67824fe 2059test_expect_success 'Q: verify second note for first commit' '
68297e0f 2060 echo "$note1b_data" >expect &&
ec2c10be
JS
2061 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2062 test_cmp expect actual
d67824fe 2063'
2a113aee 2064
d67824fe 2065test_expect_success 'Q: verify first note for second commit' '
68297e0f 2066 echo "$note2_data" >expect &&
ec2c10be
JS
2067 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2068 test_cmp expect actual
d67824fe 2069'
a8dd2e7d 2070
d67824fe 2071test_expect_success 'Q: verify first note for third commit' '
68297e0f 2072 echo "$note3_data" >expect &&
ec2c10be
JS
2073 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2074 test_cmp expect actual
d67824fe 2075'
2a113aee 2076
d67824fe 2077test_expect_success 'Q: verify third notes commit' '
68297e0f
JS
2078 cat >expect <<-EOF &&
2079 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2080 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2081
2082 notes (:11)
2083 EOF
d67824fe
JS
2084 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2085 test_cmp expect actual
2086'
2a113aee 2087
d67824fe 2088test_expect_success 'Q: verify third notes tree' '
af7dd8bd 2089 sort >expect <<-EOF &&
68297e0f
JS
2090 100644 blob $commit1
2091 EOF
d67824fe
JS
2092 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2093 test_cmp expect actual
2094'
2a113aee 2095
d67824fe 2096test_expect_success 'Q: verify third note for first commit' '
68297e0f 2097 echo "$note1c_data" >expect &&
ec2c10be
JS
2098 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2099 test_cmp expect actual
d67824fe 2100'
2a113aee 2101
d67824fe 2102test_expect_success 'Q: verify fourth notes commit' '
68297e0f 2103 cat >expect <<-EOF &&
80a6b3f0 2104 parent $(git rev-parse --verify refs/notes/foobar^)
68297e0f
JS
2105 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2106 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2107
2108 notes (:12)
2109 EOF
d67824fe
JS
2110 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2111 test_cmp expect actual
2112'
2a113aee 2113
d67824fe 2114test_expect_success 'Q: verify fourth notes tree' '
af7dd8bd 2115 sort >expect <<-EOF &&
68297e0f
JS
2116 100644 blob $commit2
2117 EOF
d67824fe
JS
2118 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2119 test_cmp expect actual
2120'
2a113aee 2121
d67824fe 2122test_expect_success 'Q: verify second note for second commit' '
68297e0f 2123 echo "$note2b_data" >expect &&
ec2c10be
JS
2124 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2125 test_cmp expect actual
d67824fe 2126'
a8dd2e7d 2127
68297e0f
JS
2128test_expect_success 'Q: deny note on empty branch' '
2129 cat >input <<-EOF &&
2130 reset refs/heads/Q0
0bc69881 2131
68297e0f
JS
2132 commit refs/heads/note-Q0
2133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2134 data <<COMMIT
2135 Note for an empty branch.
2136 COMMIT
0bc69881 2137
68297e0f
JS
2138 N inline refs/heads/Q0
2139 data <<NOTE
2140 some note
2141 NOTE
2142 EOF
d67824fe
JS
2143 test_must_fail git fast-import <input
2144'
f963bd5d 2145###
2792f26c 2146### series R (feature and option)
f963bd5d
SR
2147###
2148
f963bd5d 2149test_expect_success 'R: abort on unsupported feature' '
68297e0f
JS
2150 cat >input <<-EOF &&
2151 feature no-such-feature-exists
2152 EOF
2153
f963bd5d
SR
2154 test_must_fail git fast-import <input
2155'
2156
f963bd5d 2157test_expect_success 'R: supported feature is accepted' '
68297e0f
JS
2158 cat >input <<-EOF &&
2159 feature date-format=now
2160 EOF
2161
f963bd5d
SR
2162 git fast-import <input
2163'
2164
f963bd5d 2165test_expect_success 'R: abort on receiving feature after data command' '
68297e0f
JS
2166 cat >input <<-EOF &&
2167 blob
2168 data 3
2169 hi
2170 feature date-format=now
2171 EOF
2172
f963bd5d
SR
2173 test_must_fail git fast-import <input
2174'
2175
a52ed761
JK
2176test_expect_success 'R: import-marks features forbidden by default' '
2177 >git.marks &&
2178 echo "feature import-marks=git.marks" >input &&
2179 test_must_fail git fast-import <input &&
2180 echo "feature import-marks-if-exists=git.marks" >input &&
2181 test_must_fail git fast-import <input
2182'
2183
081751c8 2184test_expect_success 'R: only one import-marks feature allowed per stream' '
816f8067
JK
2185 >git.marks &&
2186 >git2.marks &&
68297e0f
JS
2187 cat >input <<-EOF &&
2188 feature import-marks=git.marks
2189 feature import-marks=git2.marks
2190 EOF
2191
a52ed761 2192 test_must_fail git fast-import --allow-unsafe-features <input
081751c8
SR
2193'
2194
68061e34
JK
2195test_expect_success 'R: export-marks feature forbidden by default' '
2196 echo "feature export-marks=git.marks" >input &&
081751c8
SR
2197 test_must_fail git fast-import <input
2198'
2199
68297e0f
JS
2200test_expect_success 'R: export-marks feature results in a marks file being created' '
2201 cat >input <<-EOF &&
2202 feature export-marks=git.marks
2203 blob
2204 mark :1
2205 data 3
2206 hi
f963bd5d 2207
68297e0f 2208 EOF
f963bd5d 2209
68061e34 2210 git fast-import --allow-unsafe-features <input &&
d67824fe
JS
2211 grep :1 git.marks
2212'
f963bd5d 2213
d67824fe 2214test_expect_success 'R: export-marks options can be overridden by commandline options' '
01968302
JK
2215 cat >input <<-\EOF &&
2216 feature export-marks=feature-sub/git.marks
2217 blob
2218 mark :1
2219 data 3
2220 hi
2221
2222 EOF
68061e34
JK
2223 git fast-import --allow-unsafe-features \
2224 --export-marks=cmdline-sub/other.marks <input &&
01968302
JK
2225 grep :1 cmdline-sub/other.marks &&
2226 test_path_is_missing feature-sub
d67824fe 2227'
f963bd5d 2228
dded4f12
RR
2229test_expect_success 'R: catch typo in marks file name' '
2230 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2231 echo "feature import-marks=nonexistent.marks" |
68061e34 2232 test_must_fail git fast-import --allow-unsafe-features
dded4f12
RR
2233'
2234
2235test_expect_success 'R: import and output marks can be the same file' '
2236 rm -f io.marks &&
2237 blob=$(echo hi | git hash-object --stdin) &&
2238 cat >expect <<-EOF &&
2239 :1 $blob
2240 :2 $blob
2241 EOF
2242 git fast-import --export-marks=io.marks <<-\EOF &&
2243 blob
2244 mark :1
2245 data 3
2246 hi
2247
2248 EOF
2249 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2250 blob
2251 mark :2
2252 data 3
2253 hi
2254
2255 EOF
2256 test_cmp expect io.marks
2257'
2258
2259test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2260 rm -f io.marks &&
2261 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2262 blob
2263 mark :1
2264 data 3
2265 hi
2266
2267 EOF
2268'
2269
2270test_expect_success 'R: --import-marks-if-exists' '
2271 rm -f io.marks &&
2272 blob=$(echo hi | git hash-object --stdin) &&
2273 echo ":1 $blob" >expect &&
2274 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2275 blob
2276 mark :1
2277 data 3
2278 hi
2279
2280 EOF
2281 test_cmp expect io.marks
2282'
2283
3beb4fc4
DI
2284test_expect_success 'R: feature import-marks-if-exists' '
2285 rm -f io.marks &&
3beb4fc4 2286
a52ed761
JK
2287 git fast-import --export-marks=io.marks \
2288 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2289 feature import-marks-if-exists=not_io.marks
2290 EOF
d3c6751b 2291 test_must_be_empty io.marks &&
3beb4fc4
DI
2292
2293 blob=$(echo hi | git hash-object --stdin) &&
2294
2295 echo ":1 $blob" >io.marks &&
2296 echo ":1 $blob" >expect &&
2297 echo ":2 $blob" >>expect &&
2298
a52ed761
JK
2299 git fast-import --export-marks=io.marks \
2300 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2301 feature import-marks-if-exists=io.marks
2302 blob
2303 mark :2
2304 data 3
2305 hi
2306
2307 EOF
2308 test_cmp expect io.marks &&
2309
2310 echo ":3 $blob" >>expect &&
2311
2312 git fast-import --import-marks=io.marks \
a52ed761
JK
2313 --export-marks=io.marks \
2314 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2315 feature import-marks-if-exists=not_io.marks
2316 blob
2317 mark :3
2318 data 3
2319 hi
2320
2321 EOF
2322 test_cmp expect io.marks &&
2323
3beb4fc4 2324 git fast-import --import-marks-if-exists=not_io.marks \
a52ed761
JK
2325 --export-marks=io.marks \
2326 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2327 feature import-marks-if-exists=io.marks
2328 EOF
d3c6751b 2329 test_must_be_empty io.marks
3beb4fc4
DI
2330'
2331
d67824fe 2332test_expect_success 'R: import to output marks works without any content' '
68297e0f
JS
2333 cat >input <<-EOF &&
2334 feature import-marks=marks.out
2335 feature export-marks=marks.new
2336 EOF
2337
68061e34 2338 git fast-import --allow-unsafe-features <input &&
d67824fe
JS
2339 test_cmp marks.out marks.new
2340'
f963bd5d 2341
d67824fe 2342test_expect_success 'R: import marks prefers commandline marks file over the stream' '
68297e0f
JS
2343 cat >input <<-EOF &&
2344 feature import-marks=nonexistent.marks
2345 feature export-marks=marks.new
2346 EOF
2347
68061e34 2348 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
d67824fe
JS
2349 test_cmp marks.out marks.new
2350'
f963bd5d 2351
081751c8 2352
081751c8 2353test_expect_success 'R: multiple --import-marks= should be honoured' '
68297e0f
JS
2354 cat >input <<-EOF &&
2355 feature import-marks=nonexistent.marks
2356 feature export-marks=combined.marks
2357 EOF
2358
d67824fe
JS
2359 head -n2 marks.out > one.marks &&
2360 tail -n +3 marks.out > two.marks &&
68061e34
JK
2361 git fast-import --import-marks=one.marks --import-marks=two.marks \
2362 --allow-unsafe-features <input &&
d67824fe 2363 test_cmp marks.out combined.marks
081751c8
SR
2364'
2365
bc3c79ae 2366test_expect_success 'R: feature relative-marks should be honoured' '
68297e0f
JS
2367 cat >input <<-EOF &&
2368 feature relative-marks
2369 feature import-marks=relative.in
2370 feature export-marks=relative.out
2371 EOF
2372
d67824fe
JS
2373 mkdir -p .git/info/fast-import/ &&
2374 cp marks.new .git/info/fast-import/relative.in &&
68061e34 2375 git fast-import --allow-unsafe-features <input &&
d67824fe 2376 test_cmp marks.new .git/info/fast-import/relative.out
bc3c79ae
SR
2377'
2378
bc3c79ae 2379test_expect_success 'R: feature no-relative-marks should be honoured' '
68297e0f
JS
2380 cat >input <<-EOF &&
2381 feature relative-marks
2382 feature import-marks=relative.in
2383 feature no-relative-marks
2384 feature export-marks=non-relative.out
2385 EOF
2386
68061e34 2387 git fast-import --allow-unsafe-features <input &&
d67824fe 2388 test_cmp marks.new non-relative.out
bc3c79ae
SR
2389'
2390
8dc6a373
DB
2391test_expect_success 'R: feature ls supported' '
2392 echo "feature ls" |
2393 git fast-import
2394'
2395
85c62395
DB
2396test_expect_success 'R: feature cat-blob supported' '
2397 echo "feature cat-blob" |
2398 git fast-import
2399'
2400
2401test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2402 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2403'
2404
f57a8715 2405test_expect_success !MINGW 'R: print old blob' '
85c62395
DB
2406 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2407 cat >expect <<-EOF &&
2408 ${blob} blob 11
2409 yes it can
2410
2411 EOF
2412 echo "cat-blob $blob" |
2413 git fast-import --cat-blob-fd=6 6>actual &&
2414 test_cmp expect actual
2415'
2416
f57a8715 2417test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
85c62395
DB
2418 echo hello >greeting &&
2419 blob=$(git hash-object -w greeting) &&
2420 cat >expect <<-EOF &&
2421 ${blob} blob 6
2422 hello
2423
2424 EOF
2425 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2426 cat-blob $blob
2427 EOF
2428 test_cmp expect actual.3 &&
acf3af25 2429 test_must_be_empty actual.1 &&
85c62395
DB
2430 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2431 option cat-blob-fd=3
2432 cat-blob $blob
2433 EOF
acf3af25 2434 test_must_be_empty actual.3 &&
85c62395
DB
2435 test_cmp expect actual.1
2436'
2437
28c7b1f7
MH
2438test_expect_success !MINGW 'R: print mark for new blob' '
2439 echo "effluentish" | git hash-object --stdin >expect &&
2440 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2441 blob
2442 mark :1
2443 data <<BLOB_END
2444 effluentish
2445 BLOB_END
2446 get-mark :1
2447 EOF
2448 test_cmp expect actual
2449'
2450
f57a8715 2451test_expect_success !MINGW 'R: print new blob' '
85c62395
DB
2452 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2453 cat >expect <<-EOF &&
2454 ${blob} blob 12
2455 yep yep yep
2456
2457 EOF
2458 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2459 blob
2460 mark :1
2461 data <<BLOB_END
2462 yep yep yep
2463 BLOB_END
2464 cat-blob :1
2465 EOF
2466 test_cmp expect actual
2467'
2468
f57a8715 2469test_expect_success !MINGW 'R: print new blob by sha1' '
85c62395
DB
2470 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2471 cat >expect <<-EOF &&
2472 ${blob} blob 25
2473 a new blob named by sha1
2474
2475 EOF
2476 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2477 blob
2478 data <<BLOB_END
2479 a new blob named by sha1
2480 BLOB_END
2481 cat-blob $blob
2482 EOF
2483 test_cmp expect actual
2484'
2485
2486test_expect_success 'setup: big file' '
2487 (
2488 echo "the quick brown fox jumps over the lazy dog" >big &&
2489 for i in 1 2 3
2490 do
2491 cat big big big big >bigger &&
2492 cat bigger bigger bigger bigger >big ||
2493 exit
2494 done
2495 )
2496'
2497
2498test_expect_success 'R: print two blobs to stdout' '
2499 blob1=$(git hash-object big) &&
2500 blob1_len=$(wc -c <big) &&
2501 blob2=$(echo hello | git hash-object --stdin) &&
2502 {
2503 echo ${blob1} blob $blob1_len &&
2504 cat big &&
2505 cat <<-EOF
2506
2507 ${blob2} blob 6
2508 hello
2509
2510 EOF
2511 } >expect &&
2512 {
2513 cat <<-\END_PART1 &&
2514 blob
2515 mark :1
2516 data <<data_end
2517 END_PART1
2518 cat big &&
2519 cat <<-\EOF
2520 data_end
2521 blob
2522 mark :2
2523 data <<data_end
2524 hello
2525 data_end
2526 cat-blob :1
2527 cat-blob :2
2528 EOF
2529 } |
2530 git fast-import >actual &&
2531 test_cmp expect actual
2532'
2533
85c62395
DB
2534test_expect_success PIPE 'R: copy using cat-file' '
2535 expect_id=$(git hash-object big) &&
2536 expect_len=$(wc -c <big) &&
2537 echo $expect_id blob $expect_len >expect.response &&
2538
2539 rm -f blobs &&
85c62395
DB
2540
2541 mkfifo blobs &&
2542 (
2543 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
4de0bbd8
JN
2544 cat <<-\EOF &&
2545 feature cat-blob
2546 blob
2547 mark :1
2548 data <<BLOB
2549 EOF
2550 cat big &&
2551 cat <<-\EOF &&
2552 BLOB
2553 cat-blob :1
2554 EOF
2555
2556 read blob_id type size <&3 &&
2557 echo "$blob_id $type $size" >response &&
48860819 2558 test_copy_bytes $size >blob <&3 &&
4de0bbd8
JN
2559 read newline <&3 &&
2560
2561 cat <<-EOF &&
2562 commit refs/heads/copied
2563 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2564 data <<COMMIT
2565 copy big file as file3
2566 COMMIT
2567 M 644 inline file3
2568 data <<BLOB
2569 EOF
2570 cat blob &&
2571 echo BLOB
2572 ) 3<blobs |
2573 git fast-import --cat-blob-fd=3 3>blobs &&
85c62395
DB
2574 git show copied:file3 >actual &&
2575 test_cmp expect.response response &&
2576 test_cmp big actual
2577'
2578
777f80d7
JN
2579test_expect_success PIPE 'R: print blob mid-commit' '
2580 rm -f blobs &&
2581 echo "A blob from _before_ the commit." >expect &&
2582 mkfifo blobs &&
2583 (
2584 exec 3<blobs &&
2585 cat <<-EOF &&
2586 feature cat-blob
2587 blob
2588 mark :1
2589 data <<BLOB
2590 A blob from _before_ the commit.
2591 BLOB
2592 commit refs/heads/temporary
2593 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2594 data <<COMMIT
2595 Empty commit
2596 COMMIT
2597 cat-blob :1
2598 EOF
2599
2600 read blob_id type size <&3 &&
48860819 2601 test_copy_bytes $size >actual <&3 &&
777f80d7
JN
2602 read newline <&3 &&
2603
2604 echo
2605 ) |
2606 git fast-import --cat-blob-fd=3 3>blobs &&
2607 test_cmp expect actual
2608'
2609
2610test_expect_success PIPE 'R: print staged blob within commit' '
2611 rm -f blobs &&
2612 echo "A blob from _within_ the commit." >expect &&
2613 mkfifo blobs &&
2614 (
2615 exec 3<blobs &&
2616 cat <<-EOF &&
2617 feature cat-blob
2618 commit refs/heads/within
2619 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2620 data <<COMMIT
2621 Empty commit
2622 COMMIT
2623 M 644 inline within
2624 data <<BLOB
2625 A blob from _within_ the commit.
2626 BLOB
2627 EOF
2628
2629 to_get=$(
2630 echo "A blob from _within_ the commit." |
2631 git hash-object --stdin
2632 ) &&
2633 echo "cat-blob $to_get" &&
2634
2635 read blob_id type size <&3 &&
48860819 2636 test_copy_bytes $size >actual <&3 &&
777f80d7
JN
2637 read newline <&3 &&
2638
2639 echo deleteall
2640 ) |
2641 git fast-import --cat-blob-fd=3 3>blobs &&
2642 test_cmp expect actual
2643'
2644
68297e0f
JS
2645test_expect_success 'R: quiet option results in no stats being output' '
2646 cat >input <<-EOF &&
2647 option git quiet
2648 blob
2649 data 3
2650 hi
2792f26c 2651
68297e0f 2652 EOF
2792f26c 2653
f94804c1 2654 git fast-import 2>output <input &&
acf3af25 2655 test_must_be_empty output
2792f26c
SR
2656'
2657
be56862f
SR
2658test_expect_success 'R: feature done means terminating "done" is mandatory' '
2659 echo feature done | test_must_fail git fast-import &&
2660 test_must_fail git fast-import --done </dev/null
2661'
2662
2663test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2664 git fast-import <<-\EOF &&
2665 feature done
2666 done
2667 trailing gibberish
2668 EOF
2669 git fast-import <<-\EOF
2670 done
2671 more trailing gibberish
2672 EOF
2673'
2674
2675test_expect_success 'R: terminating "done" within commit' '
2676 cat >expect <<-\EOF &&
2677 OBJID
2678 :000000 100644 OBJID OBJID A hello.c
2679 :000000 100644 OBJID OBJID A hello2.c
2680 EOF
2681 git fast-import <<-EOF &&
2682 commit refs/heads/done-ends
2683 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2684 data <<EOT
2685 Commit terminated by "done" command
2686 EOT
2687 M 100644 inline hello.c
2688 data <<EOT
2689 Hello, world.
2690 EOT
2691 C hello.c hello2.c
2692 done
2693 EOF
2694 git rev-list done-ends |
2695 git diff-tree -r --stdin --root --always |
2ece6ad2 2696 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
be56862f
SR
2697 test_cmp expect actual
2698'
2699
2792f26c 2700test_expect_success 'R: die on unknown option' '
68297e0f
JS
2701 cat >input <<-EOF &&
2702 option git non-existing-option
2703 EOF
2704
d67824fe 2705 test_must_fail git fast-import <input
2792f26c
SR
2706'
2707
2708test_expect_success 'R: unknown commandline options are rejected' '\
d67824fe 2709 test_must_fail git fast-import --non-existing-option < /dev/null
2792f26c
SR
2710'
2711
a9ff277e
JN
2712test_expect_success 'R: die on invalid option argument' '
2713 echo "option git active-branches=-5" |
2714 test_must_fail git fast-import &&
2715 echo "option git depth=" |
2716 test_must_fail git fast-import &&
2717 test_must_fail git fast-import --depth="5 elephants" </dev/null
2718'
2719
2792f26c 2720test_expect_success 'R: ignore non-git options' '
68297e0f
JS
2721 cat >input <<-EOF &&
2722 option non-existing-vcs non-existing-option
2723 EOF
2724
d67824fe 2725 git fast-import <input
2792f26c
SR
2726'
2727
f4beed60
FC
2728test_expect_success 'R: corrupt lines do not mess marks file' '
2729 rm -f io.marks &&
2730 blob=$(echo hi | git hash-object --stdin) &&
2731 cat >expect <<-EOF &&
287bb3ab 2732 :3 $ZERO_OID
f4beed60
FC
2733 :1 $blob
2734 :2 $blob
2735 EOF
2736 cp expect io.marks &&
2737 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2738
2739 EOF
2740 test_cmp expect io.marks
2741'
2742
5eef828b
SP
2743##
2744## R: very large blobs
2745##
d67824fe 2746test_expect_success 'R: blob bigger than threshold' '
68297e0f 2747 blobsize=$((2*1024*1024 + 53)) &&
c680668d 2748 test-tool genrandom bar $blobsize >expect &&
68297e0f
JS
2749 cat >input <<-INPUT_END &&
2750 commit refs/heads/big-file
2751 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2752 data <<COMMIT
2753 R - big file
2754 COMMIT
2755
2756 M 644 inline big1
2757 data $blobsize
2758 INPUT_END
2759 cat expect >>input &&
2760 cat >>input <<-INPUT_END &&
2761 M 644 inline big2
2762 data $blobsize
2763 INPUT_END
2764 cat expect >>input &&
2765 echo >>input &&
2766
d67824fe 2767 test_create_repo R &&
d9545c7f 2768 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
d67824fe
JS
2769 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2770'
05880b02
JS
2771
2772test_expect_success 'R: verify created pack' '
2773 (
2774 cd R &&
2775 verify_packs -v > ../verify
2776 )
2777'
2778
d67824fe
JS
2779test_expect_success 'R: verify written objects' '
2780 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2781 test_cmp_bin expect actual &&
2782 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2783 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2784 test $a = $b
2785'
2786
2787test_expect_success 'R: blob appears only once' '
2788 n=$(grep $a verify | wc -l) &&
2789 test 1 = $n
2790'
5eef828b 2791
06454cb9
PW
2792###
2793### series S
2794###
2795#
2796# Make sure missing spaces and EOLs after mark references
2797# cause errors.
2798#
2799# Setup:
2800#
2801# 1--2--4
2802# \ /
2803# -3-
2804#
2805# commit marks: 301, 302, 303, 304
2806# blob marks: 403, 404, resp.
2807# note mark: 202
2808#
2809# The error message when a space is missing not at the
2810# end of the line is:
2811#
2812# Missing space after ..
2813#
2814# or when extra characters come after the mark at the end
2815# of the line:
2816#
2817# Garbage after ..
2818#
2819# or when the dataref is neither "inline " or a known SHA1,
2820#
2821# Invalid dataref ..
2822#
06454cb9 2823test_expect_success 'S: initialize for S tests' '
68297e0f
JS
2824 test_tick &&
2825
2826 cat >input <<-INPUT_END &&
2827 commit refs/heads/S
2828 mark :301
2829 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2830 data <<COMMIT
2831 commit 1
2832 COMMIT
2833 M 100644 inline hello.c
2834 data <<BLOB
2835 blob 1
2836 BLOB
2837
2838 commit refs/heads/S
2839 mark :302
2840 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2841 data <<COMMIT
2842 commit 2
2843 COMMIT
2844 from :301
2845 M 100644 inline hello.c
2846 data <<BLOB
2847 blob 2
2848 BLOB
2849
2850 blob
2851 mark :403
2852 data <<BLOB
2853 blob 3
2854 BLOB
2855
2856 blob
2857 mark :202
2858 data <<BLOB
2859 note 2
2860 BLOB
2861 INPUT_END
2862
06454cb9
PW
2863 git fast-import --export-marks=marks <input
2864'
2865
2866#
2867# filemodify, three datarefs
2868#
2869test_expect_success 'S: filemodify with garbage after mark must fail' '
2870 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2871 commit refs/heads/S
2872 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2873 data <<COMMIT
2874 commit N
2875 COMMIT
2876 M 100644 :403x hello.c
2877 EOF
6789275d 2878 test_grep "space after mark" err
06454cb9
PW
2879'
2880
2881# inline is misspelled; fast-import thinks it is some unknown dataref
2882test_expect_success 'S: filemodify with garbage after inline must fail' '
2883 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2884 commit refs/heads/S
2885 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2886 data <<COMMIT
2887 commit N
2888 COMMIT
2889 M 100644 inlineX hello.c
2890 data <<BLOB
2891 inline
2892 BLOB
2893 EOF
6789275d 2894 test_grep "nvalid dataref" err
06454cb9
PW
2895'
2896
2897test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2898 sha1=$(grep :403 marks | cut -d\ -f2) &&
2899 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2900 commit refs/heads/S
2901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2902 data <<COMMIT
2903 commit N
2904 COMMIT
2905 M 100644 ${sha1}x hello.c
2906 EOF
6789275d 2907 test_grep "space after SHA1" err
06454cb9
PW
2908'
2909
2910#
2911# notemodify, three ways to say dataref
2912#
64127575 2913test_expect_success 'S: notemodify with garbage after mark dataref must fail' '
06454cb9
PW
2914 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2915 commit refs/heads/S
2916 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2917 data <<COMMIT
2918 commit S note dataref markref
2919 COMMIT
2920 N :202x :302
2921 EOF
6789275d 2922 test_grep "space after mark" err
06454cb9
PW
2923'
2924
2925test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2926 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2927 commit refs/heads/S
2928 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2929 data <<COMMIT
2930 commit S note dataref inline
2931 COMMIT
2932 N inlineX :302
2933 data <<BLOB
2934 note blob
2935 BLOB
2936 EOF
6789275d 2937 test_grep "nvalid dataref" err
06454cb9
PW
2938'
2939
2940test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2941 sha1=$(grep :202 marks | cut -d\ -f2) &&
2942 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2943 commit refs/heads/S
2944 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2945 data <<COMMIT
2946 commit S note dataref sha1
2947 COMMIT
2948 N ${sha1}x :302
2949 EOF
6789275d 2950 test_grep "space after SHA1" err
06454cb9
PW
2951'
2952
2953#
a8a5406a 2954# notemodify, mark in commit-ish
06454cb9 2955#
634c42da 2956test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
06454cb9
PW
2957 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2958 commit refs/heads/Snotes
2959 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2960 data <<COMMIT
a8a5406a 2961 commit S note commit-ish
06454cb9
PW
2962 COMMIT
2963 N :202 :302x
2964 EOF
6789275d 2965 test_grep "after mark" err
06454cb9
PW
2966'
2967
2968#
2969# from
2970#
2971test_expect_success 'S: from with garbage after mark must fail' '
0a5e3c50
JK
2972 test_must_fail \
2973 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
06454cb9
PW
2974 commit refs/heads/S2
2975 mark :303
2976 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2977 data <<COMMIT
2978 commit 3
2979 COMMIT
2980 from :301x
2981 M 100644 :403 hello.c
2982 EOF
2983
06454cb9
PW
2984
2985 # go create the commit, need it for merge test
2986 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2987 commit refs/heads/S2
2988 mark :303
2989 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2990 data <<COMMIT
2991 commit 3
2992 COMMIT
2993 from :301
2994 M 100644 :403 hello.c
2995 EOF
2996
2997 # now evaluate the error
6789275d 2998 test_grep "after mark" err
06454cb9
PW
2999'
3000
3001
3002#
3003# merge
3004#
3005test_expect_success 'S: merge with garbage after mark must fail' '
3006 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3007 commit refs/heads/S
3008 mark :304
3009 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3010 data <<COMMIT
3011 merge 4
3012 COMMIT
3013 from :302
3014 merge :303x
3015 M 100644 :403 hello.c
3016 EOF
6789275d 3017 test_grep "after mark" err
06454cb9
PW
3018'
3019
3020#
3021# tag, from markref
3022#
3023test_expect_success 'S: tag with garbage after mark must fail' '
3024 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3025 tag refs/tags/Stag
3026 from :302x
3027 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3028 data <<TAG
3029 tag S
3030 TAG
3031 EOF
6789275d 3032 test_grep "after mark" err
06454cb9
PW
3033'
3034
3035#
3036# cat-blob markref
3037#
3038test_expect_success 'S: cat-blob with garbage after mark must fail' '
3039 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3040 cat-blob :403x
3041 EOF
6789275d 3042 test_grep "after mark" err
06454cb9
PW
3043'
3044
3045#
3046# ls markref
3047#
3048test_expect_success 'S: ls with garbage after mark must fail' '
3049 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3050 ls :302x hello.c
3051 EOF
6789275d 3052 test_grep "space after mark" err
06454cb9
PW
3053'
3054
3055test_expect_success 'S: ls with garbage after sha1 must fail' '
3056 sha1=$(grep :302 marks | cut -d\ -f2) &&
3057 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3058 ls ${sha1}x hello.c
3059 EOF
6789275d 3060 test_grep "space after tree-ish" err
06454cb9
PW
3061'
3062
aca70610
JK
3063###
3064### series T (ls)
3065###
3066# Setup is carried over from series S.
3067
e0eb6b97 3068test_expect_success 'T: ls root tree' '
aca70610
JK
3069 sed -e "s/Z\$//" >expect <<-EOF &&
3070 040000 tree $(git rev-parse S^{tree}) Z
3071 EOF
3072 sha1=$(git rev-parse --verify S) &&
3073 git fast-import --import-marks=marks <<-EOF >actual &&
3074 ls $sha1 ""
3075 EOF
3076 test_cmp expect actual
3077'
3078
4ee1b225
FC
3079test_expect_success 'T: delete branch' '
3080 git branch to-delete &&
3081 git fast-import <<-EOF &&
3082 reset refs/heads/to-delete
287bb3ab 3083 from $ZERO_OID
4ee1b225
FC
3084 EOF
3085 test_must_fail git rev-parse --verify refs/heads/to-delete
3086'
3087
3088test_expect_success 'T: empty reset doesnt delete branch' '
3089 git branch not-to-delete &&
3090 git fast-import <<-EOF &&
3091 reset refs/heads/not-to-delete
3092 EOF
3093 git show-ref &&
3094 git rev-parse --verify refs/heads/not-to-delete
3095'
3096
8d30d8a8
MB
3097###
3098### series U (filedelete)
3099###
3100
8d30d8a8 3101test_expect_success 'U: initialize for U tests' '
68297e0f
JS
3102 cat >input <<-INPUT_END &&
3103 commit refs/heads/U
3104 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3105 data <<COMMIT
3106 test setup
3107 COMMIT
3108 M 100644 inline hello.c
3109 data <<BLOB
3110 blob 1
3111 BLOB
3112 M 100644 inline good/night.txt
3113 data <<BLOB
3114 sleep well
3115 BLOB
3116 M 100644 inline good/bye.txt
3117 data <<BLOB
3118 au revoir
3119 BLOB
3120
3121 INPUT_END
3122
22f18244 3123 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3124 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3125 f9id=$(echo "au revoir" | git hash-object --stdin) &&
8d30d8a8
MB
3126 git fast-import <input
3127'
3128
68297e0f
JS
3129test_expect_success 'U: filedelete file succeeds' '
3130 cat >input <<-INPUT_END &&
3131 commit refs/heads/U
3132 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3133 data <<COMMIT
3134 delete good/night.txt
3135 COMMIT
3136 from refs/heads/U^0
3137 D good/night.txt
8d30d8a8 3138
68297e0f 3139 INPUT_END
8d30d8a8 3140
8d30d8a8
MB
3141 git fast-import <input
3142'
3143
68297e0f
JS
3144test_expect_success 'U: validate file delete result' '
3145 cat >expect <<-EOF &&
22f18244 3146 :100644 000000 $f8id $ZERO_OID D good/night.txt
68297e0f 3147 EOF
8d30d8a8 3148
68297e0f 3149 git diff-tree -M -r U^1 U >actual &&
8d30d8a8 3150
8d30d8a8
MB
3151 compare_diff_raw expect actual
3152'
3153
68297e0f
JS
3154test_expect_success 'U: filedelete directory succeeds' '
3155 cat >input <<-INPUT_END &&
3156 commit refs/heads/U
3157 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3158 data <<COMMIT
3159 delete good dir
3160 COMMIT
3161 from refs/heads/U^0
3162 D good
8d30d8a8 3163
68297e0f 3164 INPUT_END
8d30d8a8 3165
8d30d8a8
MB
3166 git fast-import <input
3167'
3168
68297e0f
JS
3169test_expect_success 'U: validate directory delete result' '
3170 cat >expect <<-EOF &&
22f18244 3171 :100644 000000 $f9id $ZERO_OID D good/bye.txt
68297e0f 3172 EOF
8d30d8a8 3173
68297e0f 3174 git diff-tree -M -r U^1 U >actual &&
8d30d8a8 3175
8d30d8a8
MB
3176 compare_diff_raw expect actual
3177'
3178
68297e0f
JS
3179test_expect_success 'U: filedelete root succeeds' '
3180 cat >input <<-INPUT_END &&
3181 commit refs/heads/U
3182 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3183 data <<COMMIT
3184 must succeed
3185 COMMIT
3186 from refs/heads/U^0
3187 D ""
8d30d8a8 3188
68297e0f 3189 INPUT_END
8d30d8a8 3190
d67824fe 3191 git fast-import <input
8d30d8a8
MB
3192'
3193
68297e0f
JS
3194test_expect_success 'U: validate root delete result' '
3195 cat >expect <<-EOF &&
22f18244 3196 :100644 000000 $f7id $ZERO_OID D hello.c
68297e0f 3197 EOF
8d30d8a8 3198
68297e0f 3199 git diff-tree -M -r U^1 U >actual &&
8d30d8a8 3200
8d30d8a8
MB
3201 compare_diff_raw expect actual
3202'
3203
30e215a6
ER
3204###
3205### series V (checkpoint)
3206###
3207
3208# The commands in input_file should not produce any output on the file
3209# descriptor set with --cat-blob-fd (or stdout if unspecified).
3210#
3211# To make sure you're observing the side effects of checkpoint *before*
3212# fast-import terminates (and thus writes out its state), check that the
3213# fast-import process is still running using background_import_still_running
3214# *after* evaluating the test conditions.
3215background_import_then_checkpoint () {
3216 options=$1
3217 input_file=$2
3218
3219 mkfifo V.input
3220 exec 8<>V.input
3221 rm V.input
3222
3223 mkfifo V.output
3224 exec 9<>V.output
3225 rm V.output
3226
0d9b0d78
SG
3227 (
3228 git fast-import $options <&8 >&9 &
3229 echo $! >&9
3230 wait $!
3231 echo >&2 "background fast-import terminated too early with exit code $?"
3232 # Un-block the read loop in the main shell process.
3233 echo >&9 UNEXPECTED
3234 ) &
3235 sh_pid=$!
3236 read fi_pid <&9
30e215a6
ER
3237 # We don't mind if fast-import has already died by the time the test
3238 # ends.
ab29f1b3
SG
3239 test_when_finished "
3240 exec 8>&-; exec 9>&-;
0d9b0d78 3241 kill $sh_pid && wait $sh_pid
21f57620 3242 kill $fi_pid && wait $fi_pid
ab29f1b3 3243 true"
30e215a6
ER
3244
3245 # Start in the background to ensure we adhere strictly to (blocking)
3246 # pipes writing sequence. We want to assume that the write below could
3247 # block, e.g. if fast-import blocks writing its own output to &9
3248 # because there is no reader on &9 yet.
3249 (
3250 cat "$input_file"
3251 echo "checkpoint"
3252 echo "progress checkpoint"
3253 ) >&8 &
3254
3255 error=1 ;# assume the worst
3256 while read output <&9
3257 do
3258 if test "$output" = "progress checkpoint"
3259 then
3260 error=0
3261 break
0d9b0d78
SG
3262 elif test "$output" = "UNEXPECTED"
3263 then
3264 break
30e215a6
ER
3265 fi
3266 # otherwise ignore cruft
3267 echo >&2 "cruft: $output"
3268 done
3269
3270 if test $error -eq 1
3271 then
3272 false
3273 fi
3274}
3275
3276background_import_still_running () {
21f57620 3277 if ! kill -0 "$fi_pid"
30e215a6
ER
3278 then
3279 echo >&2 "background fast-import terminated too early"
3280 false
3281 fi
3282}
3283
3284test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' '
3285 cat >input <<-INPUT_END &&
3286 progress foo
3287 progress bar
3288
3289 INPUT_END
3290
3291 background_import_then_checkpoint "" input &&
3292 background_import_still_running
3293'
3294
3295test_expect_success PIPE 'V: checkpoint updates refs after reset' '
3296 cat >input <<-\INPUT_END &&
3297 reset refs/heads/V
3298 from refs/heads/U
3299
3300 INPUT_END
3301
3302 background_import_then_checkpoint "" input &&
3303 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3304 background_import_still_running
3305'
3306
3307test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' '
3308 cat >input <<-INPUT_END &&
3309 commit refs/heads/V
3310 mark :1
3311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3312 data 0
3313 from refs/heads/U
3314
3315 INPUT_END
3316
3317 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3318
3319 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3320
3321 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3322 test_cmp marks.expected marks.actual &&
3323 background_import_still_running
3324'
3325
3326# Re-create the exact same commit, but on a different branch: no new object is
3327# created in the database, but the refs and marks still need to be updated.
3328test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' '
3329 cat >input <<-INPUT_END &&
3330 commit refs/heads/V2
3331 mark :2
3332 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3333 data 0
3334 from refs/heads/U
3335
3336 INPUT_END
3337
3338 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3339
3340 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3341
3342 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3343 test_cmp marks.expected marks.actual &&
3344 background_import_still_running
3345'
3346
3347test_expect_success PIPE 'V: checkpoint updates tags after tag' '
3348 cat >input <<-INPUT_END &&
3349 tag Vtag
3350 from refs/heads/V
3351 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3352 data 0
3353
3354 INPUT_END
3355
3356 background_import_then_checkpoint "" input &&
3357 git show-ref -d Vtag &&
3358 background_import_still_running
3359'
3360
62edbec7
EN
3361###
3362### series W (get-mark and empty orphan commits)
3363###
3364
3365cat >>W-input <<-W_INPUT_END
3366 commit refs/heads/W-branch
3367 mark :1
3368 author Full Name <user@company.tld> 1000000000 +0100
3369 committer Full Name <user@company.tld> 1000000000 +0100
3370 data 27
3371 Intentionally empty commit
3372 LFsget-mark :1
3373 W_INPUT_END
3374
cf7b857a 3375test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' '
62edbec7
EN
3376 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3377'
3378
cf7b857a 3379test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' '
62edbec7
EN
3380 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3381'
3382
3383test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' '
3384 # Technically, this should fail as it has too many linefeeds
3385 # according to the grammar in fast-import.txt. But, for whatever
3386 # reason, it works. Since using the correct number of newlines
3387 # does not work with older (pre-2.22) versions of git, allow apps
3388 # that used this second-newline workaround to keep working by
3389 # checking it with this test...
3390 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3391'
3392
3393test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' '
3394 # ...but do NOT allow more empty lines than that (see previous test).
3395 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3396'
3397
3edfcc65
EN
3398###
3399### series X (other new features)
3400###
3401
3402test_expect_success 'X: handling encoding' '
3403 test_tick &&
3404 cat >input <<-INPUT_END &&
3405 commit refs/heads/encoding
3406 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3407 encoding iso-8859-7
3408 data <<COMMIT
3409 INPUT_END
3410
3411 printf "Pi: \360\nCOMMIT\n" >>input &&
3412
3413 git fast-import <input &&
3414 git cat-file -p encoding | grep $(printf "\360") &&
3415 git log -1 --format=%B encoding | grep $(printf "\317\200")
3416'
3417
1bdca816 3418###
3419### series Y (submodules and hash algorithms)
3420###
3421
3422cat >Y-sub-input <<\Y_INPUT_END
3423blob
3424mark :1
3425data 4
3426foo
3427
a881baa2
JS
3428reset refs/heads/main
3429commit refs/heads/main
1bdca816 3430mark :2
3431author Full Name <user@company.tld> 1000000000 +0100
3432committer Full Name <user@company.tld> 1000000000 +0100
3433data 24
3434Test submodule commit 1
3435M 100644 :1 file
3436
3437blob
3438mark :3
3439data 8
3440foo
3441bar
3442
a881baa2 3443commit refs/heads/main
1bdca816 3444mark :4
3445author Full Name <user@company.tld> 1000000001 +0100
3446committer Full Name <user@company.tld> 1000000001 +0100
3447data 24
3448Test submodule commit 2
3449from :2
3450M 100644 :3 file
3451Y_INPUT_END
3452
3453# Note that the submodule object IDs are intentionally not translated.
3454cat >Y-main-input <<\Y_INPUT_END
3455blob
3456mark :1
3457data 4
3458foo
3459
a881baa2
JS
3460reset refs/heads/main
3461commit refs/heads/main
1bdca816 3462mark :2
3463author Full Name <user@company.tld> 2000000000 +0100
3464committer Full Name <user@company.tld> 2000000000 +0100
3465data 14
3466Test commit 1
3467M 100644 :1 file
3468
3469blob
3470mark :3
3471data 73
3472[submodule "sub1"]
3473 path = sub1
3474 url = https://void.example.com/main.git
3475
a881baa2 3476commit refs/heads/main
1bdca816 3477mark :4
3478author Full Name <user@company.tld> 2000000001 +0100
3479committer Full Name <user@company.tld> 2000000001 +0100
3480data 14
3481Test commit 2
3482from :2
3483M 100644 :3 .gitmodules
3484M 160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3485
3486blob
3487mark :5
3488data 8
3489foo
3490bar
3491
a881baa2 3492commit refs/heads/main
1bdca816 3493mark :6
3494author Full Name <user@company.tld> 2000000002 +0100
3495committer Full Name <user@company.tld> 2000000002 +0100
3496data 14
3497Test commit 3
3498from :4
3499M 100644 :5 file
3500M 160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3501Y_INPUT_END
3502
3503cat >Y-marks <<\Y_INPUT_END
3504:2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3505:4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3506Y_INPUT_END
3507
3508test_expect_success 'Y: setup' '
3509 test_oid_cache <<-EOF
a881baa2
JS
3510 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3511 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
1bdca816 3512 EOF
3513'
3514
3515test_expect_success 'Y: rewrite submodules' '
3516 git init main1 &&
3517 (
3518 cd main1 &&
3519 git init sub2 &&
3520 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3521 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3522 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
a881baa2 3523 test "$(git rev-parse main)" = "$(test_oid Ymain)"
1bdca816 3524 )
3525'
3526
50aee995 3527test_done