]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9300-fast-import.sh
Start the 2.46 cycle
[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
b5062f75
TA
1062for root in '""' ''
1063do
1064 test_expect_success "M: rename root ($root) to subdirectory" '
1065 cat >input <<-INPUT_END &&
1066 commit refs/heads/M4
1067 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068 data <<COMMIT
1069 rename root
1070 COMMIT
aca70610 1071
b5062f75
TA
1072 from refs/heads/M2^0
1073 R $root sub
aca70610 1074
b5062f75 1075 INPUT_END
aca70610 1076
b5062f75
TA
1077 cat >expect <<-EOF &&
1078 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1079 :100755 100755 $f4id $f4id R100 file4 sub/file4
1080 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1081 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1082 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
1083 EOF
1084 git fast-import <input &&
1085 git diff-tree -M -r M4^ M4 >actual &&
1086 compare_diff_raw expect actual
1087 '
1088done
aca70610 1089
b6f3481b
SP
1090###
1091### series N
1092###
1093
68297e0f
JS
1094test_expect_success 'N: copy file in same subdirectory' '
1095 test_tick &&
1096 cat >input <<-INPUT_END &&
1097 commit refs/heads/N1
1098 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1099 data <<COMMIT
1100 file copy
1101 COMMIT
b6f3481b 1102
68297e0f
JS
1103 from refs/heads/branch^0
1104 C file2/newf file2/n.e.w.f
b6f3481b 1105
68297e0f 1106 INPUT_END
b6f3481b 1107
68297e0f 1108 cat >expect <<-EOF &&
22f18244 1109 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
68297e0f 1110 EOF
d67824fe
JS
1111 git fast-import <input &&
1112 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1113 compare_diff_raw expect actual
1114'
b6f3481b 1115
68297e0f
JS
1116test_expect_success 'N: copy then modify subdirectory' '
1117 cat >input <<-INPUT_END &&
1118 commit refs/heads/N2
1119 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1120 data <<COMMIT
1121 clean directory copy
1122 COMMIT
b6f3481b 1123
68297e0f
JS
1124 from refs/heads/branch^0
1125 C file2 file3
b6f3481b 1126
68297e0f
JS
1127 commit refs/heads/N2
1128 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1129 data <<COMMIT
1130 modify directory copy
1131 COMMIT
b6f3481b 1132
68297e0f
JS
1133 M 644 inline file3/file5
1134 data <<EOF
1135 $file5_data
1136 EOF
b6f3481b 1137
68297e0f 1138 INPUT_END
b6f3481b 1139
68297e0f 1140 cat >expect <<-EOF &&
22f18244 1141 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1142 :100755 100755 $newf $newf C100 file2/newf file3/newf
1143 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
68297e0f 1144 EOF
d67824fe
JS
1145 git fast-import <input &&
1146 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1147 compare_diff_raw expect actual
1148'
b6f3481b 1149
68297e0f
JS
1150test_expect_success 'N: copy dirty subdirectory' '
1151 cat >input <<-INPUT_END &&
1152 commit refs/heads/N3
1153 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1154 data <<COMMIT
1155 dirty directory copy
1156 COMMIT
b6f3481b 1157
68297e0f
JS
1158 from refs/heads/branch^0
1159 M 644 inline file2/file5
1160 data <<EOF
1161 $file5_data
1162 EOF
b6f3481b 1163
68297e0f
JS
1164 C file2 file3
1165 D file2/file5
b6f3481b 1166
68297e0f 1167 INPUT_END
b6f3481b 1168
d67824fe 1169 git fast-import <input &&
80a6b3f0 1170 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
d67824fe 1171'
b6f3481b 1172
d67824fe 1173test_expect_success 'N: copy directory by id' '
22f18244 1174 cat >expect <<-EOF &&
1175 :100755 100755 $newf $newf C100 file2/newf file3/newf
1176 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
334fba65 1177 EOF
d67824fe
JS
1178 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1179 cat >input <<-INPUT_END &&
334fba65
JN
1180 commit refs/heads/N4
1181 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1182 data <<COMMIT
1183 copy by tree hash
1184 COMMIT
1185
1186 from refs/heads/branch^0
1187 M 040000 $subdir file3
1188 INPUT_END
d67824fe
JS
1189 git fast-import <input &&
1190 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1191 compare_diff_raw expect actual
1192'
334fba65 1193
8dc6a373 1194test_expect_success PIPE 'N: read and copy directory' '
22f18244 1195 cat >expect <<-EOF &&
1196 :100755 100755 $newf $newf C100 file2/newf file3/newf
1197 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
8dc6a373
DB
1198 EOF
1199 git update-ref -d refs/heads/N4 &&
1200 rm -f backflow &&
1201 mkfifo backflow &&
1202 (
1203 exec <backflow &&
1204 cat <<-EOF &&
1205 commit refs/heads/N4
1206 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1207 data <<COMMIT
1208 copy by tree hash, part 2
1209 COMMIT
1210
1211 from refs/heads/branch^0
1212 ls "file2"
1213 EOF
1214 read mode type tree filename &&
1215 echo "M 040000 $tree file3"
1216 ) |
1217 git fast-import --cat-blob-fd=3 3>backflow &&
1218 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1219 compare_diff_raw expect actual
1220'
1221
1222test_expect_success PIPE 'N: empty directory reads as missing' '
1223 cat <<-\EOF >expect &&
1224 OBJNAME
1225 :000000 100644 OBJNAME OBJNAME A unrelated
1226 EOF
1227 echo "missing src" >expect.response &&
1228 git update-ref -d refs/heads/read-empty &&
1229 rm -f backflow &&
1230 mkfifo backflow &&
1231 (
1232 exec <backflow &&
1233 cat <<-EOF &&
1234 commit refs/heads/read-empty
1235 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1236 data <<COMMIT
1237 read "empty" (missing) directory
1238 COMMIT
1239
1240 M 100644 inline src/greeting
1241 data <<BLOB
1242 hello
1243 BLOB
1244 C src/greeting dst1/non-greeting
1245 C src/greeting unrelated
1246 # leave behind "empty" src directory
1247 D src/greeting
1248 ls "src"
1249 EOF
1250 read -r line &&
1251 printf "%s\n" "$line" >response &&
1252 cat <<-\EOF
1253 D dst1
1254 D dst2
1255 EOF
1256 ) |
1257 git fast-import --cat-blob-fd=3 3>backflow &&
1258 test_cmp expect.response response &&
1259 git rev-list read-empty |
1260 git diff-tree -r --root --stdin |
2ece6ad2 1261 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
8dc6a373
DB
1262 test_cmp expect actual
1263'
1264
b5062f75
TA
1265for root in '""' ''
1266do
1267 test_expect_success "N: copy root ($root) by tree hash" '
1268 cat >expect <<-EOF &&
1269 :100755 000000 $newf $zero D file3/newf
1270 :100644 000000 $oldf $zero D file3/oldf
1271 EOF
1272 root_tree=$(git rev-parse refs/heads/branch^0^{tree}) &&
1273 cat >input <<-INPUT_END &&
1274 commit refs/heads/N6
1275 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1276 data <<COMMIT
1277 copy root directory by tree hash
1278 COMMIT
2794ad52 1279
b5062f75
TA
1280 from refs/heads/branch^0
1281 M 040000 $root_tree $root
1282 INPUT_END
1283 git fast-import <input &&
1284 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1285 compare_diff_raw expect actual
1286 '
2794ad52 1287
b5062f75
TA
1288 test_expect_success "N: copy root ($root) by path" '
1289 cat >expect <<-EOF &&
1290 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1291 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1292 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1293 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1294 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
1295 EOF
1296 cat >input <<-INPUT_END &&
1297 commit refs/heads/N-copy-root-path
1298 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1299 data <<COMMIT
1300 copy root directory by (empty) path
1301 COMMIT
aca70610 1302
b5062f75
TA
1303 from refs/heads/branch^0
1304 C $root oldroot
1305 INPUT_END
1306 git fast-import <input &&
1307 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1308 compare_diff_raw expect actual
1309 '
1310done
aca70610 1311
d67824fe
JS
1312test_expect_success 'N: delete directory by copying' '
1313 cat >expect <<-\EOF &&
8fe533f6
JN
1314 OBJID
1315 :100644 000000 OBJID OBJID D foo/bar/qux
1316 OBJID
1317 :000000 100644 OBJID OBJID A foo/bar/baz
1318 :000000 100644 OBJID OBJID A foo/bar/qux
1319 EOF
d67824fe
JS
1320 empty_tree=$(git mktree </dev/null) &&
1321 cat >input <<-INPUT_END &&
8fe533f6
JN
1322 commit refs/heads/N-delete
1323 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1324 data <<COMMIT
1325 collect data to be deleted
1326 COMMIT
1327
1328 deleteall
1329 M 100644 inline foo/bar/baz
1330 data <<DATA_END
1331 hello
1332 DATA_END
1333 C "foo/bar/baz" "foo/bar/qux"
1334 C "foo/bar/baz" "foo/bar/quux/1"
1335 C "foo/bar/baz" "foo/bar/quuux"
1336 M 040000 $empty_tree foo/bar/quux
1337 M 040000 $empty_tree foo/bar/quuux
1338
1339 commit refs/heads/N-delete
1340 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1341 data <<COMMIT
1342 delete subdirectory
1343 COMMIT
1344
1345 M 040000 $empty_tree foo/bar/qux
1346 INPUT_END
d67824fe
JS
1347 git fast-import <input &&
1348 git rev-list N-delete |
8fe533f6 1349 git diff-tree -r --stdin --root --always |
2ece6ad2 1350 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
d67824fe
JS
1351 test_cmp expect actual
1352'
8fe533f6 1353
d67824fe 1354test_expect_success 'N: modify copied tree' '
22f18244 1355 cat >expect <<-EOF &&
1356 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1357 :100755 100755 $newf $newf C100 file2/newf file3/newf
1358 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
334fba65 1359 EOF
d67824fe
JS
1360 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1361 cat >input <<-INPUT_END &&
334fba65
JN
1362 commit refs/heads/N5
1363 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1364 data <<COMMIT
1365 copy by tree hash
1366 COMMIT
1367
1368 from refs/heads/branch^0
1369 M 040000 $subdir file3
1370
1371 commit refs/heads/N5
1372 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1373 data <<COMMIT
1374 modify directory copy
1375 COMMIT
1376
1377 M 644 inline file3/file5
1378 data <<EOF
1379 $file5_data
1380 EOF
1381 INPUT_END
d67824fe
JS
1382 git fast-import <input &&
1383 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1384 compare_diff_raw expect actual
1385'
1386
1387test_expect_success 'N: reject foo/ syntax' '
1388 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1389 test_must_fail git fast-import <<-INPUT_END
34215783
JN
1390 commit refs/heads/N5B
1391 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1392 data <<COMMIT
1393 copy with invalid syntax
1394 COMMIT
1395
1396 from refs/heads/branch^0
1397 M 040000 $subdir file3/
d67824fe
JS
1398 INPUT_END
1399'
34215783 1400
d67824fe
JS
1401test_expect_success 'N: reject foo/ syntax in copy source' '
1402 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1403 commit refs/heads/N5C
1404 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1405 data <<COMMIT
1406 copy with invalid syntax
1407 COMMIT
1408
1409 from refs/heads/branch^0
1410 C file2/ file3
d67824fe
JS
1411 INPUT_END
1412'
178e1dea 1413
d67824fe
JS
1414test_expect_success 'N: reject foo/ syntax in rename source' '
1415 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1416 commit refs/heads/N5D
1417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418 data <<COMMIT
1419 rename with invalid syntax
1420 COMMIT
1421
1422 from refs/heads/branch^0
1423 R file2/ file3
d67824fe
JS
1424 INPUT_END
1425'
178e1dea 1426
d67824fe
JS
1427test_expect_success 'N: reject foo/ syntax in ls argument' '
1428 test_must_fail git fast-import <<-INPUT_END
178e1dea
JN
1429 commit refs/heads/N5E
1430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1431 data <<COMMIT
1432 copy with invalid syntax
1433 COMMIT
1434
1435 from refs/heads/branch^0
1436 ls "file2/"
d67824fe
JS
1437 INPUT_END
1438'
178e1dea 1439
b5062f75
TA
1440for root in '""' ''
1441do
1442 test_expect_success "N: copy to root ($root) by id and modify" '
1443 echo "hello, world" >expect.foo &&
1444 echo hello >expect.bar &&
1445 git fast-import <<-SETUP_END &&
1446 commit refs/heads/N7
1447 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1448 data <<COMMIT
1449 hello, tree
1450 COMMIT
5edde510 1451
b5062f75
TA
1452 deleteall
1453 M 644 inline foo/bar
1454 data <<EOF
1455 hello
1456 EOF
1457 SETUP_END
5edde510 1458
b5062f75
TA
1459 tree=$(git rev-parse --verify N7:) &&
1460 git fast-import <<-INPUT_END &&
1461 commit refs/heads/N8
1462 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1463 data <<COMMIT
1464 copy to root by id and modify
1465 COMMIT
5edde510 1466
b5062f75
TA
1467 M 040000 $tree $root
1468 M 644 inline foo/foo
1469 data <<EOF
1470 hello, world
1471 EOF
1472 INPUT_END
1473 git show N8:foo/foo >actual.foo &&
1474 git show N8:foo/bar >actual.bar &&
1475 test_cmp expect.foo actual.foo &&
1476 test_cmp expect.bar actual.bar
1477 '
d67824fe 1478
b5062f75
TA
1479 test_expect_success "N: extract subtree to the root ($root)" '
1480 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1481 cat >input <<-INPUT_END &&
1482 commit refs/heads/N9
1483 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1484 data <<COMMIT
1485 extract subtree branch:newdir
1486 COMMIT
34215783 1487
b5062f75
TA
1488 M 040000 $branch $root
1489 C "newdir" $root
1490 INPUT_END
1491 git fast-import <input &&
1492 git diff --exit-code branch:newdir N9
1493 '
d67824fe 1494
b5062f75
TA
1495 test_expect_success "N: modify subtree, extract it to the root ($root), and modify again" '
1496 echo hello >expect.baz &&
1497 echo hello, world >expect.qux &&
1498 git fast-import <<-SETUP_END &&
1499 commit refs/heads/N10
1500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1501 data <<COMMIT
1502 hello, tree
1503 COMMIT
971728c8 1504
b5062f75
TA
1505 deleteall
1506 M 644 inline foo/bar/baz
1507 data <<EOF
1508 hello
1509 EOF
1510 SETUP_END
971728c8 1511
b5062f75
TA
1512 tree=$(git rev-parse --verify N10:) &&
1513 git fast-import <<-INPUT_END &&
1514 commit refs/heads/N11
1515 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1516 data <<COMMIT
1517 copy to root by id and modify
1518 COMMIT
971728c8 1519
b5062f75
TA
1520 M 040000 $tree $root
1521 M 100644 inline foo/bar/qux
1522 data <<EOF
1523 hello, world
1524 EOF
1525 R "foo" $root
1526 C "bar/qux" "bar/quux"
1527 INPUT_END
1528 git show N11:bar/baz >actual.baz &&
1529 git show N11:bar/qux >actual.qux &&
1530 git show N11:bar/quux >actual.quux &&
1531 test_cmp expect.baz actual.baz &&
1532 test_cmp expect.qux actual.qux &&
1533 test_cmp expect.qux actual.quux
1534 '
1535done
971728c8 1536
401d53fa
SP
1537###
1538### series O
1539###
1540
68297e0f
JS
1541test_expect_success 'O: comments are all skipped' '
1542 cat >input <<-INPUT_END &&
1543 #we will
1544 commit refs/heads/O1
1545 # -- ignore all of this text
1546 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
68297e0f
JS
1547 data <<COMMIT
1548 dirty directory copy
1549 COMMIT
1550
1551 # do not forget the import blank line!
1552 #
1553 # yes, we started from our usual base of branch^0.
1554 # i like branch^0.
1555 from refs/heads/branch^0
1556 # and we need to reuse file2/file5 from N3 above.
1557 M 644 inline file2/file5
1558 # otherwise the tree will be different
1559 data <<EOF
1560 $file5_data
1561 EOF
401d53fa 1562
68297e0f
JS
1563 # do not forget to copy file2 to file3
1564 C file2 file3
1565 #
1566 # or to delete file5 from file2.
1567 D file2/file5
1568 # are we done yet?
1569
1570 INPUT_END
401d53fa 1571
d67824fe 1572 git fast-import <input &&
80a6b3f0 1573 test $(git rev-parse N3) = $(git rev-parse O1)
d67824fe 1574'
401d53fa 1575
68297e0f
JS
1576test_expect_success 'O: blank lines not necessary after data commands' '
1577 cat >input <<-INPUT_END &&
1578 commit refs/heads/O2
1579 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1580 data <<COMMIT
1581 dirty directory copy
1582 COMMIT
1583 from refs/heads/branch^0
1584 M 644 inline file2/file5
1585 data <<EOF
1586 $file5_data
1587 EOF
1588 C file2 file3
1589 D file2/file5
2c570cde 1590
68297e0f 1591 INPUT_END
2c570cde 1592
d67824fe 1593 git fast-import <input &&
80a6b3f0 1594 test $(git rev-parse N3) = $(git rev-parse O2)
d67824fe 1595'
2c570cde 1596
d67824fe
JS
1597test_expect_success 'O: repack before next test' '
1598 git repack -a -d
1599'
1fdb649c 1600
d67824fe 1601test_expect_success 'O: blank lines not necessary after other commands' '
68297e0f
JS
1602 cat >input <<-INPUT_END &&
1603 commit refs/heads/O3
1604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1605 data <<COMMIT
1606 zstring
1607 COMMIT
1608 commit refs/heads/O3
1609 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1610 data <<COMMIT
1611 zof
1612 COMMIT
1613 checkpoint
1614 commit refs/heads/O3
1615 mark :5
1616 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1617 data <<COMMIT
1618 zempty
1619 COMMIT
1620 checkpoint
1621 commit refs/heads/O3
1622 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1623 data <<COMMIT
1624 zcommits
1625 COMMIT
1626 reset refs/tags/O3-2nd
1627 from :5
1628 reset refs/tags/O3-3rd
1629 from :5
1630 INPUT_END
1631
1632 cat >expect <<-INPUT_END &&
1633 string
1634 of
1635 empty
1636 commits
1637 INPUT_END
1638
d67824fe 1639 git fast-import <input &&
35a8a354
TB
1640 ls -la .git/objects/pack/pack-*.pack >packlist &&
1641 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1642 test_line_count = 4 idxlist &&
1643 test_line_count = 4 packlist &&
80a6b3f0 1644 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
d67824fe
JS
1645 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1646 test_cmp expect actual
1647'
1fdb649c 1648
d67824fe 1649test_expect_success 'O: progress outputs as requested by input' '
68297e0f
JS
1650 cat >input <<-INPUT_END &&
1651 commit refs/heads/O4
1652 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1653 data <<COMMIT
1654 zstring
1655 COMMIT
1656 commit refs/heads/O4
1657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1658 data <<COMMIT
1659 zof
1660 COMMIT
1661 progress Two commits down, 2 to go!
1662 commit refs/heads/O4
1663 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1664 data <<COMMIT
1665 zempty
1666 COMMIT
1667 progress Three commits down, 1 to go!
1668 commit refs/heads/O4
1669 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1670 data <<COMMIT
1671 zcommits
1672 COMMIT
1673 progress done!
1674 INPUT_END
d67824fe
JS
1675 git fast-import <input >actual &&
1676 grep "progress " <input >expect &&
1677 test_cmp expect actual
1678'
ac053c02 1679
68297e0f
JS
1680###
1681### series P (gitlinks)
1682###
1683
1684test_expect_success 'P: superproject & submodule mix' '
1685 cat >input <<-INPUT_END &&
1686 blob
1687 mark :1
1688 data 10
1689 test file
1690
1691 reset refs/heads/sub
1692 commit refs/heads/sub
1693 mark :2
1694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1695 data 12
1696 sub_initial
1697 M 100644 :1 file
1698
1699 blob
1700 mark :3
1701 data <<DATAEND
1702 [submodule "sub"]
1703 path = sub
80a6b3f0 1704 url = "$(pwd)/sub"
68297e0f
JS
1705 DATAEND
1706
1707 commit refs/heads/subuse1
1708 mark :4
1709 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1710 data 8
1711 initial
a881baa2 1712 from refs/heads/main
68297e0f
JS
1713 M 100644 :3 .gitmodules
1714 M 160000 :2 sub
1715
1716 blob
1717 mark :5
1718 data 20
1719 test file
1720 more data
1721
1722 commit refs/heads/sub
1723 mark :6
1724 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1725 data 11
1726 sub_second
1727 from :2
1728 M 100644 :5 file
1729
1730 commit refs/heads/subuse1
1731 mark :7
1732 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1733 data 7
1734 second
1735 from :4
1736 M 160000 :6 sub
1737
1738 INPUT_END
1739
1740 git fast-import <input &&
1741 git checkout subuse1 &&
1742 rm -rf sub &&
1743 mkdir sub &&
1744 (
1745 cd sub &&
1746 git init &&
a881baa2
JS
1747 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1748 git checkout main
68297e0f
JS
1749 ) &&
1750 git submodule init &&
1751 git submodule update
1752'
1753
1754test_expect_success 'P: verbatim SHA gitlinks' '
1755 SUBLAST=$(git rev-parse --verify sub) &&
1756 SUBPREV=$(git rev-parse --verify sub^) &&
1757
1758 cat >input <<-INPUT_END &&
1759 blob
1760 mark :1
1761 data <<DATAEND
1762 [submodule "sub"]
1763 path = sub
80a6b3f0 1764 url = "$(pwd)/sub"
68297e0f
JS
1765 DATAEND
1766
1767 commit refs/heads/subuse2
1768 mark :2
1769 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1770 data 8
1771 initial
a881baa2 1772 from refs/heads/main
68297e0f
JS
1773 M 100644 :1 .gitmodules
1774 M 160000 $SUBPREV sub
1775
1776 commit refs/heads/subuse2
1777 mark :3
1778 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1779 data 7
1780 second
1781 from :2
1782 M 160000 $SUBLAST sub
1783
1784 INPUT_END
1785
1786 git branch -D sub &&
c58100ab 1787 git gc --prune=now &&
68297e0f
JS
1788 git fast-import <input &&
1789 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1790'
1791
1792test_expect_success 'P: fail on inline gitlink' '
1793 test_tick &&
1794 cat >input <<-INPUT_END &&
1795 commit refs/heads/subuse3
1796 mark :1
1797 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1798 data <<COMMIT
1799 corrupt
1800 COMMIT
1801
1802 from refs/heads/subuse2
1803 M 160000 inline sub
1804 data <<DATA
1805 $SUBPREV
1806 DATA
1807
1808 INPUT_END
1809
1810 test_must_fail git fast-import <input
1811'
1812
1813test_expect_success 'P: fail on blob mark in gitlink' '
1814 test_tick &&
1815 cat >input <<-INPUT_END &&
1816 blob
1817 mark :1
1818 data <<DATA
1819 $SUBPREV
1820 DATA
1821
1822 commit refs/heads/subuse3
1823 mark :2
1824 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1825 data <<COMMIT
1826 corrupt
1827 COMMIT
1828
1829 from refs/heads/subuse2
1830 M 160000 :1 sub
1831
1832 INPUT_END
1833
1834 test_must_fail git fast-import <input
1835'
1836
1837###
1838### series Q (notes)
1839###
1840
1841test_expect_success 'Q: commit notes' '
1842 note1_data="The first note for the first commit" &&
1843 note2_data="The first note for the second commit" &&
1844 note3_data="The first note for the third commit" &&
1845 note1b_data="The second note for the first commit" &&
1846 note1c_data="The third note for the first commit" &&
1847 note2b_data="The second note for the second commit" &&
1848
1849 test_tick &&
1850 cat >input <<-INPUT_END &&
1851 blob
1852 mark :2
1853 data <<EOF
1854 $file2_data
1855 EOF
1856
1857 commit refs/heads/notes-test
1858 mark :3
1859 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1860 data <<COMMIT
1861 first (:3)
1862 COMMIT
1863
1864 M 644 :2 file2
03db4525 1865
68297e0f
JS
1866 blob
1867 mark :4
1868 data $file4_len
1869 $file4_data
1870 commit refs/heads/notes-test
1871 mark :5
1872 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1873 data <<COMMIT
1874 second (:5)
1875 COMMIT
03db4525 1876
68297e0f 1877 M 644 :4 file4
03db4525 1878
68297e0f
JS
1879 commit refs/heads/notes-test
1880 mark :6
1881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1882 data <<COMMIT
1883 third (:6)
1884 COMMIT
03db4525 1885
68297e0f
JS
1886 M 644 inline file5
1887 data <<EOF
1888 $file5_data
1889 EOF
03db4525 1890
68297e0f
JS
1891 M 755 inline file6
1892 data <<EOF
1893 $file6_data
1894 EOF
03db4525 1895
68297e0f
JS
1896 blob
1897 mark :7
1898 data <<EOF
1899 $note1_data
1900 EOF
03db4525 1901
68297e0f
JS
1902 blob
1903 mark :8
1904 data <<EOF
1905 $note2_data
1906 EOF
03db4525 1907
68297e0f
JS
1908 commit refs/notes/foobar
1909 mark :9
1910 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1911 data <<COMMIT
1912 notes (:9)
1913 COMMIT
03db4525 1914
68297e0f
JS
1915 N :7 :3
1916 N :8 :5
1917 N inline :6
1918 data <<EOF
1919 $note3_data
1920 EOF
03db4525 1921
68297e0f
JS
1922 commit refs/notes/foobar
1923 mark :10
1924 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1925 data <<COMMIT
1926 notes (:10)
1927 COMMIT
03db4525 1928
68297e0f
JS
1929 N inline :3
1930 data <<EOF
1931 $note1b_data
1932 EOF
03db4525 1933
68297e0f
JS
1934 commit refs/notes/foobar2
1935 mark :11
1936 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1937 data <<COMMIT
1938 notes (:11)
1939 COMMIT
03db4525 1940
68297e0f
JS
1941 N inline :3
1942 data <<EOF
1943 $note1c_data
1944 EOF
03db4525 1945
68297e0f
JS
1946 commit refs/notes/foobar
1947 mark :12
1948 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1949 data <<COMMIT
1950 notes (:12)
1951 COMMIT
1952
1953 deleteall
1954 N inline :5
1955 data <<EOF
1956 $note2b_data
1957 EOF
a8dd2e7d 1958
68297e0f 1959 INPUT_END
2a113aee 1960
d67824fe
JS
1961 git fast-import <input &&
1962 git whatchanged notes-test
1963'
05880b02
JS
1964
1965test_expect_success 'Q: verify pack' '
1966 verify_packs
1967'
a8dd2e7d 1968
68297e0f
JS
1969test_expect_success 'Q: verify first commit' '
1970 commit1=$(git rev-parse notes-test~2) &&
1971 commit2=$(git rev-parse notes-test^) &&
1972 commit3=$(git rev-parse notes-test) &&
a8dd2e7d 1973
68297e0f
JS
1974 cat >expect <<-EOF &&
1975 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1976 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
a8dd2e7d 1977
68297e0f
JS
1978 first (:3)
1979 EOF
d67824fe
JS
1980 git cat-file commit notes-test~2 | sed 1d >actual &&
1981 test_cmp expect actual
1982'
a8dd2e7d 1983
d67824fe 1984test_expect_success 'Q: verify second commit' '
68297e0f
JS
1985 cat >expect <<-EOF &&
1986 parent $commit1
1987 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1988 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1989
1990 second (:5)
1991 EOF
d67824fe
JS
1992 git cat-file commit notes-test^ | sed 1d >actual &&
1993 test_cmp expect actual
1994'
a8dd2e7d 1995
d67824fe 1996test_expect_success 'Q: verify third commit' '
68297e0f
JS
1997 cat >expect <<-EOF &&
1998 parent $commit2
1999 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2000 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2001
2002 third (:6)
2003 EOF
d67824fe
JS
2004 git cat-file commit notes-test | sed 1d >actual &&
2005 test_cmp expect actual
2006'
a8dd2e7d 2007
d67824fe 2008test_expect_success 'Q: verify first notes commit' '
68297e0f
JS
2009 cat >expect <<-EOF &&
2010 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2011 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2012
2013 notes (:9)
2014 EOF
d67824fe
JS
2015 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2016 test_cmp expect actual
2017'
a8dd2e7d 2018
d67824fe 2019test_expect_success 'Q: verify first notes tree' '
af7dd8bd 2020 sort >expect <<-EOF &&
68297e0f
JS
2021 100644 blob $commit1
2022 100644 blob $commit2
2023 100644 blob $commit3
2024 EOF
d67824fe
JS
2025 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2026 test_cmp expect actual
2027'
a8dd2e7d 2028
d67824fe 2029test_expect_success 'Q: verify first note for first commit' '
68297e0f 2030 echo "$note1_data" >expect &&
ec2c10be
JS
2031 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2032 test_cmp expect actual
d67824fe 2033'
a8dd2e7d 2034
d67824fe 2035test_expect_success 'Q: verify first note for second commit' '
68297e0f 2036 echo "$note2_data" >expect &&
ec2c10be
JS
2037 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2038 test_cmp expect actual
d67824fe 2039'
2a113aee 2040
d67824fe 2041test_expect_success 'Q: verify first note for third commit' '
68297e0f 2042 echo "$note3_data" >expect &&
ec2c10be
JS
2043 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2044 test_cmp expect actual
d67824fe 2045'
2a113aee 2046
d67824fe 2047test_expect_success 'Q: verify second notes commit' '
68297e0f 2048 cat >expect <<-EOF &&
80a6b3f0 2049 parent $(git rev-parse --verify refs/notes/foobar~2)
68297e0f
JS
2050 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2051 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2052
2053 notes (:10)
2054 EOF
d67824fe
JS
2055 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2056 test_cmp expect actual
2057'
2a113aee 2058
d67824fe 2059test_expect_success 'Q: verify second notes tree' '
af7dd8bd 2060 sort >expect <<-EOF &&
68297e0f
JS
2061 100644 blob $commit1
2062 100644 blob $commit2
2063 100644 blob $commit3
2064 EOF
d67824fe
JS
2065 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2066 test_cmp expect actual
2067'
2a113aee 2068
d67824fe 2069test_expect_success 'Q: verify second note for first commit' '
68297e0f 2070 echo "$note1b_data" >expect &&
ec2c10be
JS
2071 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2072 test_cmp expect actual
d67824fe 2073'
2a113aee 2074
d67824fe 2075test_expect_success 'Q: verify first note for second commit' '
68297e0f 2076 echo "$note2_data" >expect &&
ec2c10be
JS
2077 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2078 test_cmp expect actual
d67824fe 2079'
a8dd2e7d 2080
d67824fe 2081test_expect_success 'Q: verify first note for third commit' '
68297e0f 2082 echo "$note3_data" >expect &&
ec2c10be
JS
2083 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2084 test_cmp expect actual
d67824fe 2085'
2a113aee 2086
d67824fe 2087test_expect_success 'Q: verify third notes commit' '
68297e0f
JS
2088 cat >expect <<-EOF &&
2089 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2090 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2091
2092 notes (:11)
2093 EOF
d67824fe
JS
2094 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2095 test_cmp expect actual
2096'
2a113aee 2097
d67824fe 2098test_expect_success 'Q: verify third notes tree' '
af7dd8bd 2099 sort >expect <<-EOF &&
68297e0f
JS
2100 100644 blob $commit1
2101 EOF
d67824fe
JS
2102 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2103 test_cmp expect actual
2104'
2a113aee 2105
d67824fe 2106test_expect_success 'Q: verify third note for first commit' '
68297e0f 2107 echo "$note1c_data" >expect &&
ec2c10be
JS
2108 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2109 test_cmp expect actual
d67824fe 2110'
2a113aee 2111
d67824fe 2112test_expect_success 'Q: verify fourth notes commit' '
68297e0f 2113 cat >expect <<-EOF &&
80a6b3f0 2114 parent $(git rev-parse --verify refs/notes/foobar^)
68297e0f
JS
2115 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2116 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2117
2118 notes (:12)
2119 EOF
d67824fe
JS
2120 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2121 test_cmp expect actual
2122'
2a113aee 2123
d67824fe 2124test_expect_success 'Q: verify fourth notes tree' '
af7dd8bd 2125 sort >expect <<-EOF &&
68297e0f
JS
2126 100644 blob $commit2
2127 EOF
d67824fe
JS
2128 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2129 test_cmp expect actual
2130'
2a113aee 2131
d67824fe 2132test_expect_success 'Q: verify second note for second commit' '
68297e0f 2133 echo "$note2b_data" >expect &&
ec2c10be
JS
2134 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2135 test_cmp expect actual
d67824fe 2136'
a8dd2e7d 2137
68297e0f
JS
2138test_expect_success 'Q: deny note on empty branch' '
2139 cat >input <<-EOF &&
2140 reset refs/heads/Q0
0bc69881 2141
68297e0f
JS
2142 commit refs/heads/note-Q0
2143 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2144 data <<COMMIT
2145 Note for an empty branch.
2146 COMMIT
0bc69881 2147
68297e0f
JS
2148 N inline refs/heads/Q0
2149 data <<NOTE
2150 some note
2151 NOTE
2152 EOF
d67824fe
JS
2153 test_must_fail git fast-import <input
2154'
0df86b66 2155
f963bd5d 2156###
2792f26c 2157### series R (feature and option)
f963bd5d
SR
2158###
2159
f963bd5d 2160test_expect_success 'R: abort on unsupported feature' '
68297e0f
JS
2161 cat >input <<-EOF &&
2162 feature no-such-feature-exists
2163 EOF
2164
f963bd5d
SR
2165 test_must_fail git fast-import <input
2166'
2167
f963bd5d 2168test_expect_success 'R: supported feature is accepted' '
68297e0f
JS
2169 cat >input <<-EOF &&
2170 feature date-format=now
2171 EOF
2172
f963bd5d
SR
2173 git fast-import <input
2174'
2175
f963bd5d 2176test_expect_success 'R: abort on receiving feature after data command' '
68297e0f
JS
2177 cat >input <<-EOF &&
2178 blob
2179 data 3
2180 hi
2181 feature date-format=now
2182 EOF
2183
f963bd5d
SR
2184 test_must_fail git fast-import <input
2185'
2186
a52ed761
JK
2187test_expect_success 'R: import-marks features forbidden by default' '
2188 >git.marks &&
2189 echo "feature import-marks=git.marks" >input &&
2190 test_must_fail git fast-import <input &&
2191 echo "feature import-marks-if-exists=git.marks" >input &&
2192 test_must_fail git fast-import <input
2193'
2194
081751c8 2195test_expect_success 'R: only one import-marks feature allowed per stream' '
816f8067
JK
2196 >git.marks &&
2197 >git2.marks &&
68297e0f
JS
2198 cat >input <<-EOF &&
2199 feature import-marks=git.marks
2200 feature import-marks=git2.marks
2201 EOF
2202
a52ed761 2203 test_must_fail git fast-import --allow-unsafe-features <input
081751c8
SR
2204'
2205
68061e34
JK
2206test_expect_success 'R: export-marks feature forbidden by default' '
2207 echo "feature export-marks=git.marks" >input &&
081751c8
SR
2208 test_must_fail git fast-import <input
2209'
2210
68297e0f
JS
2211test_expect_success 'R: export-marks feature results in a marks file being created' '
2212 cat >input <<-EOF &&
2213 feature export-marks=git.marks
2214 blob
2215 mark :1
2216 data 3
2217 hi
f963bd5d 2218
68297e0f 2219 EOF
f963bd5d 2220
68061e34 2221 git fast-import --allow-unsafe-features <input &&
d67824fe
JS
2222 grep :1 git.marks
2223'
f963bd5d 2224
d67824fe 2225test_expect_success 'R: export-marks options can be overridden by commandline options' '
01968302
JK
2226 cat >input <<-\EOF &&
2227 feature export-marks=feature-sub/git.marks
2228 blob
2229 mark :1
2230 data 3
2231 hi
2232
2233 EOF
68061e34
JK
2234 git fast-import --allow-unsafe-features \
2235 --export-marks=cmdline-sub/other.marks <input &&
01968302
JK
2236 grep :1 cmdline-sub/other.marks &&
2237 test_path_is_missing feature-sub
d67824fe 2238'
f963bd5d 2239
dded4f12
RR
2240test_expect_success 'R: catch typo in marks file name' '
2241 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2242 echo "feature import-marks=nonexistent.marks" |
68061e34 2243 test_must_fail git fast-import --allow-unsafe-features
dded4f12
RR
2244'
2245
2246test_expect_success 'R: import and output marks can be the same file' '
2247 rm -f io.marks &&
2248 blob=$(echo hi | git hash-object --stdin) &&
2249 cat >expect <<-EOF &&
2250 :1 $blob
2251 :2 $blob
2252 EOF
2253 git fast-import --export-marks=io.marks <<-\EOF &&
2254 blob
2255 mark :1
2256 data 3
2257 hi
2258
2259 EOF
2260 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2261 blob
2262 mark :2
2263 data 3
2264 hi
2265
2266 EOF
2267 test_cmp expect io.marks
2268'
2269
2270test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2271 rm -f io.marks &&
2272 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2273 blob
2274 mark :1
2275 data 3
2276 hi
2277
2278 EOF
2279'
2280
2281test_expect_success 'R: --import-marks-if-exists' '
2282 rm -f io.marks &&
2283 blob=$(echo hi | git hash-object --stdin) &&
2284 echo ":1 $blob" >expect &&
2285 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2286 blob
2287 mark :1
2288 data 3
2289 hi
2290
2291 EOF
2292 test_cmp expect io.marks
2293'
2294
3beb4fc4
DI
2295test_expect_success 'R: feature import-marks-if-exists' '
2296 rm -f io.marks &&
3beb4fc4 2297
a52ed761
JK
2298 git fast-import --export-marks=io.marks \
2299 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2300 feature import-marks-if-exists=not_io.marks
2301 EOF
d3c6751b 2302 test_must_be_empty io.marks &&
3beb4fc4
DI
2303
2304 blob=$(echo hi | git hash-object --stdin) &&
2305
2306 echo ":1 $blob" >io.marks &&
2307 echo ":1 $blob" >expect &&
2308 echo ":2 $blob" >>expect &&
2309
a52ed761
JK
2310 git fast-import --export-marks=io.marks \
2311 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2312 feature import-marks-if-exists=io.marks
2313 blob
2314 mark :2
2315 data 3
2316 hi
2317
2318 EOF
2319 test_cmp expect io.marks &&
2320
2321 echo ":3 $blob" >>expect &&
2322
2323 git fast-import --import-marks=io.marks \
a52ed761
JK
2324 --export-marks=io.marks \
2325 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2326 feature import-marks-if-exists=not_io.marks
2327 blob
2328 mark :3
2329 data 3
2330 hi
2331
2332 EOF
2333 test_cmp expect io.marks &&
2334
3beb4fc4 2335 git fast-import --import-marks-if-exists=not_io.marks \
a52ed761
JK
2336 --export-marks=io.marks \
2337 --allow-unsafe-features <<-\EOF &&
3beb4fc4
DI
2338 feature import-marks-if-exists=io.marks
2339 EOF
d3c6751b 2340 test_must_be_empty io.marks
3beb4fc4
DI
2341'
2342
d67824fe 2343test_expect_success 'R: import to output marks works without any content' '
68297e0f
JS
2344 cat >input <<-EOF &&
2345 feature import-marks=marks.out
2346 feature export-marks=marks.new
2347 EOF
2348
68061e34 2349 git fast-import --allow-unsafe-features <input &&
d67824fe
JS
2350 test_cmp marks.out marks.new
2351'
f963bd5d 2352
d67824fe 2353test_expect_success 'R: import marks prefers commandline marks file over the stream' '
68297e0f
JS
2354 cat >input <<-EOF &&
2355 feature import-marks=nonexistent.marks
2356 feature export-marks=marks.new
2357 EOF
2358
68061e34 2359 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
d67824fe
JS
2360 test_cmp marks.out marks.new
2361'
f963bd5d 2362
081751c8 2363
081751c8 2364test_expect_success 'R: multiple --import-marks= should be honoured' '
68297e0f
JS
2365 cat >input <<-EOF &&
2366 feature import-marks=nonexistent.marks
2367 feature export-marks=combined.marks
2368 EOF
2369
d67824fe
JS
2370 head -n2 marks.out > one.marks &&
2371 tail -n +3 marks.out > two.marks &&
68061e34
JK
2372 git fast-import --import-marks=one.marks --import-marks=two.marks \
2373 --allow-unsafe-features <input &&
d67824fe 2374 test_cmp marks.out combined.marks
081751c8
SR
2375'
2376
bc3c79ae 2377test_expect_success 'R: feature relative-marks should be honoured' '
68297e0f
JS
2378 cat >input <<-EOF &&
2379 feature relative-marks
2380 feature import-marks=relative.in
2381 feature export-marks=relative.out
2382 EOF
2383
d67824fe
JS
2384 mkdir -p .git/info/fast-import/ &&
2385 cp marks.new .git/info/fast-import/relative.in &&
68061e34 2386 git fast-import --allow-unsafe-features <input &&
d67824fe 2387 test_cmp marks.new .git/info/fast-import/relative.out
bc3c79ae
SR
2388'
2389
bc3c79ae 2390test_expect_success 'R: feature no-relative-marks should be honoured' '
68297e0f
JS
2391 cat >input <<-EOF &&
2392 feature relative-marks
2393 feature import-marks=relative.in
2394 feature no-relative-marks
2395 feature export-marks=non-relative.out
2396 EOF
2397
68061e34 2398 git fast-import --allow-unsafe-features <input &&
d67824fe 2399 test_cmp marks.new non-relative.out
bc3c79ae
SR
2400'
2401
8dc6a373
DB
2402test_expect_success 'R: feature ls supported' '
2403 echo "feature ls" |
2404 git fast-import
2405'
2406
85c62395
DB
2407test_expect_success 'R: feature cat-blob supported' '
2408 echo "feature cat-blob" |
2409 git fast-import
2410'
2411
2412test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2413 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2414'
2415
f57a8715 2416test_expect_success !MINGW 'R: print old blob' '
85c62395
DB
2417 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2418 cat >expect <<-EOF &&
2419 ${blob} blob 11
2420 yes it can
2421
2422 EOF
2423 echo "cat-blob $blob" |
2424 git fast-import --cat-blob-fd=6 6>actual &&
2425 test_cmp expect actual
2426'
2427
f57a8715 2428test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
85c62395
DB
2429 echo hello >greeting &&
2430 blob=$(git hash-object -w greeting) &&
2431 cat >expect <<-EOF &&
2432 ${blob} blob 6
2433 hello
2434
2435 EOF
2436 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2437 cat-blob $blob
2438 EOF
2439 test_cmp expect actual.3 &&
acf3af25 2440 test_must_be_empty actual.1 &&
85c62395
DB
2441 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2442 option cat-blob-fd=3
2443 cat-blob $blob
2444 EOF
acf3af25 2445 test_must_be_empty actual.3 &&
85c62395
DB
2446 test_cmp expect actual.1
2447'
2448
28c7b1f7
MH
2449test_expect_success !MINGW 'R: print mark for new blob' '
2450 echo "effluentish" | git hash-object --stdin >expect &&
2451 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2452 blob
2453 mark :1
2454 data <<BLOB_END
2455 effluentish
2456 BLOB_END
2457 get-mark :1
2458 EOF
2459 test_cmp expect actual
2460'
2461
f57a8715 2462test_expect_success !MINGW 'R: print new blob' '
85c62395
DB
2463 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2464 cat >expect <<-EOF &&
2465 ${blob} blob 12
2466 yep yep yep
2467
2468 EOF
2469 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2470 blob
2471 mark :1
2472 data <<BLOB_END
2473 yep yep yep
2474 BLOB_END
2475 cat-blob :1
2476 EOF
2477 test_cmp expect actual
2478'
2479
f57a8715 2480test_expect_success !MINGW 'R: print new blob by sha1' '
85c62395
DB
2481 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2482 cat >expect <<-EOF &&
2483 ${blob} blob 25
2484 a new blob named by sha1
2485
2486 EOF
2487 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2488 blob
2489 data <<BLOB_END
2490 a new blob named by sha1
2491 BLOB_END
2492 cat-blob $blob
2493 EOF
2494 test_cmp expect actual
2495'
2496
2497test_expect_success 'setup: big file' '
2498 (
2499 echo "the quick brown fox jumps over the lazy dog" >big &&
2500 for i in 1 2 3
2501 do
2502 cat big big big big >bigger &&
2503 cat bigger bigger bigger bigger >big ||
2504 exit
2505 done
2506 )
2507'
2508
2509test_expect_success 'R: print two blobs to stdout' '
2510 blob1=$(git hash-object big) &&
2511 blob1_len=$(wc -c <big) &&
2512 blob2=$(echo hello | git hash-object --stdin) &&
2513 {
2514 echo ${blob1} blob $blob1_len &&
2515 cat big &&
2516 cat <<-EOF
2517
2518 ${blob2} blob 6
2519 hello
2520
2521 EOF
2522 } >expect &&
2523 {
2524 cat <<-\END_PART1 &&
2525 blob
2526 mark :1
2527 data <<data_end
2528 END_PART1
2529 cat big &&
2530 cat <<-\EOF
2531 data_end
2532 blob
2533 mark :2
2534 data <<data_end
2535 hello
2536 data_end
2537 cat-blob :1
2538 cat-blob :2
2539 EOF
2540 } |
2541 git fast-import >actual &&
2542 test_cmp expect actual
2543'
2544
85c62395
DB
2545test_expect_success PIPE 'R: copy using cat-file' '
2546 expect_id=$(git hash-object big) &&
2547 expect_len=$(wc -c <big) &&
2548 echo $expect_id blob $expect_len >expect.response &&
2549
2550 rm -f blobs &&
85c62395
DB
2551
2552 mkfifo blobs &&
2553 (
2554 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
4de0bbd8
JN
2555 cat <<-\EOF &&
2556 feature cat-blob
2557 blob
2558 mark :1
2559 data <<BLOB
2560 EOF
2561 cat big &&
2562 cat <<-\EOF &&
2563 BLOB
2564 cat-blob :1
2565 EOF
2566
2567 read blob_id type size <&3 &&
2568 echo "$blob_id $type $size" >response &&
48860819 2569 test_copy_bytes $size >blob <&3 &&
4de0bbd8
JN
2570 read newline <&3 &&
2571
2572 cat <<-EOF &&
2573 commit refs/heads/copied
2574 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2575 data <<COMMIT
2576 copy big file as file3
2577 COMMIT
2578 M 644 inline file3
2579 data <<BLOB
2580 EOF
2581 cat blob &&
2582 echo BLOB
2583 ) 3<blobs |
2584 git fast-import --cat-blob-fd=3 3>blobs &&
85c62395
DB
2585 git show copied:file3 >actual &&
2586 test_cmp expect.response response &&
2587 test_cmp big actual
2588'
2589
777f80d7
JN
2590test_expect_success PIPE 'R: print blob mid-commit' '
2591 rm -f blobs &&
2592 echo "A blob from _before_ the commit." >expect &&
2593 mkfifo blobs &&
2594 (
2595 exec 3<blobs &&
2596 cat <<-EOF &&
2597 feature cat-blob
2598 blob
2599 mark :1
2600 data <<BLOB
2601 A blob from _before_ the commit.
2602 BLOB
2603 commit refs/heads/temporary
2604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2605 data <<COMMIT
2606 Empty commit
2607 COMMIT
2608 cat-blob :1
2609 EOF
2610
2611 read blob_id type size <&3 &&
48860819 2612 test_copy_bytes $size >actual <&3 &&
777f80d7
JN
2613 read newline <&3 &&
2614
2615 echo
2616 ) |
2617 git fast-import --cat-blob-fd=3 3>blobs &&
2618 test_cmp expect actual
2619'
2620
2621test_expect_success PIPE 'R: print staged blob within commit' '
2622 rm -f blobs &&
2623 echo "A blob from _within_ the commit." >expect &&
2624 mkfifo blobs &&
2625 (
2626 exec 3<blobs &&
2627 cat <<-EOF &&
2628 feature cat-blob
2629 commit refs/heads/within
2630 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2631 data <<COMMIT
2632 Empty commit
2633 COMMIT
2634 M 644 inline within
2635 data <<BLOB
2636 A blob from _within_ the commit.
2637 BLOB
2638 EOF
2639
2640 to_get=$(
2641 echo "A blob from _within_ the commit." |
2642 git hash-object --stdin
2643 ) &&
2644 echo "cat-blob $to_get" &&
2645
2646 read blob_id type size <&3 &&
48860819 2647 test_copy_bytes $size >actual <&3 &&
777f80d7
JN
2648 read newline <&3 &&
2649
2650 echo deleteall
2651 ) |
2652 git fast-import --cat-blob-fd=3 3>blobs &&
2653 test_cmp expect actual
2654'
2655
68297e0f
JS
2656test_expect_success 'R: quiet option results in no stats being output' '
2657 cat >input <<-EOF &&
2658 option git quiet
2659 blob
2660 data 3
2661 hi
2792f26c 2662
68297e0f 2663 EOF
2792f26c 2664
f94804c1 2665 git fast-import 2>output <input &&
acf3af25 2666 test_must_be_empty output
2792f26c
SR
2667'
2668
be56862f
SR
2669test_expect_success 'R: feature done means terminating "done" is mandatory' '
2670 echo feature done | test_must_fail git fast-import &&
2671 test_must_fail git fast-import --done </dev/null
2672'
2673
2674test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2675 git fast-import <<-\EOF &&
2676 feature done
2677 done
2678 trailing gibberish
2679 EOF
2680 git fast-import <<-\EOF
2681 done
2682 more trailing gibberish
2683 EOF
2684'
2685
2686test_expect_success 'R: terminating "done" within commit' '
2687 cat >expect <<-\EOF &&
2688 OBJID
2689 :000000 100644 OBJID OBJID A hello.c
2690 :000000 100644 OBJID OBJID A hello2.c
2691 EOF
2692 git fast-import <<-EOF &&
2693 commit refs/heads/done-ends
2694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2695 data <<EOT
2696 Commit terminated by "done" command
2697 EOT
2698 M 100644 inline hello.c
2699 data <<EOT
2700 Hello, world.
2701 EOT
2702 C hello.c hello2.c
2703 done
2704 EOF
2705 git rev-list done-ends |
2706 git diff-tree -r --stdin --root --always |
2ece6ad2 2707 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
be56862f
SR
2708 test_cmp expect actual
2709'
2710
2792f26c 2711test_expect_success 'R: die on unknown option' '
68297e0f
JS
2712 cat >input <<-EOF &&
2713 option git non-existing-option
2714 EOF
2715
d67824fe 2716 test_must_fail git fast-import <input
2792f26c
SR
2717'
2718
2719test_expect_success 'R: unknown commandline options are rejected' '\
d67824fe 2720 test_must_fail git fast-import --non-existing-option < /dev/null
2792f26c
SR
2721'
2722
a9ff277e
JN
2723test_expect_success 'R: die on invalid option argument' '
2724 echo "option git active-branches=-5" |
2725 test_must_fail git fast-import &&
2726 echo "option git depth=" |
2727 test_must_fail git fast-import &&
2728 test_must_fail git fast-import --depth="5 elephants" </dev/null
2729'
2730
2792f26c 2731test_expect_success 'R: ignore non-git options' '
68297e0f
JS
2732 cat >input <<-EOF &&
2733 option non-existing-vcs non-existing-option
2734 EOF
2735
d67824fe 2736 git fast-import <input
2792f26c
SR
2737'
2738
f4beed60
FC
2739test_expect_success 'R: corrupt lines do not mess marks file' '
2740 rm -f io.marks &&
2741 blob=$(echo hi | git hash-object --stdin) &&
2742 cat >expect <<-EOF &&
287bb3ab 2743 :3 $ZERO_OID
f4beed60
FC
2744 :1 $blob
2745 :2 $blob
2746 EOF
2747 cp expect io.marks &&
2748 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2749
2750 EOF
2751 test_cmp expect io.marks
2752'
2753
5eef828b
SP
2754##
2755## R: very large blobs
2756##
d67824fe 2757test_expect_success 'R: blob bigger than threshold' '
68297e0f 2758 blobsize=$((2*1024*1024 + 53)) &&
c680668d 2759 test-tool genrandom bar $blobsize >expect &&
68297e0f
JS
2760 cat >input <<-INPUT_END &&
2761 commit refs/heads/big-file
2762 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2763 data <<COMMIT
2764 R - big file
2765 COMMIT
2766
2767 M 644 inline big1
2768 data $blobsize
2769 INPUT_END
2770 cat expect >>input &&
2771 cat >>input <<-INPUT_END &&
2772 M 644 inline big2
2773 data $blobsize
2774 INPUT_END
2775 cat expect >>input &&
2776 echo >>input &&
2777
d67824fe 2778 test_create_repo R &&
d9545c7f 2779 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
d67824fe
JS
2780 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2781'
05880b02
JS
2782
2783test_expect_success 'R: verify created pack' '
2784 (
2785 cd R &&
2786 verify_packs -v > ../verify
2787 )
2788'
2789
d67824fe
JS
2790test_expect_success 'R: verify written objects' '
2791 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2792 test_cmp_bin expect actual &&
2793 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2794 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2795 test $a = $b
2796'
2797
2798test_expect_success 'R: blob appears only once' '
2799 n=$(grep $a verify | wc -l) &&
2800 test 1 = $n
2801'
5eef828b 2802
06454cb9 2803###
0df86b66 2804### series S (mark and path parsing)
06454cb9
PW
2805###
2806#
2807# Make sure missing spaces and EOLs after mark references
2808# cause errors.
2809#
2810# Setup:
2811#
2812# 1--2--4
2813# \ /
2814# -3-
2815#
2816# commit marks: 301, 302, 303, 304
2817# blob marks: 403, 404, resp.
2818# note mark: 202
2819#
2820# The error message when a space is missing not at the
2821# end of the line is:
2822#
2823# Missing space after ..
2824#
2825# or when extra characters come after the mark at the end
2826# of the line:
2827#
2828# Garbage after ..
2829#
2830# or when the dataref is neither "inline " or a known SHA1,
2831#
2832# Invalid dataref ..
2833#
06454cb9 2834test_expect_success 'S: initialize for S tests' '
68297e0f
JS
2835 test_tick &&
2836
2837 cat >input <<-INPUT_END &&
2838 commit refs/heads/S
2839 mark :301
2840 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2841 data <<COMMIT
2842 commit 1
2843 COMMIT
2844 M 100644 inline hello.c
2845 data <<BLOB
2846 blob 1
2847 BLOB
2848
2849 commit refs/heads/S
2850 mark :302
2851 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2852 data <<COMMIT
2853 commit 2
2854 COMMIT
2855 from :301
2856 M 100644 inline hello.c
2857 data <<BLOB
2858 blob 2
2859 BLOB
2860
2861 blob
2862 mark :403
2863 data <<BLOB
2864 blob 3
2865 BLOB
2866
2867 blob
2868 mark :202
2869 data <<BLOB
2870 note 2
2871 BLOB
2872 INPUT_END
2873
06454cb9
PW
2874 git fast-import --export-marks=marks <input
2875'
2876
2877#
2878# filemodify, three datarefs
2879#
2880test_expect_success 'S: filemodify with garbage after mark must fail' '
2881 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2882 commit refs/heads/S
2883 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2884 data <<COMMIT
2885 commit N
2886 COMMIT
2887 M 100644 :403x hello.c
2888 EOF
6789275d 2889 test_grep "space after mark" err
06454cb9
PW
2890'
2891
2892# inline is misspelled; fast-import thinks it is some unknown dataref
2893test_expect_success 'S: filemodify with garbage after inline must fail' '
2894 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2895 commit refs/heads/S
2896 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2897 data <<COMMIT
2898 commit N
2899 COMMIT
2900 M 100644 inlineX hello.c
2901 data <<BLOB
2902 inline
2903 BLOB
2904 EOF
6789275d 2905 test_grep "nvalid dataref" err
06454cb9
PW
2906'
2907
2908test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2909 sha1=$(grep :403 marks | cut -d\ -f2) &&
2910 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2911 commit refs/heads/S
2912 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2913 data <<COMMIT
2914 commit N
2915 COMMIT
2916 M 100644 ${sha1}x hello.c
2917 EOF
6789275d 2918 test_grep "space after SHA1" err
06454cb9
PW
2919'
2920
2921#
2922# notemodify, three ways to say dataref
2923#
64127575 2924test_expect_success 'S: notemodify with garbage after mark dataref must fail' '
06454cb9
PW
2925 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2926 commit refs/heads/S
2927 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2928 data <<COMMIT
2929 commit S note dataref markref
2930 COMMIT
2931 N :202x :302
2932 EOF
6789275d 2933 test_grep "space after mark" err
06454cb9
PW
2934'
2935
2936test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2937 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2938 commit refs/heads/S
2939 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2940 data <<COMMIT
2941 commit S note dataref inline
2942 COMMIT
2943 N inlineX :302
2944 data <<BLOB
2945 note blob
2946 BLOB
2947 EOF
6789275d 2948 test_grep "nvalid dataref" err
06454cb9
PW
2949'
2950
2951test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2952 sha1=$(grep :202 marks | cut -d\ -f2) &&
2953 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2954 commit refs/heads/S
2955 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2956 data <<COMMIT
2957 commit S note dataref sha1
2958 COMMIT
2959 N ${sha1}x :302
2960 EOF
6789275d 2961 test_grep "space after SHA1" err
06454cb9
PW
2962'
2963
2964#
a8a5406a 2965# notemodify, mark in commit-ish
06454cb9 2966#
634c42da 2967test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
06454cb9
PW
2968 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2969 commit refs/heads/Snotes
2970 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2971 data <<COMMIT
a8a5406a 2972 commit S note commit-ish
06454cb9
PW
2973 COMMIT
2974 N :202 :302x
2975 EOF
6789275d 2976 test_grep "after mark" err
06454cb9
PW
2977'
2978
2979#
2980# from
2981#
2982test_expect_success 'S: from with garbage after mark must fail' '
0a5e3c50
JK
2983 test_must_fail \
2984 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
06454cb9
PW
2985 commit refs/heads/S2
2986 mark :303
2987 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2988 data <<COMMIT
2989 commit 3
2990 COMMIT
2991 from :301x
2992 M 100644 :403 hello.c
2993 EOF
2994
06454cb9
PW
2995
2996 # go create the commit, need it for merge test
2997 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2998 commit refs/heads/S2
2999 mark :303
3000 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3001 data <<COMMIT
3002 commit 3
3003 COMMIT
3004 from :301
3005 M 100644 :403 hello.c
3006 EOF
3007
3008 # now evaluate the error
6789275d 3009 test_grep "after mark" err
06454cb9
PW
3010'
3011
3012
3013#
3014# merge
3015#
3016test_expect_success 'S: merge with garbage after mark must fail' '
3017 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3018 commit refs/heads/S
3019 mark :304
3020 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3021 data <<COMMIT
3022 merge 4
3023 COMMIT
3024 from :302
3025 merge :303x
3026 M 100644 :403 hello.c
3027 EOF
6789275d 3028 test_grep "after mark" err
06454cb9
PW
3029'
3030
3031#
3032# tag, from markref
3033#
3034test_expect_success 'S: tag with garbage after mark must fail' '
3035 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3036 tag refs/tags/Stag
3037 from :302x
3038 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3039 data <<TAG
3040 tag S
3041 TAG
3042 EOF
6789275d 3043 test_grep "after mark" err
06454cb9
PW
3044'
3045
3046#
3047# cat-blob markref
3048#
3049test_expect_success 'S: cat-blob with garbage after mark must fail' '
3050 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3051 cat-blob :403x
3052 EOF
6789275d 3053 test_grep "after mark" err
06454cb9
PW
3054'
3055
3056#
3057# ls markref
3058#
3059test_expect_success 'S: ls with garbage after mark must fail' '
3060 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3061 ls :302x hello.c
3062 EOF
6789275d 3063 test_grep "space after mark" err
06454cb9
PW
3064'
3065
3066test_expect_success 'S: ls with garbage after sha1 must fail' '
3067 sha1=$(grep :302 marks | cut -d\ -f2) &&
3068 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3069 ls ${sha1}x hello.c
3070 EOF
6789275d 3071 test_grep "space after tree-ish" err
06454cb9
PW
3072'
3073
0df86b66
TA
3074#
3075# Path parsing
3076#
3077# There are two sorts of ways a path can be parsed, depending on whether it is
3078# the last field on the line. Additionally, ls without a <dataref> has a special
3079# case. Test every occurrence of <path> in the grammar against every error case.
b5062f75 3080# Paths for the root (empty strings) are tested elsewhere.
0df86b66
TA
3081#
3082
3083#
3084# Valid paths at the end of a line: filemodify, filedelete, filecopy (dest),
3085# filerename (dest), and ls.
3086#
3087# commit :301 from root -- modify hello.c (for setup)
3088# commit :302 from :301 -- modify $path
3089# commit :303 from :302 -- delete $path
3090# commit :304 from :301 -- copy hello.c $path
3091# commit :305 from :301 -- rename hello.c $path
3092# ls :305 $path
3093#
3094test_path_eol_success () {
3095 local test="$1" path="$2" unquoted_path="$3"
3096 test_expect_success "S: paths at EOL with $test must work" '
3097 test_when_finished "git branch -D S-path-eol" &&
3098
3099 git fast-import --export-marks=marks.out <<-EOF >out 2>err &&
3100 blob
3101 mark :401
3102 data <<BLOB
3103 hello world
3104 BLOB
3105
3106 blob
3107 mark :402
3108 data <<BLOB
3109 hallo welt
3110 BLOB
3111
3112 commit refs/heads/S-path-eol
3113 mark :301
3114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3115 data <<COMMIT
3116 initial commit
3117 COMMIT
3118 M 100644 :401 hello.c
3119
3120 commit refs/heads/S-path-eol
3121 mark :302
3122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3123 data <<COMMIT
3124 commit filemodify
3125 COMMIT
3126 from :301
3127 M 100644 :402 $path
3128
3129 commit refs/heads/S-path-eol
3130 mark :303
3131 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3132 data <<COMMIT
3133 commit filedelete
3134 COMMIT
3135 from :302
3136 D $path
3137
3138 commit refs/heads/S-path-eol
3139 mark :304
3140 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3141 data <<COMMIT
3142 commit filecopy dest
3143 COMMIT
3144 from :301
3145 C hello.c $path
3146
3147 commit refs/heads/S-path-eol
3148 mark :305
3149 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3150 data <<COMMIT
3151 commit filerename dest
3152 COMMIT
3153 from :301
3154 R hello.c $path
3155
3156 ls :305 $path
3157 EOF
3158
3159 commit_m=$(grep :302 marks.out | cut -d\ -f2) &&
3160 commit_d=$(grep :303 marks.out | cut -d\ -f2) &&
3161 commit_c=$(grep :304 marks.out | cut -d\ -f2) &&
3162 commit_r=$(grep :305 marks.out | cut -d\ -f2) &&
3163 blob1=$(grep :401 marks.out | cut -d\ -f2) &&
3164 blob2=$(grep :402 marks.out | cut -d\ -f2) &&
3165
3166 (
3167 printf "100644 blob $blob2\t$unquoted_path\n" &&
3168 printf "100644 blob $blob1\thello.c\n"
3169 ) | sort >tree_m.exp &&
3170 git ls-tree $commit_m | sort >tree_m.out &&
3171 test_cmp tree_m.exp tree_m.out &&
3172
3173 printf "100644 blob $blob1\thello.c\n" >tree_d.exp &&
3174 git ls-tree $commit_d >tree_d.out &&
3175 test_cmp tree_d.exp tree_d.out &&
3176
3177 (
3178 printf "100644 blob $blob1\t$unquoted_path\n" &&
3179 printf "100644 blob $blob1\thello.c\n"
3180 ) | sort >tree_c.exp &&
3181 git ls-tree $commit_c | sort >tree_c.out &&
3182 test_cmp tree_c.exp tree_c.out &&
3183
3184 printf "100644 blob $blob1\t$unquoted_path\n" >tree_r.exp &&
3185 git ls-tree $commit_r >tree_r.out &&
3186 test_cmp tree_r.exp tree_r.out &&
3187
3188 test_cmp out tree_r.exp
3189 '
3190}
3191
a923a04b
TA
3192test_path_eol_success 'quoted spaces' '" hello world.c "' ' hello world.c '
3193test_path_eol_success 'unquoted spaces' ' hello world.c ' ' hello world.c '
3194test_path_eol_success 'octal escapes' '"\150\151\056\143"' 'hi.c'
0df86b66
TA
3195
3196#
3197# Valid paths before a space: filecopy (source) and filerename (source).
3198#
3199# commit :301 from root -- modify $path (for setup)
3200# commit :302 from :301 -- copy $path hello2.c
3201# commit :303 from :301 -- rename $path hello2.c
3202#
3203test_path_space_success () {
3204 local test="$1" path="$2" unquoted_path="$3"
3205 test_expect_success "S: paths before space with $test must work" '
3206 test_when_finished "git branch -D S-path-space" &&
3207
3208 git fast-import --export-marks=marks.out <<-EOF 2>err &&
3209 blob
3210 mark :401
3211 data <<BLOB
3212 hello world
3213 BLOB
3214
3215 commit refs/heads/S-path-space
3216 mark :301
3217 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3218 data <<COMMIT
3219 initial commit
3220 COMMIT
3221 M 100644 :401 $path
3222
3223 commit refs/heads/S-path-space
3224 mark :302
3225 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3226 data <<COMMIT
3227 commit filecopy source
3228 COMMIT
3229 from :301
3230 C $path hello2.c
3231
3232 commit refs/heads/S-path-space
3233 mark :303
3234 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3235 data <<COMMIT
3236 commit filerename source
3237 COMMIT
3238 from :301
3239 R $path hello2.c
3240
3241 EOF
3242
3243 commit_c=$(grep :302 marks.out | cut -d\ -f2) &&
3244 commit_r=$(grep :303 marks.out | cut -d\ -f2) &&
3245 blob=$(grep :401 marks.out | cut -d\ -f2) &&
3246
3247 (
3248 printf "100644 blob $blob\t$unquoted_path\n" &&
3249 printf "100644 blob $blob\thello2.c\n"
3250 ) | sort >tree_c.exp &&
3251 git ls-tree $commit_c | sort >tree_c.out &&
3252 test_cmp tree_c.exp tree_c.out &&
3253
3254 printf "100644 blob $blob\thello2.c\n" >tree_r.exp &&
3255 git ls-tree $commit_r >tree_r.out &&
3256 test_cmp tree_r.exp tree_r.out
3257 '
3258}
3259
a923a04b
TA
3260test_path_space_success 'quoted spaces' '" hello world.c "' ' hello world.c '
3261test_path_space_success 'no unquoted spaces' 'hello_world.c' 'hello_world.c'
3262test_path_space_success 'octal escapes' '"\150\151\056\143"' 'hi.c'
0df86b66
TA
3263
3264#
3265# Test a single commit change with an invalid path. Run it with all occurrences
3266# of <path> in the grammar against all error kinds.
3267#
3268test_path_fail () {
3269 local change="$1" what="$2" prefix="$3" path="$4" suffix="$5" err_grep="$6"
3270 test_expect_success "S: $change with $what must fail" '
3271 test_must_fail git fast-import <<-EOF 2>err &&
3272 blob
3273 mark :1
3274 data <<BLOB
3275 hello world
3276 BLOB
3277
3278 commit refs/heads/S-path-fail
3279 mark :2
3280 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3281 data <<COMMIT
3282 commit setup
3283 COMMIT
3284 M 100644 :1 hello.c
3285
3286 commit refs/heads/S-path-fail
3287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3288 data <<COMMIT
3289 commit with bad path
3290 COMMIT
3291 from :2
3292 $prefix$path$suffix
3293 EOF
3294
3295 test_grep "$err_grep" err
3296 '
3297}
3298
3299test_path_base_fail () {
3300 local change="$1" prefix="$2" field="$3" suffix="$4"
3301 test_path_fail "$change" 'unclosed " in '"$field" "$prefix" '"hello.c' "$suffix" "Invalid $field"
3302 test_path_fail "$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "Invalid $field"
be4d6a37 3303 test_path_fail "$change" "escaped NUL in quoted $field" "$prefix" '"hello\000"' "$suffix" "NUL in $field"
0df86b66
TA
3304}
3305test_path_eol_quoted_fail () {
3306 local change="$1" prefix="$2" field="$3"
3307 test_path_base_fail "$change" "$prefix" "$field" ''
3308 test_path_fail "$change" "garbage after quoted $field" "$prefix" '"hello.c"' 'x' "Garbage after $field"
3309 test_path_fail "$change" "space after quoted $field" "$prefix" '"hello.c"' ' ' "Garbage after $field"
3310}
3311test_path_eol_fail () {
3312 local change="$1" prefix="$2" field="$3"
3313 test_path_eol_quoted_fail "$change" "$prefix" "$field"
3314}
3315test_path_space_fail () {
3316 local change="$1" prefix="$2" field="$3"
3317 test_path_base_fail "$change" "$prefix" "$field" ' world.c'
3318 test_path_fail "$change" "missing space after quoted $field" "$prefix" '"hello.c"' 'x world.c' "Missing space after $field"
3319 test_path_fail "$change" "missing space after unquoted $field" "$prefix" 'hello.c' '' "Missing space after $field"
3320}
3321
3322test_path_eol_fail filemodify 'M 100644 :1 ' path
3323test_path_eol_fail filedelete 'D ' path
3324test_path_space_fail filecopy 'C ' source
3325test_path_eol_fail filecopy 'C hello.c ' dest
3326test_path_space_fail filerename 'R ' source
3327test_path_eol_fail filerename 'R hello.c ' dest
3328test_path_eol_fail 'ls (in commit)' 'ls :2 ' path
3329
3330# When 'ls' has no <dataref>, the <path> must be quoted.
3331test_path_eol_quoted_fail 'ls (without dataref in commit)' 'ls ' path
3332
aca70610
JK
3333###
3334### series T (ls)
3335###
3336# Setup is carried over from series S.
3337
b5062f75
TA
3338for root in '""' ''
3339do
3340 test_expect_success "T: ls root ($root) tree" '
3341 sed -e "s/Z\$//" >expect <<-EOF &&
3342 040000 tree $(git rev-parse S^{tree}) Z
3343 EOF
3344 sha1=$(git rev-parse --verify S) &&
3345 git fast-import --import-marks=marks <<-EOF >actual &&
3346 ls $sha1 $root
3347 EOF
3348 test_cmp expect actual
3349 '
3350done
aca70610 3351
4ee1b225
FC
3352test_expect_success 'T: delete branch' '
3353 git branch to-delete &&
3354 git fast-import <<-EOF &&
3355 reset refs/heads/to-delete
287bb3ab 3356 from $ZERO_OID
4ee1b225
FC
3357 EOF
3358 test_must_fail git rev-parse --verify refs/heads/to-delete
3359'
3360
3361test_expect_success 'T: empty reset doesnt delete branch' '
3362 git branch not-to-delete &&
3363 git fast-import <<-EOF &&
3364 reset refs/heads/not-to-delete
3365 EOF
3366 git show-ref &&
3367 git rev-parse --verify refs/heads/not-to-delete
3368'
3369
8d30d8a8
MB
3370###
3371### series U (filedelete)
3372###
3373
8d30d8a8 3374test_expect_success 'U: initialize for U tests' '
68297e0f
JS
3375 cat >input <<-INPUT_END &&
3376 commit refs/heads/U
3377 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3378 data <<COMMIT
3379 test setup
3380 COMMIT
3381 M 100644 inline hello.c
3382 data <<BLOB
3383 blob 1
3384 BLOB
3385 M 100644 inline good/night.txt
3386 data <<BLOB
3387 sleep well
3388 BLOB
3389 M 100644 inline good/bye.txt
3390 data <<BLOB
3391 au revoir
3392 BLOB
3393
3394 INPUT_END
3395
22f18244 3396 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3397 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3398 f9id=$(echo "au revoir" | git hash-object --stdin) &&
8d30d8a8
MB
3399 git fast-import <input
3400'
3401
68297e0f
JS
3402test_expect_success 'U: filedelete file succeeds' '
3403 cat >input <<-INPUT_END &&
3404 commit refs/heads/U
3405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3406 data <<COMMIT
3407 delete good/night.txt
3408 COMMIT
3409 from refs/heads/U^0
3410 D good/night.txt
8d30d8a8 3411
68297e0f 3412 INPUT_END
8d30d8a8 3413
8d30d8a8
MB
3414 git fast-import <input
3415'
3416
68297e0f
JS
3417test_expect_success 'U: validate file delete result' '
3418 cat >expect <<-EOF &&
22f18244 3419 :100644 000000 $f8id $ZERO_OID D good/night.txt
68297e0f 3420 EOF
8d30d8a8 3421
68297e0f 3422 git diff-tree -M -r U^1 U >actual &&
8d30d8a8 3423
8d30d8a8
MB
3424 compare_diff_raw expect actual
3425'
3426
68297e0f
JS
3427test_expect_success 'U: filedelete directory succeeds' '
3428 cat >input <<-INPUT_END &&
3429 commit refs/heads/U
3430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3431 data <<COMMIT
3432 delete good dir
3433 COMMIT
3434 from refs/heads/U^0
3435 D good
8d30d8a8 3436
68297e0f 3437 INPUT_END
8d30d8a8 3438
8d30d8a8
MB
3439 git fast-import <input
3440'
3441
68297e0f
JS
3442test_expect_success 'U: validate directory delete result' '
3443 cat >expect <<-EOF &&
22f18244 3444 :100644 000000 $f9id $ZERO_OID D good/bye.txt
68297e0f 3445 EOF
8d30d8a8 3446
68297e0f 3447 git diff-tree -M -r U^1 U >actual &&
8d30d8a8 3448
8d30d8a8
MB
3449 compare_diff_raw expect actual
3450'
3451
b5062f75
TA
3452for root in '""' ''
3453do
3454 test_expect_success "U: filedelete root ($root) succeeds" '
3455 cat >input <<-INPUT_END &&
3456 commit refs/heads/U-delete-root
3457 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3458 data <<COMMIT
3459 must succeed
3460 COMMIT
3461 from refs/heads/U^0
3462 D $root
8d30d8a8 3463
b5062f75 3464 INPUT_END
8d30d8a8 3465
b5062f75
TA
3466 git fast-import <input
3467 '
8d30d8a8 3468
b5062f75
TA
3469 test_expect_success "U: validate root ($root) delete result" '
3470 cat >expect <<-EOF &&
3471 :100644 000000 $f7id $ZERO_OID D hello.c
3472 EOF
8d30d8a8 3473
b5062f75 3474 git diff-tree -M -r U U-delete-root >actual &&
8d30d8a8 3475
b5062f75
TA
3476 compare_diff_raw expect actual
3477 '
3478done
8d30d8a8 3479
30e215a6
ER
3480###
3481### series V (checkpoint)
3482###
3483
3484# The commands in input_file should not produce any output on the file
3485# descriptor set with --cat-blob-fd (or stdout if unspecified).
3486#
3487# To make sure you're observing the side effects of checkpoint *before*
3488# fast-import terminates (and thus writes out its state), check that the
3489# fast-import process is still running using background_import_still_running
3490# *after* evaluating the test conditions.
3491background_import_then_checkpoint () {
3492 options=$1
3493 input_file=$2
3494
3495 mkfifo V.input
3496 exec 8<>V.input
3497 rm V.input
3498
3499 mkfifo V.output
3500 exec 9<>V.output
3501 rm V.output
3502
0d9b0d78
SG
3503 (
3504 git fast-import $options <&8 >&9 &
3505 echo $! >&9
3506 wait $!
3507 echo >&2 "background fast-import terminated too early with exit code $?"
3508 # Un-block the read loop in the main shell process.
3509 echo >&9 UNEXPECTED
3510 ) &
3511 sh_pid=$!
3512 read fi_pid <&9
30e215a6
ER
3513 # We don't mind if fast-import has already died by the time the test
3514 # ends.
ab29f1b3
SG
3515 test_when_finished "
3516 exec 8>&-; exec 9>&-;
0d9b0d78 3517 kill $sh_pid && wait $sh_pid
21f57620 3518 kill $fi_pid && wait $fi_pid
ab29f1b3 3519 true"
30e215a6
ER
3520
3521 # Start in the background to ensure we adhere strictly to (blocking)
3522 # pipes writing sequence. We want to assume that the write below could
3523 # block, e.g. if fast-import blocks writing its own output to &9
3524 # because there is no reader on &9 yet.
3525 (
3526 cat "$input_file"
3527 echo "checkpoint"
3528 echo "progress checkpoint"
3529 ) >&8 &
3530
3531 error=1 ;# assume the worst
3532 while read output <&9
3533 do
3534 if test "$output" = "progress checkpoint"
3535 then
3536 error=0
3537 break
0d9b0d78
SG
3538 elif test "$output" = "UNEXPECTED"
3539 then
3540 break
30e215a6
ER
3541 fi
3542 # otherwise ignore cruft
3543 echo >&2 "cruft: $output"
3544 done
3545
3546 if test $error -eq 1
3547 then
3548 false
3549 fi
3550}
3551
3552background_import_still_running () {
21f57620 3553 if ! kill -0 "$fi_pid"
30e215a6
ER
3554 then
3555 echo >&2 "background fast-import terminated too early"
3556 false
3557 fi
3558}
3559
3560test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' '
3561 cat >input <<-INPUT_END &&
3562 progress foo
3563 progress bar
3564
3565 INPUT_END
3566
3567 background_import_then_checkpoint "" input &&
3568 background_import_still_running
3569'
3570
3571test_expect_success PIPE 'V: checkpoint updates refs after reset' '
3572 cat >input <<-\INPUT_END &&
3573 reset refs/heads/V
3574 from refs/heads/U
3575
3576 INPUT_END
3577
3578 background_import_then_checkpoint "" input &&
3579 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3580 background_import_still_running
3581'
3582
3583test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' '
3584 cat >input <<-INPUT_END &&
3585 commit refs/heads/V
3586 mark :1
3587 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3588 data 0
3589 from refs/heads/U
3590
3591 INPUT_END
3592
3593 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3594
3595 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3596
3597 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3598 test_cmp marks.expected marks.actual &&
3599 background_import_still_running
3600'
3601
3602# Re-create the exact same commit, but on a different branch: no new object is
3603# created in the database, but the refs and marks still need to be updated.
3604test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' '
3605 cat >input <<-INPUT_END &&
3606 commit refs/heads/V2
3607 mark :2
3608 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3609 data 0
3610 from refs/heads/U
3611
3612 INPUT_END
3613
3614 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3615
3616 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3617
3618 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3619 test_cmp marks.expected marks.actual &&
3620 background_import_still_running
3621'
3622
3623test_expect_success PIPE 'V: checkpoint updates tags after tag' '
3624 cat >input <<-INPUT_END &&
3625 tag Vtag
3626 from refs/heads/V
3627 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3628 data 0
3629
3630 INPUT_END
3631
3632 background_import_then_checkpoint "" input &&
3633 git show-ref -d Vtag &&
3634 background_import_still_running
3635'
3636
62edbec7
EN
3637###
3638### series W (get-mark and empty orphan commits)
3639###
3640
3641cat >>W-input <<-W_INPUT_END
3642 commit refs/heads/W-branch
3643 mark :1
3644 author Full Name <user@company.tld> 1000000000 +0100
3645 committer Full Name <user@company.tld> 1000000000 +0100
3646 data 27
3647 Intentionally empty commit
3648 LFsget-mark :1
3649 W_INPUT_END
3650
cf7b857a 3651test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' '
62edbec7
EN
3652 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3653'
3654
cf7b857a 3655test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' '
62edbec7
EN
3656 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3657'
3658
3659test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' '
3660 # Technically, this should fail as it has too many linefeeds
3661 # according to the grammar in fast-import.txt. But, for whatever
3662 # reason, it works. Since using the correct number of newlines
3663 # does not work with older (pre-2.22) versions of git, allow apps
3664 # that used this second-newline workaround to keep working by
3665 # checking it with this test...
3666 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3667'
3668
3669test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' '
3670 # ...but do NOT allow more empty lines than that (see previous test).
3671 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3672'
3673
3edfcc65
EN
3674###
3675### series X (other new features)
3676###
3677
3678test_expect_success 'X: handling encoding' '
3679 test_tick &&
3680 cat >input <<-INPUT_END &&
3681 commit refs/heads/encoding
3682 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3683 encoding iso-8859-7
3684 data <<COMMIT
3685 INPUT_END
3686
3687 printf "Pi: \360\nCOMMIT\n" >>input &&
3688
3689 git fast-import <input &&
3690 git cat-file -p encoding | grep $(printf "\360") &&
3691 git log -1 --format=%B encoding | grep $(printf "\317\200")
3692'
3693
1bdca816 3694###
3695### series Y (submodules and hash algorithms)
3696###
3697
3698cat >Y-sub-input <<\Y_INPUT_END
3699blob
3700mark :1
3701data 4
3702foo
3703
a881baa2
JS
3704reset refs/heads/main
3705commit refs/heads/main
1bdca816 3706mark :2
3707author Full Name <user@company.tld> 1000000000 +0100
3708committer Full Name <user@company.tld> 1000000000 +0100
3709data 24
3710Test submodule commit 1
3711M 100644 :1 file
3712
3713blob
3714mark :3
3715data 8
3716foo
3717bar
3718
a881baa2 3719commit refs/heads/main
1bdca816 3720mark :4
3721author Full Name <user@company.tld> 1000000001 +0100
3722committer Full Name <user@company.tld> 1000000001 +0100
3723data 24
3724Test submodule commit 2
3725from :2
3726M 100644 :3 file
3727Y_INPUT_END
3728
3729# Note that the submodule object IDs are intentionally not translated.
3730cat >Y-main-input <<\Y_INPUT_END
3731blob
3732mark :1
3733data 4
3734foo
3735
a881baa2
JS
3736reset refs/heads/main
3737commit refs/heads/main
1bdca816 3738mark :2
3739author Full Name <user@company.tld> 2000000000 +0100
3740committer Full Name <user@company.tld> 2000000000 +0100
3741data 14
3742Test commit 1
3743M 100644 :1 file
3744
3745blob
3746mark :3
3747data 73
3748[submodule "sub1"]
3749 path = sub1
3750 url = https://void.example.com/main.git
3751
a881baa2 3752commit refs/heads/main
1bdca816 3753mark :4
3754author Full Name <user@company.tld> 2000000001 +0100
3755committer Full Name <user@company.tld> 2000000001 +0100
3756data 14
3757Test commit 2
3758from :2
3759M 100644 :3 .gitmodules
3760M 160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3761
3762blob
3763mark :5
3764data 8
3765foo
3766bar
3767
a881baa2 3768commit refs/heads/main
1bdca816 3769mark :6
3770author Full Name <user@company.tld> 2000000002 +0100
3771committer Full Name <user@company.tld> 2000000002 +0100
3772data 14
3773Test commit 3
3774from :4
3775M 100644 :5 file
3776M 160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3777Y_INPUT_END
3778
3779cat >Y-marks <<\Y_INPUT_END
3780:2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3781:4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3782Y_INPUT_END
3783
3784test_expect_success 'Y: setup' '
3785 test_oid_cache <<-EOF
a881baa2
JS
3786 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3787 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
1bdca816 3788 EOF
3789'
3790
3791test_expect_success 'Y: rewrite submodules' '
3792 git init main1 &&
3793 (
3794 cd main1 &&
3795 git init sub2 &&
3796 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3797 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3798 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
a881baa2 3799 test "$(git rev-parse main)" = "$(test_oid Ymain)"
1bdca816 3800 )
3801'
3802
50aee995 3803test_done