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