wildmatch: properly fold case everywhere
[git.git] / t / t9300-fast-import.sh
blobac6f3b6af25c67ae3a2c0748c34f99b4cd0d4b32
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
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.
12 # This could be written as "head -c $1", but IRIX "head" does not
13 # support the -c option.
14 head_c () {
15 "$PERL_PATH" -e '
16 my $len = $ARGV[1];
17 while ($len > 0) {
18 my $s;
19 my $nread = sysread(STDIN, $s, $len);
20 die "cannot read: $!" unless defined($nread);
21 print $s;
22 $len -= $nread;
24 ' - "$1"
27 verify_packs () {
28 for p in .git/objects/pack/*.pack
30 git verify-pack "$@" "$p" || return
31 done
34 file2_data='file2
35 second line of EOF'
37 file3_data='EOF
38 in 3rd file
39 END'
41 file4_data=abcd
42 file4_len=4
44 file5_data='an inline file.
45 we should see it later.'
47 file6_data='#!/bin/sh
48 echo "$@"'
50 >empty
52 ###
53 ### series A
54 ###
56 test_tick
58 test_expect_success 'empty stream succeeds' '
59 git fast-import </dev/null
62 cat >input <<INPUT_END
63 blob
64 mark :2
65 data <<EOF
66 $file2_data
67 EOF
69 blob
70 mark :3
71 data <<END
72 $file3_data
73 END
75 blob
76 mark :4
77 data $file4_len
78 $file4_data
79 commit refs/heads/master
80 mark :5
81 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82 data <<COMMIT
83 initial
84 COMMIT
86 M 644 :2 file2
87 M 644 :3 file3
88 M 755 :4 file4
90 tag series-A
91 from :5
92 data <<EOF
93 An annotated tag without a tagger
94 EOF
96 tag series-A-blob
97 from :3
98 data <<EOF
99 An annotated tag that annotates a blob.
102 INPUT_END
103 test_expect_success \
104 'A: create pack from stdin' \
105 'git fast-import --export-marks=marks.out <input &&
106 git whatchanged master'
108 test_expect_success 'A: verify pack' '
109 verify_packs
112 cat >expect <<EOF
113 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
116 initial
118 test_expect_success \
119 'A: verify commit' \
120 'git cat-file commit master | sed 1d >actual &&
121 test_cmp expect actual'
123 cat >expect <<EOF
124 100644 blob file2
125 100644 blob file3
126 100755 blob file4
128 test_expect_success \
129 'A: verify tree' \
130 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
131 test_cmp expect actual'
133 echo "$file2_data" >expect
134 test_expect_success \
135 'A: verify file2' \
136 'git cat-file blob master:file2 >actual && test_cmp expect actual'
138 echo "$file3_data" >expect
139 test_expect_success \
140 'A: verify file3' \
141 'git cat-file blob master:file3 >actual && test_cmp expect actual'
143 printf "$file4_data" >expect
144 test_expect_success \
145 'A: verify file4' \
146 'git cat-file blob master:file4 >actual && test_cmp expect actual'
148 cat >expect <<EOF
149 object $(git rev-parse refs/heads/master)
150 type commit
151 tag series-A
153 An annotated tag without a tagger
155 test_expect_success 'A: verify tag/series-A' '
156 git cat-file tag tags/series-A >actual &&
157 test_cmp expect actual
160 cat >expect <<EOF
161 object $(git rev-parse refs/heads/master:file3)
162 type blob
163 tag series-A-blob
165 An annotated tag that annotates a blob.
167 test_expect_success 'A: verify tag/series-A-blob' '
168 git cat-file tag tags/series-A-blob >actual &&
169 test_cmp expect actual
172 cat >expect <<EOF
173 :2 `git rev-parse --verify master:file2`
174 :3 `git rev-parse --verify master:file3`
175 :4 `git rev-parse --verify master:file4`
176 :5 `git rev-parse --verify master^0`
178 test_expect_success \
179 'A: verify marks output' \
180 'test_cmp expect marks.out'
182 test_expect_success \
183 'A: verify marks import' \
184 'git fast-import \
185 --import-marks=marks.out \
186 --export-marks=marks.new \
187 </dev/null &&
188 test_cmp expect marks.new'
190 test_tick
191 new_blob=$(echo testing | git hash-object --stdin)
192 cat >input <<INPUT_END
193 tag series-A-blob-2
194 from $(git rev-parse refs/heads/master:file3)
195 data <<EOF
196 Tag blob by sha1.
199 blob
200 mark :6
201 data <<EOF
202 testing
205 commit refs/heads/new_blob
206 committer <> 0 +0000
207 data 0
208 M 644 :6 new_blob
209 #pretend we got sha1 from fast-import
210 ls "new_blob"
212 tag series-A-blob-3
213 from $new_blob
214 data <<EOF
215 Tag new_blob.
217 INPUT_END
219 cat >expect <<EOF
220 object $(git rev-parse refs/heads/master:file3)
221 type blob
222 tag series-A-blob-2
224 Tag blob by sha1.
225 object $new_blob
226 type blob
227 tag series-A-blob-3
229 Tag new_blob.
232 test_expect_success \
233 'A: tag blob by sha1' \
234 'git fast-import <input &&
235 git cat-file tag tags/series-A-blob-2 >actual &&
236 git cat-file tag tags/series-A-blob-3 >>actual &&
237 test_cmp expect actual'
239 test_tick
240 cat >input <<INPUT_END
241 commit refs/heads/verify--import-marks
242 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
243 data <<COMMIT
244 recreate from :5
245 COMMIT
247 from :5
248 M 755 :2 copy-of-file2
250 INPUT_END
251 test_expect_success \
252 'A: verify marks import does not crash' \
253 'git fast-import --import-marks=marks.out <input &&
254 git whatchanged verify--import-marks'
256 test_expect_success 'A: verify pack' '
257 verify_packs
260 cat >expect <<EOF
261 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
263 git diff-tree -M -r master verify--import-marks >actual
264 test_expect_success \
265 'A: verify diff' \
266 'compare_diff_raw expect actual &&
267 test `git rev-parse --verify master:file2` \
268 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
270 test_tick
271 mt=$(git hash-object --stdin < /dev/null)
272 : >input.blob
273 : >marks.exp
274 : >tree.exp
276 cat >input.commit <<EOF
277 commit refs/heads/verify--dump-marks
278 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
279 data <<COMMIT
280 test the sparse array dumping routines with exponentially growing marks
281 COMMIT
288 while test "$i" -lt 27; do
289 cat >>input.blob <<EOF
290 blob
291 mark :$l
292 data 0
293 blob
294 mark :$m
295 data 0
296 blob
297 mark :$n
298 data 0
300 echo "M 100644 :$l l$i" >>input.commit
301 echo "M 100644 :$m m$i" >>input.commit
302 echo "M 100644 :$n n$i" >>input.commit
304 echo ":$l $mt" >>marks.exp
305 echo ":$m $mt" >>marks.exp
306 echo ":$n $mt" >>marks.exp
308 printf "100644 blob $mt\tl$i\n" >>tree.exp
309 printf "100644 blob $mt\tm$i\n" >>tree.exp
310 printf "100644 blob $mt\tn$i\n" >>tree.exp
312 l=$(($l + $l))
313 m=$(($m + $m))
314 n=$(($l + $n))
316 i=$((1 + $i))
317 done
319 sort tree.exp > tree.exp_s
321 test_expect_success 'A: export marks with large values' '
322 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
323 git ls-tree refs/heads/verify--dump-marks >tree.out &&
324 test_cmp tree.exp_s tree.out &&
325 test_cmp marks.exp marks.large'
328 ### series B
331 test_tick
332 cat >input <<INPUT_END
333 commit refs/heads/branch
334 mark :1
335 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
336 data <<COMMIT
337 corrupt
338 COMMIT
340 from refs/heads/master
341 M 755 0000000000000000000000000000000000000001 zero1
343 INPUT_END
344 test_expect_success 'B: fail on invalid blob sha1' '
345 test_must_fail git fast-import <input
347 rm -f .git/objects/pack_* .git/objects/index_*
349 cat >input <<INPUT_END
350 commit .badbranchname
351 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
352 data <<COMMIT
353 corrupt
354 COMMIT
356 from refs/heads/master
358 INPUT_END
359 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
360 test_must_fail git fast-import <input
362 rm -f .git/objects/pack_* .git/objects/index_*
364 cat >input <<INPUT_END
365 commit bad[branch]name
366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
367 data <<COMMIT
368 corrupt
369 COMMIT
371 from refs/heads/master
373 INPUT_END
374 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
375 test_must_fail git fast-import <input
377 rm -f .git/objects/pack_* .git/objects/index_*
379 cat >input <<INPUT_END
380 commit TEMP_TAG
381 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
382 data <<COMMIT
383 tag base
384 COMMIT
386 from refs/heads/master
388 INPUT_END
389 test_expect_success \
390 'B: accept branch name "TEMP_TAG"' \
391 'git fast-import <input &&
392 test -f .git/TEMP_TAG &&
393 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
394 rm -f .git/TEMP_TAG
396 git gc 2>/dev/null >/dev/null
397 git prune 2>/dev/null >/dev/null
399 cat >input <<INPUT_END
400 commit refs/heads/empty-committer-1
401 committer <> $GIT_COMMITTER_DATE
402 data <<COMMIT
403 empty commit
404 COMMIT
405 INPUT_END
406 test_expect_success 'B: accept empty committer' '
407 git fast-import <input &&
408 out=$(git fsck) &&
409 echo "$out" &&
410 test -z "$out"
412 git update-ref -d refs/heads/empty-committer-1 || true
414 git gc 2>/dev/null >/dev/null
415 git prune 2>/dev/null >/dev/null
417 cat >input <<INPUT_END
418 commit refs/heads/empty-committer-2
419 committer <a@b.com> $GIT_COMMITTER_DATE
420 data <<COMMIT
421 empty commit
422 COMMIT
423 INPUT_END
424 test_expect_success 'B: accept and fixup committer with no name' '
425 git fast-import <input &&
426 out=$(git fsck) &&
427 echo "$out" &&
428 test -z "$out"
430 git update-ref -d refs/heads/empty-committer-2 || true
432 git gc 2>/dev/null >/dev/null
433 git prune 2>/dev/null >/dev/null
435 cat >input <<INPUT_END
436 commit refs/heads/invalid-committer
437 committer Name email> $GIT_COMMITTER_DATE
438 data <<COMMIT
439 empty commit
440 COMMIT
441 INPUT_END
442 test_expect_success 'B: fail on invalid committer (1)' '
443 test_must_fail git fast-import <input
445 git update-ref -d refs/heads/invalid-committer || true
447 cat >input <<INPUT_END
448 commit refs/heads/invalid-committer
449 committer Name <e<mail> $GIT_COMMITTER_DATE
450 data <<COMMIT
451 empty commit
452 COMMIT
453 INPUT_END
454 test_expect_success 'B: fail on invalid committer (2)' '
455 test_must_fail git fast-import <input
457 git update-ref -d refs/heads/invalid-committer || true
459 cat >input <<INPUT_END
460 commit refs/heads/invalid-committer
461 committer Name <email>> $GIT_COMMITTER_DATE
462 data <<COMMIT
463 empty commit
464 COMMIT
465 INPUT_END
466 test_expect_success 'B: fail on invalid committer (3)' '
467 test_must_fail git fast-import <input
469 git update-ref -d refs/heads/invalid-committer || true
471 cat >input <<INPUT_END
472 commit refs/heads/invalid-committer
473 committer Name <email $GIT_COMMITTER_DATE
474 data <<COMMIT
475 empty commit
476 COMMIT
477 INPUT_END
478 test_expect_success 'B: fail on invalid committer (4)' '
479 test_must_fail git fast-import <input
481 git update-ref -d refs/heads/invalid-committer || true
483 cat >input <<INPUT_END
484 commit refs/heads/invalid-committer
485 committer Name<email> $GIT_COMMITTER_DATE
486 data <<COMMIT
487 empty commit
488 COMMIT
489 INPUT_END
490 test_expect_success 'B: fail on invalid committer (5)' '
491 test_must_fail git fast-import <input
493 git update-ref -d refs/heads/invalid-committer || true
496 ### series C
499 newf=`echo hi newf | git hash-object -w --stdin`
500 oldf=`git rev-parse --verify master:file2`
501 test_tick
502 cat >input <<INPUT_END
503 commit refs/heads/branch
504 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
505 data <<COMMIT
506 second
507 COMMIT
509 from refs/heads/master
510 M 644 $oldf file2/oldf
511 M 755 $newf file2/newf
512 D file3
514 INPUT_END
515 test_expect_success \
516 'C: incremental import create pack from stdin' \
517 'git fast-import <input &&
518 git whatchanged branch'
520 test_expect_success 'C: verify pack' '
521 verify_packs
524 test_expect_success \
525 'C: validate reuse existing blob' \
526 'test $newf = `git rev-parse --verify branch:file2/newf` &&
527 test $oldf = `git rev-parse --verify branch:file2/oldf`'
529 cat >expect <<EOF
530 parent `git rev-parse --verify master^0`
531 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
532 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
534 second
536 test_expect_success \
537 'C: verify commit' \
538 'git cat-file commit branch | sed 1d >actual &&
539 test_cmp expect actual'
541 cat >expect <<EOF
542 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
543 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
544 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
546 git diff-tree -M -r master branch >actual
547 test_expect_success \
548 'C: validate rename result' \
549 'compare_diff_raw expect actual'
552 ### series D
555 test_tick
556 cat >input <<INPUT_END
557 commit refs/heads/branch
558 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
559 data <<COMMIT
560 third
561 COMMIT
563 from refs/heads/branch^0
564 M 644 inline newdir/interesting
565 data <<EOF
566 $file5_data
569 M 755 inline newdir/exec.sh
570 data <<EOF
571 $file6_data
574 INPUT_END
575 test_expect_success \
576 'D: inline data in commit' \
577 'git fast-import <input &&
578 git whatchanged branch'
580 test_expect_success 'D: verify pack' '
581 verify_packs
584 cat >expect <<EOF
585 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
586 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
588 git diff-tree -M -r branch^ branch >actual
589 test_expect_success \
590 'D: validate new files added' \
591 'compare_diff_raw expect actual'
593 echo "$file5_data" >expect
594 test_expect_success \
595 'D: verify file5' \
596 'git cat-file blob branch:newdir/interesting >actual &&
597 test_cmp expect actual'
599 echo "$file6_data" >expect
600 test_expect_success \
601 'D: verify file6' \
602 'git cat-file blob branch:newdir/exec.sh >actual &&
603 test_cmp expect actual'
606 ### series E
609 cat >input <<INPUT_END
610 commit refs/heads/branch
611 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
613 data <<COMMIT
614 RFC 2822 type date
615 COMMIT
617 from refs/heads/branch^0
619 INPUT_END
620 test_expect_success 'E: rfc2822 date, --date-format=raw' '
621 test_must_fail git fast-import --date-format=raw <input
623 test_expect_success \
624 'E: rfc2822 date, --date-format=rfc2822' \
625 'git fast-import --date-format=rfc2822 <input'
627 test_expect_success 'E: verify pack' '
628 verify_packs
631 cat >expect <<EOF
632 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
633 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
635 RFC 2822 type date
637 test_expect_success \
638 'E: verify commit' \
639 'git cat-file commit branch | sed 1,2d >actual &&
640 test_cmp expect actual'
643 ### series F
646 old_branch=`git rev-parse --verify branch^0`
647 test_tick
648 cat >input <<INPUT_END
649 commit refs/heads/branch
650 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
651 data <<COMMIT
652 losing things already?
653 COMMIT
655 from refs/heads/branch~1
657 reset refs/heads/other
658 from refs/heads/branch
660 INPUT_END
661 test_expect_success \
662 'F: non-fast-forward update skips' \
663 'if git fast-import <input
664 then
665 echo BAD gfi did not fail
666 return 1
667 else
668 if test $old_branch = `git rev-parse --verify branch^0`
669 then
670 : branch unaffected and failure returned
671 return 0
672 else
673 echo BAD gfi changed branch $old_branch
674 return 1
679 test_expect_success 'F: verify pack' '
680 verify_packs
683 cat >expect <<EOF
684 tree `git rev-parse branch~1^{tree}`
685 parent `git rev-parse branch~1`
686 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
687 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
689 losing things already?
691 test_expect_success \
692 'F: verify other commit' \
693 'git cat-file commit other >actual &&
694 test_cmp expect actual'
697 ### series G
700 old_branch=`git rev-parse --verify branch^0`
701 test_tick
702 cat >input <<INPUT_END
703 commit refs/heads/branch
704 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
705 data <<COMMIT
706 losing things already?
707 COMMIT
709 from refs/heads/branch~1
711 INPUT_END
712 test_expect_success \
713 'G: non-fast-forward update forced' \
714 'git fast-import --force <input'
716 test_expect_success 'G: verify pack' '
717 verify_packs
720 test_expect_success \
721 'G: branch changed, but logged' \
722 'test $old_branch != `git rev-parse --verify branch^0` &&
723 test $old_branch = `git rev-parse --verify branch@{1}`'
726 ### series H
729 test_tick
730 cat >input <<INPUT_END
731 commit refs/heads/H
732 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
733 data <<COMMIT
734 third
735 COMMIT
737 from refs/heads/branch^0
738 M 644 inline i-will-die
739 data <<EOF
740 this file will never exist.
743 deleteall
744 M 644 inline h/e/l/lo
745 data <<EOF
746 $file5_data
749 INPUT_END
750 test_expect_success \
751 'H: deletall, add 1' \
752 'git fast-import <input &&
753 git whatchanged H'
755 test_expect_success 'H: verify pack' '
756 verify_packs
759 cat >expect <<EOF
760 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
761 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
762 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
763 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
764 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
766 git diff-tree -M -r H^ H >actual
767 test_expect_success \
768 'H: validate old files removed, new files added' \
769 'compare_diff_raw expect actual'
771 echo "$file5_data" >expect
772 test_expect_success \
773 'H: verify file' \
774 'git cat-file blob H:h/e/l/lo >actual &&
775 test_cmp expect actual'
778 ### series I
781 cat >input <<INPUT_END
782 commit refs/heads/export-boundary
783 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
784 data <<COMMIT
785 we have a border. its only 40 characters wide.
786 COMMIT
788 from refs/heads/branch
790 INPUT_END
791 test_expect_success \
792 'I: export-pack-edges' \
793 'git fast-import --export-pack-edges=edges.list <input'
795 cat >expect <<EOF
796 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
798 test_expect_success \
799 'I: verify edge list' \
800 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
801 test_cmp expect actual'
804 ### series J
807 cat >input <<INPUT_END
808 commit refs/heads/J
809 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
810 data <<COMMIT
811 create J
812 COMMIT
814 from refs/heads/branch
816 reset refs/heads/J
818 commit refs/heads/J
819 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
820 data <<COMMIT
821 initialize J
822 COMMIT
824 INPUT_END
825 test_expect_success \
826 'J: reset existing branch creates empty commit' \
827 'git fast-import <input'
828 test_expect_success \
829 'J: branch has 1 commit, empty tree' \
830 'test 1 = `git rev-list J | wc -l` &&
831 test 0 = `git ls-tree J | wc -l`'
833 cat >input <<INPUT_END
834 reset refs/heads/J2
836 tag wrong_tag
837 from refs/heads/J2
838 data <<EOF
839 Tag branch that was reset.
841 INPUT_END
842 test_expect_success \
843 'J: tag must fail on empty branch' \
844 'test_must_fail git fast-import <input'
846 ### series K
849 cat >input <<INPUT_END
850 commit refs/heads/K
851 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
852 data <<COMMIT
853 create K
854 COMMIT
856 from refs/heads/branch
858 commit refs/heads/K
859 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
860 data <<COMMIT
861 redo K
862 COMMIT
864 from refs/heads/branch^1
866 INPUT_END
867 test_expect_success \
868 'K: reinit branch with from' \
869 'git fast-import <input'
870 test_expect_success \
871 'K: verify K^1 = branch^1' \
872 'test `git rev-parse --verify branch^1` \
873 = `git rev-parse --verify K^1`'
876 ### series L
879 cat >input <<INPUT_END
880 blob
881 mark :1
882 data <<EOF
883 some data
886 blob
887 mark :2
888 data <<EOF
889 other data
892 commit refs/heads/L
893 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
894 data <<COMMIT
895 create L
896 COMMIT
898 M 644 :1 b.
899 M 644 :1 b/other
900 M 644 :1 ba
902 commit refs/heads/L
903 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
904 data <<COMMIT
905 update L
906 COMMIT
908 M 644 :2 b.
909 M 644 :2 b/other
910 M 644 :2 ba
911 INPUT_END
913 cat >expect <<EXPECT_END
914 :100644 100644 4268632... 55d3a52... M b.
915 :040000 040000 0ae5cac... 443c768... M b
916 :100644 100644 4268632... 55d3a52... M ba
917 EXPECT_END
919 test_expect_success \
920 'L: verify internal tree sorting' \
921 'git fast-import <input &&
922 git diff-tree --abbrev --raw L^ L >output &&
923 test_cmp expect output'
925 cat >input <<INPUT_END
926 blob
927 mark :1
928 data <<EOF
929 the data
932 commit refs/heads/L2
933 committer C O Mitter <committer@example.com> 1112912473 -0700
934 data <<COMMIT
935 init L2
936 COMMIT
937 M 644 :1 a/b/c
938 M 644 :1 a/b/d
939 M 644 :1 a/e/f
941 commit refs/heads/L2
942 committer C O Mitter <committer@example.com> 1112912473 -0700
943 data <<COMMIT
944 update L2
945 COMMIT
946 C a g
947 C a/e g/b
948 M 644 :1 g/b/h
949 INPUT_END
951 cat <<EOF >expect
952 g/b/f
953 g/b/h
956 test_expect_success \
957 'L: nested tree copy does not corrupt deltas' \
958 'git fast-import <input &&
959 git ls-tree L2 g/b/ >tmp &&
960 cat tmp | cut -f 2 >actual &&
961 test_cmp expect actual &&
962 git fsck `git rev-parse L2`'
964 git update-ref -d refs/heads/L2
967 ### series M
970 test_tick
971 cat >input <<INPUT_END
972 commit refs/heads/M1
973 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
974 data <<COMMIT
975 file rename
976 COMMIT
978 from refs/heads/branch^0
979 R file2/newf file2/n.e.w.f
981 INPUT_END
983 cat >expect <<EOF
984 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
986 test_expect_success \
987 'M: rename file in same subdirectory' \
988 'git fast-import <input &&
989 git diff-tree -M -r M1^ M1 >actual &&
990 compare_diff_raw expect actual'
992 cat >input <<INPUT_END
993 commit refs/heads/M2
994 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
995 data <<COMMIT
996 file rename
997 COMMIT
999 from refs/heads/branch^0
1000 R file2/newf i/am/new/to/you
1002 INPUT_END
1004 cat >expect <<EOF
1005 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
1007 test_expect_success \
1008 'M: rename file to new subdirectory' \
1009 'git fast-import <input &&
1010 git diff-tree -M -r M2^ M2 >actual &&
1011 compare_diff_raw expect actual'
1013 cat >input <<INPUT_END
1014 commit refs/heads/M3
1015 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1016 data <<COMMIT
1017 file rename
1018 COMMIT
1020 from refs/heads/M2^0
1021 R i other/sub
1023 INPUT_END
1025 cat >expect <<EOF
1026 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
1028 test_expect_success \
1029 'M: rename subdirectory to new subdirectory' \
1030 'git fast-import <input &&
1031 git diff-tree -M -r M3^ M3 >actual &&
1032 compare_diff_raw expect actual'
1035 ### series N
1038 test_tick
1039 cat >input <<INPUT_END
1040 commit refs/heads/N1
1041 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1042 data <<COMMIT
1043 file copy
1044 COMMIT
1046 from refs/heads/branch^0
1047 C file2/newf file2/n.e.w.f
1049 INPUT_END
1051 cat >expect <<EOF
1052 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1054 test_expect_success \
1055 'N: copy file in same subdirectory' \
1056 'git fast-import <input &&
1057 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1058 compare_diff_raw expect actual'
1060 cat >input <<INPUT_END
1061 commit refs/heads/N2
1062 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1063 data <<COMMIT
1064 clean directory copy
1065 COMMIT
1067 from refs/heads/branch^0
1068 C file2 file3
1070 commit refs/heads/N2
1071 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1072 data <<COMMIT
1073 modify directory copy
1074 COMMIT
1076 M 644 inline file3/file5
1077 data <<EOF
1078 $file5_data
1081 INPUT_END
1083 cat >expect <<EOF
1084 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1085 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1086 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1088 test_expect_success \
1089 'N: copy then modify subdirectory' \
1090 'git fast-import <input &&
1091 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1092 compare_diff_raw expect actual'
1094 cat >input <<INPUT_END
1095 commit refs/heads/N3
1096 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1097 data <<COMMIT
1098 dirty directory copy
1099 COMMIT
1101 from refs/heads/branch^0
1102 M 644 inline file2/file5
1103 data <<EOF
1104 $file5_data
1107 C file2 file3
1108 D file2/file5
1110 INPUT_END
1112 test_expect_success \
1113 'N: copy dirty subdirectory' \
1114 'git fast-import <input &&
1115 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1117 test_expect_success \
1118 'N: copy directory by id' \
1119 'cat >expect <<-\EOF &&
1120 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1121 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1123 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1124 cat >input <<-INPUT_END &&
1125 commit refs/heads/N4
1126 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1127 data <<COMMIT
1128 copy by tree hash
1129 COMMIT
1131 from refs/heads/branch^0
1132 M 040000 $subdir file3
1133 INPUT_END
1134 git fast-import <input &&
1135 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1136 compare_diff_raw expect actual'
1138 test_expect_success PIPE 'N: read and copy directory' '
1139 cat >expect <<-\EOF
1140 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1141 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1143 git update-ref -d refs/heads/N4 &&
1144 rm -f backflow &&
1145 mkfifo backflow &&
1147 exec <backflow &&
1148 cat <<-EOF &&
1149 commit refs/heads/N4
1150 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1151 data <<COMMIT
1152 copy by tree hash, part 2
1153 COMMIT
1155 from refs/heads/branch^0
1156 ls "file2"
1158 read mode type tree filename &&
1159 echo "M 040000 $tree file3"
1161 git fast-import --cat-blob-fd=3 3>backflow &&
1162 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1163 compare_diff_raw expect actual
1166 test_expect_success PIPE 'N: empty directory reads as missing' '
1167 cat <<-\EOF >expect &&
1168 OBJNAME
1169 :000000 100644 OBJNAME OBJNAME A unrelated
1171 echo "missing src" >expect.response &&
1172 git update-ref -d refs/heads/read-empty &&
1173 rm -f backflow &&
1174 mkfifo backflow &&
1176 exec <backflow &&
1177 cat <<-EOF &&
1178 commit refs/heads/read-empty
1179 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1180 data <<COMMIT
1181 read "empty" (missing) directory
1182 COMMIT
1184 M 100644 inline src/greeting
1185 data <<BLOB
1186 hello
1187 BLOB
1188 C src/greeting dst1/non-greeting
1189 C src/greeting unrelated
1190 # leave behind "empty" src directory
1191 D src/greeting
1192 ls "src"
1194 read -r line &&
1195 printf "%s\n" "$line" >response &&
1196 cat <<-\EOF
1197 D dst1
1198 D dst2
1201 git fast-import --cat-blob-fd=3 3>backflow &&
1202 test_cmp expect.response response &&
1203 git rev-list read-empty |
1204 git diff-tree -r --root --stdin |
1205 sed "s/$_x40/OBJNAME/g" >actual &&
1206 test_cmp expect actual
1209 test_expect_success \
1210 'N: copy root directory by tree hash' \
1211 'cat >expect <<-\EOF &&
1212 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1213 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1215 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1216 cat >input <<-INPUT_END &&
1217 commit refs/heads/N6
1218 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1219 data <<COMMIT
1220 copy root directory by tree hash
1221 COMMIT
1223 from refs/heads/branch^0
1224 M 040000 $root ""
1225 INPUT_END
1226 git fast-import <input &&
1227 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1228 compare_diff_raw expect actual'
1230 test_expect_success \
1231 'N: delete directory by copying' \
1232 'cat >expect <<-\EOF &&
1233 OBJID
1234 :100644 000000 OBJID OBJID D foo/bar/qux
1235 OBJID
1236 :000000 100644 OBJID OBJID A foo/bar/baz
1237 :000000 100644 OBJID OBJID A foo/bar/qux
1239 empty_tree=$(git mktree </dev/null) &&
1240 cat >input <<-INPUT_END &&
1241 commit refs/heads/N-delete
1242 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1243 data <<COMMIT
1244 collect data to be deleted
1245 COMMIT
1247 deleteall
1248 M 100644 inline foo/bar/baz
1249 data <<DATA_END
1250 hello
1251 DATA_END
1252 C "foo/bar/baz" "foo/bar/qux"
1253 C "foo/bar/baz" "foo/bar/quux/1"
1254 C "foo/bar/baz" "foo/bar/quuux"
1255 M 040000 $empty_tree foo/bar/quux
1256 M 040000 $empty_tree foo/bar/quuux
1258 commit refs/heads/N-delete
1259 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1260 data <<COMMIT
1261 delete subdirectory
1262 COMMIT
1264 M 040000 $empty_tree foo/bar/qux
1265 INPUT_END
1266 git fast-import <input &&
1267 git rev-list N-delete |
1268 git diff-tree -r --stdin --root --always |
1269 sed -e "s/$_x40/OBJID/g" >actual &&
1270 test_cmp expect actual'
1272 test_expect_success \
1273 'N: modify copied tree' \
1274 'cat >expect <<-\EOF &&
1275 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1276 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1277 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1279 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1280 cat >input <<-INPUT_END &&
1281 commit refs/heads/N5
1282 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1283 data <<COMMIT
1284 copy by tree hash
1285 COMMIT
1287 from refs/heads/branch^0
1288 M 040000 $subdir file3
1290 commit refs/heads/N5
1291 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1292 data <<COMMIT
1293 modify directory copy
1294 COMMIT
1296 M 644 inline file3/file5
1297 data <<EOF
1298 $file5_data
1300 INPUT_END
1301 git fast-import <input &&
1302 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1303 compare_diff_raw expect actual'
1305 test_expect_success \
1306 'N: reject foo/ syntax' \
1307 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1308 test_must_fail git fast-import <<-INPUT_END
1309 commit refs/heads/N5B
1310 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1311 data <<COMMIT
1312 copy with invalid syntax
1313 COMMIT
1315 from refs/heads/branch^0
1316 M 040000 $subdir file3/
1317 INPUT_END'
1319 test_expect_success \
1320 'N: reject foo/ syntax in copy source' \
1321 'test_must_fail git fast-import <<-INPUT_END
1322 commit refs/heads/N5C
1323 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1324 data <<COMMIT
1325 copy with invalid syntax
1326 COMMIT
1328 from refs/heads/branch^0
1329 C file2/ file3
1330 INPUT_END'
1332 test_expect_success \
1333 'N: reject foo/ syntax in rename source' \
1334 'test_must_fail git fast-import <<-INPUT_END
1335 commit refs/heads/N5D
1336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1337 data <<COMMIT
1338 rename with invalid syntax
1339 COMMIT
1341 from refs/heads/branch^0
1342 R file2/ file3
1343 INPUT_END'
1345 test_expect_success \
1346 'N: reject foo/ syntax in ls argument' \
1347 'test_must_fail git fast-import <<-INPUT_END
1348 commit refs/heads/N5E
1349 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1350 data <<COMMIT
1351 copy with invalid syntax
1352 COMMIT
1354 from refs/heads/branch^0
1355 ls "file2/"
1356 INPUT_END'
1358 test_expect_success \
1359 'N: copy to root by id and modify' \
1360 'echo "hello, world" >expect.foo &&
1361 echo hello >expect.bar &&
1362 git fast-import <<-SETUP_END &&
1363 commit refs/heads/N7
1364 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1365 data <<COMMIT
1366 hello, tree
1367 COMMIT
1369 deleteall
1370 M 644 inline foo/bar
1371 data <<EOF
1372 hello
1374 SETUP_END
1376 tree=$(git rev-parse --verify N7:) &&
1377 git fast-import <<-INPUT_END &&
1378 commit refs/heads/N8
1379 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1380 data <<COMMIT
1381 copy to root by id and modify
1382 COMMIT
1384 M 040000 $tree ""
1385 M 644 inline foo/foo
1386 data <<EOF
1387 hello, world
1389 INPUT_END
1390 git show N8:foo/foo >actual.foo &&
1391 git show N8:foo/bar >actual.bar &&
1392 test_cmp expect.foo actual.foo &&
1393 test_cmp expect.bar actual.bar'
1395 test_expect_success \
1396 'N: extract subtree' \
1397 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1398 cat >input <<-INPUT_END &&
1399 commit refs/heads/N9
1400 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1401 data <<COMMIT
1402 extract subtree branch:newdir
1403 COMMIT
1405 M 040000 $branch ""
1406 C "newdir" ""
1407 INPUT_END
1408 git fast-import <input &&
1409 git diff --exit-code branch:newdir N9'
1411 test_expect_success \
1412 'N: modify subtree, extract it, and modify again' \
1413 'echo hello >expect.baz &&
1414 echo hello, world >expect.qux &&
1415 git fast-import <<-SETUP_END &&
1416 commit refs/heads/N10
1417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418 data <<COMMIT
1419 hello, tree
1420 COMMIT
1422 deleteall
1423 M 644 inline foo/bar/baz
1424 data <<EOF
1425 hello
1427 SETUP_END
1429 tree=$(git rev-parse --verify N10:) &&
1430 git fast-import <<-INPUT_END &&
1431 commit refs/heads/N11
1432 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1433 data <<COMMIT
1434 copy to root by id and modify
1435 COMMIT
1437 M 040000 $tree ""
1438 M 100644 inline foo/bar/qux
1439 data <<EOF
1440 hello, world
1442 R "foo" ""
1443 C "bar/qux" "bar/quux"
1444 INPUT_END
1445 git show N11:bar/baz >actual.baz &&
1446 git show N11:bar/qux >actual.qux &&
1447 git show N11:bar/quux >actual.quux &&
1448 test_cmp expect.baz actual.baz &&
1449 test_cmp expect.qux actual.qux &&
1450 test_cmp expect.qux actual.quux'
1453 ### series O
1456 cat >input <<INPUT_END
1457 #we will
1458 commit refs/heads/O1
1459 # -- ignore all of this text
1460 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1461 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1462 data <<COMMIT
1463 dirty directory copy
1464 COMMIT
1466 # don't forget the import blank line!
1468 # yes, we started from our usual base of branch^0.
1469 # i like branch^0.
1470 from refs/heads/branch^0
1471 # and we need to reuse file2/file5 from N3 above.
1472 M 644 inline file2/file5
1473 # otherwise the tree will be different
1474 data <<EOF
1475 $file5_data
1478 # don't forget to copy file2 to file3
1479 C file2 file3
1481 # or to delete file5 from file2.
1482 D file2/file5
1483 # are we done yet?
1485 INPUT_END
1487 test_expect_success \
1488 'O: comments are all skipped' \
1489 'git fast-import <input &&
1490 test `git rev-parse N3` = `git rev-parse O1`'
1492 cat >input <<INPUT_END
1493 commit refs/heads/O2
1494 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1495 data <<COMMIT
1496 dirty directory copy
1497 COMMIT
1498 from refs/heads/branch^0
1499 M 644 inline file2/file5
1500 data <<EOF
1501 $file5_data
1503 C file2 file3
1504 D file2/file5
1506 INPUT_END
1508 test_expect_success \
1509 'O: blank lines not necessary after data commands' \
1510 'git fast-import <input &&
1511 test `git rev-parse N3` = `git rev-parse O2`'
1513 test_expect_success \
1514 'O: repack before next test' \
1515 'git repack -a -d'
1517 cat >input <<INPUT_END
1518 commit refs/heads/O3
1519 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520 data <<COMMIT
1521 zstring
1522 COMMIT
1523 commit refs/heads/O3
1524 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1525 data <<COMMIT
1527 COMMIT
1528 checkpoint
1529 commit refs/heads/O3
1530 mark :5
1531 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1532 data <<COMMIT
1533 zempty
1534 COMMIT
1535 checkpoint
1536 commit refs/heads/O3
1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 data <<COMMIT
1539 zcommits
1540 COMMIT
1541 reset refs/tags/O3-2nd
1542 from :5
1543 reset refs/tags/O3-3rd
1544 from :5
1545 INPUT_END
1547 cat >expect <<INPUT_END
1548 string
1550 empty
1551 commits
1552 INPUT_END
1553 test_expect_success \
1554 'O: blank lines not necessary after other commands' \
1555 'git fast-import <input &&
1556 test 8 = `find .git/objects/pack -type f | wc -l` &&
1557 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1558 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1559 test_cmp expect actual'
1561 cat >input <<INPUT_END
1562 commit refs/heads/O4
1563 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1564 data <<COMMIT
1565 zstring
1566 COMMIT
1567 commit refs/heads/O4
1568 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1569 data <<COMMIT
1571 COMMIT
1572 progress Two commits down, 2 to go!
1573 commit refs/heads/O4
1574 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575 data <<COMMIT
1576 zempty
1577 COMMIT
1578 progress Three commits down, 1 to go!
1579 commit refs/heads/O4
1580 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1581 data <<COMMIT
1582 zcommits
1583 COMMIT
1584 progress I'm done!
1585 INPUT_END
1586 test_expect_success \
1587 'O: progress outputs as requested by input' \
1588 'git fast-import <input >actual &&
1589 grep "progress " <input >expect &&
1590 test_cmp expect actual'
1593 ### series P (gitlinks)
1596 cat >input <<INPUT_END
1597 blob
1598 mark :1
1599 data 10
1600 test file
1602 reset refs/heads/sub
1603 commit refs/heads/sub
1604 mark :2
1605 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1606 data 12
1607 sub_initial
1608 M 100644 :1 file
1610 blob
1611 mark :3
1612 data <<DATAEND
1613 [submodule "sub"]
1614 path = sub
1615 url = "`pwd`/sub"
1616 DATAEND
1618 commit refs/heads/subuse1
1619 mark :4
1620 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1621 data 8
1622 initial
1623 from refs/heads/master
1624 M 100644 :3 .gitmodules
1625 M 160000 :2 sub
1627 blob
1628 mark :5
1629 data 20
1630 test file
1631 more data
1633 commit refs/heads/sub
1634 mark :6
1635 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1636 data 11
1637 sub_second
1638 from :2
1639 M 100644 :5 file
1641 commit refs/heads/subuse1
1642 mark :7
1643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644 data 7
1645 second
1646 from :4
1647 M 160000 :6 sub
1649 INPUT_END
1651 test_expect_success \
1652 'P: superproject & submodule mix' \
1653 'git fast-import <input &&
1654 git checkout subuse1 &&
1655 rm -rf sub && mkdir sub && (cd sub &&
1656 git init &&
1657 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1658 git checkout master) &&
1659 git submodule init &&
1660 git submodule update'
1662 SUBLAST=$(git rev-parse --verify sub)
1663 SUBPREV=$(git rev-parse --verify sub^)
1665 cat >input <<INPUT_END
1666 blob
1667 mark :1
1668 data <<DATAEND
1669 [submodule "sub"]
1670 path = sub
1671 url = "`pwd`/sub"
1672 DATAEND
1674 commit refs/heads/subuse2
1675 mark :2
1676 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1677 data 8
1678 initial
1679 from refs/heads/master
1680 M 100644 :1 .gitmodules
1681 M 160000 $SUBPREV sub
1683 commit refs/heads/subuse2
1684 mark :3
1685 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1686 data 7
1687 second
1688 from :2
1689 M 160000 $SUBLAST sub
1691 INPUT_END
1693 test_expect_success \
1694 'P: verbatim SHA gitlinks' \
1695 'git branch -D sub &&
1696 git gc && git prune &&
1697 git fast-import <input &&
1698 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1700 test_tick
1701 cat >input <<INPUT_END
1702 commit refs/heads/subuse3
1703 mark :1
1704 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1705 data <<COMMIT
1706 corrupt
1707 COMMIT
1709 from refs/heads/subuse2
1710 M 160000 inline sub
1711 data <<DATA
1712 $SUBPREV
1713 DATA
1715 INPUT_END
1717 test_expect_success 'P: fail on inline gitlink' '
1718 test_must_fail git fast-import <input'
1720 test_tick
1721 cat >input <<INPUT_END
1722 blob
1723 mark :1
1724 data <<DATA
1725 $SUBPREV
1726 DATA
1728 commit refs/heads/subuse3
1729 mark :2
1730 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1731 data <<COMMIT
1732 corrupt
1733 COMMIT
1735 from refs/heads/subuse2
1736 M 160000 :1 sub
1738 INPUT_END
1740 test_expect_success 'P: fail on blob mark in gitlink' '
1741 test_must_fail git fast-import <input'
1744 ### series Q (notes)
1747 note1_data="The first note for the first commit"
1748 note2_data="The first note for the second commit"
1749 note3_data="The first note for the third commit"
1750 note1b_data="The second note for the first commit"
1751 note1c_data="The third note for the first commit"
1752 note2b_data="The second note for the second commit"
1754 test_tick
1755 cat >input <<INPUT_END
1756 blob
1757 mark :2
1758 data <<EOF
1759 $file2_data
1762 commit refs/heads/notes-test
1763 mark :3
1764 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1765 data <<COMMIT
1766 first (:3)
1767 COMMIT
1769 M 644 :2 file2
1771 blob
1772 mark :4
1773 data $file4_len
1774 $file4_data
1775 commit refs/heads/notes-test
1776 mark :5
1777 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1778 data <<COMMIT
1779 second (:5)
1780 COMMIT
1782 M 644 :4 file4
1784 commit refs/heads/notes-test
1785 mark :6
1786 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1787 data <<COMMIT
1788 third (:6)
1789 COMMIT
1791 M 644 inline file5
1792 data <<EOF
1793 $file5_data
1796 M 755 inline file6
1797 data <<EOF
1798 $file6_data
1801 blob
1802 mark :7
1803 data <<EOF
1804 $note1_data
1807 blob
1808 mark :8
1809 data <<EOF
1810 $note2_data
1813 commit refs/notes/foobar
1814 mark :9
1815 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1816 data <<COMMIT
1817 notes (:9)
1818 COMMIT
1820 N :7 :3
1821 N :8 :5
1822 N inline :6
1823 data <<EOF
1824 $note3_data
1827 commit refs/notes/foobar
1828 mark :10
1829 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1830 data <<COMMIT
1831 notes (:10)
1832 COMMIT
1834 N inline :3
1835 data <<EOF
1836 $note1b_data
1839 commit refs/notes/foobar2
1840 mark :11
1841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842 data <<COMMIT
1843 notes (:11)
1844 COMMIT
1846 N inline :3
1847 data <<EOF
1848 $note1c_data
1851 commit refs/notes/foobar
1852 mark :12
1853 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1854 data <<COMMIT
1855 notes (:12)
1856 COMMIT
1858 deleteall
1859 N inline :5
1860 data <<EOF
1861 $note2b_data
1864 INPUT_END
1866 test_expect_success \
1867 'Q: commit notes' \
1868 'git fast-import <input &&
1869 git whatchanged notes-test'
1871 test_expect_success 'Q: verify pack' '
1872 verify_packs
1875 commit1=$(git rev-parse notes-test~2)
1876 commit2=$(git rev-parse notes-test^)
1877 commit3=$(git rev-parse notes-test)
1879 cat >expect <<EOF
1880 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1883 first (:3)
1885 test_expect_success \
1886 'Q: verify first commit' \
1887 'git cat-file commit notes-test~2 | sed 1d >actual &&
1888 test_cmp expect actual'
1890 cat >expect <<EOF
1891 parent $commit1
1892 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1893 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1895 second (:5)
1897 test_expect_success \
1898 'Q: verify second commit' \
1899 'git cat-file commit notes-test^ | sed 1d >actual &&
1900 test_cmp expect actual'
1902 cat >expect <<EOF
1903 parent $commit2
1904 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1905 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1907 third (:6)
1909 test_expect_success \
1910 'Q: verify third commit' \
1911 'git cat-file commit notes-test | sed 1d >actual &&
1912 test_cmp expect actual'
1914 cat >expect <<EOF
1915 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1916 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1918 notes (:9)
1920 test_expect_success \
1921 'Q: verify first notes commit' \
1922 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1923 test_cmp expect actual'
1925 cat >expect.unsorted <<EOF
1926 100644 blob $commit1
1927 100644 blob $commit2
1928 100644 blob $commit3
1930 cat expect.unsorted | sort >expect
1931 test_expect_success \
1932 'Q: verify first notes tree' \
1933 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1934 test_cmp expect actual'
1936 echo "$note1_data" >expect
1937 test_expect_success \
1938 'Q: verify first note for first commit' \
1939 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1941 echo "$note2_data" >expect
1942 test_expect_success \
1943 'Q: verify first note for second commit' \
1944 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1946 echo "$note3_data" >expect
1947 test_expect_success \
1948 'Q: verify first note for third commit' \
1949 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1951 cat >expect <<EOF
1952 parent `git rev-parse --verify refs/notes/foobar~2`
1953 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1954 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1956 notes (:10)
1958 test_expect_success \
1959 'Q: verify second notes commit' \
1960 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1961 test_cmp expect actual'
1963 cat >expect.unsorted <<EOF
1964 100644 blob $commit1
1965 100644 blob $commit2
1966 100644 blob $commit3
1968 cat expect.unsorted | sort >expect
1969 test_expect_success \
1970 'Q: verify second notes tree' \
1971 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1972 test_cmp expect actual'
1974 echo "$note1b_data" >expect
1975 test_expect_success \
1976 'Q: verify second note for first commit' \
1977 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1979 echo "$note2_data" >expect
1980 test_expect_success \
1981 'Q: verify first note for second commit' \
1982 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1984 echo "$note3_data" >expect
1985 test_expect_success \
1986 'Q: verify first note for third commit' \
1987 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1989 cat >expect <<EOF
1990 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1991 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1993 notes (:11)
1995 test_expect_success \
1996 'Q: verify third notes commit' \
1997 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1998 test_cmp expect actual'
2000 cat >expect.unsorted <<EOF
2001 100644 blob $commit1
2003 cat expect.unsorted | sort >expect
2004 test_expect_success \
2005 'Q: verify third notes tree' \
2006 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2007 test_cmp expect actual'
2009 echo "$note1c_data" >expect
2010 test_expect_success \
2011 'Q: verify third note for first commit' \
2012 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2014 cat >expect <<EOF
2015 parent `git rev-parse --verify refs/notes/foobar^`
2016 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2017 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2019 notes (:12)
2021 test_expect_success \
2022 'Q: verify fourth notes commit' \
2023 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2024 test_cmp expect actual'
2026 cat >expect.unsorted <<EOF
2027 100644 blob $commit2
2029 cat expect.unsorted | sort >expect
2030 test_expect_success \
2031 'Q: verify fourth notes tree' \
2032 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2033 test_cmp expect actual'
2035 echo "$note2b_data" >expect
2036 test_expect_success \
2037 'Q: verify second note for second commit' \
2038 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2040 cat >input <<EOF
2041 reset refs/heads/Q0
2043 commit refs/heads/note-Q0
2044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2045 data <<COMMIT
2046 Note for an empty branch.
2047 COMMIT
2049 N inline refs/heads/Q0
2050 data <<NOTE
2051 some note
2052 NOTE
2054 test_expect_success \
2055 'Q: deny note on empty branch' \
2056 'test_must_fail git fast-import <input'
2058 ### series R (feature and option)
2061 cat >input <<EOF
2062 feature no-such-feature-exists
2065 test_expect_success 'R: abort on unsupported feature' '
2066 test_must_fail git fast-import <input
2069 cat >input <<EOF
2070 feature date-format=now
2073 test_expect_success 'R: supported feature is accepted' '
2074 git fast-import <input
2077 cat >input << EOF
2078 blob
2079 data 3
2081 feature date-format=now
2084 test_expect_success 'R: abort on receiving feature after data command' '
2085 test_must_fail git fast-import <input
2088 cat >input << EOF
2089 feature import-marks=git.marks
2090 feature import-marks=git2.marks
2093 test_expect_success 'R: only one import-marks feature allowed per stream' '
2094 test_must_fail git fast-import <input
2097 cat >input << EOF
2098 feature export-marks=git.marks
2099 blob
2100 mark :1
2101 data 3
2106 test_expect_success \
2107 'R: export-marks feature results in a marks file being created' \
2108 'cat input | git fast-import &&
2109 grep :1 git.marks'
2111 test_expect_success \
2112 'R: export-marks options can be overridden by commandline options' \
2113 'cat input | git fast-import --export-marks=other.marks &&
2114 grep :1 other.marks'
2116 test_expect_success 'R: catch typo in marks file name' '
2117 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2118 echo "feature import-marks=nonexistent.marks" |
2119 test_must_fail git fast-import
2122 test_expect_success 'R: import and output marks can be the same file' '
2123 rm -f io.marks &&
2124 blob=$(echo hi | git hash-object --stdin) &&
2125 cat >expect <<-EOF &&
2126 :1 $blob
2127 :2 $blob
2129 git fast-import --export-marks=io.marks <<-\EOF &&
2130 blob
2131 mark :1
2132 data 3
2136 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2137 blob
2138 mark :2
2139 data 3
2143 test_cmp expect io.marks
2146 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2147 rm -f io.marks &&
2148 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2149 blob
2150 mark :1
2151 data 3
2157 test_expect_success 'R: --import-marks-if-exists' '
2158 rm -f io.marks &&
2159 blob=$(echo hi | git hash-object --stdin) &&
2160 echo ":1 $blob" >expect &&
2161 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2162 blob
2163 mark :1
2164 data 3
2168 test_cmp expect io.marks
2171 test_expect_success 'R: feature import-marks-if-exists' '
2172 rm -f io.marks &&
2173 >expect &&
2175 git fast-import --export-marks=io.marks <<-\EOF &&
2176 feature import-marks-if-exists=not_io.marks
2178 test_cmp expect io.marks &&
2180 blob=$(echo hi | git hash-object --stdin) &&
2182 echo ":1 $blob" >io.marks &&
2183 echo ":1 $blob" >expect &&
2184 echo ":2 $blob" >>expect &&
2186 git fast-import --export-marks=io.marks <<-\EOF &&
2187 feature import-marks-if-exists=io.marks
2188 blob
2189 mark :2
2190 data 3
2194 test_cmp expect io.marks &&
2196 echo ":3 $blob" >>expect &&
2198 git fast-import --import-marks=io.marks \
2199 --export-marks=io.marks <<-\EOF &&
2200 feature import-marks-if-exists=not_io.marks
2201 blob
2202 mark :3
2203 data 3
2207 test_cmp expect io.marks &&
2209 >expect &&
2211 git fast-import --import-marks-if-exists=not_io.marks \
2212 --export-marks=io.marks <<-\EOF
2213 feature import-marks-if-exists=io.marks
2215 test_cmp expect io.marks
2218 cat >input << EOF
2219 feature import-marks=marks.out
2220 feature export-marks=marks.new
2223 test_expect_success \
2224 'R: import to output marks works without any content' \
2225 'cat input | git fast-import &&
2226 test_cmp marks.out marks.new'
2228 cat >input <<EOF
2229 feature import-marks=nonexistent.marks
2230 feature export-marks=marks.new
2233 test_expect_success \
2234 'R: import marks prefers commandline marks file over the stream' \
2235 'cat input | git fast-import --import-marks=marks.out &&
2236 test_cmp marks.out marks.new'
2239 cat >input <<EOF
2240 feature import-marks=nonexistent.marks
2241 feature export-marks=combined.marks
2244 test_expect_success 'R: multiple --import-marks= should be honoured' '
2245 head -n2 marks.out > one.marks &&
2246 tail -n +3 marks.out > two.marks &&
2247 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2248 test_cmp marks.out combined.marks
2251 cat >input <<EOF
2252 feature relative-marks
2253 feature import-marks=relative.in
2254 feature export-marks=relative.out
2257 test_expect_success 'R: feature relative-marks should be honoured' '
2258 mkdir -p .git/info/fast-import/ &&
2259 cp marks.new .git/info/fast-import/relative.in &&
2260 git fast-import <input &&
2261 test_cmp marks.new .git/info/fast-import/relative.out
2264 cat >input <<EOF
2265 feature relative-marks
2266 feature import-marks=relative.in
2267 feature no-relative-marks
2268 feature export-marks=non-relative.out
2271 test_expect_success 'R: feature no-relative-marks should be honoured' '
2272 git fast-import <input &&
2273 test_cmp marks.new non-relative.out
2276 test_expect_success 'R: feature ls supported' '
2277 echo "feature ls" |
2278 git fast-import
2281 test_expect_success 'R: feature cat-blob supported' '
2282 echo "feature cat-blob" |
2283 git fast-import
2286 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2287 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2290 test_expect_success NOT_MINGW 'R: print old blob' '
2291 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2292 cat >expect <<-EOF &&
2293 ${blob} blob 11
2294 yes it can
2297 echo "cat-blob $blob" |
2298 git fast-import --cat-blob-fd=6 6>actual &&
2299 test_cmp expect actual
2302 test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' '
2303 echo hello >greeting &&
2304 blob=$(git hash-object -w greeting) &&
2305 cat >expect <<-EOF &&
2306 ${blob} blob 6
2307 hello
2310 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2311 cat-blob $blob
2313 test_cmp expect actual.3 &&
2314 test_cmp empty actual.1 &&
2315 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2316 option cat-blob-fd=3
2317 cat-blob $blob
2319 test_cmp empty actual.3 &&
2320 test_cmp expect actual.1
2323 test_expect_success NOT_MINGW 'R: print new blob' '
2324 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2325 cat >expect <<-EOF &&
2326 ${blob} blob 12
2327 yep yep yep
2330 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2331 blob
2332 mark :1
2333 data <<BLOB_END
2334 yep yep yep
2335 BLOB_END
2336 cat-blob :1
2338 test_cmp expect actual
2341 test_expect_success NOT_MINGW 'R: print new blob by sha1' '
2342 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2343 cat >expect <<-EOF &&
2344 ${blob} blob 25
2345 a new blob named by sha1
2348 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2349 blob
2350 data <<BLOB_END
2351 a new blob named by sha1
2352 BLOB_END
2353 cat-blob $blob
2355 test_cmp expect actual
2358 test_expect_success 'setup: big file' '
2360 echo "the quick brown fox jumps over the lazy dog" >big &&
2361 for i in 1 2 3
2363 cat big big big big >bigger &&
2364 cat bigger bigger bigger bigger >big ||
2365 exit
2366 done
2370 test_expect_success 'R: print two blobs to stdout' '
2371 blob1=$(git hash-object big) &&
2372 blob1_len=$(wc -c <big) &&
2373 blob2=$(echo hello | git hash-object --stdin) &&
2375 echo ${blob1} blob $blob1_len &&
2376 cat big &&
2377 cat <<-EOF
2379 ${blob2} blob 6
2380 hello
2383 } >expect &&
2385 cat <<-\END_PART1 &&
2386 blob
2387 mark :1
2388 data <<data_end
2389 END_PART1
2390 cat big &&
2391 cat <<-\EOF
2392 data_end
2393 blob
2394 mark :2
2395 data <<data_end
2396 hello
2397 data_end
2398 cat-blob :1
2399 cat-blob :2
2402 git fast-import >actual &&
2403 test_cmp expect actual
2406 test_expect_success PIPE 'R: copy using cat-file' '
2407 expect_id=$(git hash-object big) &&
2408 expect_len=$(wc -c <big) &&
2409 echo $expect_id blob $expect_len >expect.response &&
2411 rm -f blobs &&
2412 cat >frontend <<-\FRONTEND_END &&
2413 #!/bin/sh
2414 FRONTEND_END
2416 mkfifo blobs &&
2418 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2419 cat <<-\EOF &&
2420 feature cat-blob
2421 blob
2422 mark :1
2423 data <<BLOB
2425 cat big &&
2426 cat <<-\EOF &&
2427 BLOB
2428 cat-blob :1
2431 read blob_id type size <&3 &&
2432 echo "$blob_id $type $size" >response &&
2433 head_c $size >blob <&3 &&
2434 read newline <&3 &&
2436 cat <<-EOF &&
2437 commit refs/heads/copied
2438 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2439 data <<COMMIT
2440 copy big file as file3
2441 COMMIT
2442 M 644 inline file3
2443 data <<BLOB
2445 cat blob &&
2446 echo BLOB
2447 ) 3<blobs |
2448 git fast-import --cat-blob-fd=3 3>blobs &&
2449 git show copied:file3 >actual &&
2450 test_cmp expect.response response &&
2451 test_cmp big actual
2454 test_expect_success PIPE 'R: print blob mid-commit' '
2455 rm -f blobs &&
2456 echo "A blob from _before_ the commit." >expect &&
2457 mkfifo blobs &&
2459 exec 3<blobs &&
2460 cat <<-EOF &&
2461 feature cat-blob
2462 blob
2463 mark :1
2464 data <<BLOB
2465 A blob from _before_ the commit.
2466 BLOB
2467 commit refs/heads/temporary
2468 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2469 data <<COMMIT
2470 Empty commit
2471 COMMIT
2472 cat-blob :1
2475 read blob_id type size <&3 &&
2476 head_c $size >actual <&3 &&
2477 read newline <&3 &&
2479 echo
2481 git fast-import --cat-blob-fd=3 3>blobs &&
2482 test_cmp expect actual
2485 test_expect_success PIPE 'R: print staged blob within commit' '
2486 rm -f blobs &&
2487 echo "A blob from _within_ the commit." >expect &&
2488 mkfifo blobs &&
2490 exec 3<blobs &&
2491 cat <<-EOF &&
2492 feature cat-blob
2493 commit refs/heads/within
2494 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2495 data <<COMMIT
2496 Empty commit
2497 COMMIT
2498 M 644 inline within
2499 data <<BLOB
2500 A blob from _within_ the commit.
2501 BLOB
2504 to_get=$(
2505 echo "A blob from _within_ the commit." |
2506 git hash-object --stdin
2507 ) &&
2508 echo "cat-blob $to_get" &&
2510 read blob_id type size <&3 &&
2511 head_c $size >actual <&3 &&
2512 read newline <&3 &&
2514 echo deleteall
2516 git fast-import --cat-blob-fd=3 3>blobs &&
2517 test_cmp expect actual
2520 cat >input << EOF
2521 option git quiet
2522 blob
2523 data 3
2528 test_expect_success 'R: quiet option results in no stats being output' '
2529 cat input | git fast-import 2> output &&
2530 test_cmp empty output
2533 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2534 echo feature done | test_must_fail git fast-import &&
2535 test_must_fail git fast-import --done </dev/null
2538 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2539 git fast-import <<-\EOF &&
2540 feature done
2541 done
2542 trailing gibberish
2544 git fast-import <<-\EOF
2545 done
2546 more trailing gibberish
2550 test_expect_success 'R: terminating "done" within commit' '
2551 cat >expect <<-\EOF &&
2552 OBJID
2553 :000000 100644 OBJID OBJID A hello.c
2554 :000000 100644 OBJID OBJID A hello2.c
2556 git fast-import <<-EOF &&
2557 commit refs/heads/done-ends
2558 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2559 data <<EOT
2560 Commit terminated by "done" command
2562 M 100644 inline hello.c
2563 data <<EOT
2564 Hello, world.
2566 C hello.c hello2.c
2567 done
2569 git rev-list done-ends |
2570 git diff-tree -r --stdin --root --always |
2571 sed -e "s/$_x40/OBJID/g" >actual &&
2572 test_cmp expect actual
2575 cat >input <<EOF
2576 option git non-existing-option
2579 test_expect_success 'R: die on unknown option' '
2580 test_must_fail git fast-import <input
2583 test_expect_success 'R: unknown commandline options are rejected' '\
2584 test_must_fail git fast-import --non-existing-option < /dev/null
2587 test_expect_success 'R: die on invalid option argument' '
2588 echo "option git active-branches=-5" |
2589 test_must_fail git fast-import &&
2590 echo "option git depth=" |
2591 test_must_fail git fast-import &&
2592 test_must_fail git fast-import --depth="5 elephants" </dev/null
2595 cat >input <<EOF
2596 option non-existing-vcs non-existing-option
2599 test_expect_success 'R: ignore non-git options' '
2600 git fast-import <input
2604 ## R: very large blobs
2606 blobsize=$((2*1024*1024 + 53))
2607 test-genrandom bar $blobsize >expect
2608 cat >input <<INPUT_END
2609 commit refs/heads/big-file
2610 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2611 data <<COMMIT
2612 R - big file
2613 COMMIT
2615 M 644 inline big1
2616 data $blobsize
2617 INPUT_END
2618 cat expect >>input
2619 cat >>input <<INPUT_END
2620 M 644 inline big2
2621 data $blobsize
2622 INPUT_END
2623 cat expect >>input
2624 echo >>input
2626 test_expect_success \
2627 'R: blob bigger than threshold' \
2628 'test_create_repo R &&
2629 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2631 test_expect_success 'R: verify created pack' '
2633 cd R &&
2634 verify_packs -v > ../verify
2638 test_expect_success \
2639 'R: verify written objects' \
2640 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2641 test_cmp expect actual &&
2642 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2643 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2644 test $a = $b'
2645 test_expect_success \
2646 'R: blob appears only once' \
2647 'n=$(grep $a verify | wc -l) &&
2648 test 1 = $n'
2651 ### series S
2654 # Make sure missing spaces and EOLs after mark references
2655 # cause errors.
2657 # Setup:
2659 # 1--2--4
2660 # \ /
2661 # -3-
2663 # commit marks: 301, 302, 303, 304
2664 # blob marks: 403, 404, resp.
2665 # note mark: 202
2667 # The error message when a space is missing not at the
2668 # end of the line is:
2670 # Missing space after ..
2672 # or when extra characters come after the mark at the end
2673 # of the line:
2675 # Garbage after ..
2677 # or when the dataref is neither "inline " or a known SHA1,
2679 # Invalid dataref ..
2681 test_tick
2683 cat >input <<INPUT_END
2684 commit refs/heads/S
2685 mark :301
2686 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2687 data <<COMMIT
2688 commit 1
2689 COMMIT
2690 M 100644 inline hello.c
2691 data <<BLOB
2692 blob 1
2693 BLOB
2695 commit refs/heads/S
2696 mark :302
2697 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2698 data <<COMMIT
2699 commit 2
2700 COMMIT
2701 from :301
2702 M 100644 inline hello.c
2703 data <<BLOB
2704 blob 2
2705 BLOB
2707 blob
2708 mark :403
2709 data <<BLOB
2710 blob 3
2711 BLOB
2713 blob
2714 mark :202
2715 data <<BLOB
2716 note 2
2717 BLOB
2718 INPUT_END
2720 test_expect_success 'S: initialize for S tests' '
2721 git fast-import --export-marks=marks <input
2725 # filemodify, three datarefs
2727 test_expect_success 'S: filemodify with garbage after mark must fail' '
2728 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2729 commit refs/heads/S
2730 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2731 data <<COMMIT
2732 commit N
2733 COMMIT
2734 M 100644 :403x hello.c
2736 cat err &&
2737 test_i18ngrep "space after mark" err
2740 # inline is misspelled; fast-import thinks it is some unknown dataref
2741 test_expect_success 'S: filemodify with garbage after inline must fail' '
2742 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2743 commit refs/heads/S
2744 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2745 data <<COMMIT
2746 commit N
2747 COMMIT
2748 M 100644 inlineX hello.c
2749 data <<BLOB
2750 inline
2751 BLOB
2753 cat err &&
2754 test_i18ngrep "nvalid dataref" err
2757 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2758 sha1=$(grep :403 marks | cut -d\ -f2) &&
2759 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2760 commit refs/heads/S
2761 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2762 data <<COMMIT
2763 commit N
2764 COMMIT
2765 M 100644 ${sha1}x hello.c
2767 cat err &&
2768 test_i18ngrep "space after SHA1" err
2772 # notemodify, three ways to say dataref
2774 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2775 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2776 commit refs/heads/S
2777 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2778 data <<COMMIT
2779 commit S note dataref markref
2780 COMMIT
2781 N :202x :302
2783 cat err &&
2784 test_i18ngrep "space after mark" err
2787 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2788 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2789 commit refs/heads/S
2790 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2791 data <<COMMIT
2792 commit S note dataref inline
2793 COMMIT
2794 N inlineX :302
2795 data <<BLOB
2796 note blob
2797 BLOB
2799 cat err &&
2800 test_i18ngrep "nvalid dataref" err
2803 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2804 sha1=$(grep :202 marks | cut -d\ -f2) &&
2805 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2806 commit refs/heads/S
2807 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2808 data <<COMMIT
2809 commit S note dataref sha1
2810 COMMIT
2811 N ${sha1}x :302
2813 cat err &&
2814 test_i18ngrep "space after SHA1" err
2818 # notemodify, mark in committish
2820 test_expect_success 'S: notemodify with garbarge after mark committish must fail' '
2821 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2822 commit refs/heads/Snotes
2823 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2824 data <<COMMIT
2825 commit S note committish
2826 COMMIT
2827 N :202 :302x
2829 cat err &&
2830 test_i18ngrep "after mark" err
2834 # from
2836 test_expect_success 'S: from with garbage after mark must fail' '
2837 # no &&
2838 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err
2839 commit refs/heads/S2
2840 mark :303
2841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842 data <<COMMIT
2843 commit 3
2844 COMMIT
2845 from :301x
2846 M 100644 :403 hello.c
2849 ret=$? &&
2850 echo returned $ret &&
2851 test $ret -ne 0 && # failed, but it created the commit
2853 # go create the commit, need it for merge test
2854 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2855 commit refs/heads/S2
2856 mark :303
2857 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2858 data <<COMMIT
2859 commit 3
2860 COMMIT
2861 from :301
2862 M 100644 :403 hello.c
2865 # now evaluate the error
2866 cat err &&
2867 test_i18ngrep "after mark" err
2872 # merge
2874 test_expect_success 'S: merge with garbage after mark must fail' '
2875 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2876 commit refs/heads/S
2877 mark :304
2878 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2879 data <<COMMIT
2880 merge 4
2881 COMMIT
2882 from :302
2883 merge :303x
2884 M 100644 :403 hello.c
2886 cat err &&
2887 test_i18ngrep "after mark" err
2891 # tag, from markref
2893 test_expect_success 'S: tag with garbage after mark must fail' '
2894 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2895 tag refs/tags/Stag
2896 from :302x
2897 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2898 data <<TAG
2899 tag S
2902 cat err &&
2903 test_i18ngrep "after mark" err
2907 # cat-blob markref
2909 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2910 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2911 cat-blob :403x
2913 cat err &&
2914 test_i18ngrep "after mark" err
2918 # ls markref
2920 test_expect_success 'S: ls with garbage after mark must fail' '
2921 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2922 ls :302x hello.c
2924 cat err &&
2925 test_i18ngrep "space after mark" err
2928 test_expect_success 'S: ls with garbage after sha1 must fail' '
2929 sha1=$(grep :302 marks | cut -d\ -f2) &&
2930 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2931 ls ${sha1}x hello.c
2933 cat err &&
2934 test_i18ngrep "space after tree-ish" err
2937 test_done