Merge branch 'tr/maint-apply-non-git-patch-parsefix'
[git] / t / t9300-fast-import.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Shawn Pearce
4 #
5
6 test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
9
10 # Print $1 bytes from stdin to stdout.
11 #
12 # This could be written as "head -c $1", but IRIX "head" does not
13 # support the -c option.
14 head_c () {
15         "$PERL_PATH" -e '
16                 my $len = $ARGV[1];
17                 while ($len > 0) {
18                         my $s;
19                         my $nread = sysread(STDIN, $s, $len);
20                         die "cannot read: $!" unless defined($nread);
21                         print $s;
22                         $len -= $nread;
23                 }
24         ' - "$1"
25 }
26
27 verify_packs () {
28         for p in .git/objects/pack/*.pack
29         do
30                 git verify-pack "$@" "$p" || return
31         done
32 }
33
34 file2_data='file2
35 second line of EOF'
36
37 file3_data='EOF
38 in 3rd file
39  END'
40
41 file4_data=abcd
42 file4_len=4
43
44 file5_data='an inline file.
45   we should see it later.'
46
47 file6_data='#!/bin/sh
48 echo "$@"'
49
50 >empty
51
52 ###
53 ### series A
54 ###
55
56 test_tick
57
58 test_expect_success 'empty stream succeeds' '
59         git fast-import </dev/null
60 '
61
62 cat >input <<INPUT_END
63 blob
64 mark :2
65 data <<EOF
66 $file2_data
67 EOF
68
69 blob
70 mark :3
71 data <<END
72 $file3_data
73 END
74
75 blob
76 mark :4
77 data $file4_len
78 $file4_data
79 commit refs/heads/master
80 mark :5
81 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82 data <<COMMIT
83 initial
84 COMMIT
85
86 M 644 :2 file2
87 M 644 :3 file3
88 M 755 :4 file4
89
90 tag series-A
91 from :5
92 data <<EOF
93 An annotated tag without a tagger
94 EOF
95
96 tag series-A-blob
97 from :3
98 data <<EOF
99 An annotated tag that annotates a blob.
100 EOF
101
102 INPUT_END
103 test_expect_success \
104     'A: create pack from stdin' \
105     'git fast-import --export-marks=marks.out <input &&
106          git whatchanged master'
107
108 test_expect_success 'A: verify pack' '
109         verify_packs
110 '
111
112 cat >expect <<EOF
113 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
115
116 initial
117 EOF
118 test_expect_success \
119         'A: verify commit' \
120         'git cat-file commit master | sed 1d >actual &&
121         test_cmp expect actual'
122
123 cat >expect <<EOF
124 100644 blob file2
125 100644 blob file3
126 100755 blob file4
127 EOF
128 test_expect_success \
129         'A: verify tree' \
130         'git cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
131          test_cmp expect actual'
132
133 echo "$file2_data" >expect
134 test_expect_success \
135         'A: verify file2' \
136         'git cat-file blob master:file2 >actual && test_cmp expect actual'
137
138 echo "$file3_data" >expect
139 test_expect_success \
140         'A: verify file3' \
141         'git cat-file blob master:file3 >actual && test_cmp expect actual'
142
143 printf "$file4_data" >expect
144 test_expect_success \
145         'A: verify file4' \
146         'git cat-file blob master:file4 >actual && test_cmp expect actual'
147
148 cat >expect <<EOF
149 object $(git rev-parse refs/heads/master)
150 type commit
151 tag series-A
152
153 An annotated tag without a tagger
154 EOF
155 test_expect_success 'A: verify tag/series-A' '
156         git cat-file tag tags/series-A >actual &&
157         test_cmp expect actual
158 '
159
160 cat >expect <<EOF
161 object $(git rev-parse refs/heads/master:file3)
162 type blob
163 tag series-A-blob
164
165 An annotated tag that annotates a blob.
166 EOF
167 test_expect_success 'A: verify tag/series-A-blob' '
168         git cat-file tag tags/series-A-blob >actual &&
169         test_cmp expect actual
170 '
171
172 cat >expect <<EOF
173 :2 `git rev-parse --verify master:file2`
174 :3 `git rev-parse --verify master:file3`
175 :4 `git rev-parse --verify master:file4`
176 :5 `git rev-parse --verify master^0`
177 EOF
178 test_expect_success \
179         'A: verify marks output' \
180         'test_cmp expect marks.out'
181
182 test_expect_success \
183         'A: verify marks import' \
184         'git fast-import \
185                 --import-marks=marks.out \
186                 --export-marks=marks.new \
187                 </dev/null &&
188         test_cmp expect marks.new'
189
190 test_tick
191 new_blob=$(echo testing | git hash-object --stdin)
192 cat >input <<INPUT_END
193 tag series-A-blob-2
194 from $(git rev-parse refs/heads/master:file3)
195 data <<EOF
196 Tag blob by sha1.
197 EOF
198
199 blob
200 mark :6
201 data <<EOF
202 testing
203 EOF
204
205 commit refs/heads/new_blob
206 committer  <> 0 +0000
207 data 0
208 M 644 :6 new_blob
209 #pretend we got sha1 from fast-import
210 ls "new_blob"
211
212 tag series-A-blob-3
213 from $new_blob
214 data <<EOF
215 Tag new_blob.
216 EOF
217 INPUT_END
218
219 cat >expect <<EOF
220 object $(git rev-parse refs/heads/master:file3)
221 type blob
222 tag series-A-blob-2
223
224 Tag blob by sha1.
225 object $new_blob
226 type blob
227 tag series-A-blob-3
228
229 Tag new_blob.
230 EOF
231
232 test_expect_success \
233         'A: tag blob by sha1' \
234         'git fast-import <input &&
235         git cat-file tag tags/series-A-blob-2 >actual &&
236         git cat-file tag tags/series-A-blob-3 >>actual &&
237         test_cmp expect actual'
238
239 test_tick
240 cat >input <<INPUT_END
241 commit refs/heads/verify--import-marks
242 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
243 data <<COMMIT
244 recreate from :5
245 COMMIT
246
247 from :5
248 M 755 :2 copy-of-file2
249
250 INPUT_END
251 test_expect_success \
252         'A: verify marks import does not crash' \
253         'git fast-import --import-marks=marks.out <input &&
254          git whatchanged verify--import-marks'
255
256 test_expect_success 'A: verify pack' '
257         verify_packs
258 '
259
260 cat >expect <<EOF
261 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
262 EOF
263 git diff-tree -M -r master verify--import-marks >actual
264 test_expect_success \
265         'A: verify diff' \
266         'compare_diff_raw expect actual &&
267          test `git rev-parse --verify master:file2` \
268             = `git rev-parse --verify verify--import-marks:copy-of-file2`'
269
270 test_tick
271 mt=$(git hash-object --stdin < /dev/null)
272 : >input.blob
273 : >marks.exp
274 : >tree.exp
275
276 cat >input.commit <<EOF
277 commit refs/heads/verify--dump-marks
278 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
279 data <<COMMIT
280 test the sparse array dumping routines with exponentially growing marks
281 COMMIT
282 EOF
283
284 i=0
285 l=4
286 m=6
287 n=7
288 while test "$i" -lt 27; do
289     cat >>input.blob <<EOF
290 blob
291 mark :$l
292 data 0
293 blob
294 mark :$m
295 data 0
296 blob
297 mark :$n
298 data 0
299 EOF
300     echo "M 100644 :$l l$i" >>input.commit
301     echo "M 100644 :$m m$i" >>input.commit
302     echo "M 100644 :$n n$i" >>input.commit
303
304     echo ":$l $mt" >>marks.exp
305     echo ":$m $mt" >>marks.exp
306     echo ":$n $mt" >>marks.exp
307
308     printf "100644 blob $mt\tl$i\n" >>tree.exp
309     printf "100644 blob $mt\tm$i\n" >>tree.exp
310     printf "100644 blob $mt\tn$i\n" >>tree.exp
311
312     l=$(($l + $l))
313     m=$(($m + $m))
314     n=$(($l + $n))
315
316     i=$((1 + $i))
317 done
318
319 sort tree.exp > tree.exp_s
320
321 test_expect_success 'A: export marks with large values' '
322         cat input.blob input.commit | git fast-import --export-marks=marks.large &&
323         git ls-tree refs/heads/verify--dump-marks >tree.out &&
324         test_cmp tree.exp_s tree.out &&
325         test_cmp marks.exp marks.large'
326
327 ###
328 ### series B
329 ###
330
331 test_tick
332 cat >input <<INPUT_END
333 commit refs/heads/branch
334 mark :1
335 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
336 data <<COMMIT
337 corrupt
338 COMMIT
339
340 from refs/heads/master
341 M 755 0000000000000000000000000000000000000001 zero1
342
343 INPUT_END
344 test_expect_success 'B: fail on invalid blob sha1' '
345     test_must_fail git fast-import <input
346 '
347 rm -f .git/objects/pack_* .git/objects/index_*
348
349 cat >input <<INPUT_END
350 commit .badbranchname
351 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
352 data <<COMMIT
353 corrupt
354 COMMIT
355
356 from refs/heads/master
357
358 INPUT_END
359 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
360     test_must_fail git fast-import <input
361 '
362 rm -f .git/objects/pack_* .git/objects/index_*
363
364 cat >input <<INPUT_END
365 commit bad[branch]name
366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
367 data <<COMMIT
368 corrupt
369 COMMIT
370
371 from refs/heads/master
372
373 INPUT_END
374 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
375     test_must_fail git fast-import <input
376 '
377 rm -f .git/objects/pack_* .git/objects/index_*
378
379 cat >input <<INPUT_END
380 commit TEMP_TAG
381 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
382 data <<COMMIT
383 tag base
384 COMMIT
385
386 from refs/heads/master
387
388 INPUT_END
389 test_expect_success \
390     'B: accept branch name "TEMP_TAG"' \
391     'git fast-import <input &&
392          test -f .git/TEMP_TAG &&
393          test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
394 rm -f .git/TEMP_TAG
395
396 git gc 2>/dev/null >/dev/null
397 git prune 2>/dev/null >/dev/null
398
399 cat >input <<INPUT_END
400 commit refs/heads/empty-committer-1
401 committer  <> $GIT_COMMITTER_DATE
402 data <<COMMIT
403 empty commit
404 COMMIT
405 INPUT_END
406 test_expect_success 'B: accept empty committer' '
407         git fast-import <input &&
408         out=$(git fsck) &&
409         echo "$out" &&
410         test -z "$out"
411 '
412 git update-ref -d refs/heads/empty-committer-1 || true
413
414 git gc 2>/dev/null >/dev/null
415 git prune 2>/dev/null >/dev/null
416
417 cat >input <<INPUT_END
418 commit refs/heads/empty-committer-2
419 committer <a@b.com> $GIT_COMMITTER_DATE
420 data <<COMMIT
421 empty commit
422 COMMIT
423 INPUT_END
424 test_expect_success 'B: accept and fixup committer with no name' '
425         git fast-import <input &&
426         out=$(git fsck) &&
427         echo "$out" &&
428         test -z "$out"
429 '
430 git update-ref -d refs/heads/empty-committer-2 || true
431
432 git gc 2>/dev/null >/dev/null
433 git prune 2>/dev/null >/dev/null
434
435 cat >input <<INPUT_END
436 commit refs/heads/invalid-committer
437 committer Name email> $GIT_COMMITTER_DATE
438 data <<COMMIT
439 empty commit
440 COMMIT
441 INPUT_END
442 test_expect_success 'B: fail on invalid committer (1)' '
443         test_must_fail git fast-import <input
444 '
445 git update-ref -d refs/heads/invalid-committer || true
446
447 cat >input <<INPUT_END
448 commit refs/heads/invalid-committer
449 committer Name <e<mail> $GIT_COMMITTER_DATE
450 data <<COMMIT
451 empty commit
452 COMMIT
453 INPUT_END
454 test_expect_success 'B: fail on invalid committer (2)' '
455         test_must_fail git fast-import <input
456 '
457 git update-ref -d refs/heads/invalid-committer || true
458
459 cat >input <<INPUT_END
460 commit refs/heads/invalid-committer
461 committer Name <email>> $GIT_COMMITTER_DATE
462 data <<COMMIT
463 empty commit
464 COMMIT
465 INPUT_END
466 test_expect_success 'B: fail on invalid committer (3)' '
467         test_must_fail git fast-import <input
468 '
469 git update-ref -d refs/heads/invalid-committer || true
470
471 cat >input <<INPUT_END
472 commit refs/heads/invalid-committer
473 committer Name <email $GIT_COMMITTER_DATE
474 data <<COMMIT
475 empty commit
476 COMMIT
477 INPUT_END
478 test_expect_success 'B: fail on invalid committer (4)' '
479         test_must_fail git fast-import <input
480 '
481 git update-ref -d refs/heads/invalid-committer || true
482
483 cat >input <<INPUT_END
484 commit refs/heads/invalid-committer
485 committer Name<email> $GIT_COMMITTER_DATE
486 data <<COMMIT
487 empty commit
488 COMMIT
489 INPUT_END
490 test_expect_success 'B: fail on invalid committer (5)' '
491         test_must_fail git fast-import <input
492 '
493 git update-ref -d refs/heads/invalid-committer || true
494
495 ###
496 ### series C
497 ###
498
499 newf=`echo hi newf | git hash-object -w --stdin`
500 oldf=`git rev-parse --verify master:file2`
501 test_tick
502 cat >input <<INPUT_END
503 commit refs/heads/branch
504 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
505 data <<COMMIT
506 second
507 COMMIT
508
509 from refs/heads/master
510 M 644 $oldf file2/oldf
511 M 755 $newf file2/newf
512 D file3
513
514 INPUT_END
515 test_expect_success \
516     'C: incremental import create pack from stdin' \
517     'git fast-import <input &&
518          git whatchanged branch'
519
520 test_expect_success 'C: verify pack' '
521         verify_packs
522 '
523
524 test_expect_success \
525         'C: validate reuse existing blob' \
526         'test $newf = `git rev-parse --verify branch:file2/newf` &&
527          test $oldf = `git rev-parse --verify branch:file2/oldf`'
528
529 cat >expect <<EOF
530 parent `git rev-parse --verify master^0`
531 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
532 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
533
534 second
535 EOF
536 test_expect_success \
537         'C: verify commit' \
538         'git cat-file commit branch | sed 1d >actual &&
539          test_cmp expect actual'
540
541 cat >expect <<EOF
542 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
543 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
544 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
545 EOF
546 git diff-tree -M -r master branch >actual
547 test_expect_success \
548         'C: validate rename result' \
549         'compare_diff_raw expect actual'
550
551 ###
552 ### series D
553 ###
554
555 test_tick
556 cat >input <<INPUT_END
557 commit refs/heads/branch
558 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
559 data <<COMMIT
560 third
561 COMMIT
562
563 from refs/heads/branch^0
564 M 644 inline newdir/interesting
565 data <<EOF
566 $file5_data
567 EOF
568
569 M 755 inline newdir/exec.sh
570 data <<EOF
571 $file6_data
572 EOF
573
574 INPUT_END
575 test_expect_success \
576     'D: inline data in commit' \
577     'git fast-import <input &&
578          git whatchanged branch'
579
580 test_expect_success 'D: verify pack' '
581         verify_packs
582 '
583
584 cat >expect <<EOF
585 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
586 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
587 EOF
588 git diff-tree -M -r branch^ branch >actual
589 test_expect_success \
590         'D: validate new files added' \
591         'compare_diff_raw expect actual'
592
593 echo "$file5_data" >expect
594 test_expect_success \
595         'D: verify file5' \
596         'git cat-file blob branch:newdir/interesting >actual &&
597          test_cmp expect actual'
598
599 echo "$file6_data" >expect
600 test_expect_success \
601         'D: verify file6' \
602         'git cat-file blob branch:newdir/exec.sh >actual &&
603          test_cmp expect actual'
604
605 ###
606 ### series E
607 ###
608
609 cat >input <<INPUT_END
610 commit refs/heads/branch
611 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
613 data <<COMMIT
614 RFC 2822 type date
615 COMMIT
616
617 from refs/heads/branch^0
618
619 INPUT_END
620 test_expect_success 'E: rfc2822 date, --date-format=raw' '
621     test_must_fail git fast-import --date-format=raw <input
622 '
623 test_expect_success \
624     'E: rfc2822 date, --date-format=rfc2822' \
625     'git fast-import --date-format=rfc2822 <input'
626
627 test_expect_success 'E: verify pack' '
628         verify_packs
629 '
630
631 cat >expect <<EOF
632 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
633 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
634
635 RFC 2822 type date
636 EOF
637 test_expect_success \
638         'E: verify commit' \
639         'git cat-file commit branch | sed 1,2d >actual &&
640         test_cmp expect actual'
641
642 ###
643 ### series F
644 ###
645
646 old_branch=`git rev-parse --verify branch^0`
647 test_tick
648 cat >input <<INPUT_END
649 commit refs/heads/branch
650 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
651 data <<COMMIT
652 losing things already?
653 COMMIT
654
655 from refs/heads/branch~1
656
657 reset refs/heads/other
658 from refs/heads/branch
659
660 INPUT_END
661 test_expect_success \
662     'F: non-fast-forward update skips' \
663     'if git fast-import <input
664          then
665                 echo BAD gfi did not fail
666                 return 1
667          else
668                 if test $old_branch = `git rev-parse --verify branch^0`
669                 then
670                         : branch unaffected and failure returned
671                         return 0
672                 else
673                         echo BAD gfi changed branch $old_branch
674                         return 1
675                 fi
676          fi
677         '
678
679 test_expect_success 'F: verify pack' '
680         verify_packs
681 '
682
683 cat >expect <<EOF
684 tree `git rev-parse branch~1^{tree}`
685 parent `git rev-parse branch~1`
686 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
687 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
688
689 losing things already?
690 EOF
691 test_expect_success \
692         'F: verify other commit' \
693         'git cat-file commit other >actual &&
694         test_cmp expect actual'
695
696 ###
697 ### series G
698 ###
699
700 old_branch=`git rev-parse --verify branch^0`
701 test_tick
702 cat >input <<INPUT_END
703 commit refs/heads/branch
704 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
705 data <<COMMIT
706 losing things already?
707 COMMIT
708
709 from refs/heads/branch~1
710
711 INPUT_END
712 test_expect_success \
713     'G: non-fast-forward update forced' \
714     'git fast-import --force <input'
715
716 test_expect_success 'G: verify pack' '
717         verify_packs
718 '
719
720 test_expect_success \
721         'G: branch changed, but logged' \
722         'test $old_branch != `git rev-parse --verify branch^0` &&
723          test $old_branch = `git rev-parse --verify branch@{1}`'
724
725 ###
726 ### series H
727 ###
728
729 test_tick
730 cat >input <<INPUT_END
731 commit refs/heads/H
732 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
733 data <<COMMIT
734 third
735 COMMIT
736
737 from refs/heads/branch^0
738 M 644 inline i-will-die
739 data <<EOF
740 this file will never exist.
741 EOF
742
743 deleteall
744 M 644 inline h/e/l/lo
745 data <<EOF
746 $file5_data
747 EOF
748
749 INPUT_END
750 test_expect_success \
751     'H: deletall, add 1' \
752     'git fast-import <input &&
753          git whatchanged H'
754
755 test_expect_success 'H: verify pack' '
756         verify_packs
757 '
758
759 cat >expect <<EOF
760 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
761 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
762 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
763 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
764 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
765 EOF
766 git diff-tree -M -r H^ H >actual
767 test_expect_success \
768         'H: validate old files removed, new files added' \
769         'compare_diff_raw expect actual'
770
771 echo "$file5_data" >expect
772 test_expect_success \
773         'H: verify file' \
774         'git cat-file blob H:h/e/l/lo >actual &&
775          test_cmp expect actual'
776
777 ###
778 ### series I
779 ###
780
781 cat >input <<INPUT_END
782 commit refs/heads/export-boundary
783 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
784 data <<COMMIT
785 we have a border.  its only 40 characters wide.
786 COMMIT
787
788 from refs/heads/branch
789
790 INPUT_END
791 test_expect_success \
792     'I: export-pack-edges' \
793     'git fast-import --export-pack-edges=edges.list <input'
794
795 cat >expect <<EOF
796 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
797 EOF
798 test_expect_success \
799         'I: verify edge list' \
800         'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
801          test_cmp expect actual'
802
803 ###
804 ### series J
805 ###
806
807 cat >input <<INPUT_END
808 commit refs/heads/J
809 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
810 data <<COMMIT
811 create J
812 COMMIT
813
814 from refs/heads/branch
815
816 reset refs/heads/J
817
818 commit refs/heads/J
819 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
820 data <<COMMIT
821 initialize J
822 COMMIT
823
824 INPUT_END
825 test_expect_success \
826     'J: reset existing branch creates empty commit' \
827     'git fast-import <input'
828 test_expect_success \
829         'J: branch has 1 commit, empty tree' \
830         'test 1 = `git rev-list J | wc -l` &&
831          test 0 = `git ls-tree J | wc -l`'
832
833 cat >input <<INPUT_END
834 reset refs/heads/J2
835
836 tag wrong_tag
837 from refs/heads/J2
838 data <<EOF
839 Tag branch that was reset.
840 EOF
841 INPUT_END
842 test_expect_success \
843         'J: tag must fail on empty branch' \
844         'test_must_fail git fast-import <input'
845 ###
846 ### series K
847 ###
848
849 cat >input <<INPUT_END
850 commit refs/heads/K
851 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
852 data <<COMMIT
853 create K
854 COMMIT
855
856 from refs/heads/branch
857
858 commit refs/heads/K
859 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
860 data <<COMMIT
861 redo K
862 COMMIT
863
864 from refs/heads/branch^1
865
866 INPUT_END
867 test_expect_success \
868     'K: reinit branch with from' \
869     'git fast-import <input'
870 test_expect_success \
871     'K: verify K^1 = branch^1' \
872     'test `git rev-parse --verify branch^1` \
873                 = `git rev-parse --verify K^1`'
874
875 ###
876 ### series L
877 ###
878
879 cat >input <<INPUT_END
880 blob
881 mark :1
882 data <<EOF
883 some data
884 EOF
885
886 blob
887 mark :2
888 data <<EOF
889 other data
890 EOF
891
892 commit refs/heads/L
893 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
894 data <<COMMIT
895 create L
896 COMMIT
897
898 M 644 :1 b.
899 M 644 :1 b/other
900 M 644 :1 ba
901
902 commit refs/heads/L
903 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
904 data <<COMMIT
905 update L
906 COMMIT
907
908 M 644 :2 b.
909 M 644 :2 b/other
910 M 644 :2 ba
911 INPUT_END
912
913 cat >expect <<EXPECT_END
914 :100644 100644 4268632... 55d3a52... M  b.
915 :040000 040000 0ae5cac... 443c768... M  b
916 :100644 100644 4268632... 55d3a52... M  ba
917 EXPECT_END
918
919 test_expect_success \
920     'L: verify internal tree sorting' \
921         'git fast-import <input &&
922          git diff-tree --abbrev --raw L^ L >output &&
923          test_cmp expect output'
924
925 cat >input <<INPUT_END
926 blob
927 mark :1
928 data <<EOF
929 the data
930 EOF
931
932 commit refs/heads/L2
933 committer C O Mitter <committer@example.com> 1112912473 -0700
934 data <<COMMIT
935 init L2
936 COMMIT
937 M 644 :1 a/b/c
938 M 644 :1 a/b/d
939 M 644 :1 a/e/f
940
941 commit refs/heads/L2
942 committer C O Mitter <committer@example.com> 1112912473 -0700
943 data <<COMMIT
944 update L2
945 COMMIT
946 C a g
947 C a/e g/b
948 M 644 :1 g/b/h
949 INPUT_END
950
951 cat <<EOF >expect
952 g/b/f
953 g/b/h
954 EOF
955
956 test_expect_success \
957     'L: nested tree copy does not corrupt deltas' \
958         'git fast-import <input &&
959         git ls-tree L2 g/b/ >tmp &&
960         cat tmp | cut -f 2 >actual &&
961         test_cmp expect actual &&
962         git fsck `git rev-parse L2`'
963
964 git update-ref -d refs/heads/L2
965
966 ###
967 ### series M
968 ###
969
970 test_tick
971 cat >input <<INPUT_END
972 commit refs/heads/M1
973 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
974 data <<COMMIT
975 file rename
976 COMMIT
977
978 from refs/heads/branch^0
979 R file2/newf file2/n.e.w.f
980
981 INPUT_END
982
983 cat >expect <<EOF
984 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
985 EOF
986 test_expect_success \
987         'M: rename file in same subdirectory' \
988         'git fast-import <input &&
989          git diff-tree -M -r M1^ M1 >actual &&
990          compare_diff_raw expect actual'
991
992 cat >input <<INPUT_END
993 commit refs/heads/M2
994 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
995 data <<COMMIT
996 file rename
997 COMMIT
998
999 from refs/heads/branch^0
1000 R file2/newf i/am/new/to/you
1001
1002 INPUT_END
1003
1004 cat >expect <<EOF
1005 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
1006 EOF
1007 test_expect_success \
1008         'M: rename file to new subdirectory' \
1009         'git fast-import <input &&
1010          git diff-tree -M -r M2^ M2 >actual &&
1011          compare_diff_raw expect actual'
1012
1013 cat >input <<INPUT_END
1014 commit refs/heads/M3
1015 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1016 data <<COMMIT
1017 file rename
1018 COMMIT
1019
1020 from refs/heads/M2^0
1021 R i other/sub
1022
1023 INPUT_END
1024
1025 cat >expect <<EOF
1026 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
1027 EOF
1028 test_expect_success \
1029         'M: rename subdirectory to new subdirectory' \
1030         'git fast-import <input &&
1031          git diff-tree -M -r M3^ M3 >actual &&
1032          compare_diff_raw expect actual'
1033
1034 ###
1035 ### series N
1036 ###
1037
1038 test_tick
1039 cat >input <<INPUT_END
1040 commit refs/heads/N1
1041 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1042 data <<COMMIT
1043 file copy
1044 COMMIT
1045
1046 from refs/heads/branch^0
1047 C file2/newf file2/n.e.w.f
1048
1049 INPUT_END
1050
1051 cat >expect <<EOF
1052 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
1053 EOF
1054 test_expect_success \
1055         'N: copy file in same subdirectory' \
1056         'git fast-import <input &&
1057          git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1058          compare_diff_raw expect actual'
1059
1060 cat >input <<INPUT_END
1061 commit refs/heads/N2
1062 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1063 data <<COMMIT
1064 clean directory copy
1065 COMMIT
1066
1067 from refs/heads/branch^0
1068 C file2 file3
1069
1070 commit refs/heads/N2
1071 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1072 data <<COMMIT
1073 modify directory copy
1074 COMMIT
1075
1076 M 644 inline file3/file5
1077 data <<EOF
1078 $file5_data
1079 EOF
1080
1081 INPUT_END
1082
1083 cat >expect <<EOF
1084 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1085 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1086 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1087 EOF
1088 test_expect_success \
1089         'N: copy then modify subdirectory' \
1090         'git fast-import <input &&
1091          git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1092          compare_diff_raw expect actual'
1093
1094 cat >input <<INPUT_END
1095 commit refs/heads/N3
1096 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1097 data <<COMMIT
1098 dirty directory copy
1099 COMMIT
1100
1101 from refs/heads/branch^0
1102 M 644 inline file2/file5
1103 data <<EOF
1104 $file5_data
1105 EOF
1106
1107 C file2 file3
1108 D file2/file5
1109
1110 INPUT_END
1111
1112 test_expect_success \
1113         'N: copy dirty subdirectory' \
1114         'git fast-import <input &&
1115          test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1116
1117 test_expect_success \
1118         'N: copy directory by id' \
1119         'cat >expect <<-\EOF &&
1120         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1121         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1122         EOF
1123          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1124          cat >input <<-INPUT_END &&
1125         commit refs/heads/N4
1126         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1127         data <<COMMIT
1128         copy by tree hash
1129         COMMIT
1130
1131         from refs/heads/branch^0
1132         M 040000 $subdir file3
1133         INPUT_END
1134          git fast-import <input &&
1135          git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1136          compare_diff_raw expect actual'
1137
1138 test_expect_success PIPE 'N: read and copy directory' '
1139         cat >expect <<-\EOF
1140         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1141         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1142         EOF
1143         git update-ref -d refs/heads/N4 &&
1144         rm -f backflow &&
1145         mkfifo backflow &&
1146         (
1147                 exec <backflow &&
1148                 cat <<-EOF &&
1149                 commit refs/heads/N4
1150                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1151                 data <<COMMIT
1152                 copy by tree hash, part 2
1153                 COMMIT
1154
1155                 from refs/heads/branch^0
1156                 ls "file2"
1157                 EOF
1158                 read mode type tree filename &&
1159                 echo "M 040000 $tree file3"
1160         ) |
1161         git fast-import --cat-blob-fd=3 3>backflow &&
1162         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1163         compare_diff_raw expect actual
1164 '
1165
1166 test_expect_success PIPE 'N: empty directory reads as missing' '
1167         cat <<-\EOF >expect &&
1168         OBJNAME
1169         :000000 100644 OBJNAME OBJNAME A        unrelated
1170         EOF
1171         echo "missing src" >expect.response &&
1172         git update-ref -d refs/heads/read-empty &&
1173         rm -f backflow &&
1174         mkfifo backflow &&
1175         (
1176                 exec <backflow &&
1177                 cat <<-EOF &&
1178                 commit refs/heads/read-empty
1179                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1180                 data <<COMMIT
1181                 read "empty" (missing) directory
1182                 COMMIT
1183
1184                 M 100644 inline src/greeting
1185                 data <<BLOB
1186                 hello
1187                 BLOB
1188                 C src/greeting dst1/non-greeting
1189                 C src/greeting unrelated
1190                 # leave behind "empty" src directory
1191                 D src/greeting
1192                 ls "src"
1193                 EOF
1194                 read -r line &&
1195                 printf "%s\n" "$line" >response &&
1196                 cat <<-\EOF
1197                 D dst1
1198                 D dst2
1199                 EOF
1200         ) |
1201         git fast-import --cat-blob-fd=3 3>backflow &&
1202         test_cmp expect.response response &&
1203         git rev-list read-empty |
1204         git diff-tree -r --root --stdin |
1205         sed "s/$_x40/OBJNAME/g" >actual &&
1206         test_cmp expect actual
1207 '
1208
1209 test_expect_success \
1210         'N: copy root directory by tree hash' \
1211         'cat >expect <<-\EOF &&
1212         :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1213         :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1214         EOF
1215          root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1216          cat >input <<-INPUT_END &&
1217         commit refs/heads/N6
1218         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1219         data <<COMMIT
1220         copy root directory by tree hash
1221         COMMIT
1222
1223         from refs/heads/branch^0
1224         M 040000 $root ""
1225         INPUT_END
1226          git fast-import <input &&
1227          git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1228          compare_diff_raw expect actual'
1229
1230 test_expect_success \
1231         'N: delete directory by copying' \
1232         'cat >expect <<-\EOF &&
1233         OBJID
1234         :100644 000000 OBJID OBJID D    foo/bar/qux
1235         OBJID
1236         :000000 100644 OBJID OBJID A    foo/bar/baz
1237         :000000 100644 OBJID OBJID A    foo/bar/qux
1238         EOF
1239          empty_tree=$(git mktree </dev/null) &&
1240          cat >input <<-INPUT_END &&
1241         commit refs/heads/N-delete
1242         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1243         data <<COMMIT
1244         collect data to be deleted
1245         COMMIT
1246
1247         deleteall
1248         M 100644 inline foo/bar/baz
1249         data <<DATA_END
1250         hello
1251         DATA_END
1252         C "foo/bar/baz" "foo/bar/qux"
1253         C "foo/bar/baz" "foo/bar/quux/1"
1254         C "foo/bar/baz" "foo/bar/quuux"
1255         M 040000 $empty_tree foo/bar/quux
1256         M 040000 $empty_tree foo/bar/quuux
1257
1258         commit refs/heads/N-delete
1259         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1260         data <<COMMIT
1261         delete subdirectory
1262         COMMIT
1263
1264         M 040000 $empty_tree foo/bar/qux
1265         INPUT_END
1266          git fast-import <input &&
1267          git rev-list N-delete |
1268                 git diff-tree -r --stdin --root --always |
1269                 sed -e "s/$_x40/OBJID/g" >actual &&
1270          test_cmp expect actual'
1271
1272 test_expect_success \
1273         'N: modify copied tree' \
1274         'cat >expect <<-\EOF &&
1275         :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1276         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1277         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1278         EOF
1279          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1280          cat >input <<-INPUT_END &&
1281         commit refs/heads/N5
1282         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1283         data <<COMMIT
1284         copy by tree hash
1285         COMMIT
1286
1287         from refs/heads/branch^0
1288         M 040000 $subdir file3
1289
1290         commit refs/heads/N5
1291         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1292         data <<COMMIT
1293         modify directory copy
1294         COMMIT
1295
1296         M 644 inline file3/file5
1297         data <<EOF
1298         $file5_data
1299         EOF
1300         INPUT_END
1301          git fast-import <input &&
1302          git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1303          compare_diff_raw expect actual'
1304
1305 test_expect_success \
1306         'N: reject foo/ syntax' \
1307         'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1308          test_must_fail git fast-import <<-INPUT_END
1309         commit refs/heads/N5B
1310         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1311         data <<COMMIT
1312         copy with invalid syntax
1313         COMMIT
1314
1315         from refs/heads/branch^0
1316         M 040000 $subdir file3/
1317         INPUT_END'
1318
1319 test_expect_success \
1320         'N: reject foo/ syntax in copy source' \
1321         'test_must_fail git fast-import <<-INPUT_END
1322         commit refs/heads/N5C
1323         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1324         data <<COMMIT
1325         copy with invalid syntax
1326         COMMIT
1327
1328         from refs/heads/branch^0
1329         C file2/ file3
1330         INPUT_END'
1331
1332 test_expect_success \
1333         'N: reject foo/ syntax in rename source' \
1334         'test_must_fail git fast-import <<-INPUT_END
1335         commit refs/heads/N5D
1336         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1337         data <<COMMIT
1338         rename with invalid syntax
1339         COMMIT
1340
1341         from refs/heads/branch^0
1342         R file2/ file3
1343         INPUT_END'
1344
1345 test_expect_success \
1346         'N: reject foo/ syntax in ls argument' \
1347         'test_must_fail git fast-import <<-INPUT_END
1348         commit refs/heads/N5E
1349         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1350         data <<COMMIT
1351         copy with invalid syntax
1352         COMMIT
1353
1354         from refs/heads/branch^0
1355         ls "file2/"
1356         INPUT_END'
1357
1358 test_expect_success \
1359         'N: copy to root by id and modify' \
1360         'echo "hello, world" >expect.foo &&
1361          echo hello >expect.bar &&
1362          git fast-import <<-SETUP_END &&
1363         commit refs/heads/N7
1364         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1365         data <<COMMIT
1366         hello, tree
1367         COMMIT
1368
1369         deleteall
1370         M 644 inline foo/bar
1371         data <<EOF
1372         hello
1373         EOF
1374         SETUP_END
1375
1376          tree=$(git rev-parse --verify N7:) &&
1377          git fast-import <<-INPUT_END &&
1378         commit refs/heads/N8
1379         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1380         data <<COMMIT
1381         copy to root by id and modify
1382         COMMIT
1383
1384         M 040000 $tree ""
1385         M 644 inline foo/foo
1386         data <<EOF
1387         hello, world
1388         EOF
1389         INPUT_END
1390          git show N8:foo/foo >actual.foo &&
1391          git show N8:foo/bar >actual.bar &&
1392          test_cmp expect.foo actual.foo &&
1393          test_cmp expect.bar actual.bar'
1394
1395 test_expect_success \
1396         'N: extract subtree' \
1397         'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1398          cat >input <<-INPUT_END &&
1399         commit refs/heads/N9
1400         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1401         data <<COMMIT
1402         extract subtree branch:newdir
1403         COMMIT
1404
1405         M 040000 $branch ""
1406         C "newdir" ""
1407         INPUT_END
1408          git fast-import <input &&
1409          git diff --exit-code branch:newdir N9'
1410
1411 test_expect_success \
1412         'N: modify subtree, extract it, and modify again' \
1413         'echo hello >expect.baz &&
1414          echo hello, world >expect.qux &&
1415          git fast-import <<-SETUP_END &&
1416         commit refs/heads/N10
1417         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418         data <<COMMIT
1419         hello, tree
1420         COMMIT
1421
1422         deleteall
1423         M 644 inline foo/bar/baz
1424         data <<EOF
1425         hello
1426         EOF
1427         SETUP_END
1428
1429          tree=$(git rev-parse --verify N10:) &&
1430          git fast-import <<-INPUT_END &&
1431         commit refs/heads/N11
1432         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1433         data <<COMMIT
1434         copy to root by id and modify
1435         COMMIT
1436
1437         M 040000 $tree ""
1438         M 100644 inline foo/bar/qux
1439         data <<EOF
1440         hello, world
1441         EOF
1442         R "foo" ""
1443         C "bar/qux" "bar/quux"
1444         INPUT_END
1445          git show N11:bar/baz >actual.baz &&
1446          git show N11:bar/qux >actual.qux &&
1447          git show N11:bar/quux >actual.quux &&
1448          test_cmp expect.baz actual.baz &&
1449          test_cmp expect.qux actual.qux &&
1450          test_cmp expect.qux actual.quux'
1451
1452 ###
1453 ### series O
1454 ###
1455
1456 cat >input <<INPUT_END
1457 #we will
1458 commit refs/heads/O1
1459 # -- ignore all of this text
1460 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1461 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1462 data <<COMMIT
1463 dirty directory copy
1464 COMMIT
1465
1466 # don't forget the import blank line!
1467 #
1468 # yes, we started from our usual base of branch^0.
1469 # i like branch^0.
1470 from refs/heads/branch^0
1471 # and we need to reuse file2/file5 from N3 above.
1472 M 644 inline file2/file5
1473 # otherwise the tree will be different
1474 data <<EOF
1475 $file5_data
1476 EOF
1477
1478 # don't forget to copy file2 to file3
1479 C file2 file3
1480 #
1481 # or to delete file5 from file2.
1482 D file2/file5
1483 # are we done yet?
1484
1485 INPUT_END
1486
1487 test_expect_success \
1488         'O: comments are all skipped' \
1489         'git fast-import <input &&
1490          test `git rev-parse N3` = `git rev-parse O1`'
1491
1492 cat >input <<INPUT_END
1493 commit refs/heads/O2
1494 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1495 data <<COMMIT
1496 dirty directory copy
1497 COMMIT
1498 from refs/heads/branch^0
1499 M 644 inline file2/file5
1500 data <<EOF
1501 $file5_data
1502 EOF
1503 C file2 file3
1504 D file2/file5
1505
1506 INPUT_END
1507
1508 test_expect_success \
1509         'O: blank lines not necessary after data commands' \
1510         'git fast-import <input &&
1511          test `git rev-parse N3` = `git rev-parse O2`'
1512
1513 test_expect_success \
1514         'O: repack before next test' \
1515         'git repack -a -d'
1516
1517 cat >input <<INPUT_END
1518 commit refs/heads/O3
1519 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520 data <<COMMIT
1521 zstring
1522 COMMIT
1523 commit refs/heads/O3
1524 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1525 data <<COMMIT
1526 zof
1527 COMMIT
1528 checkpoint
1529 commit refs/heads/O3
1530 mark :5
1531 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1532 data <<COMMIT
1533 zempty
1534 COMMIT
1535 checkpoint
1536 commit refs/heads/O3
1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 data <<COMMIT
1539 zcommits
1540 COMMIT
1541 reset refs/tags/O3-2nd
1542 from :5
1543 reset refs/tags/O3-3rd
1544 from :5
1545 INPUT_END
1546
1547 cat >expect <<INPUT_END
1548 string
1549 of
1550 empty
1551 commits
1552 INPUT_END
1553 test_expect_success \
1554         'O: blank lines not necessary after other commands' \
1555         'git fast-import <input &&
1556          test 8 = `find .git/objects/pack -type f | wc -l` &&
1557          test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1558          git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1559          test_cmp expect actual'
1560
1561 cat >input <<INPUT_END
1562 commit refs/heads/O4
1563 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1564 data <<COMMIT
1565 zstring
1566 COMMIT
1567 commit refs/heads/O4
1568 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1569 data <<COMMIT
1570 zof
1571 COMMIT
1572 progress Two commits down, 2 to go!
1573 commit refs/heads/O4
1574 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575 data <<COMMIT
1576 zempty
1577 COMMIT
1578 progress Three commits down, 1 to go!
1579 commit refs/heads/O4
1580 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1581 data <<COMMIT
1582 zcommits
1583 COMMIT
1584 progress I'm done!
1585 INPUT_END
1586 test_expect_success \
1587         'O: progress outputs as requested by input' \
1588         'git fast-import <input >actual &&
1589          grep "progress " <input >expect &&
1590          test_cmp expect actual'
1591
1592 ###
1593 ### series P (gitlinks)
1594 ###
1595
1596 cat >input <<INPUT_END
1597 blob
1598 mark :1
1599 data 10
1600 test file
1601
1602 reset refs/heads/sub
1603 commit refs/heads/sub
1604 mark :2
1605 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1606 data 12
1607 sub_initial
1608 M 100644 :1 file
1609
1610 blob
1611 mark :3
1612 data <<DATAEND
1613 [submodule "sub"]
1614         path = sub
1615         url = "`pwd`/sub"
1616 DATAEND
1617
1618 commit refs/heads/subuse1
1619 mark :4
1620 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1621 data 8
1622 initial
1623 from refs/heads/master
1624 M 100644 :3 .gitmodules
1625 M 160000 :2 sub
1626
1627 blob
1628 mark :5
1629 data 20
1630 test file
1631 more data
1632
1633 commit refs/heads/sub
1634 mark :6
1635 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1636 data 11
1637 sub_second
1638 from :2
1639 M 100644 :5 file
1640
1641 commit refs/heads/subuse1
1642 mark :7
1643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644 data 7
1645 second
1646 from :4
1647 M 160000 :6 sub
1648
1649 INPUT_END
1650
1651 test_expect_success \
1652         'P: superproject & submodule mix' \
1653         'git fast-import <input &&
1654          git checkout subuse1 &&
1655          rm -rf sub && mkdir sub && (cd sub &&
1656          git init &&
1657          git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1658          git checkout master) &&
1659          git submodule init &&
1660          git submodule update'
1661
1662 SUBLAST=$(git rev-parse --verify sub)
1663 SUBPREV=$(git rev-parse --verify sub^)
1664
1665 cat >input <<INPUT_END
1666 blob
1667 mark :1
1668 data <<DATAEND
1669 [submodule "sub"]
1670         path = sub
1671         url = "`pwd`/sub"
1672 DATAEND
1673
1674 commit refs/heads/subuse2
1675 mark :2
1676 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1677 data 8
1678 initial
1679 from refs/heads/master
1680 M 100644 :1 .gitmodules
1681 M 160000 $SUBPREV sub
1682
1683 commit refs/heads/subuse2
1684 mark :3
1685 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1686 data 7
1687 second
1688 from :2
1689 M 160000 $SUBLAST sub
1690
1691 INPUT_END
1692
1693 test_expect_success \
1694         'P: verbatim SHA gitlinks' \
1695         'git branch -D sub &&
1696          git gc && git prune &&
1697          git fast-import <input &&
1698          test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1699
1700 test_tick
1701 cat >input <<INPUT_END
1702 commit refs/heads/subuse3
1703 mark :1
1704 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1705 data <<COMMIT
1706 corrupt
1707 COMMIT
1708
1709 from refs/heads/subuse2
1710 M 160000 inline sub
1711 data <<DATA
1712 $SUBPREV
1713 DATA
1714
1715 INPUT_END
1716
1717 test_expect_success 'P: fail on inline gitlink' '
1718     test_must_fail git fast-import <input'
1719
1720 test_tick
1721 cat >input <<INPUT_END
1722 blob
1723 mark :1
1724 data <<DATA
1725 $SUBPREV
1726 DATA
1727
1728 commit refs/heads/subuse3
1729 mark :2
1730 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1731 data <<COMMIT
1732 corrupt
1733 COMMIT
1734
1735 from refs/heads/subuse2
1736 M 160000 :1 sub
1737
1738 INPUT_END
1739
1740 test_expect_success 'P: fail on blob mark in gitlink' '
1741     test_must_fail git fast-import <input'
1742
1743 ###
1744 ### series Q (notes)
1745 ###
1746
1747 note1_data="The first note for the first commit"
1748 note2_data="The first note for the second commit"
1749 note3_data="The first note for the third commit"
1750 note1b_data="The second note for the first commit"
1751 note1c_data="The third note for the first commit"
1752 note2b_data="The second note for the second commit"
1753
1754 test_tick
1755 cat >input <<INPUT_END
1756 blob
1757 mark :2
1758 data <<EOF
1759 $file2_data
1760 EOF
1761
1762 commit refs/heads/notes-test
1763 mark :3
1764 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1765 data <<COMMIT
1766 first (:3)
1767 COMMIT
1768
1769 M 644 :2 file2
1770
1771 blob
1772 mark :4
1773 data $file4_len
1774 $file4_data
1775 commit refs/heads/notes-test
1776 mark :5
1777 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1778 data <<COMMIT
1779 second (:5)
1780 COMMIT
1781
1782 M 644 :4 file4
1783
1784 commit refs/heads/notes-test
1785 mark :6
1786 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1787 data <<COMMIT
1788 third (:6)
1789 COMMIT
1790
1791 M 644 inline file5
1792 data <<EOF
1793 $file5_data
1794 EOF
1795
1796 M 755 inline file6
1797 data <<EOF
1798 $file6_data
1799 EOF
1800
1801 blob
1802 mark :7
1803 data <<EOF
1804 $note1_data
1805 EOF
1806
1807 blob
1808 mark :8
1809 data <<EOF
1810 $note2_data
1811 EOF
1812
1813 commit refs/notes/foobar
1814 mark :9
1815 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1816 data <<COMMIT
1817 notes (:9)
1818 COMMIT
1819
1820 N :7 :3
1821 N :8 :5
1822 N inline :6
1823 data <<EOF
1824 $note3_data
1825 EOF
1826
1827 commit refs/notes/foobar
1828 mark :10
1829 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1830 data <<COMMIT
1831 notes (:10)
1832 COMMIT
1833
1834 N inline :3
1835 data <<EOF
1836 $note1b_data
1837 EOF
1838
1839 commit refs/notes/foobar2
1840 mark :11
1841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842 data <<COMMIT
1843 notes (:11)
1844 COMMIT
1845
1846 N inline :3
1847 data <<EOF
1848 $note1c_data
1849 EOF
1850
1851 commit refs/notes/foobar
1852 mark :12
1853 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1854 data <<COMMIT
1855 notes (:12)
1856 COMMIT
1857
1858 deleteall
1859 N inline :5
1860 data <<EOF
1861 $note2b_data
1862 EOF
1863
1864 INPUT_END
1865
1866 test_expect_success \
1867         'Q: commit notes' \
1868         'git fast-import <input &&
1869          git whatchanged notes-test'
1870
1871 test_expect_success 'Q: verify pack' '
1872         verify_packs
1873 '
1874
1875 commit1=$(git rev-parse notes-test~2)
1876 commit2=$(git rev-parse notes-test^)
1877 commit3=$(git rev-parse notes-test)
1878
1879 cat >expect <<EOF
1880 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1882
1883 first (:3)
1884 EOF
1885 test_expect_success \
1886         'Q: verify first commit' \
1887         'git cat-file commit notes-test~2 | sed 1d >actual &&
1888         test_cmp expect actual'
1889
1890 cat >expect <<EOF
1891 parent $commit1
1892 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1893 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1894
1895 second (:5)
1896 EOF
1897 test_expect_success \
1898         'Q: verify second commit' \
1899         'git cat-file commit notes-test^ | sed 1d >actual &&
1900         test_cmp expect actual'
1901
1902 cat >expect <<EOF
1903 parent $commit2
1904 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1905 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1906
1907 third (:6)
1908 EOF
1909 test_expect_success \
1910         'Q: verify third commit' \
1911         'git cat-file commit notes-test | sed 1d >actual &&
1912         test_cmp expect actual'
1913
1914 cat >expect <<EOF
1915 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1916 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1917
1918 notes (:9)
1919 EOF
1920 test_expect_success \
1921         'Q: verify first notes commit' \
1922         'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1923         test_cmp expect actual'
1924
1925 cat >expect.unsorted <<EOF
1926 100644 blob $commit1
1927 100644 blob $commit2
1928 100644 blob $commit3
1929 EOF
1930 cat expect.unsorted | sort >expect
1931 test_expect_success \
1932         'Q: verify first notes tree' \
1933         'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1934          test_cmp expect actual'
1935
1936 echo "$note1_data" >expect
1937 test_expect_success \
1938         'Q: verify first note for first commit' \
1939         'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1940
1941 echo "$note2_data" >expect
1942 test_expect_success \
1943         'Q: verify first note for second commit' \
1944         'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1945
1946 echo "$note3_data" >expect
1947 test_expect_success \
1948         'Q: verify first note for third commit' \
1949         'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1950
1951 cat >expect <<EOF
1952 parent `git rev-parse --verify refs/notes/foobar~2`
1953 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1954 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1955
1956 notes (:10)
1957 EOF
1958 test_expect_success \
1959         'Q: verify second notes commit' \
1960         'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1961         test_cmp expect actual'
1962
1963 cat >expect.unsorted <<EOF
1964 100644 blob $commit1
1965 100644 blob $commit2
1966 100644 blob $commit3
1967 EOF
1968 cat expect.unsorted | sort >expect
1969 test_expect_success \
1970         'Q: verify second notes tree' \
1971         'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1972          test_cmp expect actual'
1973
1974 echo "$note1b_data" >expect
1975 test_expect_success \
1976         'Q: verify second note for first commit' \
1977         'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1978
1979 echo "$note2_data" >expect
1980 test_expect_success \
1981         'Q: verify first note for second commit' \
1982         'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1983
1984 echo "$note3_data" >expect
1985 test_expect_success \
1986         'Q: verify first note for third commit' \
1987         'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1988
1989 cat >expect <<EOF
1990 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1991 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1992
1993 notes (:11)
1994 EOF
1995 test_expect_success \
1996         'Q: verify third notes commit' \
1997         'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1998         test_cmp expect actual'
1999
2000 cat >expect.unsorted <<EOF
2001 100644 blob $commit1
2002 EOF
2003 cat expect.unsorted | sort >expect
2004 test_expect_success \
2005         'Q: verify third notes tree' \
2006         'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
2007          test_cmp expect actual'
2008
2009 echo "$note1c_data" >expect
2010 test_expect_success \
2011         'Q: verify third note for first commit' \
2012         'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2013
2014 cat >expect <<EOF
2015 parent `git rev-parse --verify refs/notes/foobar^`
2016 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2017 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2018
2019 notes (:12)
2020 EOF
2021 test_expect_success \
2022         'Q: verify fourth notes commit' \
2023         'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2024         test_cmp expect actual'
2025
2026 cat >expect.unsorted <<EOF
2027 100644 blob $commit2
2028 EOF
2029 cat expect.unsorted | sort >expect
2030 test_expect_success \
2031         'Q: verify fourth notes tree' \
2032         'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
2033          test_cmp expect actual'
2034
2035 echo "$note2b_data" >expect
2036 test_expect_success \
2037         'Q: verify second note for second commit' \
2038         'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2039
2040 cat >input <<EOF
2041 reset refs/heads/Q0
2042
2043 commit refs/heads/note-Q0
2044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2045 data <<COMMIT
2046 Note for an empty branch.
2047 COMMIT
2048
2049 N inline refs/heads/Q0
2050 data <<NOTE
2051 some note
2052 NOTE
2053 EOF
2054 test_expect_success \
2055         'Q: deny note on empty branch' \
2056         'test_must_fail git fast-import <input'
2057 ###
2058 ### series R (feature and option)
2059 ###
2060
2061 cat >input <<EOF
2062 feature no-such-feature-exists
2063 EOF
2064
2065 test_expect_success 'R: abort on unsupported feature' '
2066         test_must_fail git fast-import <input
2067 '
2068
2069 cat >input <<EOF
2070 feature date-format=now
2071 EOF
2072
2073 test_expect_success 'R: supported feature is accepted' '
2074         git fast-import <input
2075 '
2076
2077 cat >input << EOF
2078 blob
2079 data 3
2080 hi
2081 feature date-format=now
2082 EOF
2083
2084 test_expect_success 'R: abort on receiving feature after data command' '
2085         test_must_fail git fast-import <input
2086 '
2087
2088 cat >input << EOF
2089 feature import-marks=git.marks
2090 feature import-marks=git2.marks
2091 EOF
2092
2093 test_expect_success 'R: only one import-marks feature allowed per stream' '
2094         test_must_fail git fast-import <input
2095 '
2096
2097 cat >input << EOF
2098 feature export-marks=git.marks
2099 blob
2100 mark :1
2101 data 3
2102 hi
2103
2104 EOF
2105
2106 test_expect_success \
2107     'R: export-marks feature results in a marks file being created' \
2108     'cat input | git fast-import &&
2109     grep :1 git.marks'
2110
2111 test_expect_success \
2112     'R: export-marks options can be overridden by commandline options' \
2113     'cat input | git fast-import --export-marks=other.marks &&
2114     grep :1 other.marks'
2115
2116 test_expect_success 'R: catch typo in marks file name' '
2117         test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2118         echo "feature import-marks=nonexistent.marks" |
2119         test_must_fail git fast-import
2120 '
2121
2122 test_expect_success 'R: import and output marks can be the same file' '
2123         rm -f io.marks &&
2124         blob=$(echo hi | git hash-object --stdin) &&
2125         cat >expect <<-EOF &&
2126         :1 $blob
2127         :2 $blob
2128         EOF
2129         git fast-import --export-marks=io.marks <<-\EOF &&
2130         blob
2131         mark :1
2132         data 3
2133         hi
2134
2135         EOF
2136         git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2137         blob
2138         mark :2
2139         data 3
2140         hi
2141
2142         EOF
2143         test_cmp expect io.marks
2144 '
2145
2146 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2147         rm -f io.marks &&
2148         test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2149         blob
2150         mark :1
2151         data 3
2152         hi
2153
2154         EOF
2155 '
2156
2157 test_expect_success 'R: --import-marks-if-exists' '
2158         rm -f io.marks &&
2159         blob=$(echo hi | git hash-object --stdin) &&
2160         echo ":1 $blob" >expect &&
2161         git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2162         blob
2163         mark :1
2164         data 3
2165         hi
2166
2167         EOF
2168         test_cmp expect io.marks
2169 '
2170
2171 test_expect_success 'R: feature import-marks-if-exists' '
2172         rm -f io.marks &&
2173         >expect &&
2174
2175         git fast-import --export-marks=io.marks <<-\EOF &&
2176         feature import-marks-if-exists=not_io.marks
2177         EOF
2178         test_cmp expect io.marks &&
2179
2180         blob=$(echo hi | git hash-object --stdin) &&
2181
2182         echo ":1 $blob" >io.marks &&
2183         echo ":1 $blob" >expect &&
2184         echo ":2 $blob" >>expect &&
2185
2186         git fast-import --export-marks=io.marks <<-\EOF &&
2187         feature import-marks-if-exists=io.marks
2188         blob
2189         mark :2
2190         data 3
2191         hi
2192
2193         EOF
2194         test_cmp expect io.marks &&
2195
2196         echo ":3 $blob" >>expect &&
2197
2198         git fast-import --import-marks=io.marks \
2199                         --export-marks=io.marks <<-\EOF &&
2200         feature import-marks-if-exists=not_io.marks
2201         blob
2202         mark :3
2203         data 3
2204         hi
2205
2206         EOF
2207         test_cmp expect io.marks &&
2208
2209         >expect &&
2210
2211         git fast-import --import-marks-if-exists=not_io.marks \
2212                         --export-marks=io.marks <<-\EOF
2213         feature import-marks-if-exists=io.marks
2214         EOF
2215         test_cmp expect io.marks
2216 '
2217
2218 cat >input << EOF
2219 feature import-marks=marks.out
2220 feature export-marks=marks.new
2221 EOF
2222
2223 test_expect_success \
2224     'R: import to output marks works without any content' \
2225     'cat input | git fast-import &&
2226     test_cmp marks.out marks.new'
2227
2228 cat >input <<EOF
2229 feature import-marks=nonexistent.marks
2230 feature export-marks=marks.new
2231 EOF
2232
2233 test_expect_success \
2234     'R: import marks prefers commandline marks file over the stream' \
2235     'cat input | git fast-import --import-marks=marks.out &&
2236     test_cmp marks.out marks.new'
2237
2238
2239 cat >input <<EOF
2240 feature import-marks=nonexistent.marks
2241 feature export-marks=combined.marks
2242 EOF
2243
2244 test_expect_success 'R: multiple --import-marks= should be honoured' '
2245     head -n2 marks.out > one.marks &&
2246     tail -n +3 marks.out > two.marks &&
2247     git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2248     test_cmp marks.out combined.marks
2249 '
2250
2251 cat >input <<EOF
2252 feature relative-marks
2253 feature import-marks=relative.in
2254 feature export-marks=relative.out
2255 EOF
2256
2257 test_expect_success 'R: feature relative-marks should be honoured' '
2258     mkdir -p .git/info/fast-import/ &&
2259     cp marks.new .git/info/fast-import/relative.in &&
2260     git fast-import <input &&
2261     test_cmp marks.new .git/info/fast-import/relative.out
2262 '
2263
2264 cat >input <<EOF
2265 feature relative-marks
2266 feature import-marks=relative.in
2267 feature no-relative-marks
2268 feature export-marks=non-relative.out
2269 EOF
2270
2271 test_expect_success 'R: feature no-relative-marks should be honoured' '
2272     git fast-import <input &&
2273     test_cmp marks.new non-relative.out
2274 '
2275
2276 test_expect_success 'R: feature ls supported' '
2277         echo "feature ls" |
2278         git fast-import
2279 '
2280
2281 test_expect_success 'R: feature cat-blob supported' '
2282         echo "feature cat-blob" |
2283         git fast-import
2284 '
2285
2286 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2287         test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2288 '
2289
2290 test_expect_success NOT_MINGW 'R: print old blob' '
2291         blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2292         cat >expect <<-EOF &&
2293         ${blob} blob 11
2294         yes it can
2295
2296         EOF
2297         echo "cat-blob $blob" |
2298         git fast-import --cat-blob-fd=6 6>actual &&
2299         test_cmp expect actual
2300 '
2301
2302 test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' '
2303         echo hello >greeting &&
2304         blob=$(git hash-object -w greeting) &&
2305         cat >expect <<-EOF &&
2306         ${blob} blob 6
2307         hello
2308
2309         EOF
2310         git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2311         cat-blob $blob
2312         EOF
2313         test_cmp expect actual.3 &&
2314         test_cmp empty actual.1 &&
2315         git fast-import 3>actual.3 >actual.1 <<-EOF &&
2316         option cat-blob-fd=3
2317         cat-blob $blob
2318         EOF
2319         test_cmp empty actual.3 &&
2320         test_cmp expect actual.1
2321 '
2322
2323 test_expect_success NOT_MINGW 'R: print new blob' '
2324         blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2325         cat >expect <<-EOF &&
2326         ${blob} blob 12
2327         yep yep yep
2328
2329         EOF
2330         git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2331         blob
2332         mark :1
2333         data <<BLOB_END
2334         yep yep yep
2335         BLOB_END
2336         cat-blob :1
2337         EOF
2338         test_cmp expect actual
2339 '
2340
2341 test_expect_success NOT_MINGW 'R: print new blob by sha1' '
2342         blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2343         cat >expect <<-EOF &&
2344         ${blob} blob 25
2345         a new blob named by sha1
2346
2347         EOF
2348         git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2349         blob
2350         data <<BLOB_END
2351         a new blob named by sha1
2352         BLOB_END
2353         cat-blob $blob
2354         EOF
2355         test_cmp expect actual
2356 '
2357
2358 test_expect_success 'setup: big file' '
2359         (
2360                 echo "the quick brown fox jumps over the lazy dog" >big &&
2361                 for i in 1 2 3
2362                 do
2363                         cat big big big big >bigger &&
2364                         cat bigger bigger bigger bigger >big ||
2365                         exit
2366                 done
2367         )
2368 '
2369
2370 test_expect_success 'R: print two blobs to stdout' '
2371         blob1=$(git hash-object big) &&
2372         blob1_len=$(wc -c <big) &&
2373         blob2=$(echo hello | git hash-object --stdin) &&
2374         {
2375                 echo ${blob1} blob $blob1_len &&
2376                 cat big &&
2377                 cat <<-EOF
2378
2379                 ${blob2} blob 6
2380                 hello
2381
2382                 EOF
2383         } >expect &&
2384         {
2385                 cat <<-\END_PART1 &&
2386                         blob
2387                         mark :1
2388                         data <<data_end
2389                 END_PART1
2390                 cat big &&
2391                 cat <<-\EOF
2392                         data_end
2393                         blob
2394                         mark :2
2395                         data <<data_end
2396                         hello
2397                         data_end
2398                         cat-blob :1
2399                         cat-blob :2
2400                 EOF
2401         } |
2402         git fast-import >actual &&
2403         test_cmp expect actual
2404 '
2405
2406 test_expect_success PIPE 'R: copy using cat-file' '
2407         expect_id=$(git hash-object big) &&
2408         expect_len=$(wc -c <big) &&
2409         echo $expect_id blob $expect_len >expect.response &&
2410
2411         rm -f blobs &&
2412         cat >frontend <<-\FRONTEND_END &&
2413         #!/bin/sh
2414         FRONTEND_END
2415
2416         mkfifo blobs &&
2417         (
2418                 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2419                 cat <<-\EOF &&
2420                 feature cat-blob
2421                 blob
2422                 mark :1
2423                 data <<BLOB
2424                 EOF
2425                 cat big &&
2426                 cat <<-\EOF &&
2427                 BLOB
2428                 cat-blob :1
2429                 EOF
2430
2431                 read blob_id type size <&3 &&
2432                 echo "$blob_id $type $size" >response &&
2433                 head_c $size >blob <&3 &&
2434                 read newline <&3 &&
2435
2436                 cat <<-EOF &&
2437                 commit refs/heads/copied
2438                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2439                 data <<COMMIT
2440                 copy big file as file3
2441                 COMMIT
2442                 M 644 inline file3
2443                 data <<BLOB
2444                 EOF
2445                 cat blob &&
2446                 echo BLOB
2447         ) 3<blobs |
2448         git fast-import --cat-blob-fd=3 3>blobs &&
2449         git show copied:file3 >actual &&
2450         test_cmp expect.response response &&
2451         test_cmp big actual
2452 '
2453
2454 test_expect_success PIPE 'R: print blob mid-commit' '
2455         rm -f blobs &&
2456         echo "A blob from _before_ the commit." >expect &&
2457         mkfifo blobs &&
2458         (
2459                 exec 3<blobs &&
2460                 cat <<-EOF &&
2461                 feature cat-blob
2462                 blob
2463                 mark :1
2464                 data <<BLOB
2465                 A blob from _before_ the commit.
2466                 BLOB
2467                 commit refs/heads/temporary
2468                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2469                 data <<COMMIT
2470                 Empty commit
2471                 COMMIT
2472                 cat-blob :1
2473                 EOF
2474
2475                 read blob_id type size <&3 &&
2476                 head_c $size >actual <&3 &&
2477                 read newline <&3 &&
2478
2479                 echo
2480         ) |
2481         git fast-import --cat-blob-fd=3 3>blobs &&
2482         test_cmp expect actual
2483 '
2484
2485 test_expect_success PIPE 'R: print staged blob within commit' '
2486         rm -f blobs &&
2487         echo "A blob from _within_ the commit." >expect &&
2488         mkfifo blobs &&
2489         (
2490                 exec 3<blobs &&
2491                 cat <<-EOF &&
2492                 feature cat-blob
2493                 commit refs/heads/within
2494                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2495                 data <<COMMIT
2496                 Empty commit
2497                 COMMIT
2498                 M 644 inline within
2499                 data <<BLOB
2500                 A blob from _within_ the commit.
2501                 BLOB
2502                 EOF
2503
2504                 to_get=$(
2505                         echo "A blob from _within_ the commit." |
2506                         git hash-object --stdin
2507                 ) &&
2508                 echo "cat-blob $to_get" &&
2509
2510                 read blob_id type size <&3 &&
2511                 head_c $size >actual <&3 &&
2512                 read newline <&3 &&
2513
2514                 echo deleteall
2515         ) |
2516         git fast-import --cat-blob-fd=3 3>blobs &&
2517         test_cmp expect actual
2518 '
2519
2520 cat >input << EOF
2521 option git quiet
2522 blob
2523 data 3
2524 hi
2525
2526 EOF
2527
2528 test_expect_success 'R: quiet option results in no stats being output' '
2529     cat input | git fast-import 2> output &&
2530     test_cmp empty output
2531 '
2532
2533 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2534         echo feature done | test_must_fail git fast-import &&
2535         test_must_fail git fast-import --done </dev/null
2536 '
2537
2538 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2539         git fast-import <<-\EOF &&
2540         feature done
2541         done
2542         trailing gibberish
2543         EOF
2544         git fast-import <<-\EOF
2545         done
2546         more trailing gibberish
2547         EOF
2548 '
2549
2550 test_expect_success 'R: terminating "done" within commit' '
2551         cat >expect <<-\EOF &&
2552         OBJID
2553         :000000 100644 OBJID OBJID A    hello.c
2554         :000000 100644 OBJID OBJID A    hello2.c
2555         EOF
2556         git fast-import <<-EOF &&
2557         commit refs/heads/done-ends
2558         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2559         data <<EOT
2560         Commit terminated by "done" command
2561         EOT
2562         M 100644 inline hello.c
2563         data <<EOT
2564         Hello, world.
2565         EOT
2566         C hello.c hello2.c
2567         done
2568         EOF
2569         git rev-list done-ends |
2570         git diff-tree -r --stdin --root --always |
2571         sed -e "s/$_x40/OBJID/g" >actual &&
2572         test_cmp expect actual
2573 '
2574
2575 cat >input <<EOF
2576 option git non-existing-option
2577 EOF
2578
2579 test_expect_success 'R: die on unknown option' '
2580     test_must_fail git fast-import <input
2581 '
2582
2583 test_expect_success 'R: unknown commandline options are rejected' '\
2584     test_must_fail git fast-import --non-existing-option < /dev/null
2585 '
2586
2587 test_expect_success 'R: die on invalid option argument' '
2588         echo "option git active-branches=-5" |
2589         test_must_fail git fast-import &&
2590         echo "option git depth=" |
2591         test_must_fail git fast-import &&
2592         test_must_fail git fast-import --depth="5 elephants" </dev/null
2593 '
2594
2595 cat >input <<EOF
2596 option non-existing-vcs non-existing-option
2597 EOF
2598
2599 test_expect_success 'R: ignore non-git options' '
2600     git fast-import <input
2601 '
2602
2603 ##
2604 ## R: very large blobs
2605 ##
2606 blobsize=$((2*1024*1024 + 53))
2607 test-genrandom bar $blobsize >expect
2608 cat >input <<INPUT_END
2609 commit refs/heads/big-file
2610 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2611 data <<COMMIT
2612 R - big file
2613 COMMIT
2614
2615 M 644 inline big1
2616 data $blobsize
2617 INPUT_END
2618 cat expect >>input
2619 cat >>input <<INPUT_END
2620 M 644 inline big2
2621 data $blobsize
2622 INPUT_END
2623 cat expect >>input
2624 echo >>input
2625
2626 test_expect_success \
2627         'R: blob bigger than threshold' \
2628         'test_create_repo R &&
2629          git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2630
2631 test_expect_success 'R: verify created pack' '
2632         (
2633                 cd R &&
2634                 verify_packs -v > ../verify
2635         )
2636 '
2637
2638 test_expect_success \
2639         'R: verify written objects' \
2640         'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2641          test_cmp expect actual &&
2642          a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2643          b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2644          test $a = $b'
2645 test_expect_success \
2646         'R: blob appears only once' \
2647         'n=$(grep $a verify | wc -l) &&
2648          test 1 = $n'
2649
2650 ###
2651 ### series S
2652 ###
2653 #
2654 # Make sure missing spaces and EOLs after mark references
2655 # cause errors.
2656 #
2657 # Setup:
2658 #
2659 #   1--2--4
2660 #    \   /
2661 #     -3-
2662 #
2663 #   commit marks:  301, 302, 303, 304
2664 #   blob marks:              403, 404, resp.
2665 #   note mark:          202
2666 #
2667 # The error message when a space is missing not at the
2668 # end of the line is:
2669 #
2670 #   Missing space after ..
2671 #
2672 # or when extra characters come after the mark at the end
2673 # of the line:
2674 #
2675 #   Garbage after ..
2676 #
2677 # or when the dataref is neither "inline " or a known SHA1,
2678 #
2679 #   Invalid dataref ..
2680 #
2681 test_tick
2682
2683 cat >input <<INPUT_END
2684 commit refs/heads/S
2685 mark :301
2686 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2687 data <<COMMIT
2688 commit 1
2689 COMMIT
2690 M 100644 inline hello.c
2691 data <<BLOB
2692 blob 1
2693 BLOB
2694
2695 commit refs/heads/S
2696 mark :302
2697 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2698 data <<COMMIT
2699 commit 2
2700 COMMIT
2701 from :301
2702 M 100644 inline hello.c
2703 data <<BLOB
2704 blob 2
2705 BLOB
2706
2707 blob
2708 mark :403
2709 data <<BLOB
2710 blob 3
2711 BLOB
2712
2713 blob
2714 mark :202
2715 data <<BLOB
2716 note 2
2717 BLOB
2718 INPUT_END
2719
2720 test_expect_success 'S: initialize for S tests' '
2721         git fast-import --export-marks=marks <input
2722 '
2723
2724 #
2725 # filemodify, three datarefs
2726 #
2727 test_expect_success 'S: filemodify with garbage after mark must fail' '
2728         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2729         commit refs/heads/S
2730         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2731         data <<COMMIT
2732         commit N
2733         COMMIT
2734         M 100644 :403x hello.c
2735         EOF
2736         cat err &&
2737         test_i18ngrep "space after mark" err
2738 '
2739
2740 # inline is misspelled; fast-import thinks it is some unknown dataref
2741 test_expect_success 'S: filemodify with garbage after inline must fail' '
2742         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2743         commit refs/heads/S
2744         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2745         data <<COMMIT
2746         commit N
2747         COMMIT
2748         M 100644 inlineX hello.c
2749         data <<BLOB
2750         inline
2751         BLOB
2752         EOF
2753         cat err &&
2754         test_i18ngrep "nvalid dataref" err
2755 '
2756
2757 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2758         sha1=$(grep :403 marks | cut -d\  -f2) &&
2759         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2760         commit refs/heads/S
2761         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2762         data <<COMMIT
2763         commit N
2764         COMMIT
2765         M 100644 ${sha1}x hello.c
2766         EOF
2767         cat err &&
2768         test_i18ngrep "space after SHA1" err
2769 '
2770
2771 #
2772 # notemodify, three ways to say dataref
2773 #
2774 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2775         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2776         commit refs/heads/S
2777         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2778         data <<COMMIT
2779         commit S note dataref markref
2780         COMMIT
2781         N :202x :302
2782         EOF
2783         cat err &&
2784         test_i18ngrep "space after mark" err
2785 '
2786
2787 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2788         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2789         commit refs/heads/S
2790         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2791         data <<COMMIT
2792         commit S note dataref inline
2793         COMMIT
2794         N inlineX :302
2795         data <<BLOB
2796         note blob
2797         BLOB
2798         EOF
2799         cat err &&
2800         test_i18ngrep "nvalid dataref" err
2801 '
2802
2803 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2804         sha1=$(grep :202 marks | cut -d\  -f2) &&
2805         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2806         commit refs/heads/S
2807         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2808         data <<COMMIT
2809         commit S note dataref sha1
2810         COMMIT
2811         N ${sha1}x :302
2812         EOF
2813         cat err &&
2814         test_i18ngrep "space after SHA1" err
2815 '
2816
2817 #
2818 # notemodify, mark in committish
2819 #
2820 test_expect_success 'S: notemodify with garbarge after mark committish must fail' '
2821         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2822         commit refs/heads/Snotes
2823         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2824         data <<COMMIT
2825         commit S note committish
2826         COMMIT
2827         N :202 :302x
2828         EOF
2829         cat err &&
2830         test_i18ngrep "after mark" err
2831 '
2832
2833 #
2834 # from
2835 #
2836 test_expect_success 'S: from with garbage after mark must fail' '
2837         # no &&
2838         git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err
2839         commit refs/heads/S2
2840         mark :303
2841         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842         data <<COMMIT
2843         commit 3
2844         COMMIT
2845         from :301x
2846         M 100644 :403 hello.c
2847         EOF
2848
2849         ret=$? &&
2850         echo returned $ret &&
2851         test $ret -ne 0 && # failed, but it created the commit
2852
2853         # go create the commit, need it for merge test
2854         git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2855         commit refs/heads/S2
2856         mark :303
2857         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2858         data <<COMMIT
2859         commit 3
2860         COMMIT
2861         from :301
2862         M 100644 :403 hello.c
2863         EOF
2864
2865         # now evaluate the error
2866         cat err &&
2867         test_i18ngrep "after mark" err
2868 '
2869
2870
2871 #
2872 # merge
2873 #
2874 test_expect_success 'S: merge with garbage after mark must fail' '
2875         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2876         commit refs/heads/S
2877         mark :304
2878         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2879         data <<COMMIT
2880         merge 4
2881         COMMIT
2882         from :302
2883         merge :303x
2884         M 100644 :403 hello.c
2885         EOF
2886         cat err &&
2887         test_i18ngrep "after mark" err
2888 '
2889
2890 #
2891 # tag, from markref
2892 #
2893 test_expect_success 'S: tag with garbage after mark must fail' '
2894         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2895         tag refs/tags/Stag
2896         from :302x
2897         tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2898         data <<TAG
2899         tag S
2900         TAG
2901         EOF
2902         cat err &&
2903         test_i18ngrep "after mark" err
2904 '
2905
2906 #
2907 # cat-blob markref
2908 #
2909 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2910         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2911         cat-blob :403x
2912         EOF
2913         cat err &&
2914         test_i18ngrep "after mark" err
2915 '
2916
2917 #
2918 # ls markref
2919 #
2920 test_expect_success 'S: ls with garbage after mark must fail' '
2921         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2922         ls :302x hello.c
2923         EOF
2924         cat err &&
2925         test_i18ngrep "space after mark" err
2926 '
2927
2928 test_expect_success 'S: ls with garbage after sha1 must fail' '
2929         sha1=$(grep :302 marks | cut -d\  -f2) &&
2930         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2931         ls ${sha1}x hello.c
2932         EOF
2933         cat err &&
2934         test_i18ngrep "space after tree-ish" err
2935 '
2936
2937 test_done