]> git.scripts.mit.edu Git - git.git/blob - t/t9300-fast-import.sh
88fc407ed6aa96acd21eb249d10832fe3ff8723d
[git.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 cat >input <<INPUT_END
1035 commit refs/heads/M4
1036 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1037 data <<COMMIT
1038 rename root
1039 COMMIT
1040
1041 from refs/heads/M2^0
1042 R "" sub
1043
1044 INPUT_END
1045
1046 cat >expect <<EOF
1047 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2/oldf      sub/file2/oldf
1048 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100   file4   sub/file4
1049 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you sub/i/am/new/to/you
1050 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100   newdir/exec.sh  sub/newdir/exec.sh
1051 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      sub/newdir/interesting
1052 EOF
1053 test_expect_success \
1054         'M: rename root to subdirectory' \
1055         'git fast-import <input &&
1056          git diff-tree -M -r M4^ M4 >actual &&
1057          cat actual &&
1058          compare_diff_raw expect actual'
1059
1060 ###
1061 ### series N
1062 ###
1063
1064 test_tick
1065 cat >input <<INPUT_END
1066 commit refs/heads/N1
1067 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068 data <<COMMIT
1069 file copy
1070 COMMIT
1071
1072 from refs/heads/branch^0
1073 C file2/newf file2/n.e.w.f
1074
1075 INPUT_END
1076
1077 cat >expect <<EOF
1078 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
1079 EOF
1080 test_expect_success \
1081         'N: copy file in same subdirectory' \
1082         'git fast-import <input &&
1083          git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1084          compare_diff_raw expect actual'
1085
1086 cat >input <<INPUT_END
1087 commit refs/heads/N2
1088 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1089 data <<COMMIT
1090 clean directory copy
1091 COMMIT
1092
1093 from refs/heads/branch^0
1094 C file2 file3
1095
1096 commit refs/heads/N2
1097 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1098 data <<COMMIT
1099 modify directory copy
1100 COMMIT
1101
1102 M 644 inline file3/file5
1103 data <<EOF
1104 $file5_data
1105 EOF
1106
1107 INPUT_END
1108
1109 cat >expect <<EOF
1110 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1111 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1112 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1113 EOF
1114 test_expect_success \
1115         'N: copy then modify subdirectory' \
1116         'git fast-import <input &&
1117          git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1118          compare_diff_raw expect actual'
1119
1120 cat >input <<INPUT_END
1121 commit refs/heads/N3
1122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1123 data <<COMMIT
1124 dirty directory copy
1125 COMMIT
1126
1127 from refs/heads/branch^0
1128 M 644 inline file2/file5
1129 data <<EOF
1130 $file5_data
1131 EOF
1132
1133 C file2 file3
1134 D file2/file5
1135
1136 INPUT_END
1137
1138 test_expect_success \
1139         'N: copy dirty subdirectory' \
1140         'git fast-import <input &&
1141          test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1142
1143 test_expect_success \
1144         'N: copy directory by id' \
1145         'cat >expect <<-\EOF &&
1146         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1147         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1148         EOF
1149          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1150          cat >input <<-INPUT_END &&
1151         commit refs/heads/N4
1152         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1153         data <<COMMIT
1154         copy by tree hash
1155         COMMIT
1156
1157         from refs/heads/branch^0
1158         M 040000 $subdir file3
1159         INPUT_END
1160          git fast-import <input &&
1161          git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1162          compare_diff_raw expect actual'
1163
1164 test_expect_success PIPE 'N: read and copy directory' '
1165         cat >expect <<-\EOF
1166         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1167         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1168         EOF
1169         git update-ref -d refs/heads/N4 &&
1170         rm -f backflow &&
1171         mkfifo backflow &&
1172         (
1173                 exec <backflow &&
1174                 cat <<-EOF &&
1175                 commit refs/heads/N4
1176                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1177                 data <<COMMIT
1178                 copy by tree hash, part 2
1179                 COMMIT
1180
1181                 from refs/heads/branch^0
1182                 ls "file2"
1183                 EOF
1184                 read mode type tree filename &&
1185                 echo "M 040000 $tree file3"
1186         ) |
1187         git fast-import --cat-blob-fd=3 3>backflow &&
1188         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1189         compare_diff_raw expect actual
1190 '
1191
1192 test_expect_success PIPE 'N: empty directory reads as missing' '
1193         cat <<-\EOF >expect &&
1194         OBJNAME
1195         :000000 100644 OBJNAME OBJNAME A        unrelated
1196         EOF
1197         echo "missing src" >expect.response &&
1198         git update-ref -d refs/heads/read-empty &&
1199         rm -f backflow &&
1200         mkfifo backflow &&
1201         (
1202                 exec <backflow &&
1203                 cat <<-EOF &&
1204                 commit refs/heads/read-empty
1205                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1206                 data <<COMMIT
1207                 read "empty" (missing) directory
1208                 COMMIT
1209
1210                 M 100644 inline src/greeting
1211                 data <<BLOB
1212                 hello
1213                 BLOB
1214                 C src/greeting dst1/non-greeting
1215                 C src/greeting unrelated
1216                 # leave behind "empty" src directory
1217                 D src/greeting
1218                 ls "src"
1219                 EOF
1220                 read -r line &&
1221                 printf "%s\n" "$line" >response &&
1222                 cat <<-\EOF
1223                 D dst1
1224                 D dst2
1225                 EOF
1226         ) |
1227         git fast-import --cat-blob-fd=3 3>backflow &&
1228         test_cmp expect.response response &&
1229         git rev-list read-empty |
1230         git diff-tree -r --root --stdin |
1231         sed "s/$_x40/OBJNAME/g" >actual &&
1232         test_cmp expect actual
1233 '
1234
1235 test_expect_success \
1236         'N: copy root directory by tree hash' \
1237         'cat >expect <<-\EOF &&
1238         :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1239         :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1240         EOF
1241          root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1242          cat >input <<-INPUT_END &&
1243         commit refs/heads/N6
1244         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1245         data <<COMMIT
1246         copy root directory by tree hash
1247         COMMIT
1248
1249         from refs/heads/branch^0
1250         M 040000 $root ""
1251         INPUT_END
1252          git fast-import <input &&
1253          git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1254          compare_diff_raw expect actual'
1255
1256 test_expect_success \
1257         'N: copy root by path' \
1258         'cat >expect <<-\EOF &&
1259         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      oldroot/file2/newf
1260         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      oldroot/file2/oldf
1261         :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100   file4   oldroot/file4
1262         :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100   newdir/exec.sh  oldroot/newdir/exec.sh
1263         :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      oldroot/newdir/interesting
1264         EOF
1265          cat >input <<-INPUT_END &&
1266         commit refs/heads/N-copy-root-path
1267         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1268         data <<COMMIT
1269         copy root directory by (empty) path
1270         COMMIT
1271
1272         from refs/heads/branch^0
1273         C "" oldroot
1274         INPUT_END
1275          git fast-import <input &&
1276          git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1277          compare_diff_raw expect actual'
1278
1279 test_expect_success \
1280         'N: delete directory by copying' \
1281         'cat >expect <<-\EOF &&
1282         OBJID
1283         :100644 000000 OBJID OBJID D    foo/bar/qux
1284         OBJID
1285         :000000 100644 OBJID OBJID A    foo/bar/baz
1286         :000000 100644 OBJID OBJID A    foo/bar/qux
1287         EOF
1288          empty_tree=$(git mktree </dev/null) &&
1289          cat >input <<-INPUT_END &&
1290         commit refs/heads/N-delete
1291         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1292         data <<COMMIT
1293         collect data to be deleted
1294         COMMIT
1295
1296         deleteall
1297         M 100644 inline foo/bar/baz
1298         data <<DATA_END
1299         hello
1300         DATA_END
1301         C "foo/bar/baz" "foo/bar/qux"
1302         C "foo/bar/baz" "foo/bar/quux/1"
1303         C "foo/bar/baz" "foo/bar/quuux"
1304         M 040000 $empty_tree foo/bar/quux
1305         M 040000 $empty_tree foo/bar/quuux
1306
1307         commit refs/heads/N-delete
1308         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1309         data <<COMMIT
1310         delete subdirectory
1311         COMMIT
1312
1313         M 040000 $empty_tree foo/bar/qux
1314         INPUT_END
1315          git fast-import <input &&
1316          git rev-list N-delete |
1317                 git diff-tree -r --stdin --root --always |
1318                 sed -e "s/$_x40/OBJID/g" >actual &&
1319          test_cmp expect actual'
1320
1321 test_expect_success \
1322         'N: modify copied tree' \
1323         'cat >expect <<-\EOF &&
1324         :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1325         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1326         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1327         EOF
1328          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1329          cat >input <<-INPUT_END &&
1330         commit refs/heads/N5
1331         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1332         data <<COMMIT
1333         copy by tree hash
1334         COMMIT
1335
1336         from refs/heads/branch^0
1337         M 040000 $subdir file3
1338
1339         commit refs/heads/N5
1340         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1341         data <<COMMIT
1342         modify directory copy
1343         COMMIT
1344
1345         M 644 inline file3/file5
1346         data <<EOF
1347         $file5_data
1348         EOF
1349         INPUT_END
1350          git fast-import <input &&
1351          git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1352          compare_diff_raw expect actual'
1353
1354 test_expect_success \
1355         'N: reject foo/ syntax' \
1356         'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1357          test_must_fail git fast-import <<-INPUT_END
1358         commit refs/heads/N5B
1359         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1360         data <<COMMIT
1361         copy with invalid syntax
1362         COMMIT
1363
1364         from refs/heads/branch^0
1365         M 040000 $subdir file3/
1366         INPUT_END'
1367
1368 test_expect_success \
1369         'N: reject foo/ syntax in copy source' \
1370         'test_must_fail git fast-import <<-INPUT_END
1371         commit refs/heads/N5C
1372         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1373         data <<COMMIT
1374         copy with invalid syntax
1375         COMMIT
1376
1377         from refs/heads/branch^0
1378         C file2/ file3
1379         INPUT_END'
1380
1381 test_expect_success \
1382         'N: reject foo/ syntax in rename source' \
1383         'test_must_fail git fast-import <<-INPUT_END
1384         commit refs/heads/N5D
1385         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1386         data <<COMMIT
1387         rename with invalid syntax
1388         COMMIT
1389
1390         from refs/heads/branch^0
1391         R file2/ file3
1392         INPUT_END'
1393
1394 test_expect_success \
1395         'N: reject foo/ syntax in ls argument' \
1396         'test_must_fail git fast-import <<-INPUT_END
1397         commit refs/heads/N5E
1398         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1399         data <<COMMIT
1400         copy with invalid syntax
1401         COMMIT
1402
1403         from refs/heads/branch^0
1404         ls "file2/"
1405         INPUT_END'
1406
1407 test_expect_success \
1408         'N: copy to root by id and modify' \
1409         'echo "hello, world" >expect.foo &&
1410          echo hello >expect.bar &&
1411          git fast-import <<-SETUP_END &&
1412         commit refs/heads/N7
1413         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1414         data <<COMMIT
1415         hello, tree
1416         COMMIT
1417
1418         deleteall
1419         M 644 inline foo/bar
1420         data <<EOF
1421         hello
1422         EOF
1423         SETUP_END
1424
1425          tree=$(git rev-parse --verify N7:) &&
1426          git fast-import <<-INPUT_END &&
1427         commit refs/heads/N8
1428         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1429         data <<COMMIT
1430         copy to root by id and modify
1431         COMMIT
1432
1433         M 040000 $tree ""
1434         M 644 inline foo/foo
1435         data <<EOF
1436         hello, world
1437         EOF
1438         INPUT_END
1439          git show N8:foo/foo >actual.foo &&
1440          git show N8:foo/bar >actual.bar &&
1441          test_cmp expect.foo actual.foo &&
1442          test_cmp expect.bar actual.bar'
1443
1444 test_expect_success \
1445         'N: extract subtree' \
1446         'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1447          cat >input <<-INPUT_END &&
1448         commit refs/heads/N9
1449         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1450         data <<COMMIT
1451         extract subtree branch:newdir
1452         COMMIT
1453
1454         M 040000 $branch ""
1455         C "newdir" ""
1456         INPUT_END
1457          git fast-import <input &&
1458          git diff --exit-code branch:newdir N9'
1459
1460 test_expect_success \
1461         'N: modify subtree, extract it, and modify again' \
1462         'echo hello >expect.baz &&
1463          echo hello, world >expect.qux &&
1464          git fast-import <<-SETUP_END &&
1465         commit refs/heads/N10
1466         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1467         data <<COMMIT
1468         hello, tree
1469         COMMIT
1470
1471         deleteall
1472         M 644 inline foo/bar/baz
1473         data <<EOF
1474         hello
1475         EOF
1476         SETUP_END
1477
1478          tree=$(git rev-parse --verify N10:) &&
1479          git fast-import <<-INPUT_END &&
1480         commit refs/heads/N11
1481         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1482         data <<COMMIT
1483         copy to root by id and modify
1484         COMMIT
1485
1486         M 040000 $tree ""
1487         M 100644 inline foo/bar/qux
1488         data <<EOF
1489         hello, world
1490         EOF
1491         R "foo" ""
1492         C "bar/qux" "bar/quux"
1493         INPUT_END
1494          git show N11:bar/baz >actual.baz &&
1495          git show N11:bar/qux >actual.qux &&
1496          git show N11:bar/quux >actual.quux &&
1497          test_cmp expect.baz actual.baz &&
1498          test_cmp expect.qux actual.qux &&
1499          test_cmp expect.qux actual.quux'
1500
1501 ###
1502 ### series O
1503 ###
1504
1505 cat >input <<INPUT_END
1506 #we will
1507 commit refs/heads/O1
1508 # -- ignore all of this text
1509 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1510 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1511 data <<COMMIT
1512 dirty directory copy
1513 COMMIT
1514
1515 # don't forget the import blank line!
1516 #
1517 # yes, we started from our usual base of branch^0.
1518 # i like branch^0.
1519 from refs/heads/branch^0
1520 # and we need to reuse file2/file5 from N3 above.
1521 M 644 inline file2/file5
1522 # otherwise the tree will be different
1523 data <<EOF
1524 $file5_data
1525 EOF
1526
1527 # don't forget to copy file2 to file3
1528 C file2 file3
1529 #
1530 # or to delete file5 from file2.
1531 D file2/file5
1532 # are we done yet?
1533
1534 INPUT_END
1535
1536 test_expect_success \
1537         'O: comments are all skipped' \
1538         'git fast-import <input &&
1539          test `git rev-parse N3` = `git rev-parse O1`'
1540
1541 cat >input <<INPUT_END
1542 commit refs/heads/O2
1543 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1544 data <<COMMIT
1545 dirty directory copy
1546 COMMIT
1547 from refs/heads/branch^0
1548 M 644 inline file2/file5
1549 data <<EOF
1550 $file5_data
1551 EOF
1552 C file2 file3
1553 D file2/file5
1554
1555 INPUT_END
1556
1557 test_expect_success \
1558         'O: blank lines not necessary after data commands' \
1559         'git fast-import <input &&
1560          test `git rev-parse N3` = `git rev-parse O2`'
1561
1562 test_expect_success \
1563         'O: repack before next test' \
1564         'git repack -a -d'
1565
1566 cat >input <<INPUT_END
1567 commit refs/heads/O3
1568 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1569 data <<COMMIT
1570 zstring
1571 COMMIT
1572 commit refs/heads/O3
1573 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1574 data <<COMMIT
1575 zof
1576 COMMIT
1577 checkpoint
1578 commit refs/heads/O3
1579 mark :5
1580 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1581 data <<COMMIT
1582 zempty
1583 COMMIT
1584 checkpoint
1585 commit refs/heads/O3
1586 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1587 data <<COMMIT
1588 zcommits
1589 COMMIT
1590 reset refs/tags/O3-2nd
1591 from :5
1592 reset refs/tags/O3-3rd
1593 from :5
1594 INPUT_END
1595
1596 cat >expect <<INPUT_END
1597 string
1598 of
1599 empty
1600 commits
1601 INPUT_END
1602 test_expect_success \
1603         'O: blank lines not necessary after other commands' \
1604         'git fast-import <input &&
1605          test 8 = `find .git/objects/pack -type f | wc -l` &&
1606          test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1607          git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1608          test_cmp expect actual'
1609
1610 cat >input <<INPUT_END
1611 commit refs/heads/O4
1612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1613 data <<COMMIT
1614 zstring
1615 COMMIT
1616 commit refs/heads/O4
1617 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1618 data <<COMMIT
1619 zof
1620 COMMIT
1621 progress Two commits down, 2 to go!
1622 commit refs/heads/O4
1623 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1624 data <<COMMIT
1625 zempty
1626 COMMIT
1627 progress Three commits down, 1 to go!
1628 commit refs/heads/O4
1629 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1630 data <<COMMIT
1631 zcommits
1632 COMMIT
1633 progress I'm done!
1634 INPUT_END
1635 test_expect_success \
1636         'O: progress outputs as requested by input' \
1637         'git fast-import <input >actual &&
1638          grep "progress " <input >expect &&
1639          test_cmp expect actual'
1640
1641 ###
1642 ### series P (gitlinks)
1643 ###
1644
1645 cat >input <<INPUT_END
1646 blob
1647 mark :1
1648 data 10
1649 test file
1650
1651 reset refs/heads/sub
1652 commit refs/heads/sub
1653 mark :2
1654 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655 data 12
1656 sub_initial
1657 M 100644 :1 file
1658
1659 blob
1660 mark :3
1661 data <<DATAEND
1662 [submodule "sub"]
1663         path = sub
1664         url = "`pwd`/sub"
1665 DATAEND
1666
1667 commit refs/heads/subuse1
1668 mark :4
1669 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1670 data 8
1671 initial
1672 from refs/heads/master
1673 M 100644 :3 .gitmodules
1674 M 160000 :2 sub
1675
1676 blob
1677 mark :5
1678 data 20
1679 test file
1680 more data
1681
1682 commit refs/heads/sub
1683 mark :6
1684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1685 data 11
1686 sub_second
1687 from :2
1688 M 100644 :5 file
1689
1690 commit refs/heads/subuse1
1691 mark :7
1692 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1693 data 7
1694 second
1695 from :4
1696 M 160000 :6 sub
1697
1698 INPUT_END
1699
1700 test_expect_success \
1701         'P: superproject & submodule mix' \
1702         'git fast-import <input &&
1703          git checkout subuse1 &&
1704          rm -rf sub && mkdir sub && (cd sub &&
1705          git init &&
1706          git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1707          git checkout master) &&
1708          git submodule init &&
1709          git submodule update'
1710
1711 SUBLAST=$(git rev-parse --verify sub)
1712 SUBPREV=$(git rev-parse --verify sub^)
1713
1714 cat >input <<INPUT_END
1715 blob
1716 mark :1
1717 data <<DATAEND
1718 [submodule "sub"]
1719         path = sub
1720         url = "`pwd`/sub"
1721 DATAEND
1722
1723 commit refs/heads/subuse2
1724 mark :2
1725 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1726 data 8
1727 initial
1728 from refs/heads/master
1729 M 100644 :1 .gitmodules
1730 M 160000 $SUBPREV sub
1731
1732 commit refs/heads/subuse2
1733 mark :3
1734 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1735 data 7
1736 second
1737 from :2
1738 M 160000 $SUBLAST sub
1739
1740 INPUT_END
1741
1742 test_expect_success \
1743         'P: verbatim SHA gitlinks' \
1744         'git branch -D sub &&
1745          git gc && git prune &&
1746          git fast-import <input &&
1747          test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1748
1749 test_tick
1750 cat >input <<INPUT_END
1751 commit refs/heads/subuse3
1752 mark :1
1753 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1754 data <<COMMIT
1755 corrupt
1756 COMMIT
1757
1758 from refs/heads/subuse2
1759 M 160000 inline sub
1760 data <<DATA
1761 $SUBPREV
1762 DATA
1763
1764 INPUT_END
1765
1766 test_expect_success 'P: fail on inline gitlink' '
1767     test_must_fail git fast-import <input'
1768
1769 test_tick
1770 cat >input <<INPUT_END
1771 blob
1772 mark :1
1773 data <<DATA
1774 $SUBPREV
1775 DATA
1776
1777 commit refs/heads/subuse3
1778 mark :2
1779 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1780 data <<COMMIT
1781 corrupt
1782 COMMIT
1783
1784 from refs/heads/subuse2
1785 M 160000 :1 sub
1786
1787 INPUT_END
1788
1789 test_expect_success 'P: fail on blob mark in gitlink' '
1790     test_must_fail git fast-import <input'
1791
1792 ###
1793 ### series Q (notes)
1794 ###
1795
1796 note1_data="The first note for the first commit"
1797 note2_data="The first note for the second commit"
1798 note3_data="The first note for the third commit"
1799 note1b_data="The second note for the first commit"
1800 note1c_data="The third note for the first commit"
1801 note2b_data="The second note for the second commit"
1802
1803 test_tick
1804 cat >input <<INPUT_END
1805 blob
1806 mark :2
1807 data <<EOF
1808 $file2_data
1809 EOF
1810
1811 commit refs/heads/notes-test
1812 mark :3
1813 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1814 data <<COMMIT
1815 first (:3)
1816 COMMIT
1817
1818 M 644 :2 file2
1819
1820 blob
1821 mark :4
1822 data $file4_len
1823 $file4_data
1824 commit refs/heads/notes-test
1825 mark :5
1826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1827 data <<COMMIT
1828 second (:5)
1829 COMMIT
1830
1831 M 644 :4 file4
1832
1833 commit refs/heads/notes-test
1834 mark :6
1835 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1836 data <<COMMIT
1837 third (:6)
1838 COMMIT
1839
1840 M 644 inline file5
1841 data <<EOF
1842 $file5_data
1843 EOF
1844
1845 M 755 inline file6
1846 data <<EOF
1847 $file6_data
1848 EOF
1849
1850 blob
1851 mark :7
1852 data <<EOF
1853 $note1_data
1854 EOF
1855
1856 blob
1857 mark :8
1858 data <<EOF
1859 $note2_data
1860 EOF
1861
1862 commit refs/notes/foobar
1863 mark :9
1864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1865 data <<COMMIT
1866 notes (:9)
1867 COMMIT
1868
1869 N :7 :3
1870 N :8 :5
1871 N inline :6
1872 data <<EOF
1873 $note3_data
1874 EOF
1875
1876 commit refs/notes/foobar
1877 mark :10
1878 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1879 data <<COMMIT
1880 notes (:10)
1881 COMMIT
1882
1883 N inline :3
1884 data <<EOF
1885 $note1b_data
1886 EOF
1887
1888 commit refs/notes/foobar2
1889 mark :11
1890 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1891 data <<COMMIT
1892 notes (:11)
1893 COMMIT
1894
1895 N inline :3
1896 data <<EOF
1897 $note1c_data
1898 EOF
1899
1900 commit refs/notes/foobar
1901 mark :12
1902 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1903 data <<COMMIT
1904 notes (:12)
1905 COMMIT
1906
1907 deleteall
1908 N inline :5
1909 data <<EOF
1910 $note2b_data
1911 EOF
1912
1913 INPUT_END
1914
1915 test_expect_success \
1916         'Q: commit notes' \
1917         'git fast-import <input &&
1918          git whatchanged notes-test'
1919
1920 test_expect_success 'Q: verify pack' '
1921         verify_packs
1922 '
1923
1924 commit1=$(git rev-parse notes-test~2)
1925 commit2=$(git rev-parse notes-test^)
1926 commit3=$(git rev-parse notes-test)
1927
1928 cat >expect <<EOF
1929 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1930 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1931
1932 first (:3)
1933 EOF
1934 test_expect_success \
1935         'Q: verify first commit' \
1936         'git cat-file commit notes-test~2 | sed 1d >actual &&
1937         test_cmp expect actual'
1938
1939 cat >expect <<EOF
1940 parent $commit1
1941 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1942 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1943
1944 second (:5)
1945 EOF
1946 test_expect_success \
1947         'Q: verify second commit' \
1948         'git cat-file commit notes-test^ | sed 1d >actual &&
1949         test_cmp expect actual'
1950
1951 cat >expect <<EOF
1952 parent $commit2
1953 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1954 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1955
1956 third (:6)
1957 EOF
1958 test_expect_success \
1959         'Q: verify third commit' \
1960         'git cat-file commit notes-test | sed 1d >actual &&
1961         test_cmp expect actual'
1962
1963 cat >expect <<EOF
1964 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1965 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1966
1967 notes (:9)
1968 EOF
1969 test_expect_success \
1970         'Q: verify first notes commit' \
1971         'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1972         test_cmp expect actual'
1973
1974 cat >expect.unsorted <<EOF
1975 100644 blob $commit1
1976 100644 blob $commit2
1977 100644 blob $commit3
1978 EOF
1979 cat expect.unsorted | sort >expect
1980 test_expect_success \
1981         'Q: verify first notes tree' \
1982         'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1983          test_cmp expect actual'
1984
1985 echo "$note1_data" >expect
1986 test_expect_success \
1987         'Q: verify first note for first commit' \
1988         'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1989
1990 echo "$note2_data" >expect
1991 test_expect_success \
1992         'Q: verify first note for second commit' \
1993         'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1994
1995 echo "$note3_data" >expect
1996 test_expect_success \
1997         'Q: verify first note for third commit' \
1998         'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1999
2000 cat >expect <<EOF
2001 parent `git rev-parse --verify refs/notes/foobar~2`
2002 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2003 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2004
2005 notes (:10)
2006 EOF
2007 test_expect_success \
2008         'Q: verify second notes commit' \
2009         'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2010         test_cmp expect actual'
2011
2012 cat >expect.unsorted <<EOF
2013 100644 blob $commit1
2014 100644 blob $commit2
2015 100644 blob $commit3
2016 EOF
2017 cat expect.unsorted | sort >expect
2018 test_expect_success \
2019         'Q: verify second notes tree' \
2020         'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
2021          test_cmp expect actual'
2022
2023 echo "$note1b_data" >expect
2024 test_expect_success \
2025         'Q: verify second note for first commit' \
2026         'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
2027
2028 echo "$note2_data" >expect
2029 test_expect_success \
2030         'Q: verify first note for second commit' \
2031         'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
2032
2033 echo "$note3_data" >expect
2034 test_expect_success \
2035         'Q: verify first note for third commit' \
2036         'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
2037
2038 cat >expect <<EOF
2039 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2040 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2041
2042 notes (:11)
2043 EOF
2044 test_expect_success \
2045         'Q: verify third notes commit' \
2046         'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2047         test_cmp expect actual'
2048
2049 cat >expect.unsorted <<EOF
2050 100644 blob $commit1
2051 EOF
2052 cat expect.unsorted | sort >expect
2053 test_expect_success \
2054         'Q: verify third notes tree' \
2055         'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
2056          test_cmp expect actual'
2057
2058 echo "$note1c_data" >expect
2059 test_expect_success \
2060         'Q: verify third note for first commit' \
2061         'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2062
2063 cat >expect <<EOF
2064 parent `git rev-parse --verify refs/notes/foobar^`
2065 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2066 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2067
2068 notes (:12)
2069 EOF
2070 test_expect_success \
2071         'Q: verify fourth notes commit' \
2072         'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2073         test_cmp expect actual'
2074
2075 cat >expect.unsorted <<EOF
2076 100644 blob $commit2
2077 EOF
2078 cat expect.unsorted | sort >expect
2079 test_expect_success \
2080         'Q: verify fourth notes tree' \
2081         'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
2082          test_cmp expect actual'
2083
2084 echo "$note2b_data" >expect
2085 test_expect_success \
2086         'Q: verify second note for second commit' \
2087         'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2088
2089 cat >input <<EOF
2090 reset refs/heads/Q0
2091
2092 commit refs/heads/note-Q0
2093 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2094 data <<COMMIT
2095 Note for an empty branch.
2096 COMMIT
2097
2098 N inline refs/heads/Q0
2099 data <<NOTE
2100 some note
2101 NOTE
2102 EOF
2103 test_expect_success \
2104         'Q: deny note on empty branch' \
2105         'test_must_fail git fast-import <input'
2106 ###
2107 ### series R (feature and option)
2108 ###
2109
2110 cat >input <<EOF
2111 feature no-such-feature-exists
2112 EOF
2113
2114 test_expect_success 'R: abort on unsupported feature' '
2115         test_must_fail git fast-import <input
2116 '
2117
2118 cat >input <<EOF
2119 feature date-format=now
2120 EOF
2121
2122 test_expect_success 'R: supported feature is accepted' '
2123         git fast-import <input
2124 '
2125
2126 cat >input << EOF
2127 blob
2128 data 3
2129 hi
2130 feature date-format=now
2131 EOF
2132
2133 test_expect_success 'R: abort on receiving feature after data command' '
2134         test_must_fail git fast-import <input
2135 '
2136
2137 cat >input << EOF
2138 feature import-marks=git.marks
2139 feature import-marks=git2.marks
2140 EOF
2141
2142 test_expect_success 'R: only one import-marks feature allowed per stream' '
2143         test_must_fail git fast-import <input
2144 '
2145
2146 cat >input << EOF
2147 feature export-marks=git.marks
2148 blob
2149 mark :1
2150 data 3
2151 hi
2152
2153 EOF
2154
2155 test_expect_success \
2156     'R: export-marks feature results in a marks file being created' \
2157     'cat input | git fast-import &&
2158     grep :1 git.marks'
2159
2160 test_expect_success \
2161     'R: export-marks options can be overridden by commandline options' \
2162     'cat input | git fast-import --export-marks=other.marks &&
2163     grep :1 other.marks'
2164
2165 test_expect_success 'R: catch typo in marks file name' '
2166         test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2167         echo "feature import-marks=nonexistent.marks" |
2168         test_must_fail git fast-import
2169 '
2170
2171 test_expect_success 'R: import and output marks can be the same file' '
2172         rm -f io.marks &&
2173         blob=$(echo hi | git hash-object --stdin) &&
2174         cat >expect <<-EOF &&
2175         :1 $blob
2176         :2 $blob
2177         EOF
2178         git fast-import --export-marks=io.marks <<-\EOF &&
2179         blob
2180         mark :1
2181         data 3
2182         hi
2183
2184         EOF
2185         git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2186         blob
2187         mark :2
2188         data 3
2189         hi
2190
2191         EOF
2192         test_cmp expect io.marks
2193 '
2194
2195 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2196         rm -f io.marks &&
2197         test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2198         blob
2199         mark :1
2200         data 3
2201         hi
2202
2203         EOF
2204 '
2205
2206 test_expect_success 'R: --import-marks-if-exists' '
2207         rm -f io.marks &&
2208         blob=$(echo hi | git hash-object --stdin) &&
2209         echo ":1 $blob" >expect &&
2210         git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2211         blob
2212         mark :1
2213         data 3
2214         hi
2215
2216         EOF
2217         test_cmp expect io.marks
2218 '
2219
2220 test_expect_success 'R: feature import-marks-if-exists' '
2221         rm -f io.marks &&
2222         >expect &&
2223
2224         git fast-import --export-marks=io.marks <<-\EOF &&
2225         feature import-marks-if-exists=not_io.marks
2226         EOF
2227         test_cmp expect io.marks &&
2228
2229         blob=$(echo hi | git hash-object --stdin) &&
2230
2231         echo ":1 $blob" >io.marks &&
2232         echo ":1 $blob" >expect &&
2233         echo ":2 $blob" >>expect &&
2234
2235         git fast-import --export-marks=io.marks <<-\EOF &&
2236         feature import-marks-if-exists=io.marks
2237         blob
2238         mark :2
2239         data 3
2240         hi
2241
2242         EOF
2243         test_cmp expect io.marks &&
2244
2245         echo ":3 $blob" >>expect &&
2246
2247         git fast-import --import-marks=io.marks \
2248                         --export-marks=io.marks <<-\EOF &&
2249         feature import-marks-if-exists=not_io.marks
2250         blob
2251         mark :3
2252         data 3
2253         hi
2254
2255         EOF
2256         test_cmp expect io.marks &&
2257
2258         >expect &&
2259
2260         git fast-import --import-marks-if-exists=not_io.marks \
2261                         --export-marks=io.marks <<-\EOF
2262         feature import-marks-if-exists=io.marks
2263         EOF
2264         test_cmp expect io.marks
2265 '
2266
2267 cat >input << EOF
2268 feature import-marks=marks.out
2269 feature export-marks=marks.new
2270 EOF
2271
2272 test_expect_success \
2273     'R: import to output marks works without any content' \
2274     'cat input | git fast-import &&
2275     test_cmp marks.out marks.new'
2276
2277 cat >input <<EOF
2278 feature import-marks=nonexistent.marks
2279 feature export-marks=marks.new
2280 EOF
2281
2282 test_expect_success \
2283     'R: import marks prefers commandline marks file over the stream' \
2284     'cat input | git fast-import --import-marks=marks.out &&
2285     test_cmp marks.out marks.new'
2286
2287
2288 cat >input <<EOF
2289 feature import-marks=nonexistent.marks
2290 feature export-marks=combined.marks
2291 EOF
2292
2293 test_expect_success 'R: multiple --import-marks= should be honoured' '
2294     head -n2 marks.out > one.marks &&
2295     tail -n +3 marks.out > two.marks &&
2296     git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2297     test_cmp marks.out combined.marks
2298 '
2299
2300 cat >input <<EOF
2301 feature relative-marks
2302 feature import-marks=relative.in
2303 feature export-marks=relative.out
2304 EOF
2305
2306 test_expect_success 'R: feature relative-marks should be honoured' '
2307     mkdir -p .git/info/fast-import/ &&
2308     cp marks.new .git/info/fast-import/relative.in &&
2309     git fast-import <input &&
2310     test_cmp marks.new .git/info/fast-import/relative.out
2311 '
2312
2313 cat >input <<EOF
2314 feature relative-marks
2315 feature import-marks=relative.in
2316 feature no-relative-marks
2317 feature export-marks=non-relative.out
2318 EOF
2319
2320 test_expect_success 'R: feature no-relative-marks should be honoured' '
2321     git fast-import <input &&
2322     test_cmp marks.new non-relative.out
2323 '
2324
2325 test_expect_success 'R: feature ls supported' '
2326         echo "feature ls" |
2327         git fast-import
2328 '
2329
2330 test_expect_success 'R: feature cat-blob supported' '
2331         echo "feature cat-blob" |
2332         git fast-import
2333 '
2334
2335 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2336         test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2337 '
2338
2339 test_expect_success NOT_MINGW 'R: print old blob' '
2340         blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2341         cat >expect <<-EOF &&
2342         ${blob} blob 11
2343         yes it can
2344
2345         EOF
2346         echo "cat-blob $blob" |
2347         git fast-import --cat-blob-fd=6 6>actual &&
2348         test_cmp expect actual
2349 '
2350
2351 test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' '
2352         echo hello >greeting &&
2353         blob=$(git hash-object -w greeting) &&
2354         cat >expect <<-EOF &&
2355         ${blob} blob 6
2356         hello
2357
2358         EOF
2359         git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2360         cat-blob $blob
2361         EOF
2362         test_cmp expect actual.3 &&
2363         test_cmp empty actual.1 &&
2364         git fast-import 3>actual.3 >actual.1 <<-EOF &&
2365         option cat-blob-fd=3
2366         cat-blob $blob
2367         EOF
2368         test_cmp empty actual.3 &&
2369         test_cmp expect actual.1
2370 '
2371
2372 test_expect_success NOT_MINGW 'R: print new blob' '
2373         blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2374         cat >expect <<-EOF &&
2375         ${blob} blob 12
2376         yep yep yep
2377
2378         EOF
2379         git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2380         blob
2381         mark :1
2382         data <<BLOB_END
2383         yep yep yep
2384         BLOB_END
2385         cat-blob :1
2386         EOF
2387         test_cmp expect actual
2388 '
2389
2390 test_expect_success NOT_MINGW 'R: print new blob by sha1' '
2391         blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2392         cat >expect <<-EOF &&
2393         ${blob} blob 25
2394         a new blob named by sha1
2395
2396         EOF
2397         git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2398         blob
2399         data <<BLOB_END
2400         a new blob named by sha1
2401         BLOB_END
2402         cat-blob $blob
2403         EOF
2404         test_cmp expect actual
2405 '
2406
2407 test_expect_success 'setup: big file' '
2408         (
2409                 echo "the quick brown fox jumps over the lazy dog" >big &&
2410                 for i in 1 2 3
2411                 do
2412                         cat big big big big >bigger &&
2413                         cat bigger bigger bigger bigger >big ||
2414                         exit
2415                 done
2416         )
2417 '
2418
2419 test_expect_success 'R: print two blobs to stdout' '
2420         blob1=$(git hash-object big) &&
2421         blob1_len=$(wc -c <big) &&
2422         blob2=$(echo hello | git hash-object --stdin) &&
2423         {
2424                 echo ${blob1} blob $blob1_len &&
2425                 cat big &&
2426                 cat <<-EOF
2427
2428                 ${blob2} blob 6
2429                 hello
2430
2431                 EOF
2432         } >expect &&
2433         {
2434                 cat <<-\END_PART1 &&
2435                         blob
2436                         mark :1
2437                         data <<data_end
2438                 END_PART1
2439                 cat big &&
2440                 cat <<-\EOF
2441                         data_end
2442                         blob
2443                         mark :2
2444                         data <<data_end
2445                         hello
2446                         data_end
2447                         cat-blob :1
2448                         cat-blob :2
2449                 EOF
2450         } |
2451         git fast-import >actual &&
2452         test_cmp expect actual
2453 '
2454
2455 test_expect_success PIPE 'R: copy using cat-file' '
2456         expect_id=$(git hash-object big) &&
2457         expect_len=$(wc -c <big) &&
2458         echo $expect_id blob $expect_len >expect.response &&
2459
2460         rm -f blobs &&
2461         cat >frontend <<-\FRONTEND_END &&
2462         #!/bin/sh
2463         FRONTEND_END
2464
2465         mkfifo blobs &&
2466         (
2467                 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2468                 cat <<-\EOF &&
2469                 feature cat-blob
2470                 blob
2471                 mark :1
2472                 data <<BLOB
2473                 EOF
2474                 cat big &&
2475                 cat <<-\EOF &&
2476                 BLOB
2477                 cat-blob :1
2478                 EOF
2479
2480                 read blob_id type size <&3 &&
2481                 echo "$blob_id $type $size" >response &&
2482                 head_c $size >blob <&3 &&
2483                 read newline <&3 &&
2484
2485                 cat <<-EOF &&
2486                 commit refs/heads/copied
2487                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2488                 data <<COMMIT
2489                 copy big file as file3
2490                 COMMIT
2491                 M 644 inline file3
2492                 data <<BLOB
2493                 EOF
2494                 cat blob &&
2495                 echo BLOB
2496         ) 3<blobs |
2497         git fast-import --cat-blob-fd=3 3>blobs &&
2498         git show copied:file3 >actual &&
2499         test_cmp expect.response response &&
2500         test_cmp big actual
2501 '
2502
2503 test_expect_success PIPE 'R: print blob mid-commit' '
2504         rm -f blobs &&
2505         echo "A blob from _before_ the commit." >expect &&
2506         mkfifo blobs &&
2507         (
2508                 exec 3<blobs &&
2509                 cat <<-EOF &&
2510                 feature cat-blob
2511                 blob
2512                 mark :1
2513                 data <<BLOB
2514                 A blob from _before_ the commit.
2515                 BLOB
2516                 commit refs/heads/temporary
2517                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2518                 data <<COMMIT
2519                 Empty commit
2520                 COMMIT
2521                 cat-blob :1
2522                 EOF
2523
2524                 read blob_id type size <&3 &&
2525                 head_c $size >actual <&3 &&
2526                 read newline <&3 &&
2527
2528                 echo
2529         ) |
2530         git fast-import --cat-blob-fd=3 3>blobs &&
2531         test_cmp expect actual
2532 '
2533
2534 test_expect_success PIPE 'R: print staged blob within commit' '
2535         rm -f blobs &&
2536         echo "A blob from _within_ the commit." >expect &&
2537         mkfifo blobs &&
2538         (
2539                 exec 3<blobs &&
2540                 cat <<-EOF &&
2541                 feature cat-blob
2542                 commit refs/heads/within
2543                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2544                 data <<COMMIT
2545                 Empty commit
2546                 COMMIT
2547                 M 644 inline within
2548                 data <<BLOB
2549                 A blob from _within_ the commit.
2550                 BLOB
2551                 EOF
2552
2553                 to_get=$(
2554                         echo "A blob from _within_ the commit." |
2555                         git hash-object --stdin
2556                 ) &&
2557                 echo "cat-blob $to_get" &&
2558
2559                 read blob_id type size <&3 &&
2560                 head_c $size >actual <&3 &&
2561                 read newline <&3 &&
2562
2563                 echo deleteall
2564         ) |
2565         git fast-import --cat-blob-fd=3 3>blobs &&
2566         test_cmp expect actual
2567 '
2568
2569 cat >input << EOF
2570 option git quiet
2571 blob
2572 data 3
2573 hi
2574
2575 EOF
2576
2577 test_expect_success 'R: quiet option results in no stats being output' '
2578     cat input | git fast-import 2> output &&
2579     test_cmp empty output
2580 '
2581
2582 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2583         echo feature done | test_must_fail git fast-import &&
2584         test_must_fail git fast-import --done </dev/null
2585 '
2586
2587 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2588         git fast-import <<-\EOF &&
2589         feature done
2590         done
2591         trailing gibberish
2592         EOF
2593         git fast-import <<-\EOF
2594         done
2595         more trailing gibberish
2596         EOF
2597 '
2598
2599 test_expect_success 'R: terminating "done" within commit' '
2600         cat >expect <<-\EOF &&
2601         OBJID
2602         :000000 100644 OBJID OBJID A    hello.c
2603         :000000 100644 OBJID OBJID A    hello2.c
2604         EOF
2605         git fast-import <<-EOF &&
2606         commit refs/heads/done-ends
2607         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2608         data <<EOT
2609         Commit terminated by "done" command
2610         EOT
2611         M 100644 inline hello.c
2612         data <<EOT
2613         Hello, world.
2614         EOT
2615         C hello.c hello2.c
2616         done
2617         EOF
2618         git rev-list done-ends |
2619         git diff-tree -r --stdin --root --always |
2620         sed -e "s/$_x40/OBJID/g" >actual &&
2621         test_cmp expect actual
2622 '
2623
2624 cat >input <<EOF
2625 option git non-existing-option
2626 EOF
2627
2628 test_expect_success 'R: die on unknown option' '
2629     test_must_fail git fast-import <input
2630 '
2631
2632 test_expect_success 'R: unknown commandline options are rejected' '\
2633     test_must_fail git fast-import --non-existing-option < /dev/null
2634 '
2635
2636 test_expect_success 'R: die on invalid option argument' '
2637         echo "option git active-branches=-5" |
2638         test_must_fail git fast-import &&
2639         echo "option git depth=" |
2640         test_must_fail git fast-import &&
2641         test_must_fail git fast-import --depth="5 elephants" </dev/null
2642 '
2643
2644 cat >input <<EOF
2645 option non-existing-vcs non-existing-option
2646 EOF
2647
2648 test_expect_success 'R: ignore non-git options' '
2649     git fast-import <input
2650 '
2651
2652 ##
2653 ## R: very large blobs
2654 ##
2655 blobsize=$((2*1024*1024 + 53))
2656 test-genrandom bar $blobsize >expect
2657 cat >input <<INPUT_END
2658 commit refs/heads/big-file
2659 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2660 data <<COMMIT
2661 R - big file
2662 COMMIT
2663
2664 M 644 inline big1
2665 data $blobsize
2666 INPUT_END
2667 cat expect >>input
2668 cat >>input <<INPUT_END
2669 M 644 inline big2
2670 data $blobsize
2671 INPUT_END
2672 cat expect >>input
2673 echo >>input
2674
2675 test_expect_success \
2676         'R: blob bigger than threshold' \
2677         'test_create_repo R &&
2678          git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2679
2680 test_expect_success 'R: verify created pack' '
2681         (
2682                 cd R &&
2683                 verify_packs -v > ../verify
2684         )
2685 '
2686
2687 test_expect_success \
2688         'R: verify written objects' \
2689         'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2690          test_cmp expect actual &&
2691          a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2692          b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2693          test $a = $b'
2694 test_expect_success \
2695         'R: blob appears only once' \
2696         'n=$(grep $a verify | wc -l) &&
2697          test 1 = $n'
2698
2699 ###
2700 ### series S
2701 ###
2702 #
2703 # Make sure missing spaces and EOLs after mark references
2704 # cause errors.
2705 #
2706 # Setup:
2707 #
2708 #   1--2--4
2709 #    \   /
2710 #     -3-
2711 #
2712 #   commit marks:  301, 302, 303, 304
2713 #   blob marks:              403, 404, resp.
2714 #   note mark:          202
2715 #
2716 # The error message when a space is missing not at the
2717 # end of the line is:
2718 #
2719 #   Missing space after ..
2720 #
2721 # or when extra characters come after the mark at the end
2722 # of the line:
2723 #
2724 #   Garbage after ..
2725 #
2726 # or when the dataref is neither "inline " or a known SHA1,
2727 #
2728 #   Invalid dataref ..
2729 #
2730 test_tick
2731
2732 cat >input <<INPUT_END
2733 commit refs/heads/S
2734 mark :301
2735 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2736 data <<COMMIT
2737 commit 1
2738 COMMIT
2739 M 100644 inline hello.c
2740 data <<BLOB
2741 blob 1
2742 BLOB
2743
2744 commit refs/heads/S
2745 mark :302
2746 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2747 data <<COMMIT
2748 commit 2
2749 COMMIT
2750 from :301
2751 M 100644 inline hello.c
2752 data <<BLOB
2753 blob 2
2754 BLOB
2755
2756 blob
2757 mark :403
2758 data <<BLOB
2759 blob 3
2760 BLOB
2761
2762 blob
2763 mark :202
2764 data <<BLOB
2765 note 2
2766 BLOB
2767 INPUT_END
2768
2769 test_expect_success 'S: initialize for S tests' '
2770         git fast-import --export-marks=marks <input
2771 '
2772
2773 #
2774 # filemodify, three datarefs
2775 #
2776 test_expect_success 'S: filemodify with garbage after mark must fail' '
2777         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2778         commit refs/heads/S
2779         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2780         data <<COMMIT
2781         commit N
2782         COMMIT
2783         M 100644 :403x hello.c
2784         EOF
2785         cat err &&
2786         test_i18ngrep "space after mark" err
2787 '
2788
2789 # inline is misspelled; fast-import thinks it is some unknown dataref
2790 test_expect_success 'S: filemodify with garbage after inline must fail' '
2791         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2792         commit refs/heads/S
2793         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2794         data <<COMMIT
2795         commit N
2796         COMMIT
2797         M 100644 inlineX hello.c
2798         data <<BLOB
2799         inline
2800         BLOB
2801         EOF
2802         cat err &&
2803         test_i18ngrep "nvalid dataref" err
2804 '
2805
2806 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2807         sha1=$(grep :403 marks | cut -d\  -f2) &&
2808         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2809         commit refs/heads/S
2810         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2811         data <<COMMIT
2812         commit N
2813         COMMIT
2814         M 100644 ${sha1}x hello.c
2815         EOF
2816         cat err &&
2817         test_i18ngrep "space after SHA1" err
2818 '
2819
2820 #
2821 # notemodify, three ways to say dataref
2822 #
2823 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2824         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2825         commit refs/heads/S
2826         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2827         data <<COMMIT
2828         commit S note dataref markref
2829         COMMIT
2830         N :202x :302
2831         EOF
2832         cat err &&
2833         test_i18ngrep "space after mark" err
2834 '
2835
2836 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2837         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2838         commit refs/heads/S
2839         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2840         data <<COMMIT
2841         commit S note dataref inline
2842         COMMIT
2843         N inlineX :302
2844         data <<BLOB
2845         note blob
2846         BLOB
2847         EOF
2848         cat err &&
2849         test_i18ngrep "nvalid dataref" err
2850 '
2851
2852 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2853         sha1=$(grep :202 marks | cut -d\  -f2) &&
2854         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2855         commit refs/heads/S
2856         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2857         data <<COMMIT
2858         commit S note dataref sha1
2859         COMMIT
2860         N ${sha1}x :302
2861         EOF
2862         cat err &&
2863         test_i18ngrep "space after SHA1" err
2864 '
2865
2866 #
2867 # notemodify, mark in commit-ish
2868 #
2869 test_expect_success 'S: notemodify with garbarge after mark commit-ish must fail' '
2870         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2871         commit refs/heads/Snotes
2872         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2873         data <<COMMIT
2874         commit S note commit-ish
2875         COMMIT
2876         N :202 :302x
2877         EOF
2878         cat err &&
2879         test_i18ngrep "after mark" err
2880 '
2881
2882 #
2883 # from
2884 #
2885 test_expect_success 'S: from with garbage after mark must fail' '
2886         # no &&
2887         git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err
2888         commit refs/heads/S2
2889         mark :303
2890         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2891         data <<COMMIT
2892         commit 3
2893         COMMIT
2894         from :301x
2895         M 100644 :403 hello.c
2896         EOF
2897
2898         ret=$? &&
2899         echo returned $ret &&
2900         test $ret -ne 0 && # failed, but it created the commit
2901
2902         # go create the commit, need it for merge test
2903         git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2904         commit refs/heads/S2
2905         mark :303
2906         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2907         data <<COMMIT
2908         commit 3
2909         COMMIT
2910         from :301
2911         M 100644 :403 hello.c
2912         EOF
2913
2914         # now evaluate the error
2915         cat err &&
2916         test_i18ngrep "after mark" err
2917 '
2918
2919
2920 #
2921 # merge
2922 #
2923 test_expect_success 'S: merge with garbage after mark must fail' '
2924         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2925         commit refs/heads/S
2926         mark :304
2927         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2928         data <<COMMIT
2929         merge 4
2930         COMMIT
2931         from :302
2932         merge :303x
2933         M 100644 :403 hello.c
2934         EOF
2935         cat err &&
2936         test_i18ngrep "after mark" err
2937 '
2938
2939 #
2940 # tag, from markref
2941 #
2942 test_expect_success 'S: tag with garbage after mark must fail' '
2943         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2944         tag refs/tags/Stag
2945         from :302x
2946         tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2947         data <<TAG
2948         tag S
2949         TAG
2950         EOF
2951         cat err &&
2952         test_i18ngrep "after mark" err
2953 '
2954
2955 #
2956 # cat-blob markref
2957 #
2958 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2959         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2960         cat-blob :403x
2961         EOF
2962         cat err &&
2963         test_i18ngrep "after mark" err
2964 '
2965
2966 #
2967 # ls markref
2968 #
2969 test_expect_success 'S: ls with garbage after mark must fail' '
2970         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2971         ls :302x hello.c
2972         EOF
2973         cat err &&
2974         test_i18ngrep "space after mark" err
2975 '
2976
2977 test_expect_success 'S: ls with garbage after sha1 must fail' '
2978         sha1=$(grep :302 marks | cut -d\  -f2) &&
2979         test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2980         ls ${sha1}x hello.c
2981         EOF
2982         cat err &&
2983         test_i18ngrep "space after tree-ish" err
2984 '
2985
2986 ###
2987 ### series T (ls)
2988 ###
2989 # Setup is carried over from series S.
2990
2991 test_expect_success 'T: ls root tree' '
2992         sed -e "s/Z\$//" >expect <<-EOF &&
2993         040000 tree $(git rev-parse S^{tree})   Z
2994         EOF
2995         sha1=$(git rev-parse --verify S) &&
2996         git fast-import --import-marks=marks <<-EOF >actual &&
2997         ls $sha1 ""
2998         EOF
2999         test_cmp expect actual
3000 '
3001
3002 test_done