Code

fast-import: check committer name more strictly
[git.git] / t / t9300-fast-import.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Shawn Pearce
4 #
6 test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
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 }
27 file2_data='file2
28 second line of EOF'
30 file3_data='EOF
31 in 3rd file
32  END'
34 file4_data=abcd
35 file4_len=4
37 file5_data='an inline file.
38   we should see it later.'
40 file6_data='#!/bin/sh
41 echo "$@"'
43 >empty
45 test_expect_success 'setup: have pipes?' '
46         rm -f frob &&
47         if mkfifo frob
48         then
49                 test_set_prereq PIPE
50         fi
51 '
53 ###
54 ### series A
55 ###
57 test_tick
59 test_expect_success 'empty stream succeeds' '
60         git fast-import </dev/null
61 '
63 cat >input <<INPUT_END
64 blob
65 mark :2
66 data <<EOF
67 $file2_data
68 EOF
70 blob
71 mark :3
72 data <<END
73 $file3_data
74 END
76 blob
77 mark :4
78 data $file4_len
79 $file4_data
80 commit refs/heads/master
81 mark :5
82 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
83 data <<COMMIT
84 initial
85 COMMIT
87 M 644 :2 file2
88 M 644 :3 file3
89 M 755 :4 file4
91 tag series-A
92 from :5
93 data <<EOF
94 An annotated tag without a tagger
95 EOF
97 INPUT_END
98 test_expect_success \
99     'A: create pack from stdin' \
100     'git fast-import --export-marks=marks.out <input &&
101          git whatchanged master'
102 test_expect_success \
103         'A: verify pack' \
104         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
106 cat >expect <<EOF
107 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
110 initial
111 EOF
112 test_expect_success \
113         'A: verify commit' \
114         'git cat-file commit master | sed 1d >actual &&
115         test_cmp expect actual'
117 cat >expect <<EOF
118 100644 blob file2
119 100644 blob file3
120 100755 blob file4
121 EOF
122 test_expect_success \
123         'A: verify tree' \
124         'git cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
125          test_cmp expect actual'
127 echo "$file2_data" >expect
128 test_expect_success \
129         'A: verify file2' \
130         'git cat-file blob master:file2 >actual && test_cmp expect actual'
132 echo "$file3_data" >expect
133 test_expect_success \
134         'A: verify file3' \
135         'git cat-file blob master:file3 >actual && test_cmp expect actual'
137 printf "$file4_data" >expect
138 test_expect_success \
139         'A: verify file4' \
140         'git cat-file blob master:file4 >actual && test_cmp expect actual'
142 cat >expect <<EOF
143 object $(git rev-parse refs/heads/master)
144 type commit
145 tag series-A
147 An annotated tag without a tagger
148 EOF
149 test_expect_success 'A: verify tag/series-A' '
150         git cat-file tag tags/series-A >actual &&
151         test_cmp expect actual
154 cat >expect <<EOF
155 :2 `git rev-parse --verify master:file2`
156 :3 `git rev-parse --verify master:file3`
157 :4 `git rev-parse --verify master:file4`
158 :5 `git rev-parse --verify master^0`
159 EOF
160 test_expect_success \
161         'A: verify marks output' \
162         'test_cmp expect marks.out'
164 test_expect_success \
165         'A: verify marks import' \
166         'git fast-import \
167                 --import-marks=marks.out \
168                 --export-marks=marks.new \
169                 </dev/null &&
170         test_cmp expect marks.new'
172 test_tick
173 cat >input <<INPUT_END
174 commit refs/heads/verify--import-marks
175 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
176 data <<COMMIT
177 recreate from :5
178 COMMIT
180 from :5
181 M 755 :2 copy-of-file2
183 INPUT_END
184 test_expect_success \
185         'A: verify marks import does not crash' \
186         'git fast-import --import-marks=marks.out <input &&
187          git whatchanged verify--import-marks'
188 test_expect_success \
189         'A: verify pack' \
190         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
191 cat >expect <<EOF
192 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
193 EOF
194 git diff-tree -M -r master verify--import-marks >actual
195 test_expect_success \
196         'A: verify diff' \
197         'compare_diff_raw expect actual &&
198          test `git rev-parse --verify master:file2` \
199             = `git rev-parse --verify verify--import-marks:copy-of-file2`'
201 test_tick
202 mt=$(git hash-object --stdin < /dev/null)
203 : >input.blob
204 : >marks.exp
205 : >tree.exp
207 cat >input.commit <<EOF
208 commit refs/heads/verify--dump-marks
209 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
210 data <<COMMIT
211 test the sparse array dumping routines with exponentially growing marks
212 COMMIT
213 EOF
215 i=0
216 l=4
217 m=6
218 n=7
219 while test "$i" -lt 27; do
220     cat >>input.blob <<EOF
221 blob
222 mark :$l
223 data 0
224 blob
225 mark :$m
226 data 0
227 blob
228 mark :$n
229 data 0
230 EOF
231     echo "M 100644 :$l l$i" >>input.commit
232     echo "M 100644 :$m m$i" >>input.commit
233     echo "M 100644 :$n n$i" >>input.commit
235     echo ":$l $mt" >>marks.exp
236     echo ":$m $mt" >>marks.exp
237     echo ":$n $mt" >>marks.exp
239     printf "100644 blob $mt\tl$i\n" >>tree.exp
240     printf "100644 blob $mt\tm$i\n" >>tree.exp
241     printf "100644 blob $mt\tn$i\n" >>tree.exp
243     l=$(($l + $l))
244     m=$(($m + $m))
245     n=$(($l + $n))
247     i=$((1 + $i))
248 done
250 sort tree.exp > tree.exp_s
252 test_expect_success 'A: export marks with large values' '
253         cat input.blob input.commit | git fast-import --export-marks=marks.large &&
254         git ls-tree refs/heads/verify--dump-marks >tree.out &&
255         test_cmp tree.exp_s tree.out &&
256         test_cmp marks.exp marks.large'
258 ###
259 ### series B
260 ###
262 test_tick
263 cat >input <<INPUT_END
264 commit refs/heads/branch
265 mark :1
266 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
267 data <<COMMIT
268 corrupt
269 COMMIT
271 from refs/heads/master
272 M 755 0000000000000000000000000000000000000001 zero1
274 INPUT_END
275 test_expect_success 'B: fail on invalid blob sha1' '
276     test_must_fail git fast-import <input
278 rm -f .git/objects/pack_* .git/objects/index_*
280 cat >input <<INPUT_END
281 commit .badbranchname
282 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
283 data <<COMMIT
284 corrupt
285 COMMIT
287 from refs/heads/master
289 INPUT_END
290 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
291     test_must_fail git fast-import <input
293 rm -f .git/objects/pack_* .git/objects/index_*
295 cat >input <<INPUT_END
296 commit bad[branch]name
297 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
298 data <<COMMIT
299 corrupt
300 COMMIT
302 from refs/heads/master
304 INPUT_END
305 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
306     test_must_fail git fast-import <input
308 rm -f .git/objects/pack_* .git/objects/index_*
310 cat >input <<INPUT_END
311 commit TEMP_TAG
312 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
313 data <<COMMIT
314 tag base
315 COMMIT
317 from refs/heads/master
319 INPUT_END
320 test_expect_success \
321     'B: accept branch name "TEMP_TAG"' \
322     'git fast-import <input &&
323          test -f .git/TEMP_TAG &&
324          test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
325 rm -f .git/TEMP_TAG
327 git gc 2>/dev/null >/dev/null
328 git prune 2>/dev/null >/dev/null
330 cat >input <<INPUT_END
331 commit refs/heads/empty-committer-1
332 committer  <> $GIT_COMMITTER_DATE
333 data <<COMMIT
334 empty commit
335 COMMIT
336 INPUT_END
337 test_expect_success 'B: accept empty committer' '
338         git fast-import <input &&
339         out=$(git fsck) &&
340         echo "$out" &&
341         test -z "$out"
343 git update-ref -d refs/heads/empty-committer-1 || true
345 git gc 2>/dev/null >/dev/null
346 git prune 2>/dev/null >/dev/null
348 cat >input <<INPUT_END
349 commit refs/heads/empty-committer-2
350 committer <a@b.com> $GIT_COMMITTER_DATE
351 data <<COMMIT
352 empty commit
353 COMMIT
354 INPUT_END
355 test_expect_success 'B: accept and fixup committer with no name' '
356         git fast-import <input &&
357         out=$(git fsck) &&
358         echo "$out" &&
359         test -z "$out"
361 git update-ref -d refs/heads/empty-committer-2 || true
363 git gc 2>/dev/null >/dev/null
364 git prune 2>/dev/null >/dev/null
366 cat >input <<INPUT_END
367 commit refs/heads/invalid-committer
368 committer Name email> $GIT_COMMITTER_DATE
369 data <<COMMIT
370 empty commit
371 COMMIT
372 INPUT_END
373 test_expect_success 'B: fail on invalid committer (1)' '
374         test_must_fail git fast-import <input
376 git update-ref -d refs/heads/invalid-committer || true
378 cat >input <<INPUT_END
379 commit refs/heads/invalid-committer
380 committer Name <e<mail> $GIT_COMMITTER_DATE
381 data <<COMMIT
382 empty commit
383 COMMIT
384 INPUT_END
385 test_expect_success 'B: fail on invalid committer (2)' '
386         test_must_fail git fast-import <input
388 git update-ref -d refs/heads/invalid-committer || true
390 cat >input <<INPUT_END
391 commit refs/heads/invalid-committer
392 committer Name <email>> $GIT_COMMITTER_DATE
393 data <<COMMIT
394 empty commit
395 COMMIT
396 INPUT_END
397 test_expect_success 'B: fail on invalid committer (3)' '
398         test_must_fail git fast-import <input
400 git update-ref -d refs/heads/invalid-committer || true
402 cat >input <<INPUT_END
403 commit refs/heads/invalid-committer
404 committer Name <email $GIT_COMMITTER_DATE
405 data <<COMMIT
406 empty commit
407 COMMIT
408 INPUT_END
409 test_expect_success 'B: fail on invalid committer (4)' '
410         test_must_fail git fast-import <input
412 git update-ref -d refs/heads/invalid-committer || true
414 cat >input <<INPUT_END
415 commit refs/heads/invalid-committer
416 committer Name<email> $GIT_COMMITTER_DATE
417 data <<COMMIT
418 empty commit
419 COMMIT
420 INPUT_END
421 test_expect_success 'B: fail on invalid committer (5)' '
422         test_must_fail git fast-import <input
424 git update-ref -d refs/heads/invalid-committer || true
426 ###
427 ### series C
428 ###
430 newf=`echo hi newf | git hash-object -w --stdin`
431 oldf=`git rev-parse --verify master:file2`
432 test_tick
433 cat >input <<INPUT_END
434 commit refs/heads/branch
435 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
436 data <<COMMIT
437 second
438 COMMIT
440 from refs/heads/master
441 M 644 $oldf file2/oldf
442 M 755 $newf file2/newf
443 D file3
445 INPUT_END
446 test_expect_success \
447     'C: incremental import create pack from stdin' \
448     'git fast-import <input &&
449          git whatchanged branch'
450 test_expect_success \
451         'C: verify pack' \
452         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
453 test_expect_success \
454         'C: validate reuse existing blob' \
455         'test $newf = `git rev-parse --verify branch:file2/newf` &&
456          test $oldf = `git rev-parse --verify branch:file2/oldf`'
458 cat >expect <<EOF
459 parent `git rev-parse --verify master^0`
460 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
461 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
463 second
464 EOF
465 test_expect_success \
466         'C: verify commit' \
467         'git cat-file commit branch | sed 1d >actual &&
468          test_cmp expect actual'
470 cat >expect <<EOF
471 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
472 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
473 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
474 EOF
475 git diff-tree -M -r master branch >actual
476 test_expect_success \
477         'C: validate rename result' \
478         'compare_diff_raw expect actual'
480 ###
481 ### series D
482 ###
484 test_tick
485 cat >input <<INPUT_END
486 commit refs/heads/branch
487 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
488 data <<COMMIT
489 third
490 COMMIT
492 from refs/heads/branch^0
493 M 644 inline newdir/interesting
494 data <<EOF
495 $file5_data
496 EOF
498 M 755 inline newdir/exec.sh
499 data <<EOF
500 $file6_data
501 EOF
503 INPUT_END
504 test_expect_success \
505     'D: inline data in commit' \
506     'git fast-import <input &&
507          git whatchanged branch'
508 test_expect_success \
509         'D: verify pack' \
510         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
512 cat >expect <<EOF
513 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
514 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
515 EOF
516 git diff-tree -M -r branch^ branch >actual
517 test_expect_success \
518         'D: validate new files added' \
519         'compare_diff_raw expect actual'
521 echo "$file5_data" >expect
522 test_expect_success \
523         'D: verify file5' \
524         'git cat-file blob branch:newdir/interesting >actual &&
525          test_cmp expect actual'
527 echo "$file6_data" >expect
528 test_expect_success \
529         'D: verify file6' \
530         'git cat-file blob branch:newdir/exec.sh >actual &&
531          test_cmp expect actual'
533 ###
534 ### series E
535 ###
537 cat >input <<INPUT_END
538 commit refs/heads/branch
539 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
540 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
541 data <<COMMIT
542 RFC 2822 type date
543 COMMIT
545 from refs/heads/branch^0
547 INPUT_END
548 test_expect_success 'E: rfc2822 date, --date-format=raw' '
549     test_must_fail git fast-import --date-format=raw <input
551 test_expect_success \
552     'E: rfc2822 date, --date-format=rfc2822' \
553     'git fast-import --date-format=rfc2822 <input'
554 test_expect_success \
555         'E: verify pack' \
556         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
558 cat >expect <<EOF
559 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
560 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
562 RFC 2822 type date
563 EOF
564 test_expect_success \
565         'E: verify commit' \
566         'git cat-file commit branch | sed 1,2d >actual &&
567         test_cmp expect actual'
569 ###
570 ### series F
571 ###
573 old_branch=`git rev-parse --verify branch^0`
574 test_tick
575 cat >input <<INPUT_END
576 commit refs/heads/branch
577 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
578 data <<COMMIT
579 losing things already?
580 COMMIT
582 from refs/heads/branch~1
584 reset refs/heads/other
585 from refs/heads/branch
587 INPUT_END
588 test_expect_success \
589     'F: non-fast-forward update skips' \
590     'if git fast-import <input
591          then
592                 echo BAD gfi did not fail
593                 return 1
594          else
595                 if test $old_branch = `git rev-parse --verify branch^0`
596                 then
597                         : branch unaffected and failure returned
598                         return 0
599                 else
600                         echo BAD gfi changed branch $old_branch
601                         return 1
602                 fi
603          fi
604         '
605 test_expect_success \
606         'F: verify pack' \
607         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
609 cat >expect <<EOF
610 tree `git rev-parse branch~1^{tree}`
611 parent `git rev-parse branch~1`
612 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
613 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
615 losing things already?
616 EOF
617 test_expect_success \
618         'F: verify other commit' \
619         'git cat-file commit other >actual &&
620         test_cmp expect actual'
622 ###
623 ### series G
624 ###
626 old_branch=`git rev-parse --verify branch^0`
627 test_tick
628 cat >input <<INPUT_END
629 commit refs/heads/branch
630 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
631 data <<COMMIT
632 losing things already?
633 COMMIT
635 from refs/heads/branch~1
637 INPUT_END
638 test_expect_success \
639     'G: non-fast-forward update forced' \
640     'git fast-import --force <input'
641 test_expect_success \
642         'G: verify pack' \
643         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
644 test_expect_success \
645         'G: branch changed, but logged' \
646         'test $old_branch != `git rev-parse --verify branch^0` &&
647          test $old_branch = `git rev-parse --verify branch@{1}`'
649 ###
650 ### series H
651 ###
653 test_tick
654 cat >input <<INPUT_END
655 commit refs/heads/H
656 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
657 data <<COMMIT
658 third
659 COMMIT
661 from refs/heads/branch^0
662 M 644 inline i-will-die
663 data <<EOF
664 this file will never exist.
665 EOF
667 deleteall
668 M 644 inline h/e/l/lo
669 data <<EOF
670 $file5_data
671 EOF
673 INPUT_END
674 test_expect_success \
675     'H: deletall, add 1' \
676     'git fast-import <input &&
677          git whatchanged H'
678 test_expect_success \
679         'H: verify pack' \
680         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
682 cat >expect <<EOF
683 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
684 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
685 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
686 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
687 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
688 EOF
689 git diff-tree -M -r H^ H >actual
690 test_expect_success \
691         'H: validate old files removed, new files added' \
692         'compare_diff_raw expect actual'
694 echo "$file5_data" >expect
695 test_expect_success \
696         'H: verify file' \
697         'git cat-file blob H:h/e/l/lo >actual &&
698          test_cmp expect actual'
700 ###
701 ### series I
702 ###
704 cat >input <<INPUT_END
705 commit refs/heads/export-boundary
706 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
707 data <<COMMIT
708 we have a border.  its only 40 characters wide.
709 COMMIT
711 from refs/heads/branch
713 INPUT_END
714 test_expect_success \
715     'I: export-pack-edges' \
716     'git fast-import --export-pack-edges=edges.list <input'
718 cat >expect <<EOF
719 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
720 EOF
721 test_expect_success \
722         'I: verify edge list' \
723         'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
724          test_cmp expect actual'
726 ###
727 ### series J
728 ###
730 cat >input <<INPUT_END
731 commit refs/heads/J
732 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
733 data <<COMMIT
734 create J
735 COMMIT
737 from refs/heads/branch
739 reset refs/heads/J
741 commit refs/heads/J
742 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
743 data <<COMMIT
744 initialize J
745 COMMIT
747 INPUT_END
748 test_expect_success \
749     'J: reset existing branch creates empty commit' \
750     'git fast-import <input'
751 test_expect_success \
752         'J: branch has 1 commit, empty tree' \
753         'test 1 = `git rev-list J | wc -l` &&
754          test 0 = `git ls-tree J | wc -l`'
756 ###
757 ### series K
758 ###
760 cat >input <<INPUT_END
761 commit refs/heads/K
762 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
763 data <<COMMIT
764 create K
765 COMMIT
767 from refs/heads/branch
769 commit refs/heads/K
770 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
771 data <<COMMIT
772 redo K
773 COMMIT
775 from refs/heads/branch^1
777 INPUT_END
778 test_expect_success \
779     'K: reinit branch with from' \
780     'git fast-import <input'
781 test_expect_success \
782     'K: verify K^1 = branch^1' \
783     'test `git rev-parse --verify branch^1` \
784                 = `git rev-parse --verify K^1`'
786 ###
787 ### series L
788 ###
790 cat >input <<INPUT_END
791 blob
792 mark :1
793 data <<EOF
794 some data
795 EOF
797 blob
798 mark :2
799 data <<EOF
800 other data
801 EOF
803 commit refs/heads/L
804 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
805 data <<COMMIT
806 create L
807 COMMIT
809 M 644 :1 b.
810 M 644 :1 b/other
811 M 644 :1 ba
813 commit refs/heads/L
814 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
815 data <<COMMIT
816 update L
817 COMMIT
819 M 644 :2 b.
820 M 644 :2 b/other
821 M 644 :2 ba
822 INPUT_END
824 cat >expect <<EXPECT_END
825 :100644 100644 4268632... 55d3a52... M  b.
826 :040000 040000 0ae5cac... 443c768... M  b
827 :100644 100644 4268632... 55d3a52... M  ba
828 EXPECT_END
830 test_expect_success \
831     'L: verify internal tree sorting' \
832         'git fast-import <input &&
833          git diff-tree --abbrev --raw L^ L >output &&
834          test_cmp expect output'
836 ###
837 ### series M
838 ###
840 test_tick
841 cat >input <<INPUT_END
842 commit refs/heads/M1
843 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
844 data <<COMMIT
845 file rename
846 COMMIT
848 from refs/heads/branch^0
849 R file2/newf file2/n.e.w.f
851 INPUT_END
853 cat >expect <<EOF
854 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
855 EOF
856 test_expect_success \
857         'M: rename file in same subdirectory' \
858         'git fast-import <input &&
859          git diff-tree -M -r M1^ M1 >actual &&
860          compare_diff_raw expect actual'
862 cat >input <<INPUT_END
863 commit refs/heads/M2
864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
865 data <<COMMIT
866 file rename
867 COMMIT
869 from refs/heads/branch^0
870 R file2/newf i/am/new/to/you
872 INPUT_END
874 cat >expect <<EOF
875 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
876 EOF
877 test_expect_success \
878         'M: rename file to new subdirectory' \
879         'git fast-import <input &&
880          git diff-tree -M -r M2^ M2 >actual &&
881          compare_diff_raw expect actual'
883 cat >input <<INPUT_END
884 commit refs/heads/M3
885 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
886 data <<COMMIT
887 file rename
888 COMMIT
890 from refs/heads/M2^0
891 R i other/sub
893 INPUT_END
895 cat >expect <<EOF
896 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
897 EOF
898 test_expect_success \
899         'M: rename subdirectory to new subdirectory' \
900         'git fast-import <input &&
901          git diff-tree -M -r M3^ M3 >actual &&
902          compare_diff_raw expect actual'
904 ###
905 ### series N
906 ###
908 test_tick
909 cat >input <<INPUT_END
910 commit refs/heads/N1
911 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
912 data <<COMMIT
913 file copy
914 COMMIT
916 from refs/heads/branch^0
917 C file2/newf file2/n.e.w.f
919 INPUT_END
921 cat >expect <<EOF
922 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
923 EOF
924 test_expect_success \
925         'N: copy file in same subdirectory' \
926         'git fast-import <input &&
927          git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
928          compare_diff_raw expect actual'
930 cat >input <<INPUT_END
931 commit refs/heads/N2
932 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
933 data <<COMMIT
934 clean directory copy
935 COMMIT
937 from refs/heads/branch^0
938 C file2 file3
940 commit refs/heads/N2
941 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
942 data <<COMMIT
943 modify directory copy
944 COMMIT
946 M 644 inline file3/file5
947 data <<EOF
948 $file5_data
949 EOF
951 INPUT_END
953 cat >expect <<EOF
954 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
955 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
956 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
957 EOF
958 test_expect_success \
959         'N: copy then modify subdirectory' \
960         'git fast-import <input &&
961          git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
962          compare_diff_raw expect actual'
964 cat >input <<INPUT_END
965 commit refs/heads/N3
966 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
967 data <<COMMIT
968 dirty directory copy
969 COMMIT
971 from refs/heads/branch^0
972 M 644 inline file2/file5
973 data <<EOF
974 $file5_data
975 EOF
977 C file2 file3
978 D file2/file5
980 INPUT_END
982 test_expect_success \
983         'N: copy dirty subdirectory' \
984         'git fast-import <input &&
985          test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
987 test_expect_success \
988         'N: copy directory by id' \
989         'cat >expect <<-\EOF &&
990         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
991         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
992         EOF
993          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
994          cat >input <<-INPUT_END &&
995         commit refs/heads/N4
996         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
997         data <<COMMIT
998         copy by tree hash
999         COMMIT
1001         from refs/heads/branch^0
1002         M 040000 $subdir file3
1003         INPUT_END
1004          git fast-import <input &&
1005          git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1006          compare_diff_raw expect actual'
1008 test_expect_success PIPE 'N: read and copy directory' '
1009         cat >expect <<-\EOF
1010         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1011         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1012         EOF
1013         git update-ref -d refs/heads/N4 &&
1014         rm -f backflow &&
1015         mkfifo backflow &&
1016         (
1017                 exec <backflow &&
1018                 cat <<-EOF &&
1019                 commit refs/heads/N4
1020                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1021                 data <<COMMIT
1022                 copy by tree hash, part 2
1023                 COMMIT
1025                 from refs/heads/branch^0
1026                 ls "file2"
1027                 EOF
1028                 read mode type tree filename &&
1029                 echo "M 040000 $tree file3"
1030         ) |
1031         git fast-import --cat-blob-fd=3 3>backflow &&
1032         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1033         compare_diff_raw expect actual
1036 test_expect_success PIPE 'N: empty directory reads as missing' '
1037         cat <<-\EOF >expect &&
1038         OBJNAME
1039         :000000 100644 OBJNAME OBJNAME A        unrelated
1040         EOF
1041         echo "missing src" >expect.response &&
1042         git update-ref -d refs/heads/read-empty &&
1043         rm -f backflow &&
1044         mkfifo backflow &&
1045         (
1046                 exec <backflow &&
1047                 cat <<-EOF &&
1048                 commit refs/heads/read-empty
1049                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1050                 data <<COMMIT
1051                 read "empty" (missing) directory
1052                 COMMIT
1054                 M 100644 inline src/greeting
1055                 data <<BLOB
1056                 hello
1057                 BLOB
1058                 C src/greeting dst1/non-greeting
1059                 C src/greeting unrelated
1060                 # leave behind "empty" src directory
1061                 D src/greeting
1062                 ls "src"
1063                 EOF
1064                 read -r line &&
1065                 printf "%s\n" "$line" >response &&
1066                 cat <<-\EOF
1067                 D dst1
1068                 D dst2
1069                 EOF
1070         ) |
1071         git fast-import --cat-blob-fd=3 3>backflow &&
1072         test_cmp expect.response response &&
1073         git rev-list read-empty |
1074         git diff-tree -r --root --stdin |
1075         sed "s/$_x40/OBJNAME/g" >actual &&
1076         test_cmp expect actual
1079 test_expect_success \
1080         'N: copy root directory by tree hash' \
1081         'cat >expect <<-\EOF &&
1082         :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1083         :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1084         EOF
1085          root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1086          cat >input <<-INPUT_END &&
1087         commit refs/heads/N6
1088         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1089         data <<COMMIT
1090         copy root directory by tree hash
1091         COMMIT
1093         from refs/heads/branch^0
1094         M 040000 $root ""
1095         INPUT_END
1096          git fast-import <input &&
1097          git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1098          compare_diff_raw expect actual'
1100 test_expect_success \
1101         'N: delete directory by copying' \
1102         'cat >expect <<-\EOF &&
1103         OBJID
1104         :100644 000000 OBJID OBJID D    foo/bar/qux
1105         OBJID
1106         :000000 100644 OBJID OBJID A    foo/bar/baz
1107         :000000 100644 OBJID OBJID A    foo/bar/qux
1108         EOF
1109          empty_tree=$(git mktree </dev/null) &&
1110          cat >input <<-INPUT_END &&
1111         commit refs/heads/N-delete
1112         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1113         data <<COMMIT
1114         collect data to be deleted
1115         COMMIT
1117         deleteall
1118         M 100644 inline foo/bar/baz
1119         data <<DATA_END
1120         hello
1121         DATA_END
1122         C "foo/bar/baz" "foo/bar/qux"
1123         C "foo/bar/baz" "foo/bar/quux/1"
1124         C "foo/bar/baz" "foo/bar/quuux"
1125         M 040000 $empty_tree foo/bar/quux
1126         M 040000 $empty_tree foo/bar/quuux
1128         commit refs/heads/N-delete
1129         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1130         data <<COMMIT
1131         delete subdirectory
1132         COMMIT
1134         M 040000 $empty_tree foo/bar/qux
1135         INPUT_END
1136          git fast-import <input &&
1137          git rev-list N-delete |
1138                 git diff-tree -r --stdin --root --always |
1139                 sed -e "s/$_x40/OBJID/g" >actual &&
1140          test_cmp expect actual'
1142 test_expect_success \
1143         'N: modify copied tree' \
1144         'cat >expect <<-\EOF &&
1145         :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
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/N5
1152         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1153         data <<COMMIT
1154         copy by tree hash
1155         COMMIT
1157         from refs/heads/branch^0
1158         M 040000 $subdir file3
1160         commit refs/heads/N5
1161         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1162         data <<COMMIT
1163         modify directory copy
1164         COMMIT
1166         M 644 inline file3/file5
1167         data <<EOF
1168         $file5_data
1169         EOF
1170         INPUT_END
1171          git fast-import <input &&
1172          git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1173          compare_diff_raw expect actual'
1175 test_expect_success \
1176         'N: reject foo/ syntax' \
1177         'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1178          test_must_fail git fast-import <<-INPUT_END
1179         commit refs/heads/N5B
1180         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1181         data <<COMMIT
1182         copy with invalid syntax
1183         COMMIT
1185         from refs/heads/branch^0
1186         M 040000 $subdir file3/
1187         INPUT_END'
1189 test_expect_success \
1190         'N: copy to root by id and modify' \
1191         'echo "hello, world" >expect.foo &&
1192          echo hello >expect.bar &&
1193          git fast-import <<-SETUP_END &&
1194         commit refs/heads/N7
1195         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1196         data <<COMMIT
1197         hello, tree
1198         COMMIT
1200         deleteall
1201         M 644 inline foo/bar
1202         data <<EOF
1203         hello
1204         EOF
1205         SETUP_END
1207          tree=$(git rev-parse --verify N7:) &&
1208          git fast-import <<-INPUT_END &&
1209         commit refs/heads/N8
1210         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1211         data <<COMMIT
1212         copy to root by id and modify
1213         COMMIT
1215         M 040000 $tree ""
1216         M 644 inline foo/foo
1217         data <<EOF
1218         hello, world
1219         EOF
1220         INPUT_END
1221          git show N8:foo/foo >actual.foo &&
1222          git show N8:foo/bar >actual.bar &&
1223          test_cmp expect.foo actual.foo &&
1224          test_cmp expect.bar actual.bar'
1226 test_expect_success \
1227         'N: extract subtree' \
1228         'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1229          cat >input <<-INPUT_END &&
1230         commit refs/heads/N9
1231         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1232         data <<COMMIT
1233         extract subtree branch:newdir
1234         COMMIT
1236         M 040000 $branch ""
1237         C "newdir" ""
1238         INPUT_END
1239          git fast-import <input &&
1240          git diff --exit-code branch:newdir N9'
1242 test_expect_success \
1243         'N: modify subtree, extract it, and modify again' \
1244         'echo hello >expect.baz &&
1245          echo hello, world >expect.qux &&
1246          git fast-import <<-SETUP_END &&
1247         commit refs/heads/N10
1248         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1249         data <<COMMIT
1250         hello, tree
1251         COMMIT
1253         deleteall
1254         M 644 inline foo/bar/baz
1255         data <<EOF
1256         hello
1257         EOF
1258         SETUP_END
1260          tree=$(git rev-parse --verify N10:) &&
1261          git fast-import <<-INPUT_END &&
1262         commit refs/heads/N11
1263         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1264         data <<COMMIT
1265         copy to root by id and modify
1266         COMMIT
1268         M 040000 $tree ""
1269         M 100644 inline foo/bar/qux
1270         data <<EOF
1271         hello, world
1272         EOF
1273         R "foo" ""
1274         C "bar/qux" "bar/quux"
1275         INPUT_END
1276          git show N11:bar/baz >actual.baz &&
1277          git show N11:bar/qux >actual.qux &&
1278          git show N11:bar/quux >actual.quux &&
1279          test_cmp expect.baz actual.baz &&
1280          test_cmp expect.qux actual.qux &&
1281          test_cmp expect.qux actual.quux'
1283 ###
1284 ### series O
1285 ###
1287 cat >input <<INPUT_END
1288 #we will
1289 commit refs/heads/O1
1290 # -- ignore all of this text
1291 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1292 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1293 data <<COMMIT
1294 dirty directory copy
1295 COMMIT
1297 # don't forget the import blank line!
1299 # yes, we started from our usual base of branch^0.
1300 # i like branch^0.
1301 from refs/heads/branch^0
1302 # and we need to reuse file2/file5 from N3 above.
1303 M 644 inline file2/file5
1304 # otherwise the tree will be different
1305 data <<EOF
1306 $file5_data
1307 EOF
1309 # don't forget to copy file2 to file3
1310 C file2 file3
1312 # or to delete file5 from file2.
1313 D file2/file5
1314 # are we done yet?
1316 INPUT_END
1318 test_expect_success \
1319         'O: comments are all skipped' \
1320         'git fast-import <input &&
1321          test `git rev-parse N3` = `git rev-parse O1`'
1323 cat >input <<INPUT_END
1324 commit refs/heads/O2
1325 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1326 data <<COMMIT
1327 dirty directory copy
1328 COMMIT
1329 from refs/heads/branch^0
1330 M 644 inline file2/file5
1331 data <<EOF
1332 $file5_data
1333 EOF
1334 C file2 file3
1335 D file2/file5
1337 INPUT_END
1339 test_expect_success \
1340         'O: blank lines not necessary after data commands' \
1341         'git fast-import <input &&
1342          test `git rev-parse N3` = `git rev-parse O2`'
1344 test_expect_success \
1345         'O: repack before next test' \
1346         'git repack -a -d'
1348 cat >input <<INPUT_END
1349 commit refs/heads/O3
1350 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1351 data <<COMMIT
1352 zstring
1353 COMMIT
1354 commit refs/heads/O3
1355 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1356 data <<COMMIT
1357 zof
1358 COMMIT
1359 checkpoint
1360 commit refs/heads/O3
1361 mark :5
1362 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1363 data <<COMMIT
1364 zempty
1365 COMMIT
1366 checkpoint
1367 commit refs/heads/O3
1368 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1369 data <<COMMIT
1370 zcommits
1371 COMMIT
1372 reset refs/tags/O3-2nd
1373 from :5
1374 reset refs/tags/O3-3rd
1375 from :5
1376 INPUT_END
1378 cat >expect <<INPUT_END
1379 string
1380 of
1381 empty
1382 commits
1383 INPUT_END
1384 test_expect_success \
1385         'O: blank lines not necessary after other commands' \
1386         'git fast-import <input &&
1387          test 8 = `find .git/objects/pack -type f | wc -l` &&
1388          test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1389          git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1390          test_cmp expect actual'
1392 cat >input <<INPUT_END
1393 commit refs/heads/O4
1394 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1395 data <<COMMIT
1396 zstring
1397 COMMIT
1398 commit refs/heads/O4
1399 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1400 data <<COMMIT
1401 zof
1402 COMMIT
1403 progress Two commits down, 2 to go!
1404 commit refs/heads/O4
1405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1406 data <<COMMIT
1407 zempty
1408 COMMIT
1409 progress Three commits down, 1 to go!
1410 commit refs/heads/O4
1411 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1412 data <<COMMIT
1413 zcommits
1414 COMMIT
1415 progress I'm done!
1416 INPUT_END
1417 test_expect_success \
1418         'O: progress outputs as requested by input' \
1419         'git fast-import <input >actual &&
1420          grep "progress " <input >expect &&
1421          test_cmp expect actual'
1423 ###
1424 ### series P (gitlinks)
1425 ###
1427 cat >input <<INPUT_END
1428 blob
1429 mark :1
1430 data 10
1431 test file
1433 reset refs/heads/sub
1434 commit refs/heads/sub
1435 mark :2
1436 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1437 data 12
1438 sub_initial
1439 M 100644 :1 file
1441 blob
1442 mark :3
1443 data <<DATAEND
1444 [submodule "sub"]
1445         path = sub
1446         url = "`pwd`/sub"
1447 DATAEND
1449 commit refs/heads/subuse1
1450 mark :4
1451 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1452 data 8
1453 initial
1454 from refs/heads/master
1455 M 100644 :3 .gitmodules
1456 M 160000 :2 sub
1458 blob
1459 mark :5
1460 data 20
1461 test file
1462 more data
1464 commit refs/heads/sub
1465 mark :6
1466 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1467 data 11
1468 sub_second
1469 from :2
1470 M 100644 :5 file
1472 commit refs/heads/subuse1
1473 mark :7
1474 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1475 data 7
1476 second
1477 from :4
1478 M 160000 :6 sub
1480 INPUT_END
1482 test_expect_success \
1483         'P: supermodule & submodule mix' \
1484         'git fast-import <input &&
1485          git checkout subuse1 &&
1486          rm -rf sub && mkdir sub && (cd sub &&
1487          git init &&
1488          git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1489          git checkout master) &&
1490          git submodule init &&
1491          git submodule update'
1493 SUBLAST=$(git rev-parse --verify sub)
1494 SUBPREV=$(git rev-parse --verify sub^)
1496 cat >input <<INPUT_END
1497 blob
1498 mark :1
1499 data <<DATAEND
1500 [submodule "sub"]
1501         path = sub
1502         url = "`pwd`/sub"
1503 DATAEND
1505 commit refs/heads/subuse2
1506 mark :2
1507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1508 data 8
1509 initial
1510 from refs/heads/master
1511 M 100644 :1 .gitmodules
1512 M 160000 $SUBPREV sub
1514 commit refs/heads/subuse2
1515 mark :3
1516 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1517 data 7
1518 second
1519 from :2
1520 M 160000 $SUBLAST sub
1522 INPUT_END
1524 test_expect_success \
1525         'P: verbatim SHA gitlinks' \
1526         'git branch -D sub &&
1527          git gc && git prune &&
1528          git fast-import <input &&
1529          test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1531 test_tick
1532 cat >input <<INPUT_END
1533 commit refs/heads/subuse3
1534 mark :1
1535 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1536 data <<COMMIT
1537 corrupt
1538 COMMIT
1540 from refs/heads/subuse2
1541 M 160000 inline sub
1542 data <<DATA
1543 $SUBPREV
1544 DATA
1546 INPUT_END
1548 test_expect_success 'P: fail on inline gitlink' '
1549     test_must_fail git fast-import <input'
1551 test_tick
1552 cat >input <<INPUT_END
1553 blob
1554 mark :1
1555 data <<DATA
1556 $SUBPREV
1557 DATA
1559 commit refs/heads/subuse3
1560 mark :2
1561 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1562 data <<COMMIT
1563 corrupt
1564 COMMIT
1566 from refs/heads/subuse2
1567 M 160000 :1 sub
1569 INPUT_END
1571 test_expect_success 'P: fail on blob mark in gitlink' '
1572     test_must_fail git fast-import <input'
1574 ###
1575 ### series Q (notes)
1576 ###
1578 note1_data="The first note for the first commit"
1579 note2_data="The first note for the second commit"
1580 note3_data="The first note for the third commit"
1581 note1b_data="The second note for the first commit"
1582 note1c_data="The third note for the first commit"
1583 note2b_data="The second note for the second commit"
1585 test_tick
1586 cat >input <<INPUT_END
1587 blob
1588 mark :2
1589 data <<EOF
1590 $file2_data
1591 EOF
1593 commit refs/heads/notes-test
1594 mark :3
1595 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1596 data <<COMMIT
1597 first (:3)
1598 COMMIT
1600 M 644 :2 file2
1602 blob
1603 mark :4
1604 data $file4_len
1605 $file4_data
1606 commit refs/heads/notes-test
1607 mark :5
1608 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1609 data <<COMMIT
1610 second (:5)
1611 COMMIT
1613 M 644 :4 file4
1615 commit refs/heads/notes-test
1616 mark :6
1617 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1618 data <<COMMIT
1619 third (:6)
1620 COMMIT
1622 M 644 inline file5
1623 data <<EOF
1624 $file5_data
1625 EOF
1627 M 755 inline file6
1628 data <<EOF
1629 $file6_data
1630 EOF
1632 blob
1633 mark :7
1634 data <<EOF
1635 $note1_data
1636 EOF
1638 blob
1639 mark :8
1640 data <<EOF
1641 $note2_data
1642 EOF
1644 commit refs/notes/foobar
1645 mark :9
1646 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1647 data <<COMMIT
1648 notes (:9)
1649 COMMIT
1651 N :7 :3
1652 N :8 :5
1653 N inline :6
1654 data <<EOF
1655 $note3_data
1656 EOF
1658 commit refs/notes/foobar
1659 mark :10
1660 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1661 data <<COMMIT
1662 notes (:10)
1663 COMMIT
1665 N inline :3
1666 data <<EOF
1667 $note1b_data
1668 EOF
1670 commit refs/notes/foobar2
1671 mark :11
1672 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1673 data <<COMMIT
1674 notes (:11)
1675 COMMIT
1677 N inline :3
1678 data <<EOF
1679 $note1c_data
1680 EOF
1682 commit refs/notes/foobar
1683 mark :12
1684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1685 data <<COMMIT
1686 notes (:12)
1687 COMMIT
1689 deleteall
1690 N inline :5
1691 data <<EOF
1692 $note2b_data
1693 EOF
1695 INPUT_END
1697 test_expect_success \
1698         'Q: commit notes' \
1699         'git fast-import <input &&
1700          git whatchanged notes-test'
1701 test_expect_success \
1702         'Q: verify pack' \
1703         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1705 commit1=$(git rev-parse notes-test~2)
1706 commit2=$(git rev-parse notes-test^)
1707 commit3=$(git rev-parse notes-test)
1709 cat >expect <<EOF
1710 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1711 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1713 first (:3)
1714 EOF
1715 test_expect_success \
1716         'Q: verify first commit' \
1717         'git cat-file commit notes-test~2 | sed 1d >actual &&
1718         test_cmp expect actual'
1720 cat >expect <<EOF
1721 parent $commit1
1722 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1723 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1725 second (:5)
1726 EOF
1727 test_expect_success \
1728         'Q: verify second commit' \
1729         'git cat-file commit notes-test^ | sed 1d >actual &&
1730         test_cmp expect actual'
1732 cat >expect <<EOF
1733 parent $commit2
1734 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1735 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1737 third (:6)
1738 EOF
1739 test_expect_success \
1740         'Q: verify third commit' \
1741         'git cat-file commit notes-test | sed 1d >actual &&
1742         test_cmp expect actual'
1744 cat >expect <<EOF
1745 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1746 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1748 notes (:9)
1749 EOF
1750 test_expect_success \
1751         'Q: verify first notes commit' \
1752         'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1753         test_cmp expect actual'
1755 cat >expect.unsorted <<EOF
1756 100644 blob $commit1
1757 100644 blob $commit2
1758 100644 blob $commit3
1759 EOF
1760 cat expect.unsorted | sort >expect
1761 test_expect_success \
1762         'Q: verify first notes tree' \
1763         'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1764          test_cmp expect actual'
1766 echo "$note1_data" >expect
1767 test_expect_success \
1768         'Q: verify first note for first commit' \
1769         'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1771 echo "$note2_data" >expect
1772 test_expect_success \
1773         'Q: verify first note for second commit' \
1774         'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1776 echo "$note3_data" >expect
1777 test_expect_success \
1778         'Q: verify first note for third commit' \
1779         'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1781 cat >expect <<EOF
1782 parent `git rev-parse --verify refs/notes/foobar~2`
1783 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1784 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1786 notes (:10)
1787 EOF
1788 test_expect_success \
1789         'Q: verify second notes commit' \
1790         'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1791         test_cmp expect actual'
1793 cat >expect.unsorted <<EOF
1794 100644 blob $commit1
1795 100644 blob $commit2
1796 100644 blob $commit3
1797 EOF
1798 cat expect.unsorted | sort >expect
1799 test_expect_success \
1800         'Q: verify second notes tree' \
1801         'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1802          test_cmp expect actual'
1804 echo "$note1b_data" >expect
1805 test_expect_success \
1806         'Q: verify second note for first commit' \
1807         'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1809 echo "$note2_data" >expect
1810 test_expect_success \
1811         'Q: verify first note for second commit' \
1812         'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1814 echo "$note3_data" >expect
1815 test_expect_success \
1816         'Q: verify first note for third commit' \
1817         'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1819 cat >expect <<EOF
1820 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1821 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1823 notes (:11)
1824 EOF
1825 test_expect_success \
1826         'Q: verify third notes commit' \
1827         'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1828         test_cmp expect actual'
1830 cat >expect.unsorted <<EOF
1831 100644 blob $commit1
1832 EOF
1833 cat expect.unsorted | sort >expect
1834 test_expect_success \
1835         'Q: verify third notes tree' \
1836         'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1837          test_cmp expect actual'
1839 echo "$note1c_data" >expect
1840 test_expect_success \
1841         'Q: verify third note for first commit' \
1842         'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1844 cat >expect <<EOF
1845 parent `git rev-parse --verify refs/notes/foobar^`
1846 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1847 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1849 notes (:12)
1850 EOF
1851 test_expect_success \
1852         'Q: verify fourth notes commit' \
1853         'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1854         test_cmp expect actual'
1856 cat >expect.unsorted <<EOF
1857 100644 blob $commit2
1858 EOF
1859 cat expect.unsorted | sort >expect
1860 test_expect_success \
1861         'Q: verify fourth notes tree' \
1862         'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1863          test_cmp expect actual'
1865 echo "$note2b_data" >expect
1866 test_expect_success \
1867         'Q: verify second note for second commit' \
1868         'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1870 ###
1871 ### series R (feature and option)
1872 ###
1874 cat >input <<EOF
1875 feature no-such-feature-exists
1876 EOF
1878 test_expect_success 'R: abort on unsupported feature' '
1879         test_must_fail git fast-import <input
1882 cat >input <<EOF
1883 feature date-format=now
1884 EOF
1886 test_expect_success 'R: supported feature is accepted' '
1887         git fast-import <input
1890 cat >input << EOF
1891 blob
1892 data 3
1893 hi
1894 feature date-format=now
1895 EOF
1897 test_expect_success 'R: abort on receiving feature after data command' '
1898         test_must_fail git fast-import <input
1901 cat >input << EOF
1902 feature import-marks=git.marks
1903 feature import-marks=git2.marks
1904 EOF
1906 test_expect_success 'R: only one import-marks feature allowed per stream' '
1907         test_must_fail git fast-import <input
1910 cat >input << EOF
1911 feature export-marks=git.marks
1912 blob
1913 mark :1
1914 data 3
1915 hi
1917 EOF
1919 test_expect_success \
1920     'R: export-marks feature results in a marks file being created' \
1921     'cat input | git fast-import &&
1922     grep :1 git.marks'
1924 test_expect_success \
1925     'R: export-marks options can be overriden by commandline options' \
1926     'cat input | git fast-import --export-marks=other.marks &&
1927     grep :1 other.marks'
1929 test_expect_success 'R: catch typo in marks file name' '
1930         test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
1931         echo "feature import-marks=nonexistent.marks" |
1932         test_must_fail git fast-import
1935 test_expect_success 'R: import and output marks can be the same file' '
1936         rm -f io.marks &&
1937         blob=$(echo hi | git hash-object --stdin) &&
1938         cat >expect <<-EOF &&
1939         :1 $blob
1940         :2 $blob
1941         EOF
1942         git fast-import --export-marks=io.marks <<-\EOF &&
1943         blob
1944         mark :1
1945         data 3
1946         hi
1948         EOF
1949         git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
1950         blob
1951         mark :2
1952         data 3
1953         hi
1955         EOF
1956         test_cmp expect io.marks
1959 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
1960         rm -f io.marks &&
1961         test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
1962         blob
1963         mark :1
1964         data 3
1965         hi
1967         EOF
1970 test_expect_success 'R: --import-marks-if-exists' '
1971         rm -f io.marks &&
1972         blob=$(echo hi | git hash-object --stdin) &&
1973         echo ":1 $blob" >expect &&
1974         git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
1975         blob
1976         mark :1
1977         data 3
1978         hi
1980         EOF
1981         test_cmp expect io.marks
1984 cat >input << EOF
1985 feature import-marks=marks.out
1986 feature export-marks=marks.new
1987 EOF
1989 test_expect_success \
1990     'R: import to output marks works without any content' \
1991     'cat input | git fast-import &&
1992     test_cmp marks.out marks.new'
1994 cat >input <<EOF
1995 feature import-marks=nonexistent.marks
1996 feature export-marks=marks.new
1997 EOF
1999 test_expect_success \
2000     'R: import marks prefers commandline marks file over the stream' \
2001     'cat input | git fast-import --import-marks=marks.out &&
2002     test_cmp marks.out marks.new'
2005 cat >input <<EOF
2006 feature import-marks=nonexistent.marks
2007 feature export-marks=combined.marks
2008 EOF
2010 test_expect_success 'R: multiple --import-marks= should be honoured' '
2011     head -n2 marks.out > one.marks &&
2012     tail -n +3 marks.out > two.marks &&
2013     git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2014     test_cmp marks.out combined.marks
2017 cat >input <<EOF
2018 feature relative-marks
2019 feature import-marks=relative.in
2020 feature export-marks=relative.out
2021 EOF
2023 test_expect_success 'R: feature relative-marks should be honoured' '
2024     mkdir -p .git/info/fast-import/ &&
2025     cp marks.new .git/info/fast-import/relative.in &&
2026     git fast-import <input &&
2027     test_cmp marks.new .git/info/fast-import/relative.out
2030 cat >input <<EOF
2031 feature relative-marks
2032 feature import-marks=relative.in
2033 feature no-relative-marks
2034 feature export-marks=non-relative.out
2035 EOF
2037 test_expect_success 'R: feature no-relative-marks should be honoured' '
2038     git fast-import <input &&
2039     test_cmp marks.new non-relative.out
2042 test_expect_success 'R: feature ls supported' '
2043         echo "feature ls" |
2044         git fast-import
2047 test_expect_success 'R: feature cat-blob supported' '
2048         echo "feature cat-blob" |
2049         git fast-import
2052 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2053         test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2056 test_expect_success 'R: print old blob' '
2057         blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2058         cat >expect <<-EOF &&
2059         ${blob} blob 11
2060         yes it can
2062         EOF
2063         echo "cat-blob $blob" |
2064         git fast-import --cat-blob-fd=6 6>actual &&
2065         test_cmp expect actual
2068 test_expect_success 'R: in-stream cat-blob-fd not respected' '
2069         echo hello >greeting &&
2070         blob=$(git hash-object -w greeting) &&
2071         cat >expect <<-EOF &&
2072         ${blob} blob 6
2073         hello
2075         EOF
2076         git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2077         cat-blob $blob
2078         EOF
2079         test_cmp expect actual.3 &&
2080         test_cmp empty actual.1 &&
2081         git fast-import 3>actual.3 >actual.1 <<-EOF &&
2082         option cat-blob-fd=3
2083         cat-blob $blob
2084         EOF
2085         test_cmp empty actual.3 &&
2086         test_cmp expect actual.1
2089 test_expect_success 'R: print new blob' '
2090         blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2091         cat >expect <<-EOF &&
2092         ${blob} blob 12
2093         yep yep yep
2095         EOF
2096         git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2097         blob
2098         mark :1
2099         data <<BLOB_END
2100         yep yep yep
2101         BLOB_END
2102         cat-blob :1
2103         EOF
2104         test_cmp expect actual
2107 test_expect_success 'R: print new blob by sha1' '
2108         blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2109         cat >expect <<-EOF &&
2110         ${blob} blob 25
2111         a new blob named by sha1
2113         EOF
2114         git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2115         blob
2116         data <<BLOB_END
2117         a new blob named by sha1
2118         BLOB_END
2119         cat-blob $blob
2120         EOF
2121         test_cmp expect actual
2124 test_expect_success 'setup: big file' '
2125         (
2126                 echo "the quick brown fox jumps over the lazy dog" >big &&
2127                 for i in 1 2 3
2128                 do
2129                         cat big big big big >bigger &&
2130                         cat bigger bigger bigger bigger >big ||
2131                         exit
2132                 done
2133         )
2136 test_expect_success 'R: print two blobs to stdout' '
2137         blob1=$(git hash-object big) &&
2138         blob1_len=$(wc -c <big) &&
2139         blob2=$(echo hello | git hash-object --stdin) &&
2140         {
2141                 echo ${blob1} blob $blob1_len &&
2142                 cat big &&
2143                 cat <<-EOF
2145                 ${blob2} blob 6
2146                 hello
2148                 EOF
2149         } >expect &&
2150         {
2151                 cat <<-\END_PART1 &&
2152                         blob
2153                         mark :1
2154                         data <<data_end
2155                 END_PART1
2156                 cat big &&
2157                 cat <<-\EOF
2158                         data_end
2159                         blob
2160                         mark :2
2161                         data <<data_end
2162                         hello
2163                         data_end
2164                         cat-blob :1
2165                         cat-blob :2
2166                 EOF
2167         } |
2168         git fast-import >actual &&
2169         test_cmp expect actual
2172 test_expect_success PIPE 'R: copy using cat-file' '
2173         expect_id=$(git hash-object big) &&
2174         expect_len=$(wc -c <big) &&
2175         echo $expect_id blob $expect_len >expect.response &&
2177         rm -f blobs &&
2178         cat >frontend <<-\FRONTEND_END &&
2179         #!/bin/sh
2180         FRONTEND_END
2182         mkfifo blobs &&
2183         (
2184                 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2185                 cat <<-\EOF &&
2186                 feature cat-blob
2187                 blob
2188                 mark :1
2189                 data <<BLOB
2190                 EOF
2191                 cat big &&
2192                 cat <<-\EOF &&
2193                 BLOB
2194                 cat-blob :1
2195                 EOF
2197                 read blob_id type size <&3 &&
2198                 echo "$blob_id $type $size" >response &&
2199                 head_c $size >blob <&3 &&
2200                 read newline <&3 &&
2202                 cat <<-EOF &&
2203                 commit refs/heads/copied
2204                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2205                 data <<COMMIT
2206                 copy big file as file3
2207                 COMMIT
2208                 M 644 inline file3
2209                 data <<BLOB
2210                 EOF
2211                 cat blob &&
2212                 echo BLOB
2213         ) 3<blobs |
2214         git fast-import --cat-blob-fd=3 3>blobs &&
2215         git show copied:file3 >actual &&
2216         test_cmp expect.response response &&
2217         test_cmp big actual
2220 test_expect_success PIPE 'R: print blob mid-commit' '
2221         rm -f blobs &&
2222         echo "A blob from _before_ the commit." >expect &&
2223         mkfifo blobs &&
2224         (
2225                 exec 3<blobs &&
2226                 cat <<-EOF &&
2227                 feature cat-blob
2228                 blob
2229                 mark :1
2230                 data <<BLOB
2231                 A blob from _before_ the commit.
2232                 BLOB
2233                 commit refs/heads/temporary
2234                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2235                 data <<COMMIT
2236                 Empty commit
2237                 COMMIT
2238                 cat-blob :1
2239                 EOF
2241                 read blob_id type size <&3 &&
2242                 head_c $size >actual <&3 &&
2243                 read newline <&3 &&
2245                 echo
2246         ) |
2247         git fast-import --cat-blob-fd=3 3>blobs &&
2248         test_cmp expect actual
2251 test_expect_success PIPE 'R: print staged blob within commit' '
2252         rm -f blobs &&
2253         echo "A blob from _within_ the commit." >expect &&
2254         mkfifo blobs &&
2255         (
2256                 exec 3<blobs &&
2257                 cat <<-EOF &&
2258                 feature cat-blob
2259                 commit refs/heads/within
2260                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2261                 data <<COMMIT
2262                 Empty commit
2263                 COMMIT
2264                 M 644 inline within
2265                 data <<BLOB
2266                 A blob from _within_ the commit.
2267                 BLOB
2268                 EOF
2270                 to_get=$(
2271                         echo "A blob from _within_ the commit." |
2272                         git hash-object --stdin
2273                 ) &&
2274                 echo "cat-blob $to_get" &&
2276                 read blob_id type size <&3 &&
2277                 head_c $size >actual <&3 &&
2278                 read newline <&3 &&
2280                 echo deleteall
2281         ) |
2282         git fast-import --cat-blob-fd=3 3>blobs &&
2283         test_cmp expect actual
2286 cat >input << EOF
2287 option git quiet
2288 blob
2289 data 3
2290 hi
2292 EOF
2294 test_expect_success 'R: quiet option results in no stats being output' '
2295     cat input | git fast-import 2> output &&
2296     test_cmp empty output
2299 cat >input <<EOF
2300 option git non-existing-option
2301 EOF
2303 test_expect_success 'R: die on unknown option' '
2304     test_must_fail git fast-import <input
2307 test_expect_success 'R: unknown commandline options are rejected' '\
2308     test_must_fail git fast-import --non-existing-option < /dev/null
2311 test_expect_success 'R: die on invalid option argument' '
2312         echo "option git active-branches=-5" |
2313         test_must_fail git fast-import &&
2314         echo "option git depth=" |
2315         test_must_fail git fast-import &&
2316         test_must_fail git fast-import --depth="5 elephants" </dev/null
2319 cat >input <<EOF
2320 option non-existing-vcs non-existing-option
2321 EOF
2323 test_expect_success 'R: ignore non-git options' '
2324     git fast-import <input
2327 ##
2328 ## R: very large blobs
2329 ##
2330 blobsize=$((2*1024*1024 + 53))
2331 test-genrandom bar $blobsize >expect
2332 cat >input <<INPUT_END
2333 commit refs/heads/big-file
2334 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2335 data <<COMMIT
2336 R - big file
2337 COMMIT
2339 M 644 inline big1
2340 data $blobsize
2341 INPUT_END
2342 cat expect >>input
2343 cat >>input <<INPUT_END
2344 M 644 inline big2
2345 data $blobsize
2346 INPUT_END
2347 cat expect >>input
2348 echo >>input
2350 test_expect_success \
2351         'R: blob bigger than threshold' \
2352         'test_create_repo R &&
2353          git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2354 test_expect_success \
2355         'R: verify created pack' \
2356         ': >verify &&
2357          for p in R/.git/objects/pack/*.pack;
2358          do
2359            git verify-pack -v $p >>verify || exit;
2360          done'
2361 test_expect_success \
2362         'R: verify written objects' \
2363         'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2364          test_cmp expect actual &&
2365          a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2366          b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2367          test $a = $b'
2368 test_expect_success \
2369         'R: blob appears only once' \
2370         'n=$(grep $a verify | wc -l) &&
2371          test 1 = $n'
2373 test_done