Code

Merge branch 'di/fast-import-deltified-tree'
[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 cat >input <<INPUT_END
837 blob
838 mark :1
839 data <<EOF
840 the data
841 EOF
843 commit refs/heads/L2
844 committer C O Mitter <committer@example.com> 1112912473 -0700
845 data <<COMMIT
846 init L2
847 COMMIT
848 M 644 :1 a/b/c
849 M 644 :1 a/b/d
850 M 644 :1 a/e/f
852 commit refs/heads/L2
853 committer C O Mitter <committer@example.com> 1112912473 -0700
854 data <<COMMIT
855 update L2
856 COMMIT
857 C a g
858 C a/e g/b
859 M 644 :1 g/b/h
860 INPUT_END
862 cat <<EOF >expect
863 g/b/f
864 g/b/h
865 EOF
867 test_expect_success \
868     'L: nested tree copy does not corrupt deltas' \
869         'git fast-import <input &&
870         git ls-tree L2 g/b/ >tmp &&
871         cat tmp | cut -f 2 >actual &&
872         test_cmp expect actual &&
873         git fsck `git rev-parse L2`'
875 git update-ref -d refs/heads/L2
877 ###
878 ### series M
879 ###
881 test_tick
882 cat >input <<INPUT_END
883 commit refs/heads/M1
884 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
885 data <<COMMIT
886 file rename
887 COMMIT
889 from refs/heads/branch^0
890 R file2/newf file2/n.e.w.f
892 INPUT_END
894 cat >expect <<EOF
895 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
896 EOF
897 test_expect_success \
898         'M: rename file in same subdirectory' \
899         'git fast-import <input &&
900          git diff-tree -M -r M1^ M1 >actual &&
901          compare_diff_raw expect actual'
903 cat >input <<INPUT_END
904 commit refs/heads/M2
905 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
906 data <<COMMIT
907 file rename
908 COMMIT
910 from refs/heads/branch^0
911 R file2/newf i/am/new/to/you
913 INPUT_END
915 cat >expect <<EOF
916 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
917 EOF
918 test_expect_success \
919         'M: rename file to new subdirectory' \
920         'git fast-import <input &&
921          git diff-tree -M -r M2^ M2 >actual &&
922          compare_diff_raw expect actual'
924 cat >input <<INPUT_END
925 commit refs/heads/M3
926 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
927 data <<COMMIT
928 file rename
929 COMMIT
931 from refs/heads/M2^0
932 R i other/sub
934 INPUT_END
936 cat >expect <<EOF
937 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
938 EOF
939 test_expect_success \
940         'M: rename subdirectory to new subdirectory' \
941         'git fast-import <input &&
942          git diff-tree -M -r M3^ M3 >actual &&
943          compare_diff_raw expect actual'
945 ###
946 ### series N
947 ###
949 test_tick
950 cat >input <<INPUT_END
951 commit refs/heads/N1
952 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
953 data <<COMMIT
954 file copy
955 COMMIT
957 from refs/heads/branch^0
958 C file2/newf file2/n.e.w.f
960 INPUT_END
962 cat >expect <<EOF
963 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
964 EOF
965 test_expect_success \
966         'N: copy file in same subdirectory' \
967         'git fast-import <input &&
968          git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
969          compare_diff_raw expect actual'
971 cat >input <<INPUT_END
972 commit refs/heads/N2
973 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
974 data <<COMMIT
975 clean directory copy
976 COMMIT
978 from refs/heads/branch^0
979 C file2 file3
981 commit refs/heads/N2
982 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
983 data <<COMMIT
984 modify directory copy
985 COMMIT
987 M 644 inline file3/file5
988 data <<EOF
989 $file5_data
990 EOF
992 INPUT_END
994 cat >expect <<EOF
995 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
996 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
997 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
998 EOF
999 test_expect_success \
1000         'N: copy then modify subdirectory' \
1001         'git fast-import <input &&
1002          git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1003          compare_diff_raw expect actual'
1005 cat >input <<INPUT_END
1006 commit refs/heads/N3
1007 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1008 data <<COMMIT
1009 dirty directory copy
1010 COMMIT
1012 from refs/heads/branch^0
1013 M 644 inline file2/file5
1014 data <<EOF
1015 $file5_data
1016 EOF
1018 C file2 file3
1019 D file2/file5
1021 INPUT_END
1023 test_expect_success \
1024         'N: copy dirty subdirectory' \
1025         'git fast-import <input &&
1026          test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1028 test_expect_success \
1029         'N: copy directory by id' \
1030         'cat >expect <<-\EOF &&
1031         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1032         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1033         EOF
1034          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1035          cat >input <<-INPUT_END &&
1036         commit refs/heads/N4
1037         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1038         data <<COMMIT
1039         copy by tree hash
1040         COMMIT
1042         from refs/heads/branch^0
1043         M 040000 $subdir file3
1044         INPUT_END
1045          git fast-import <input &&
1046          git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1047          compare_diff_raw expect actual'
1049 test_expect_success PIPE 'N: read and copy directory' '
1050         cat >expect <<-\EOF
1051         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1052         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1053         EOF
1054         git update-ref -d refs/heads/N4 &&
1055         rm -f backflow &&
1056         mkfifo backflow &&
1057         (
1058                 exec <backflow &&
1059                 cat <<-EOF &&
1060                 commit refs/heads/N4
1061                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1062                 data <<COMMIT
1063                 copy by tree hash, part 2
1064                 COMMIT
1066                 from refs/heads/branch^0
1067                 ls "file2"
1068                 EOF
1069                 read mode type tree filename &&
1070                 echo "M 040000 $tree file3"
1071         ) |
1072         git fast-import --cat-blob-fd=3 3>backflow &&
1073         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1074         compare_diff_raw expect actual
1077 test_expect_success PIPE 'N: empty directory reads as missing' '
1078         cat <<-\EOF >expect &&
1079         OBJNAME
1080         :000000 100644 OBJNAME OBJNAME A        unrelated
1081         EOF
1082         echo "missing src" >expect.response &&
1083         git update-ref -d refs/heads/read-empty &&
1084         rm -f backflow &&
1085         mkfifo backflow &&
1086         (
1087                 exec <backflow &&
1088                 cat <<-EOF &&
1089                 commit refs/heads/read-empty
1090                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1091                 data <<COMMIT
1092                 read "empty" (missing) directory
1093                 COMMIT
1095                 M 100644 inline src/greeting
1096                 data <<BLOB
1097                 hello
1098                 BLOB
1099                 C src/greeting dst1/non-greeting
1100                 C src/greeting unrelated
1101                 # leave behind "empty" src directory
1102                 D src/greeting
1103                 ls "src"
1104                 EOF
1105                 read -r line &&
1106                 printf "%s\n" "$line" >response &&
1107                 cat <<-\EOF
1108                 D dst1
1109                 D dst2
1110                 EOF
1111         ) |
1112         git fast-import --cat-blob-fd=3 3>backflow &&
1113         test_cmp expect.response response &&
1114         git rev-list read-empty |
1115         git diff-tree -r --root --stdin |
1116         sed "s/$_x40/OBJNAME/g" >actual &&
1117         test_cmp expect actual
1120 test_expect_success \
1121         'N: copy root directory by tree hash' \
1122         'cat >expect <<-\EOF &&
1123         :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1124         :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1125         EOF
1126          root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1127          cat >input <<-INPUT_END &&
1128         commit refs/heads/N6
1129         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1130         data <<COMMIT
1131         copy root directory by tree hash
1132         COMMIT
1134         from refs/heads/branch^0
1135         M 040000 $root ""
1136         INPUT_END
1137          git fast-import <input &&
1138          git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1139          compare_diff_raw expect actual'
1141 test_expect_success \
1142         'N: delete directory by copying' \
1143         'cat >expect <<-\EOF &&
1144         OBJID
1145         :100644 000000 OBJID OBJID D    foo/bar/qux
1146         OBJID
1147         :000000 100644 OBJID OBJID A    foo/bar/baz
1148         :000000 100644 OBJID OBJID A    foo/bar/qux
1149         EOF
1150          empty_tree=$(git mktree </dev/null) &&
1151          cat >input <<-INPUT_END &&
1152         commit refs/heads/N-delete
1153         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1154         data <<COMMIT
1155         collect data to be deleted
1156         COMMIT
1158         deleteall
1159         M 100644 inline foo/bar/baz
1160         data <<DATA_END
1161         hello
1162         DATA_END
1163         C "foo/bar/baz" "foo/bar/qux"
1164         C "foo/bar/baz" "foo/bar/quux/1"
1165         C "foo/bar/baz" "foo/bar/quuux"
1166         M 040000 $empty_tree foo/bar/quux
1167         M 040000 $empty_tree foo/bar/quuux
1169         commit refs/heads/N-delete
1170         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1171         data <<COMMIT
1172         delete subdirectory
1173         COMMIT
1175         M 040000 $empty_tree foo/bar/qux
1176         INPUT_END
1177          git fast-import <input &&
1178          git rev-list N-delete |
1179                 git diff-tree -r --stdin --root --always |
1180                 sed -e "s/$_x40/OBJID/g" >actual &&
1181          test_cmp expect actual'
1183 test_expect_success \
1184         'N: modify copied tree' \
1185         'cat >expect <<-\EOF &&
1186         :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1187         :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1188         :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1189         EOF
1190          subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1191          cat >input <<-INPUT_END &&
1192         commit refs/heads/N5
1193         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1194         data <<COMMIT
1195         copy by tree hash
1196         COMMIT
1198         from refs/heads/branch^0
1199         M 040000 $subdir file3
1201         commit refs/heads/N5
1202         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1203         data <<COMMIT
1204         modify directory copy
1205         COMMIT
1207         M 644 inline file3/file5
1208         data <<EOF
1209         $file5_data
1210         EOF
1211         INPUT_END
1212          git fast-import <input &&
1213          git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1214          compare_diff_raw expect actual'
1216 test_expect_success \
1217         'N: reject foo/ syntax' \
1218         'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1219          test_must_fail git fast-import <<-INPUT_END
1220         commit refs/heads/N5B
1221         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1222         data <<COMMIT
1223         copy with invalid syntax
1224         COMMIT
1226         from refs/heads/branch^0
1227         M 040000 $subdir file3/
1228         INPUT_END'
1230 test_expect_success \
1231         'N: copy to root by id and modify' \
1232         'echo "hello, world" >expect.foo &&
1233          echo hello >expect.bar &&
1234          git fast-import <<-SETUP_END &&
1235         commit refs/heads/N7
1236         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1237         data <<COMMIT
1238         hello, tree
1239         COMMIT
1241         deleteall
1242         M 644 inline foo/bar
1243         data <<EOF
1244         hello
1245         EOF
1246         SETUP_END
1248          tree=$(git rev-parse --verify N7:) &&
1249          git fast-import <<-INPUT_END &&
1250         commit refs/heads/N8
1251         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1252         data <<COMMIT
1253         copy to root by id and modify
1254         COMMIT
1256         M 040000 $tree ""
1257         M 644 inline foo/foo
1258         data <<EOF
1259         hello, world
1260         EOF
1261         INPUT_END
1262          git show N8:foo/foo >actual.foo &&
1263          git show N8:foo/bar >actual.bar &&
1264          test_cmp expect.foo actual.foo &&
1265          test_cmp expect.bar actual.bar'
1267 test_expect_success \
1268         'N: extract subtree' \
1269         'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1270          cat >input <<-INPUT_END &&
1271         commit refs/heads/N9
1272         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1273         data <<COMMIT
1274         extract subtree branch:newdir
1275         COMMIT
1277         M 040000 $branch ""
1278         C "newdir" ""
1279         INPUT_END
1280          git fast-import <input &&
1281          git diff --exit-code branch:newdir N9'
1283 test_expect_success \
1284         'N: modify subtree, extract it, and modify again' \
1285         'echo hello >expect.baz &&
1286          echo hello, world >expect.qux &&
1287          git fast-import <<-SETUP_END &&
1288         commit refs/heads/N10
1289         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1290         data <<COMMIT
1291         hello, tree
1292         COMMIT
1294         deleteall
1295         M 644 inline foo/bar/baz
1296         data <<EOF
1297         hello
1298         EOF
1299         SETUP_END
1301          tree=$(git rev-parse --verify N10:) &&
1302          git fast-import <<-INPUT_END &&
1303         commit refs/heads/N11
1304         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1305         data <<COMMIT
1306         copy to root by id and modify
1307         COMMIT
1309         M 040000 $tree ""
1310         M 100644 inline foo/bar/qux
1311         data <<EOF
1312         hello, world
1313         EOF
1314         R "foo" ""
1315         C "bar/qux" "bar/quux"
1316         INPUT_END
1317          git show N11:bar/baz >actual.baz &&
1318          git show N11:bar/qux >actual.qux &&
1319          git show N11:bar/quux >actual.quux &&
1320          test_cmp expect.baz actual.baz &&
1321          test_cmp expect.qux actual.qux &&
1322          test_cmp expect.qux actual.quux'
1324 ###
1325 ### series O
1326 ###
1328 cat >input <<INPUT_END
1329 #we will
1330 commit refs/heads/O1
1331 # -- ignore all of this text
1332 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1333 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1334 data <<COMMIT
1335 dirty directory copy
1336 COMMIT
1338 # don't forget the import blank line!
1340 # yes, we started from our usual base of branch^0.
1341 # i like branch^0.
1342 from refs/heads/branch^0
1343 # and we need to reuse file2/file5 from N3 above.
1344 M 644 inline file2/file5
1345 # otherwise the tree will be different
1346 data <<EOF
1347 $file5_data
1348 EOF
1350 # don't forget to copy file2 to file3
1351 C file2 file3
1353 # or to delete file5 from file2.
1354 D file2/file5
1355 # are we done yet?
1357 INPUT_END
1359 test_expect_success \
1360         'O: comments are all skipped' \
1361         'git fast-import <input &&
1362          test `git rev-parse N3` = `git rev-parse O1`'
1364 cat >input <<INPUT_END
1365 commit refs/heads/O2
1366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1367 data <<COMMIT
1368 dirty directory copy
1369 COMMIT
1370 from refs/heads/branch^0
1371 M 644 inline file2/file5
1372 data <<EOF
1373 $file5_data
1374 EOF
1375 C file2 file3
1376 D file2/file5
1378 INPUT_END
1380 test_expect_success \
1381         'O: blank lines not necessary after data commands' \
1382         'git fast-import <input &&
1383          test `git rev-parse N3` = `git rev-parse O2`'
1385 test_expect_success \
1386         'O: repack before next test' \
1387         'git repack -a -d'
1389 cat >input <<INPUT_END
1390 commit refs/heads/O3
1391 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1392 data <<COMMIT
1393 zstring
1394 COMMIT
1395 commit refs/heads/O3
1396 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1397 data <<COMMIT
1398 zof
1399 COMMIT
1400 checkpoint
1401 commit refs/heads/O3
1402 mark :5
1403 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1404 data <<COMMIT
1405 zempty
1406 COMMIT
1407 checkpoint
1408 commit refs/heads/O3
1409 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1410 data <<COMMIT
1411 zcommits
1412 COMMIT
1413 reset refs/tags/O3-2nd
1414 from :5
1415 reset refs/tags/O3-3rd
1416 from :5
1417 INPUT_END
1419 cat >expect <<INPUT_END
1420 string
1421 of
1422 empty
1423 commits
1424 INPUT_END
1425 test_expect_success \
1426         'O: blank lines not necessary after other commands' \
1427         'git fast-import <input &&
1428          test 8 = `find .git/objects/pack -type f | wc -l` &&
1429          test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1430          git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1431          test_cmp expect actual'
1433 cat >input <<INPUT_END
1434 commit refs/heads/O4
1435 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1436 data <<COMMIT
1437 zstring
1438 COMMIT
1439 commit refs/heads/O4
1440 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1441 data <<COMMIT
1442 zof
1443 COMMIT
1444 progress Two commits down, 2 to go!
1445 commit refs/heads/O4
1446 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1447 data <<COMMIT
1448 zempty
1449 COMMIT
1450 progress Three commits down, 1 to go!
1451 commit refs/heads/O4
1452 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1453 data <<COMMIT
1454 zcommits
1455 COMMIT
1456 progress I'm done!
1457 INPUT_END
1458 test_expect_success \
1459         'O: progress outputs as requested by input' \
1460         'git fast-import <input >actual &&
1461          grep "progress " <input >expect &&
1462          test_cmp expect actual'
1464 ###
1465 ### series P (gitlinks)
1466 ###
1468 cat >input <<INPUT_END
1469 blob
1470 mark :1
1471 data 10
1472 test file
1474 reset refs/heads/sub
1475 commit refs/heads/sub
1476 mark :2
1477 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1478 data 12
1479 sub_initial
1480 M 100644 :1 file
1482 blob
1483 mark :3
1484 data <<DATAEND
1485 [submodule "sub"]
1486         path = sub
1487         url = "`pwd`/sub"
1488 DATAEND
1490 commit refs/heads/subuse1
1491 mark :4
1492 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1493 data 8
1494 initial
1495 from refs/heads/master
1496 M 100644 :3 .gitmodules
1497 M 160000 :2 sub
1499 blob
1500 mark :5
1501 data 20
1502 test file
1503 more data
1505 commit refs/heads/sub
1506 mark :6
1507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1508 data 11
1509 sub_second
1510 from :2
1511 M 100644 :5 file
1513 commit refs/heads/subuse1
1514 mark :7
1515 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1516 data 7
1517 second
1518 from :4
1519 M 160000 :6 sub
1521 INPUT_END
1523 test_expect_success \
1524         'P: supermodule & submodule mix' \
1525         'git fast-import <input &&
1526          git checkout subuse1 &&
1527          rm -rf sub && mkdir sub && (cd sub &&
1528          git init &&
1529          git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1530          git checkout master) &&
1531          git submodule init &&
1532          git submodule update'
1534 SUBLAST=$(git rev-parse --verify sub)
1535 SUBPREV=$(git rev-parse --verify sub^)
1537 cat >input <<INPUT_END
1538 blob
1539 mark :1
1540 data <<DATAEND
1541 [submodule "sub"]
1542         path = sub
1543         url = "`pwd`/sub"
1544 DATAEND
1546 commit refs/heads/subuse2
1547 mark :2
1548 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1549 data 8
1550 initial
1551 from refs/heads/master
1552 M 100644 :1 .gitmodules
1553 M 160000 $SUBPREV sub
1555 commit refs/heads/subuse2
1556 mark :3
1557 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1558 data 7
1559 second
1560 from :2
1561 M 160000 $SUBLAST sub
1563 INPUT_END
1565 test_expect_success \
1566         'P: verbatim SHA gitlinks' \
1567         'git branch -D sub &&
1568          git gc && git prune &&
1569          git fast-import <input &&
1570          test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1572 test_tick
1573 cat >input <<INPUT_END
1574 commit refs/heads/subuse3
1575 mark :1
1576 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1577 data <<COMMIT
1578 corrupt
1579 COMMIT
1581 from refs/heads/subuse2
1582 M 160000 inline sub
1583 data <<DATA
1584 $SUBPREV
1585 DATA
1587 INPUT_END
1589 test_expect_success 'P: fail on inline gitlink' '
1590     test_must_fail git fast-import <input'
1592 test_tick
1593 cat >input <<INPUT_END
1594 blob
1595 mark :1
1596 data <<DATA
1597 $SUBPREV
1598 DATA
1600 commit refs/heads/subuse3
1601 mark :2
1602 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1603 data <<COMMIT
1604 corrupt
1605 COMMIT
1607 from refs/heads/subuse2
1608 M 160000 :1 sub
1610 INPUT_END
1612 test_expect_success 'P: fail on blob mark in gitlink' '
1613     test_must_fail git fast-import <input'
1615 ###
1616 ### series Q (notes)
1617 ###
1619 note1_data="The first note for the first commit"
1620 note2_data="The first note for the second commit"
1621 note3_data="The first note for the third commit"
1622 note1b_data="The second note for the first commit"
1623 note1c_data="The third note for the first commit"
1624 note2b_data="The second note for the second commit"
1626 test_tick
1627 cat >input <<INPUT_END
1628 blob
1629 mark :2
1630 data <<EOF
1631 $file2_data
1632 EOF
1634 commit refs/heads/notes-test
1635 mark :3
1636 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1637 data <<COMMIT
1638 first (:3)
1639 COMMIT
1641 M 644 :2 file2
1643 blob
1644 mark :4
1645 data $file4_len
1646 $file4_data
1647 commit refs/heads/notes-test
1648 mark :5
1649 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1650 data <<COMMIT
1651 second (:5)
1652 COMMIT
1654 M 644 :4 file4
1656 commit refs/heads/notes-test
1657 mark :6
1658 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1659 data <<COMMIT
1660 third (:6)
1661 COMMIT
1663 M 644 inline file5
1664 data <<EOF
1665 $file5_data
1666 EOF
1668 M 755 inline file6
1669 data <<EOF
1670 $file6_data
1671 EOF
1673 blob
1674 mark :7
1675 data <<EOF
1676 $note1_data
1677 EOF
1679 blob
1680 mark :8
1681 data <<EOF
1682 $note2_data
1683 EOF
1685 commit refs/notes/foobar
1686 mark :9
1687 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1688 data <<COMMIT
1689 notes (:9)
1690 COMMIT
1692 N :7 :3
1693 N :8 :5
1694 N inline :6
1695 data <<EOF
1696 $note3_data
1697 EOF
1699 commit refs/notes/foobar
1700 mark :10
1701 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1702 data <<COMMIT
1703 notes (:10)
1704 COMMIT
1706 N inline :3
1707 data <<EOF
1708 $note1b_data
1709 EOF
1711 commit refs/notes/foobar2
1712 mark :11
1713 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1714 data <<COMMIT
1715 notes (:11)
1716 COMMIT
1718 N inline :3
1719 data <<EOF
1720 $note1c_data
1721 EOF
1723 commit refs/notes/foobar
1724 mark :12
1725 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1726 data <<COMMIT
1727 notes (:12)
1728 COMMIT
1730 deleteall
1731 N inline :5
1732 data <<EOF
1733 $note2b_data
1734 EOF
1736 INPUT_END
1738 test_expect_success \
1739         'Q: commit notes' \
1740         'git fast-import <input &&
1741          git whatchanged notes-test'
1742 test_expect_success \
1743         'Q: verify pack' \
1744         'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1746 commit1=$(git rev-parse notes-test~2)
1747 commit2=$(git rev-parse notes-test^)
1748 commit3=$(git rev-parse notes-test)
1750 cat >expect <<EOF
1751 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1752 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1754 first (:3)
1755 EOF
1756 test_expect_success \
1757         'Q: verify first commit' \
1758         'git cat-file commit notes-test~2 | sed 1d >actual &&
1759         test_cmp expect actual'
1761 cat >expect <<EOF
1762 parent $commit1
1763 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1764 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1766 second (:5)
1767 EOF
1768 test_expect_success \
1769         'Q: verify second commit' \
1770         'git cat-file commit notes-test^ | sed 1d >actual &&
1771         test_cmp expect actual'
1773 cat >expect <<EOF
1774 parent $commit2
1775 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1776 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1778 third (:6)
1779 EOF
1780 test_expect_success \
1781         'Q: verify third commit' \
1782         'git cat-file commit notes-test | sed 1d >actual &&
1783         test_cmp expect actual'
1785 cat >expect <<EOF
1786 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1787 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1789 notes (:9)
1790 EOF
1791 test_expect_success \
1792         'Q: verify first notes commit' \
1793         'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1794         test_cmp expect actual'
1796 cat >expect.unsorted <<EOF
1797 100644 blob $commit1
1798 100644 blob $commit2
1799 100644 blob $commit3
1800 EOF
1801 cat expect.unsorted | sort >expect
1802 test_expect_success \
1803         'Q: verify first notes tree' \
1804         'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1805          test_cmp expect actual'
1807 echo "$note1_data" >expect
1808 test_expect_success \
1809         'Q: verify first note for first commit' \
1810         'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1812 echo "$note2_data" >expect
1813 test_expect_success \
1814         'Q: verify first note for second commit' \
1815         'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1817 echo "$note3_data" >expect
1818 test_expect_success \
1819         'Q: verify first note for third commit' \
1820         'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1822 cat >expect <<EOF
1823 parent `git rev-parse --verify refs/notes/foobar~2`
1824 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1825 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1827 notes (:10)
1828 EOF
1829 test_expect_success \
1830         'Q: verify second notes commit' \
1831         'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1832         test_cmp expect actual'
1834 cat >expect.unsorted <<EOF
1835 100644 blob $commit1
1836 100644 blob $commit2
1837 100644 blob $commit3
1838 EOF
1839 cat expect.unsorted | sort >expect
1840 test_expect_success \
1841         'Q: verify second notes tree' \
1842         'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1843          test_cmp expect actual'
1845 echo "$note1b_data" >expect
1846 test_expect_success \
1847         'Q: verify second note for first commit' \
1848         'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1850 echo "$note2_data" >expect
1851 test_expect_success \
1852         'Q: verify first note for second commit' \
1853         'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1855 echo "$note3_data" >expect
1856 test_expect_success \
1857         'Q: verify first note for third commit' \
1858         'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1860 cat >expect <<EOF
1861 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1862 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1864 notes (:11)
1865 EOF
1866 test_expect_success \
1867         'Q: verify third notes commit' \
1868         'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1869         test_cmp expect actual'
1871 cat >expect.unsorted <<EOF
1872 100644 blob $commit1
1873 EOF
1874 cat expect.unsorted | sort >expect
1875 test_expect_success \
1876         'Q: verify third notes tree' \
1877         'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1878          test_cmp expect actual'
1880 echo "$note1c_data" >expect
1881 test_expect_success \
1882         'Q: verify third note for first commit' \
1883         'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1885 cat >expect <<EOF
1886 parent `git rev-parse --verify refs/notes/foobar^`
1887 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1890 notes (:12)
1891 EOF
1892 test_expect_success \
1893         'Q: verify fourth notes commit' \
1894         'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1895         test_cmp expect actual'
1897 cat >expect.unsorted <<EOF
1898 100644 blob $commit2
1899 EOF
1900 cat expect.unsorted | sort >expect
1901 test_expect_success \
1902         'Q: verify fourth notes tree' \
1903         'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1904          test_cmp expect actual'
1906 echo "$note2b_data" >expect
1907 test_expect_success \
1908         'Q: verify second note for second commit' \
1909         'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1911 ###
1912 ### series R (feature and option)
1913 ###
1915 cat >input <<EOF
1916 feature no-such-feature-exists
1917 EOF
1919 test_expect_success 'R: abort on unsupported feature' '
1920         test_must_fail git fast-import <input
1923 cat >input <<EOF
1924 feature date-format=now
1925 EOF
1927 test_expect_success 'R: supported feature is accepted' '
1928         git fast-import <input
1931 cat >input << EOF
1932 blob
1933 data 3
1934 hi
1935 feature date-format=now
1936 EOF
1938 test_expect_success 'R: abort on receiving feature after data command' '
1939         test_must_fail git fast-import <input
1942 cat >input << EOF
1943 feature import-marks=git.marks
1944 feature import-marks=git2.marks
1945 EOF
1947 test_expect_success 'R: only one import-marks feature allowed per stream' '
1948         test_must_fail git fast-import <input
1951 cat >input << EOF
1952 feature export-marks=git.marks
1953 blob
1954 mark :1
1955 data 3
1956 hi
1958 EOF
1960 test_expect_success \
1961     'R: export-marks feature results in a marks file being created' \
1962     'cat input | git fast-import &&
1963     grep :1 git.marks'
1965 test_expect_success \
1966     'R: export-marks options can be overriden by commandline options' \
1967     'cat input | git fast-import --export-marks=other.marks &&
1968     grep :1 other.marks'
1970 test_expect_success 'R: catch typo in marks file name' '
1971         test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
1972         echo "feature import-marks=nonexistent.marks" |
1973         test_must_fail git fast-import
1976 test_expect_success 'R: import and output marks can be the same file' '
1977         rm -f io.marks &&
1978         blob=$(echo hi | git hash-object --stdin) &&
1979         cat >expect <<-EOF &&
1980         :1 $blob
1981         :2 $blob
1982         EOF
1983         git fast-import --export-marks=io.marks <<-\EOF &&
1984         blob
1985         mark :1
1986         data 3
1987         hi
1989         EOF
1990         git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
1991         blob
1992         mark :2
1993         data 3
1994         hi
1996         EOF
1997         test_cmp expect io.marks
2000 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2001         rm -f io.marks &&
2002         test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2003         blob
2004         mark :1
2005         data 3
2006         hi
2008         EOF
2011 test_expect_success 'R: --import-marks-if-exists' '
2012         rm -f io.marks &&
2013         blob=$(echo hi | git hash-object --stdin) &&
2014         echo ":1 $blob" >expect &&
2015         git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2016         blob
2017         mark :1
2018         data 3
2019         hi
2021         EOF
2022         test_cmp expect io.marks
2025 test_expect_success 'R: feature import-marks-if-exists' '
2026         rm -f io.marks &&
2027         >expect &&
2029         git fast-import --export-marks=io.marks <<-\EOF &&
2030         feature import-marks-if-exists=not_io.marks
2031         EOF
2032         test_cmp expect io.marks &&
2034         blob=$(echo hi | git hash-object --stdin) &&
2036         echo ":1 $blob" >io.marks &&
2037         echo ":1 $blob" >expect &&
2038         echo ":2 $blob" >>expect &&
2040         git fast-import --export-marks=io.marks <<-\EOF &&
2041         feature import-marks-if-exists=io.marks
2042         blob
2043         mark :2
2044         data 3
2045         hi
2047         EOF
2048         test_cmp expect io.marks &&
2050         echo ":3 $blob" >>expect &&
2052         git fast-import --import-marks=io.marks \
2053                         --export-marks=io.marks <<-\EOF &&
2054         feature import-marks-if-exists=not_io.marks
2055         blob
2056         mark :3
2057         data 3
2058         hi
2060         EOF
2061         test_cmp expect io.marks &&
2063         >expect &&
2065         git fast-import --import-marks-if-exists=not_io.marks \
2066                         --export-marks=io.marks <<-\EOF
2067         feature import-marks-if-exists=io.marks
2068         EOF
2069         test_cmp expect io.marks
2072 cat >input << EOF
2073 feature import-marks=marks.out
2074 feature export-marks=marks.new
2075 EOF
2077 test_expect_success \
2078     'R: import to output marks works without any content' \
2079     'cat input | git fast-import &&
2080     test_cmp marks.out marks.new'
2082 cat >input <<EOF
2083 feature import-marks=nonexistent.marks
2084 feature export-marks=marks.new
2085 EOF
2087 test_expect_success \
2088     'R: import marks prefers commandline marks file over the stream' \
2089     'cat input | git fast-import --import-marks=marks.out &&
2090     test_cmp marks.out marks.new'
2093 cat >input <<EOF
2094 feature import-marks=nonexistent.marks
2095 feature export-marks=combined.marks
2096 EOF
2098 test_expect_success 'R: multiple --import-marks= should be honoured' '
2099     head -n2 marks.out > one.marks &&
2100     tail -n +3 marks.out > two.marks &&
2101     git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2102     test_cmp marks.out combined.marks
2105 cat >input <<EOF
2106 feature relative-marks
2107 feature import-marks=relative.in
2108 feature export-marks=relative.out
2109 EOF
2111 test_expect_success 'R: feature relative-marks should be honoured' '
2112     mkdir -p .git/info/fast-import/ &&
2113     cp marks.new .git/info/fast-import/relative.in &&
2114     git fast-import <input &&
2115     test_cmp marks.new .git/info/fast-import/relative.out
2118 cat >input <<EOF
2119 feature relative-marks
2120 feature import-marks=relative.in
2121 feature no-relative-marks
2122 feature export-marks=non-relative.out
2123 EOF
2125 test_expect_success 'R: feature no-relative-marks should be honoured' '
2126     git fast-import <input &&
2127     test_cmp marks.new non-relative.out
2130 test_expect_success 'R: feature ls supported' '
2131         echo "feature ls" |
2132         git fast-import
2135 test_expect_success 'R: feature cat-blob supported' '
2136         echo "feature cat-blob" |
2137         git fast-import
2140 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2141         test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2144 test_expect_success 'R: print old blob' '
2145         blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2146         cat >expect <<-EOF &&
2147         ${blob} blob 11
2148         yes it can
2150         EOF
2151         echo "cat-blob $blob" |
2152         git fast-import --cat-blob-fd=6 6>actual &&
2153         test_cmp expect actual
2156 test_expect_success 'R: in-stream cat-blob-fd not respected' '
2157         echo hello >greeting &&
2158         blob=$(git hash-object -w greeting) &&
2159         cat >expect <<-EOF &&
2160         ${blob} blob 6
2161         hello
2163         EOF
2164         git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2165         cat-blob $blob
2166         EOF
2167         test_cmp expect actual.3 &&
2168         test_cmp empty actual.1 &&
2169         git fast-import 3>actual.3 >actual.1 <<-EOF &&
2170         option cat-blob-fd=3
2171         cat-blob $blob
2172         EOF
2173         test_cmp empty actual.3 &&
2174         test_cmp expect actual.1
2177 test_expect_success 'R: print new blob' '
2178         blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2179         cat >expect <<-EOF &&
2180         ${blob} blob 12
2181         yep yep yep
2183         EOF
2184         git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2185         blob
2186         mark :1
2187         data <<BLOB_END
2188         yep yep yep
2189         BLOB_END
2190         cat-blob :1
2191         EOF
2192         test_cmp expect actual
2195 test_expect_success 'R: print new blob by sha1' '
2196         blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2197         cat >expect <<-EOF &&
2198         ${blob} blob 25
2199         a new blob named by sha1
2201         EOF
2202         git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2203         blob
2204         data <<BLOB_END
2205         a new blob named by sha1
2206         BLOB_END
2207         cat-blob $blob
2208         EOF
2209         test_cmp expect actual
2212 test_expect_success 'setup: big file' '
2213         (
2214                 echo "the quick brown fox jumps over the lazy dog" >big &&
2215                 for i in 1 2 3
2216                 do
2217                         cat big big big big >bigger &&
2218                         cat bigger bigger bigger bigger >big ||
2219                         exit
2220                 done
2221         )
2224 test_expect_success 'R: print two blobs to stdout' '
2225         blob1=$(git hash-object big) &&
2226         blob1_len=$(wc -c <big) &&
2227         blob2=$(echo hello | git hash-object --stdin) &&
2228         {
2229                 echo ${blob1} blob $blob1_len &&
2230                 cat big &&
2231                 cat <<-EOF
2233                 ${blob2} blob 6
2234                 hello
2236                 EOF
2237         } >expect &&
2238         {
2239                 cat <<-\END_PART1 &&
2240                         blob
2241                         mark :1
2242                         data <<data_end
2243                 END_PART1
2244                 cat big &&
2245                 cat <<-\EOF
2246                         data_end
2247                         blob
2248                         mark :2
2249                         data <<data_end
2250                         hello
2251                         data_end
2252                         cat-blob :1
2253                         cat-blob :2
2254                 EOF
2255         } |
2256         git fast-import >actual &&
2257         test_cmp expect actual
2260 test_expect_success PIPE 'R: copy using cat-file' '
2261         expect_id=$(git hash-object big) &&
2262         expect_len=$(wc -c <big) &&
2263         echo $expect_id blob $expect_len >expect.response &&
2265         rm -f blobs &&
2266         cat >frontend <<-\FRONTEND_END &&
2267         #!/bin/sh
2268         FRONTEND_END
2270         mkfifo blobs &&
2271         (
2272                 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2273                 cat <<-\EOF &&
2274                 feature cat-blob
2275                 blob
2276                 mark :1
2277                 data <<BLOB
2278                 EOF
2279                 cat big &&
2280                 cat <<-\EOF &&
2281                 BLOB
2282                 cat-blob :1
2283                 EOF
2285                 read blob_id type size <&3 &&
2286                 echo "$blob_id $type $size" >response &&
2287                 head_c $size >blob <&3 &&
2288                 read newline <&3 &&
2290                 cat <<-EOF &&
2291                 commit refs/heads/copied
2292                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2293                 data <<COMMIT
2294                 copy big file as file3
2295                 COMMIT
2296                 M 644 inline file3
2297                 data <<BLOB
2298                 EOF
2299                 cat blob &&
2300                 echo BLOB
2301         ) 3<blobs |
2302         git fast-import --cat-blob-fd=3 3>blobs &&
2303         git show copied:file3 >actual &&
2304         test_cmp expect.response response &&
2305         test_cmp big actual
2308 test_expect_success PIPE 'R: print blob mid-commit' '
2309         rm -f blobs &&
2310         echo "A blob from _before_ the commit." >expect &&
2311         mkfifo blobs &&
2312         (
2313                 exec 3<blobs &&
2314                 cat <<-EOF &&
2315                 feature cat-blob
2316                 blob
2317                 mark :1
2318                 data <<BLOB
2319                 A blob from _before_ the commit.
2320                 BLOB
2321                 commit refs/heads/temporary
2322                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2323                 data <<COMMIT
2324                 Empty commit
2325                 COMMIT
2326                 cat-blob :1
2327                 EOF
2329                 read blob_id type size <&3 &&
2330                 head_c $size >actual <&3 &&
2331                 read newline <&3 &&
2333                 echo
2334         ) |
2335         git fast-import --cat-blob-fd=3 3>blobs &&
2336         test_cmp expect actual
2339 test_expect_success PIPE 'R: print staged blob within commit' '
2340         rm -f blobs &&
2341         echo "A blob from _within_ the commit." >expect &&
2342         mkfifo blobs &&
2343         (
2344                 exec 3<blobs &&
2345                 cat <<-EOF &&
2346                 feature cat-blob
2347                 commit refs/heads/within
2348                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2349                 data <<COMMIT
2350                 Empty commit
2351                 COMMIT
2352                 M 644 inline within
2353                 data <<BLOB
2354                 A blob from _within_ the commit.
2355                 BLOB
2356                 EOF
2358                 to_get=$(
2359                         echo "A blob from _within_ the commit." |
2360                         git hash-object --stdin
2361                 ) &&
2362                 echo "cat-blob $to_get" &&
2364                 read blob_id type size <&3 &&
2365                 head_c $size >actual <&3 &&
2366                 read newline <&3 &&
2368                 echo deleteall
2369         ) |
2370         git fast-import --cat-blob-fd=3 3>blobs &&
2371         test_cmp expect actual
2374 cat >input << EOF
2375 option git quiet
2376 blob
2377 data 3
2378 hi
2380 EOF
2382 test_expect_success 'R: quiet option results in no stats being output' '
2383     cat input | git fast-import 2> output &&
2384     test_cmp empty output
2387 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2388         echo feature done | test_must_fail git fast-import &&
2389         test_must_fail git fast-import --done </dev/null
2392 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2393         git fast-import <<-\EOF &&
2394         feature done
2395         done
2396         trailing gibberish
2397         EOF
2398         git fast-import <<-\EOF
2399         done
2400         more trailing gibberish
2401         EOF
2404 test_expect_success 'R: terminating "done" within commit' '
2405         cat >expect <<-\EOF &&
2406         OBJID
2407         :000000 100644 OBJID OBJID A    hello.c
2408         :000000 100644 OBJID OBJID A    hello2.c
2409         EOF
2410         git fast-import <<-EOF &&
2411         commit refs/heads/done-ends
2412         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2413         data <<EOT
2414         Commit terminated by "done" command
2415         EOT
2416         M 100644 inline hello.c
2417         data <<EOT
2418         Hello, world.
2419         EOT
2420         C hello.c hello2.c
2421         done
2422         EOF
2423         git rev-list done-ends |
2424         git diff-tree -r --stdin --root --always |
2425         sed -e "s/$_x40/OBJID/g" >actual &&
2426         test_cmp expect actual
2429 cat >input <<EOF
2430 option git non-existing-option
2431 EOF
2433 test_expect_success 'R: die on unknown option' '
2434     test_must_fail git fast-import <input
2437 test_expect_success 'R: unknown commandline options are rejected' '\
2438     test_must_fail git fast-import --non-existing-option < /dev/null
2441 test_expect_success 'R: die on invalid option argument' '
2442         echo "option git active-branches=-5" |
2443         test_must_fail git fast-import &&
2444         echo "option git depth=" |
2445         test_must_fail git fast-import &&
2446         test_must_fail git fast-import --depth="5 elephants" </dev/null
2449 cat >input <<EOF
2450 option non-existing-vcs non-existing-option
2451 EOF
2453 test_expect_success 'R: ignore non-git options' '
2454     git fast-import <input
2457 ##
2458 ## R: very large blobs
2459 ##
2460 blobsize=$((2*1024*1024 + 53))
2461 test-genrandom bar $blobsize >expect
2462 cat >input <<INPUT_END
2463 commit refs/heads/big-file
2464 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2465 data <<COMMIT
2466 R - big file
2467 COMMIT
2469 M 644 inline big1
2470 data $blobsize
2471 INPUT_END
2472 cat expect >>input
2473 cat >>input <<INPUT_END
2474 M 644 inline big2
2475 data $blobsize
2476 INPUT_END
2477 cat expect >>input
2478 echo >>input
2480 test_expect_success \
2481         'R: blob bigger than threshold' \
2482         'test_create_repo R &&
2483          git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2484 test_expect_success \
2485         'R: verify created pack' \
2486         ': >verify &&
2487          for p in R/.git/objects/pack/*.pack;
2488          do
2489            git verify-pack -v $p >>verify || exit;
2490          done'
2491 test_expect_success \
2492         'R: verify written objects' \
2493         'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2494          test_cmp expect actual &&
2495          a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2496          b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2497          test $a = $b'
2498 test_expect_success \
2499         'R: blob appears only once' \
2500         'n=$(grep $a verify | wc -l) &&
2501          test 1 = $n'
2503 test_done