Merge branch 'jk/color-and-pager'
[git/jnareb-git.git] / t / t9300-fast-import.sh
blob1a6c06631c1c2a8fc29b66c9265541b54e8a9715
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 -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 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
53 ###
54 ### series A
55 ###
57 test_tick
59 test_expect_success 'empty stream succeeds' '
60 git fast-import </dev/null
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 tag series-A-blob
98 from :3
99 data <<EOF
100 An annotated tag that annotates a blob.
103 INPUT_END
104 test_expect_success \
105 'A: create pack from stdin' \
106 'git fast-import --export-marks=marks.out <input &&
107 git whatchanged master'
108 test_expect_success \
109 'A: verify pack' \
110 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
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'
255 test_expect_success \
256 'A: verify pack' \
257 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
258 cat >expect <<EOF
259 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
261 git diff-tree -M -r master verify--import-marks >actual
262 test_expect_success \
263 'A: verify diff' \
264 'compare_diff_raw expect actual &&
265 test `git rev-parse --verify master:file2` \
266 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
268 test_tick
269 mt=$(git hash-object --stdin < /dev/null)
270 : >input.blob
271 : >marks.exp
272 : >tree.exp
274 cat >input.commit <<EOF
275 commit refs/heads/verify--dump-marks
276 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
277 data <<COMMIT
278 test the sparse array dumping routines with exponentially growing marks
279 COMMIT
286 while test "$i" -lt 27; do
287 cat >>input.blob <<EOF
288 blob
289 mark :$l
290 data 0
291 blob
292 mark :$m
293 data 0
294 blob
295 mark :$n
296 data 0
298 echo "M 100644 :$l l$i" >>input.commit
299 echo "M 100644 :$m m$i" >>input.commit
300 echo "M 100644 :$n n$i" >>input.commit
302 echo ":$l $mt" >>marks.exp
303 echo ":$m $mt" >>marks.exp
304 echo ":$n $mt" >>marks.exp
306 printf "100644 blob $mt\tl$i\n" >>tree.exp
307 printf "100644 blob $mt\tm$i\n" >>tree.exp
308 printf "100644 blob $mt\tn$i\n" >>tree.exp
310 l=$(($l + $l))
311 m=$(($m + $m))
312 n=$(($l + $n))
314 i=$((1 + $i))
315 done
317 sort tree.exp > tree.exp_s
319 test_expect_success 'A: export marks with large values' '
320 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
321 git ls-tree refs/heads/verify--dump-marks >tree.out &&
322 test_cmp tree.exp_s tree.out &&
323 test_cmp marks.exp marks.large'
326 ### series B
329 test_tick
330 cat >input <<INPUT_END
331 commit refs/heads/branch
332 mark :1
333 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
334 data <<COMMIT
335 corrupt
336 COMMIT
338 from refs/heads/master
339 M 755 0000000000000000000000000000000000000001 zero1
341 INPUT_END
342 test_expect_success 'B: fail on invalid blob sha1' '
343 test_must_fail git fast-import <input
345 rm -f .git/objects/pack_* .git/objects/index_*
347 cat >input <<INPUT_END
348 commit .badbranchname
349 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
350 data <<COMMIT
351 corrupt
352 COMMIT
354 from refs/heads/master
356 INPUT_END
357 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
358 test_must_fail git fast-import <input
360 rm -f .git/objects/pack_* .git/objects/index_*
362 cat >input <<INPUT_END
363 commit bad[branch]name
364 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
365 data <<COMMIT
366 corrupt
367 COMMIT
369 from refs/heads/master
371 INPUT_END
372 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
373 test_must_fail git fast-import <input
375 rm -f .git/objects/pack_* .git/objects/index_*
377 cat >input <<INPUT_END
378 commit TEMP_TAG
379 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
380 data <<COMMIT
381 tag base
382 COMMIT
384 from refs/heads/master
386 INPUT_END
387 test_expect_success \
388 'B: accept branch name "TEMP_TAG"' \
389 'git fast-import <input &&
390 test -f .git/TEMP_TAG &&
391 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
392 rm -f .git/TEMP_TAG
394 git gc 2>/dev/null >/dev/null
395 git prune 2>/dev/null >/dev/null
397 cat >input <<INPUT_END
398 commit refs/heads/empty-committer-1
399 committer <> $GIT_COMMITTER_DATE
400 data <<COMMIT
401 empty commit
402 COMMIT
403 INPUT_END
404 test_expect_success 'B: accept empty committer' '
405 git fast-import <input &&
406 out=$(git fsck) &&
407 echo "$out" &&
408 test -z "$out"
410 git update-ref -d refs/heads/empty-committer-1 || true
412 git gc 2>/dev/null >/dev/null
413 git prune 2>/dev/null >/dev/null
415 cat >input <<INPUT_END
416 commit refs/heads/empty-committer-2
417 committer <a@b.com> $GIT_COMMITTER_DATE
418 data <<COMMIT
419 empty commit
420 COMMIT
421 INPUT_END
422 test_expect_success 'B: accept and fixup committer with no name' '
423 git fast-import <input &&
424 out=$(git fsck) &&
425 echo "$out" &&
426 test -z "$out"
428 git update-ref -d refs/heads/empty-committer-2 || true
430 git gc 2>/dev/null >/dev/null
431 git prune 2>/dev/null >/dev/null
433 cat >input <<INPUT_END
434 commit refs/heads/invalid-committer
435 committer Name email> $GIT_COMMITTER_DATE
436 data <<COMMIT
437 empty commit
438 COMMIT
439 INPUT_END
440 test_expect_success 'B: fail on invalid committer (1)' '
441 test_must_fail git fast-import <input
443 git update-ref -d refs/heads/invalid-committer || true
445 cat >input <<INPUT_END
446 commit refs/heads/invalid-committer
447 committer Name <e<mail> $GIT_COMMITTER_DATE
448 data <<COMMIT
449 empty commit
450 COMMIT
451 INPUT_END
452 test_expect_success 'B: fail on invalid committer (2)' '
453 test_must_fail git fast-import <input
455 git update-ref -d refs/heads/invalid-committer || true
457 cat >input <<INPUT_END
458 commit refs/heads/invalid-committer
459 committer Name <email>> $GIT_COMMITTER_DATE
460 data <<COMMIT
461 empty commit
462 COMMIT
463 INPUT_END
464 test_expect_success 'B: fail on invalid committer (3)' '
465 test_must_fail git fast-import <input
467 git update-ref -d refs/heads/invalid-committer || true
469 cat >input <<INPUT_END
470 commit refs/heads/invalid-committer
471 committer Name <email $GIT_COMMITTER_DATE
472 data <<COMMIT
473 empty commit
474 COMMIT
475 INPUT_END
476 test_expect_success 'B: fail on invalid committer (4)' '
477 test_must_fail git fast-import <input
479 git update-ref -d refs/heads/invalid-committer || true
481 cat >input <<INPUT_END
482 commit refs/heads/invalid-committer
483 committer Name<email> $GIT_COMMITTER_DATE
484 data <<COMMIT
485 empty commit
486 COMMIT
487 INPUT_END
488 test_expect_success 'B: fail on invalid committer (5)' '
489 test_must_fail git fast-import <input
491 git update-ref -d refs/heads/invalid-committer || true
494 ### series C
497 newf=`echo hi newf | git hash-object -w --stdin`
498 oldf=`git rev-parse --verify master:file2`
499 test_tick
500 cat >input <<INPUT_END
501 commit refs/heads/branch
502 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
503 data <<COMMIT
504 second
505 COMMIT
507 from refs/heads/master
508 M 644 $oldf file2/oldf
509 M 755 $newf file2/newf
510 D file3
512 INPUT_END
513 test_expect_success \
514 'C: incremental import create pack from stdin' \
515 'git fast-import <input &&
516 git whatchanged branch'
517 test_expect_success \
518 'C: verify pack' \
519 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
520 test_expect_success \
521 'C: validate reuse existing blob' \
522 'test $newf = `git rev-parse --verify branch:file2/newf` &&
523 test $oldf = `git rev-parse --verify branch:file2/oldf`'
525 cat >expect <<EOF
526 parent `git rev-parse --verify master^0`
527 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
528 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
530 second
532 test_expect_success \
533 'C: verify commit' \
534 'git cat-file commit branch | sed 1d >actual &&
535 test_cmp expect actual'
537 cat >expect <<EOF
538 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
539 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
540 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
542 git diff-tree -M -r master branch >actual
543 test_expect_success \
544 'C: validate rename result' \
545 'compare_diff_raw expect actual'
548 ### series D
551 test_tick
552 cat >input <<INPUT_END
553 commit refs/heads/branch
554 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
555 data <<COMMIT
556 third
557 COMMIT
559 from refs/heads/branch^0
560 M 644 inline newdir/interesting
561 data <<EOF
562 $file5_data
565 M 755 inline newdir/exec.sh
566 data <<EOF
567 $file6_data
570 INPUT_END
571 test_expect_success \
572 'D: inline data in commit' \
573 'git fast-import <input &&
574 git whatchanged branch'
575 test_expect_success \
576 'D: verify pack' \
577 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
579 cat >expect <<EOF
580 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
581 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
583 git diff-tree -M -r branch^ branch >actual
584 test_expect_success \
585 'D: validate new files added' \
586 'compare_diff_raw expect actual'
588 echo "$file5_data" >expect
589 test_expect_success \
590 'D: verify file5' \
591 'git cat-file blob branch:newdir/interesting >actual &&
592 test_cmp expect actual'
594 echo "$file6_data" >expect
595 test_expect_success \
596 'D: verify file6' \
597 'git cat-file blob branch:newdir/exec.sh >actual &&
598 test_cmp expect actual'
601 ### series E
604 cat >input <<INPUT_END
605 commit refs/heads/branch
606 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
607 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
608 data <<COMMIT
609 RFC 2822 type date
610 COMMIT
612 from refs/heads/branch^0
614 INPUT_END
615 test_expect_success 'E: rfc2822 date, --date-format=raw' '
616 test_must_fail git fast-import --date-format=raw <input
618 test_expect_success \
619 'E: rfc2822 date, --date-format=rfc2822' \
620 'git fast-import --date-format=rfc2822 <input'
621 test_expect_success \
622 'E: verify pack' \
623 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
625 cat >expect <<EOF
626 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
627 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
629 RFC 2822 type date
631 test_expect_success \
632 'E: verify commit' \
633 'git cat-file commit branch | sed 1,2d >actual &&
634 test_cmp expect actual'
637 ### series F
640 old_branch=`git rev-parse --verify branch^0`
641 test_tick
642 cat >input <<INPUT_END
643 commit refs/heads/branch
644 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
645 data <<COMMIT
646 losing things already?
647 COMMIT
649 from refs/heads/branch~1
651 reset refs/heads/other
652 from refs/heads/branch
654 INPUT_END
655 test_expect_success \
656 'F: non-fast-forward update skips' \
657 'if git fast-import <input
658 then
659 echo BAD gfi did not fail
660 return 1
661 else
662 if test $old_branch = `git rev-parse --verify branch^0`
663 then
664 : branch unaffected and failure returned
665 return 0
666 else
667 echo BAD gfi changed branch $old_branch
668 return 1
672 test_expect_success \
673 'F: verify pack' \
674 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
676 cat >expect <<EOF
677 tree `git rev-parse branch~1^{tree}`
678 parent `git rev-parse branch~1`
679 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
680 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
682 losing things already?
684 test_expect_success \
685 'F: verify other commit' \
686 'git cat-file commit other >actual &&
687 test_cmp expect actual'
690 ### series G
693 old_branch=`git rev-parse --verify branch^0`
694 test_tick
695 cat >input <<INPUT_END
696 commit refs/heads/branch
697 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
698 data <<COMMIT
699 losing things already?
700 COMMIT
702 from refs/heads/branch~1
704 INPUT_END
705 test_expect_success \
706 'G: non-fast-forward update forced' \
707 'git fast-import --force <input'
708 test_expect_success \
709 'G: verify pack' \
710 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
711 test_expect_success \
712 'G: branch changed, but logged' \
713 'test $old_branch != `git rev-parse --verify branch^0` &&
714 test $old_branch = `git rev-parse --verify branch@{1}`'
717 ### series H
720 test_tick
721 cat >input <<INPUT_END
722 commit refs/heads/H
723 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
724 data <<COMMIT
725 third
726 COMMIT
728 from refs/heads/branch^0
729 M 644 inline i-will-die
730 data <<EOF
731 this file will never exist.
734 deleteall
735 M 644 inline h/e/l/lo
736 data <<EOF
737 $file5_data
740 INPUT_END
741 test_expect_success \
742 'H: deletall, add 1' \
743 'git fast-import <input &&
744 git whatchanged H'
745 test_expect_success \
746 'H: verify pack' \
747 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
749 cat >expect <<EOF
750 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
751 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
752 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
753 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
754 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
756 git diff-tree -M -r H^ H >actual
757 test_expect_success \
758 'H: validate old files removed, new files added' \
759 'compare_diff_raw expect actual'
761 echo "$file5_data" >expect
762 test_expect_success \
763 'H: verify file' \
764 'git cat-file blob H:h/e/l/lo >actual &&
765 test_cmp expect actual'
768 ### series I
771 cat >input <<INPUT_END
772 commit refs/heads/export-boundary
773 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
774 data <<COMMIT
775 we have a border. its only 40 characters wide.
776 COMMIT
778 from refs/heads/branch
780 INPUT_END
781 test_expect_success \
782 'I: export-pack-edges' \
783 'git fast-import --export-pack-edges=edges.list <input'
785 cat >expect <<EOF
786 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
788 test_expect_success \
789 'I: verify edge list' \
790 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
791 test_cmp expect actual'
794 ### series J
797 cat >input <<INPUT_END
798 commit refs/heads/J
799 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
800 data <<COMMIT
801 create J
802 COMMIT
804 from refs/heads/branch
806 reset refs/heads/J
808 commit refs/heads/J
809 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
810 data <<COMMIT
811 initialize J
812 COMMIT
814 INPUT_END
815 test_expect_success \
816 'J: reset existing branch creates empty commit' \
817 'git fast-import <input'
818 test_expect_success \
819 'J: branch has 1 commit, empty tree' \
820 'test 1 = `git rev-list J | wc -l` &&
821 test 0 = `git ls-tree J | wc -l`'
824 ### series K
827 cat >input <<INPUT_END
828 commit refs/heads/K
829 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
830 data <<COMMIT
831 create K
832 COMMIT
834 from refs/heads/branch
836 commit refs/heads/K
837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
838 data <<COMMIT
839 redo K
840 COMMIT
842 from refs/heads/branch^1
844 INPUT_END
845 test_expect_success \
846 'K: reinit branch with from' \
847 'git fast-import <input'
848 test_expect_success \
849 'K: verify K^1 = branch^1' \
850 'test `git rev-parse --verify branch^1` \
851 = `git rev-parse --verify K^1`'
854 ### series L
857 cat >input <<INPUT_END
858 blob
859 mark :1
860 data <<EOF
861 some data
864 blob
865 mark :2
866 data <<EOF
867 other data
870 commit refs/heads/L
871 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
872 data <<COMMIT
873 create L
874 COMMIT
876 M 644 :1 b.
877 M 644 :1 b/other
878 M 644 :1 ba
880 commit refs/heads/L
881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
882 data <<COMMIT
883 update L
884 COMMIT
886 M 644 :2 b.
887 M 644 :2 b/other
888 M 644 :2 ba
889 INPUT_END
891 cat >expect <<EXPECT_END
892 :100644 100644 4268632... 55d3a52... M b.
893 :040000 040000 0ae5cac... 443c768... M b
894 :100644 100644 4268632... 55d3a52... M ba
895 EXPECT_END
897 test_expect_success \
898 'L: verify internal tree sorting' \
899 'git fast-import <input &&
900 git diff-tree --abbrev --raw L^ L >output &&
901 test_cmp expect output'
903 cat >input <<INPUT_END
904 blob
905 mark :1
906 data <<EOF
907 the data
910 commit refs/heads/L2
911 committer C O Mitter <committer@example.com> 1112912473 -0700
912 data <<COMMIT
913 init L2
914 COMMIT
915 M 644 :1 a/b/c
916 M 644 :1 a/b/d
917 M 644 :1 a/e/f
919 commit refs/heads/L2
920 committer C O Mitter <committer@example.com> 1112912473 -0700
921 data <<COMMIT
922 update L2
923 COMMIT
924 C a g
925 C a/e g/b
926 M 644 :1 g/b/h
927 INPUT_END
929 cat <<EOF >expect
930 g/b/f
931 g/b/h
934 test_expect_success \
935 'L: nested tree copy does not corrupt deltas' \
936 'git fast-import <input &&
937 git ls-tree L2 g/b/ >tmp &&
938 cat tmp | cut -f 2 >actual &&
939 test_cmp expect actual &&
940 git fsck `git rev-parse L2`'
942 git update-ref -d refs/heads/L2
945 ### series M
948 test_tick
949 cat >input <<INPUT_END
950 commit refs/heads/M1
951 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
952 data <<COMMIT
953 file rename
954 COMMIT
956 from refs/heads/branch^0
957 R file2/newf file2/n.e.w.f
959 INPUT_END
961 cat >expect <<EOF
962 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
964 test_expect_success \
965 'M: rename file in same subdirectory' \
966 'git fast-import <input &&
967 git diff-tree -M -r M1^ M1 >actual &&
968 compare_diff_raw expect actual'
970 cat >input <<INPUT_END
971 commit refs/heads/M2
972 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
973 data <<COMMIT
974 file rename
975 COMMIT
977 from refs/heads/branch^0
978 R file2/newf i/am/new/to/you
980 INPUT_END
982 cat >expect <<EOF
983 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
985 test_expect_success \
986 'M: rename file to new subdirectory' \
987 'git fast-import <input &&
988 git diff-tree -M -r M2^ M2 >actual &&
989 compare_diff_raw expect actual'
991 cat >input <<INPUT_END
992 commit refs/heads/M3
993 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
994 data <<COMMIT
995 file rename
996 COMMIT
998 from refs/heads/M2^0
999 R i other/sub
1001 INPUT_END
1003 cat >expect <<EOF
1004 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
1006 test_expect_success \
1007 'M: rename subdirectory to new subdirectory' \
1008 'git fast-import <input &&
1009 git diff-tree -M -r M3^ M3 >actual &&
1010 compare_diff_raw expect actual'
1013 ### series N
1016 test_tick
1017 cat >input <<INPUT_END
1018 commit refs/heads/N1
1019 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1020 data <<COMMIT
1021 file copy
1022 COMMIT
1024 from refs/heads/branch^0
1025 C file2/newf file2/n.e.w.f
1027 INPUT_END
1029 cat >expect <<EOF
1030 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1032 test_expect_success \
1033 'N: copy file in same subdirectory' \
1034 'git fast-import <input &&
1035 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1036 compare_diff_raw expect actual'
1038 cat >input <<INPUT_END
1039 commit refs/heads/N2
1040 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1041 data <<COMMIT
1042 clean directory copy
1043 COMMIT
1045 from refs/heads/branch^0
1046 C file2 file3
1048 commit refs/heads/N2
1049 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1050 data <<COMMIT
1051 modify directory copy
1052 COMMIT
1054 M 644 inline file3/file5
1055 data <<EOF
1056 $file5_data
1059 INPUT_END
1061 cat >expect <<EOF
1062 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1063 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1064 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1066 test_expect_success \
1067 'N: copy then modify subdirectory' \
1068 'git fast-import <input &&
1069 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1070 compare_diff_raw expect actual'
1072 cat >input <<INPUT_END
1073 commit refs/heads/N3
1074 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1075 data <<COMMIT
1076 dirty directory copy
1077 COMMIT
1079 from refs/heads/branch^0
1080 M 644 inline file2/file5
1081 data <<EOF
1082 $file5_data
1085 C file2 file3
1086 D file2/file5
1088 INPUT_END
1090 test_expect_success \
1091 'N: copy dirty subdirectory' \
1092 'git fast-import <input &&
1093 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1095 test_expect_success \
1096 'N: copy directory by id' \
1097 'cat >expect <<-\EOF &&
1098 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1099 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1101 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1102 cat >input <<-INPUT_END &&
1103 commit refs/heads/N4
1104 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1105 data <<COMMIT
1106 copy by tree hash
1107 COMMIT
1109 from refs/heads/branch^0
1110 M 040000 $subdir file3
1111 INPUT_END
1112 git fast-import <input &&
1113 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1114 compare_diff_raw expect actual'
1116 test_expect_success PIPE 'N: read and copy directory' '
1117 cat >expect <<-\EOF
1118 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1119 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1121 git update-ref -d refs/heads/N4 &&
1122 rm -f backflow &&
1123 mkfifo backflow &&
1125 exec <backflow &&
1126 cat <<-EOF &&
1127 commit refs/heads/N4
1128 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1129 data <<COMMIT
1130 copy by tree hash, part 2
1131 COMMIT
1133 from refs/heads/branch^0
1134 ls "file2"
1136 read mode type tree filename &&
1137 echo "M 040000 $tree file3"
1139 git fast-import --cat-blob-fd=3 3>backflow &&
1140 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1141 compare_diff_raw expect actual
1144 test_expect_success PIPE 'N: empty directory reads as missing' '
1145 cat <<-\EOF >expect &&
1146 OBJNAME
1147 :000000 100644 OBJNAME OBJNAME A unrelated
1149 echo "missing src" >expect.response &&
1150 git update-ref -d refs/heads/read-empty &&
1151 rm -f backflow &&
1152 mkfifo backflow &&
1154 exec <backflow &&
1155 cat <<-EOF &&
1156 commit refs/heads/read-empty
1157 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1158 data <<COMMIT
1159 read "empty" (missing) directory
1160 COMMIT
1162 M 100644 inline src/greeting
1163 data <<BLOB
1164 hello
1165 BLOB
1166 C src/greeting dst1/non-greeting
1167 C src/greeting unrelated
1168 # leave behind "empty" src directory
1169 D src/greeting
1170 ls "src"
1172 read -r line &&
1173 printf "%s\n" "$line" >response &&
1174 cat <<-\EOF
1175 D dst1
1176 D dst2
1179 git fast-import --cat-blob-fd=3 3>backflow &&
1180 test_cmp expect.response response &&
1181 git rev-list read-empty |
1182 git diff-tree -r --root --stdin |
1183 sed "s/$_x40/OBJNAME/g" >actual &&
1184 test_cmp expect actual
1187 test_expect_success \
1188 'N: copy root directory by tree hash' \
1189 'cat >expect <<-\EOF &&
1190 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1191 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1193 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1194 cat >input <<-INPUT_END &&
1195 commit refs/heads/N6
1196 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1197 data <<COMMIT
1198 copy root directory by tree hash
1199 COMMIT
1201 from refs/heads/branch^0
1202 M 040000 $root ""
1203 INPUT_END
1204 git fast-import <input &&
1205 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1206 compare_diff_raw expect actual'
1208 test_expect_success \
1209 'N: delete directory by copying' \
1210 'cat >expect <<-\EOF &&
1211 OBJID
1212 :100644 000000 OBJID OBJID D foo/bar/qux
1213 OBJID
1214 :000000 100644 OBJID OBJID A foo/bar/baz
1215 :000000 100644 OBJID OBJID A foo/bar/qux
1217 empty_tree=$(git mktree </dev/null) &&
1218 cat >input <<-INPUT_END &&
1219 commit refs/heads/N-delete
1220 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1221 data <<COMMIT
1222 collect data to be deleted
1223 COMMIT
1225 deleteall
1226 M 100644 inline foo/bar/baz
1227 data <<DATA_END
1228 hello
1229 DATA_END
1230 C "foo/bar/baz" "foo/bar/qux"
1231 C "foo/bar/baz" "foo/bar/quux/1"
1232 C "foo/bar/baz" "foo/bar/quuux"
1233 M 040000 $empty_tree foo/bar/quux
1234 M 040000 $empty_tree foo/bar/quuux
1236 commit refs/heads/N-delete
1237 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1238 data <<COMMIT
1239 delete subdirectory
1240 COMMIT
1242 M 040000 $empty_tree foo/bar/qux
1243 INPUT_END
1244 git fast-import <input &&
1245 git rev-list N-delete |
1246 git diff-tree -r --stdin --root --always |
1247 sed -e "s/$_x40/OBJID/g" >actual &&
1248 test_cmp expect actual'
1250 test_expect_success \
1251 'N: modify copied tree' \
1252 'cat >expect <<-\EOF &&
1253 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1254 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1255 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1257 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1258 cat >input <<-INPUT_END &&
1259 commit refs/heads/N5
1260 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1261 data <<COMMIT
1262 copy by tree hash
1263 COMMIT
1265 from refs/heads/branch^0
1266 M 040000 $subdir file3
1268 commit refs/heads/N5
1269 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1270 data <<COMMIT
1271 modify directory copy
1272 COMMIT
1274 M 644 inline file3/file5
1275 data <<EOF
1276 $file5_data
1278 INPUT_END
1279 git fast-import <input &&
1280 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1281 compare_diff_raw expect actual'
1283 test_expect_success \
1284 'N: reject foo/ syntax' \
1285 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1286 test_must_fail git fast-import <<-INPUT_END
1287 commit refs/heads/N5B
1288 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1289 data <<COMMIT
1290 copy with invalid syntax
1291 COMMIT
1293 from refs/heads/branch^0
1294 M 040000 $subdir file3/
1295 INPUT_END'
1297 test_expect_success \
1298 'N: copy to root by id and modify' \
1299 'echo "hello, world" >expect.foo &&
1300 echo hello >expect.bar &&
1301 git fast-import <<-SETUP_END &&
1302 commit refs/heads/N7
1303 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1304 data <<COMMIT
1305 hello, tree
1306 COMMIT
1308 deleteall
1309 M 644 inline foo/bar
1310 data <<EOF
1311 hello
1313 SETUP_END
1315 tree=$(git rev-parse --verify N7:) &&
1316 git fast-import <<-INPUT_END &&
1317 commit refs/heads/N8
1318 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1319 data <<COMMIT
1320 copy to root by id and modify
1321 COMMIT
1323 M 040000 $tree ""
1324 M 644 inline foo/foo
1325 data <<EOF
1326 hello, world
1328 INPUT_END
1329 git show N8:foo/foo >actual.foo &&
1330 git show N8:foo/bar >actual.bar &&
1331 test_cmp expect.foo actual.foo &&
1332 test_cmp expect.bar actual.bar'
1334 test_expect_success \
1335 'N: extract subtree' \
1336 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1337 cat >input <<-INPUT_END &&
1338 commit refs/heads/N9
1339 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1340 data <<COMMIT
1341 extract subtree branch:newdir
1342 COMMIT
1344 M 040000 $branch ""
1345 C "newdir" ""
1346 INPUT_END
1347 git fast-import <input &&
1348 git diff --exit-code branch:newdir N9'
1350 test_expect_success \
1351 'N: modify subtree, extract it, and modify again' \
1352 'echo hello >expect.baz &&
1353 echo hello, world >expect.qux &&
1354 git fast-import <<-SETUP_END &&
1355 commit refs/heads/N10
1356 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1357 data <<COMMIT
1358 hello, tree
1359 COMMIT
1361 deleteall
1362 M 644 inline foo/bar/baz
1363 data <<EOF
1364 hello
1366 SETUP_END
1368 tree=$(git rev-parse --verify N10:) &&
1369 git fast-import <<-INPUT_END &&
1370 commit refs/heads/N11
1371 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1372 data <<COMMIT
1373 copy to root by id and modify
1374 COMMIT
1376 M 040000 $tree ""
1377 M 100644 inline foo/bar/qux
1378 data <<EOF
1379 hello, world
1381 R "foo" ""
1382 C "bar/qux" "bar/quux"
1383 INPUT_END
1384 git show N11:bar/baz >actual.baz &&
1385 git show N11:bar/qux >actual.qux &&
1386 git show N11:bar/quux >actual.quux &&
1387 test_cmp expect.baz actual.baz &&
1388 test_cmp expect.qux actual.qux &&
1389 test_cmp expect.qux actual.quux'
1392 ### series O
1395 cat >input <<INPUT_END
1396 #we will
1397 commit refs/heads/O1
1398 # -- ignore all of this text
1399 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1400 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1401 data <<COMMIT
1402 dirty directory copy
1403 COMMIT
1405 # don't forget the import blank line!
1407 # yes, we started from our usual base of branch^0.
1408 # i like branch^0.
1409 from refs/heads/branch^0
1410 # and we need to reuse file2/file5 from N3 above.
1411 M 644 inline file2/file5
1412 # otherwise the tree will be different
1413 data <<EOF
1414 $file5_data
1417 # don't forget to copy file2 to file3
1418 C file2 file3
1420 # or to delete file5 from file2.
1421 D file2/file5
1422 # are we done yet?
1424 INPUT_END
1426 test_expect_success \
1427 'O: comments are all skipped' \
1428 'git fast-import <input &&
1429 test `git rev-parse N3` = `git rev-parse O1`'
1431 cat >input <<INPUT_END
1432 commit refs/heads/O2
1433 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1434 data <<COMMIT
1435 dirty directory copy
1436 COMMIT
1437 from refs/heads/branch^0
1438 M 644 inline file2/file5
1439 data <<EOF
1440 $file5_data
1442 C file2 file3
1443 D file2/file5
1445 INPUT_END
1447 test_expect_success \
1448 'O: blank lines not necessary after data commands' \
1449 'git fast-import <input &&
1450 test `git rev-parse N3` = `git rev-parse O2`'
1452 test_expect_success \
1453 'O: repack before next test' \
1454 'git repack -a -d'
1456 cat >input <<INPUT_END
1457 commit refs/heads/O3
1458 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1459 data <<COMMIT
1460 zstring
1461 COMMIT
1462 commit refs/heads/O3
1463 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1464 data <<COMMIT
1466 COMMIT
1467 checkpoint
1468 commit refs/heads/O3
1469 mark :5
1470 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1471 data <<COMMIT
1472 zempty
1473 COMMIT
1474 checkpoint
1475 commit refs/heads/O3
1476 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1477 data <<COMMIT
1478 zcommits
1479 COMMIT
1480 reset refs/tags/O3-2nd
1481 from :5
1482 reset refs/tags/O3-3rd
1483 from :5
1484 INPUT_END
1486 cat >expect <<INPUT_END
1487 string
1489 empty
1490 commits
1491 INPUT_END
1492 test_expect_success \
1493 'O: blank lines not necessary after other commands' \
1494 'git fast-import <input &&
1495 test 8 = `find .git/objects/pack -type f | wc -l` &&
1496 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1497 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1498 test_cmp expect actual'
1500 cat >input <<INPUT_END
1501 commit refs/heads/O4
1502 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1503 data <<COMMIT
1504 zstring
1505 COMMIT
1506 commit refs/heads/O4
1507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1508 data <<COMMIT
1510 COMMIT
1511 progress Two commits down, 2 to go!
1512 commit refs/heads/O4
1513 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1514 data <<COMMIT
1515 zempty
1516 COMMIT
1517 progress Three commits down, 1 to go!
1518 commit refs/heads/O4
1519 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520 data <<COMMIT
1521 zcommits
1522 COMMIT
1523 progress I'm done!
1524 INPUT_END
1525 test_expect_success \
1526 'O: progress outputs as requested by input' \
1527 'git fast-import <input >actual &&
1528 grep "progress " <input >expect &&
1529 test_cmp expect actual'
1532 ### series P (gitlinks)
1535 cat >input <<INPUT_END
1536 blob
1537 mark :1
1538 data 10
1539 test file
1541 reset refs/heads/sub
1542 commit refs/heads/sub
1543 mark :2
1544 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1545 data 12
1546 sub_initial
1547 M 100644 :1 file
1549 blob
1550 mark :3
1551 data <<DATAEND
1552 [submodule "sub"]
1553 path = sub
1554 url = "`pwd`/sub"
1555 DATAEND
1557 commit refs/heads/subuse1
1558 mark :4
1559 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1560 data 8
1561 initial
1562 from refs/heads/master
1563 M 100644 :3 .gitmodules
1564 M 160000 :2 sub
1566 blob
1567 mark :5
1568 data 20
1569 test file
1570 more data
1572 commit refs/heads/sub
1573 mark :6
1574 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575 data 11
1576 sub_second
1577 from :2
1578 M 100644 :5 file
1580 commit refs/heads/subuse1
1581 mark :7
1582 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583 data 7
1584 second
1585 from :4
1586 M 160000 :6 sub
1588 INPUT_END
1590 test_expect_success \
1591 'P: supermodule & submodule mix' \
1592 'git fast-import <input &&
1593 git checkout subuse1 &&
1594 rm -rf sub && mkdir sub && (cd sub &&
1595 git init &&
1596 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1597 git checkout master) &&
1598 git submodule init &&
1599 git submodule update'
1601 SUBLAST=$(git rev-parse --verify sub)
1602 SUBPREV=$(git rev-parse --verify sub^)
1604 cat >input <<INPUT_END
1605 blob
1606 mark :1
1607 data <<DATAEND
1608 [submodule "sub"]
1609 path = sub
1610 url = "`pwd`/sub"
1611 DATAEND
1613 commit refs/heads/subuse2
1614 mark :2
1615 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1616 data 8
1617 initial
1618 from refs/heads/master
1619 M 100644 :1 .gitmodules
1620 M 160000 $SUBPREV sub
1622 commit refs/heads/subuse2
1623 mark :3
1624 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625 data 7
1626 second
1627 from :2
1628 M 160000 $SUBLAST sub
1630 INPUT_END
1632 test_expect_success \
1633 'P: verbatim SHA gitlinks' \
1634 'git branch -D sub &&
1635 git gc && git prune &&
1636 git fast-import <input &&
1637 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1639 test_tick
1640 cat >input <<INPUT_END
1641 commit refs/heads/subuse3
1642 mark :1
1643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644 data <<COMMIT
1645 corrupt
1646 COMMIT
1648 from refs/heads/subuse2
1649 M 160000 inline sub
1650 data <<DATA
1651 $SUBPREV
1652 DATA
1654 INPUT_END
1656 test_expect_success 'P: fail on inline gitlink' '
1657 test_must_fail git fast-import <input'
1659 test_tick
1660 cat >input <<INPUT_END
1661 blob
1662 mark :1
1663 data <<DATA
1664 $SUBPREV
1665 DATA
1667 commit refs/heads/subuse3
1668 mark :2
1669 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1670 data <<COMMIT
1671 corrupt
1672 COMMIT
1674 from refs/heads/subuse2
1675 M 160000 :1 sub
1677 INPUT_END
1679 test_expect_success 'P: fail on blob mark in gitlink' '
1680 test_must_fail git fast-import <input'
1683 ### series Q (notes)
1686 note1_data="The first note for the first commit"
1687 note2_data="The first note for the second commit"
1688 note3_data="The first note for the third commit"
1689 note1b_data="The second note for the first commit"
1690 note1c_data="The third note for the first commit"
1691 note2b_data="The second note for the second commit"
1693 test_tick
1694 cat >input <<INPUT_END
1695 blob
1696 mark :2
1697 data <<EOF
1698 $file2_data
1701 commit refs/heads/notes-test
1702 mark :3
1703 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1704 data <<COMMIT
1705 first (:3)
1706 COMMIT
1708 M 644 :2 file2
1710 blob
1711 mark :4
1712 data $file4_len
1713 $file4_data
1714 commit refs/heads/notes-test
1715 mark :5
1716 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1717 data <<COMMIT
1718 second (:5)
1719 COMMIT
1721 M 644 :4 file4
1723 commit refs/heads/notes-test
1724 mark :6
1725 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1726 data <<COMMIT
1727 third (:6)
1728 COMMIT
1730 M 644 inline file5
1731 data <<EOF
1732 $file5_data
1735 M 755 inline file6
1736 data <<EOF
1737 $file6_data
1740 blob
1741 mark :7
1742 data <<EOF
1743 $note1_data
1746 blob
1747 mark :8
1748 data <<EOF
1749 $note2_data
1752 commit refs/notes/foobar
1753 mark :9
1754 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1755 data <<COMMIT
1756 notes (:9)
1757 COMMIT
1759 N :7 :3
1760 N :8 :5
1761 N inline :6
1762 data <<EOF
1763 $note3_data
1766 commit refs/notes/foobar
1767 mark :10
1768 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1769 data <<COMMIT
1770 notes (:10)
1771 COMMIT
1773 N inline :3
1774 data <<EOF
1775 $note1b_data
1778 commit refs/notes/foobar2
1779 mark :11
1780 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1781 data <<COMMIT
1782 notes (:11)
1783 COMMIT
1785 N inline :3
1786 data <<EOF
1787 $note1c_data
1790 commit refs/notes/foobar
1791 mark :12
1792 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1793 data <<COMMIT
1794 notes (:12)
1795 COMMIT
1797 deleteall
1798 N inline :5
1799 data <<EOF
1800 $note2b_data
1803 INPUT_END
1805 test_expect_success \
1806 'Q: commit notes' \
1807 'git fast-import <input &&
1808 git whatchanged notes-test'
1809 test_expect_success \
1810 'Q: verify pack' \
1811 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1813 commit1=$(git rev-parse notes-test~2)
1814 commit2=$(git rev-parse notes-test^)
1815 commit3=$(git rev-parse notes-test)
1817 cat >expect <<EOF
1818 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1819 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1821 first (:3)
1823 test_expect_success \
1824 'Q: verify first commit' \
1825 'git cat-file commit notes-test~2 | sed 1d >actual &&
1826 test_cmp expect actual'
1828 cat >expect <<EOF
1829 parent $commit1
1830 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1831 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1833 second (:5)
1835 test_expect_success \
1836 'Q: verify second commit' \
1837 'git cat-file commit notes-test^ | sed 1d >actual &&
1838 test_cmp expect actual'
1840 cat >expect <<EOF
1841 parent $commit2
1842 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1843 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1845 third (:6)
1847 test_expect_success \
1848 'Q: verify third commit' \
1849 'git cat-file commit notes-test | sed 1d >actual &&
1850 test_cmp expect actual'
1852 cat >expect <<EOF
1853 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1854 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1856 notes (:9)
1858 test_expect_success \
1859 'Q: verify first notes commit' \
1860 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1861 test_cmp expect actual'
1863 cat >expect.unsorted <<EOF
1864 100644 blob $commit1
1865 100644 blob $commit2
1866 100644 blob $commit3
1868 cat expect.unsorted | sort >expect
1869 test_expect_success \
1870 'Q: verify first notes tree' \
1871 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1872 test_cmp expect actual'
1874 echo "$note1_data" >expect
1875 test_expect_success \
1876 'Q: verify first note for first commit' \
1877 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1879 echo "$note2_data" >expect
1880 test_expect_success \
1881 'Q: verify first note for second commit' \
1882 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1884 echo "$note3_data" >expect
1885 test_expect_success \
1886 'Q: verify first note for third commit' \
1887 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1889 cat >expect <<EOF
1890 parent `git rev-parse --verify refs/notes/foobar~2`
1891 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1892 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1894 notes (:10)
1896 test_expect_success \
1897 'Q: verify second notes commit' \
1898 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1899 test_cmp expect actual'
1901 cat >expect.unsorted <<EOF
1902 100644 blob $commit1
1903 100644 blob $commit2
1904 100644 blob $commit3
1906 cat expect.unsorted | sort >expect
1907 test_expect_success \
1908 'Q: verify second notes tree' \
1909 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1910 test_cmp expect actual'
1912 echo "$note1b_data" >expect
1913 test_expect_success \
1914 'Q: verify second note for first commit' \
1915 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1917 echo "$note2_data" >expect
1918 test_expect_success \
1919 'Q: verify first note for second commit' \
1920 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1922 echo "$note3_data" >expect
1923 test_expect_success \
1924 'Q: verify first note for third commit' \
1925 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1927 cat >expect <<EOF
1928 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1929 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1931 notes (:11)
1933 test_expect_success \
1934 'Q: verify third notes commit' \
1935 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1936 test_cmp expect actual'
1938 cat >expect.unsorted <<EOF
1939 100644 blob $commit1
1941 cat expect.unsorted | sort >expect
1942 test_expect_success \
1943 'Q: verify third notes tree' \
1944 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1945 test_cmp expect actual'
1947 echo "$note1c_data" >expect
1948 test_expect_success \
1949 'Q: verify third note for first commit' \
1950 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1952 cat >expect <<EOF
1953 parent `git rev-parse --verify refs/notes/foobar^`
1954 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1955 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1957 notes (:12)
1959 test_expect_success \
1960 'Q: verify fourth notes commit' \
1961 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1962 test_cmp expect actual'
1964 cat >expect.unsorted <<EOF
1965 100644 blob $commit2
1967 cat expect.unsorted | sort >expect
1968 test_expect_success \
1969 'Q: verify fourth notes tree' \
1970 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1971 test_cmp expect actual'
1973 echo "$note2b_data" >expect
1974 test_expect_success \
1975 'Q: verify second note for second commit' \
1976 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1979 ### series R (feature and option)
1982 cat >input <<EOF
1983 feature no-such-feature-exists
1986 test_expect_success 'R: abort on unsupported feature' '
1987 test_must_fail git fast-import <input
1990 cat >input <<EOF
1991 feature date-format=now
1994 test_expect_success 'R: supported feature is accepted' '
1995 git fast-import <input
1998 cat >input << EOF
1999 blob
2000 data 3
2002 feature date-format=now
2005 test_expect_success 'R: abort on receiving feature after data command' '
2006 test_must_fail git fast-import <input
2009 cat >input << EOF
2010 feature import-marks=git.marks
2011 feature import-marks=git2.marks
2014 test_expect_success 'R: only one import-marks feature allowed per stream' '
2015 test_must_fail git fast-import <input
2018 cat >input << EOF
2019 feature export-marks=git.marks
2020 blob
2021 mark :1
2022 data 3
2027 test_expect_success \
2028 'R: export-marks feature results in a marks file being created' \
2029 'cat input | git fast-import &&
2030 grep :1 git.marks'
2032 test_expect_success \
2033 'R: export-marks options can be overriden by commandline options' \
2034 'cat input | git fast-import --export-marks=other.marks &&
2035 grep :1 other.marks'
2037 test_expect_success 'R: catch typo in marks file name' '
2038 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2039 echo "feature import-marks=nonexistent.marks" |
2040 test_must_fail git fast-import
2043 test_expect_success 'R: import and output marks can be the same file' '
2044 rm -f io.marks &&
2045 blob=$(echo hi | git hash-object --stdin) &&
2046 cat >expect <<-EOF &&
2047 :1 $blob
2048 :2 $blob
2050 git fast-import --export-marks=io.marks <<-\EOF &&
2051 blob
2052 mark :1
2053 data 3
2057 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2058 blob
2059 mark :2
2060 data 3
2064 test_cmp expect io.marks
2067 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2068 rm -f io.marks &&
2069 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2070 blob
2071 mark :1
2072 data 3
2078 test_expect_success 'R: --import-marks-if-exists' '
2079 rm -f io.marks &&
2080 blob=$(echo hi | git hash-object --stdin) &&
2081 echo ":1 $blob" >expect &&
2082 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2083 blob
2084 mark :1
2085 data 3
2089 test_cmp expect io.marks
2092 test_expect_success 'R: feature import-marks-if-exists' '
2093 rm -f io.marks &&
2094 >expect &&
2096 git fast-import --export-marks=io.marks <<-\EOF &&
2097 feature import-marks-if-exists=not_io.marks
2099 test_cmp expect io.marks &&
2101 blob=$(echo hi | git hash-object --stdin) &&
2103 echo ":1 $blob" >io.marks &&
2104 echo ":1 $blob" >expect &&
2105 echo ":2 $blob" >>expect &&
2107 git fast-import --export-marks=io.marks <<-\EOF &&
2108 feature import-marks-if-exists=io.marks
2109 blob
2110 mark :2
2111 data 3
2115 test_cmp expect io.marks &&
2117 echo ":3 $blob" >>expect &&
2119 git fast-import --import-marks=io.marks \
2120 --export-marks=io.marks <<-\EOF &&
2121 feature import-marks-if-exists=not_io.marks
2122 blob
2123 mark :3
2124 data 3
2128 test_cmp expect io.marks &&
2130 >expect &&
2132 git fast-import --import-marks-if-exists=not_io.marks \
2133 --export-marks=io.marks <<-\EOF
2134 feature import-marks-if-exists=io.marks
2136 test_cmp expect io.marks
2139 cat >input << EOF
2140 feature import-marks=marks.out
2141 feature export-marks=marks.new
2144 test_expect_success \
2145 'R: import to output marks works without any content' \
2146 'cat input | git fast-import &&
2147 test_cmp marks.out marks.new'
2149 cat >input <<EOF
2150 feature import-marks=nonexistent.marks
2151 feature export-marks=marks.new
2154 test_expect_success \
2155 'R: import marks prefers commandline marks file over the stream' \
2156 'cat input | git fast-import --import-marks=marks.out &&
2157 test_cmp marks.out marks.new'
2160 cat >input <<EOF
2161 feature import-marks=nonexistent.marks
2162 feature export-marks=combined.marks
2165 test_expect_success 'R: multiple --import-marks= should be honoured' '
2166 head -n2 marks.out > one.marks &&
2167 tail -n +3 marks.out > two.marks &&
2168 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2169 test_cmp marks.out combined.marks
2172 cat >input <<EOF
2173 feature relative-marks
2174 feature import-marks=relative.in
2175 feature export-marks=relative.out
2178 test_expect_success 'R: feature relative-marks should be honoured' '
2179 mkdir -p .git/info/fast-import/ &&
2180 cp marks.new .git/info/fast-import/relative.in &&
2181 git fast-import <input &&
2182 test_cmp marks.new .git/info/fast-import/relative.out
2185 cat >input <<EOF
2186 feature relative-marks
2187 feature import-marks=relative.in
2188 feature no-relative-marks
2189 feature export-marks=non-relative.out
2192 test_expect_success 'R: feature no-relative-marks should be honoured' '
2193 git fast-import <input &&
2194 test_cmp marks.new non-relative.out
2197 test_expect_success 'R: feature ls supported' '
2198 echo "feature ls" |
2199 git fast-import
2202 test_expect_success 'R: feature cat-blob supported' '
2203 echo "feature cat-blob" |
2204 git fast-import
2207 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2208 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2211 test_expect_success 'R: print old blob' '
2212 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2213 cat >expect <<-EOF &&
2214 ${blob} blob 11
2215 yes it can
2218 echo "cat-blob $blob" |
2219 git fast-import --cat-blob-fd=6 6>actual &&
2220 test_cmp expect actual
2223 test_expect_success 'R: in-stream cat-blob-fd not respected' '
2224 echo hello >greeting &&
2225 blob=$(git hash-object -w greeting) &&
2226 cat >expect <<-EOF &&
2227 ${blob} blob 6
2228 hello
2231 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2232 cat-blob $blob
2234 test_cmp expect actual.3 &&
2235 test_cmp empty actual.1 &&
2236 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2237 option cat-blob-fd=3
2238 cat-blob $blob
2240 test_cmp empty actual.3 &&
2241 test_cmp expect actual.1
2244 test_expect_success 'R: print new blob' '
2245 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2246 cat >expect <<-EOF &&
2247 ${blob} blob 12
2248 yep yep yep
2251 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2252 blob
2253 mark :1
2254 data <<BLOB_END
2255 yep yep yep
2256 BLOB_END
2257 cat-blob :1
2259 test_cmp expect actual
2262 test_expect_success 'R: print new blob by sha1' '
2263 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2264 cat >expect <<-EOF &&
2265 ${blob} blob 25
2266 a new blob named by sha1
2269 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2270 blob
2271 data <<BLOB_END
2272 a new blob named by sha1
2273 BLOB_END
2274 cat-blob $blob
2276 test_cmp expect actual
2279 test_expect_success 'setup: big file' '
2281 echo "the quick brown fox jumps over the lazy dog" >big &&
2282 for i in 1 2 3
2284 cat big big big big >bigger &&
2285 cat bigger bigger bigger bigger >big ||
2286 exit
2287 done
2291 test_expect_success 'R: print two blobs to stdout' '
2292 blob1=$(git hash-object big) &&
2293 blob1_len=$(wc -c <big) &&
2294 blob2=$(echo hello | git hash-object --stdin) &&
2296 echo ${blob1} blob $blob1_len &&
2297 cat big &&
2298 cat <<-EOF
2300 ${blob2} blob 6
2301 hello
2304 } >expect &&
2306 cat <<-\END_PART1 &&
2307 blob
2308 mark :1
2309 data <<data_end
2310 END_PART1
2311 cat big &&
2312 cat <<-\EOF
2313 data_end
2314 blob
2315 mark :2
2316 data <<data_end
2317 hello
2318 data_end
2319 cat-blob :1
2320 cat-blob :2
2323 git fast-import >actual &&
2324 test_cmp expect actual
2327 test_expect_success PIPE 'R: copy using cat-file' '
2328 expect_id=$(git hash-object big) &&
2329 expect_len=$(wc -c <big) &&
2330 echo $expect_id blob $expect_len >expect.response &&
2332 rm -f blobs &&
2333 cat >frontend <<-\FRONTEND_END &&
2334 #!/bin/sh
2335 FRONTEND_END
2337 mkfifo blobs &&
2339 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2340 cat <<-\EOF &&
2341 feature cat-blob
2342 blob
2343 mark :1
2344 data <<BLOB
2346 cat big &&
2347 cat <<-\EOF &&
2348 BLOB
2349 cat-blob :1
2352 read blob_id type size <&3 &&
2353 echo "$blob_id $type $size" >response &&
2354 head_c $size >blob <&3 &&
2355 read newline <&3 &&
2357 cat <<-EOF &&
2358 commit refs/heads/copied
2359 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2360 data <<COMMIT
2361 copy big file as file3
2362 COMMIT
2363 M 644 inline file3
2364 data <<BLOB
2366 cat blob &&
2367 echo BLOB
2368 ) 3<blobs |
2369 git fast-import --cat-blob-fd=3 3>blobs &&
2370 git show copied:file3 >actual &&
2371 test_cmp expect.response response &&
2372 test_cmp big actual
2375 test_expect_success PIPE 'R: print blob mid-commit' '
2376 rm -f blobs &&
2377 echo "A blob from _before_ the commit." >expect &&
2378 mkfifo blobs &&
2380 exec 3<blobs &&
2381 cat <<-EOF &&
2382 feature cat-blob
2383 blob
2384 mark :1
2385 data <<BLOB
2386 A blob from _before_ the commit.
2387 BLOB
2388 commit refs/heads/temporary
2389 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2390 data <<COMMIT
2391 Empty commit
2392 COMMIT
2393 cat-blob :1
2396 read blob_id type size <&3 &&
2397 head_c $size >actual <&3 &&
2398 read newline <&3 &&
2400 echo
2402 git fast-import --cat-blob-fd=3 3>blobs &&
2403 test_cmp expect actual
2406 test_expect_success PIPE 'R: print staged blob within commit' '
2407 rm -f blobs &&
2408 echo "A blob from _within_ the commit." >expect &&
2409 mkfifo blobs &&
2411 exec 3<blobs &&
2412 cat <<-EOF &&
2413 feature cat-blob
2414 commit refs/heads/within
2415 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2416 data <<COMMIT
2417 Empty commit
2418 COMMIT
2419 M 644 inline within
2420 data <<BLOB
2421 A blob from _within_ the commit.
2422 BLOB
2425 to_get=$(
2426 echo "A blob from _within_ the commit." |
2427 git hash-object --stdin
2428 ) &&
2429 echo "cat-blob $to_get" &&
2431 read blob_id type size <&3 &&
2432 head_c $size >actual <&3 &&
2433 read newline <&3 &&
2435 echo deleteall
2437 git fast-import --cat-blob-fd=3 3>blobs &&
2438 test_cmp expect actual
2441 cat >input << EOF
2442 option git quiet
2443 blob
2444 data 3
2449 test_expect_success 'R: quiet option results in no stats being output' '
2450 cat input | git fast-import 2> output &&
2451 test_cmp empty output
2454 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2455 echo feature done | test_must_fail git fast-import &&
2456 test_must_fail git fast-import --done </dev/null
2459 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2460 git fast-import <<-\EOF &&
2461 feature done
2462 done
2463 trailing gibberish
2465 git fast-import <<-\EOF
2466 done
2467 more trailing gibberish
2471 test_expect_success 'R: terminating "done" within commit' '
2472 cat >expect <<-\EOF &&
2473 OBJID
2474 :000000 100644 OBJID OBJID A hello.c
2475 :000000 100644 OBJID OBJID A hello2.c
2477 git fast-import <<-EOF &&
2478 commit refs/heads/done-ends
2479 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2480 data <<EOT
2481 Commit terminated by "done" command
2483 M 100644 inline hello.c
2484 data <<EOT
2485 Hello, world.
2487 C hello.c hello2.c
2488 done
2490 git rev-list done-ends |
2491 git diff-tree -r --stdin --root --always |
2492 sed -e "s/$_x40/OBJID/g" >actual &&
2493 test_cmp expect actual
2496 cat >input <<EOF
2497 option git non-existing-option
2500 test_expect_success 'R: die on unknown option' '
2501 test_must_fail git fast-import <input
2504 test_expect_success 'R: unknown commandline options are rejected' '\
2505 test_must_fail git fast-import --non-existing-option < /dev/null
2508 test_expect_success 'R: die on invalid option argument' '
2509 echo "option git active-branches=-5" |
2510 test_must_fail git fast-import &&
2511 echo "option git depth=" |
2512 test_must_fail git fast-import &&
2513 test_must_fail git fast-import --depth="5 elephants" </dev/null
2516 cat >input <<EOF
2517 option non-existing-vcs non-existing-option
2520 test_expect_success 'R: ignore non-git options' '
2521 git fast-import <input
2525 ## R: very large blobs
2527 blobsize=$((2*1024*1024 + 53))
2528 test-genrandom bar $blobsize >expect
2529 cat >input <<INPUT_END
2530 commit refs/heads/big-file
2531 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2532 data <<COMMIT
2533 R - big file
2534 COMMIT
2536 M 644 inline big1
2537 data $blobsize
2538 INPUT_END
2539 cat expect >>input
2540 cat >>input <<INPUT_END
2541 M 644 inline big2
2542 data $blobsize
2543 INPUT_END
2544 cat expect >>input
2545 echo >>input
2547 test_expect_success \
2548 'R: blob bigger than threshold' \
2549 'test_create_repo R &&
2550 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2551 test_expect_success \
2552 'R: verify created pack' \
2553 ': >verify &&
2554 for p in R/.git/objects/pack/*.pack;
2556 git verify-pack -v $p >>verify || exit;
2557 done'
2558 test_expect_success \
2559 'R: verify written objects' \
2560 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2561 test_cmp expect actual &&
2562 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2563 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2564 test $a = $b'
2565 test_expect_success \
2566 'R: blob appears only once' \
2567 'n=$(grep $a verify | wc -l) &&
2568 test 1 = $n'
2570 test_done