Fix typo: existant->existent
[git/gitweb.git] / t / t9300-fast-import.sh
blob2a53640c5b29c19a2327570148638dbf94bc2afa
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 INPUT_END
98 test_expect_success \
99 'A: create pack from stdin' \
100 'git fast-import --export-marks=marks.out <input &&
101 git whatchanged master'
102 test_expect_success \
103 'A: verify pack' \
104 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
106 cat >expect <<EOF
107 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
110 initial
112 test_expect_success \
113 'A: verify commit' \
114 'git cat-file commit master | sed 1d >actual &&
115 test_cmp expect actual'
117 cat >expect <<EOF
118 100644 blob file2
119 100644 blob file3
120 100755 blob file4
122 test_expect_success \
123 'A: verify tree' \
124 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
125 test_cmp expect actual'
127 echo "$file2_data" >expect
128 test_expect_success \
129 'A: verify file2' \
130 'git cat-file blob master:file2 >actual && test_cmp expect actual'
132 echo "$file3_data" >expect
133 test_expect_success \
134 'A: verify file3' \
135 'git cat-file blob master:file3 >actual && test_cmp expect actual'
137 printf "$file4_data" >expect
138 test_expect_success \
139 'A: verify file4' \
140 'git cat-file blob master:file4 >actual && test_cmp expect actual'
142 cat >expect <<EOF
143 object $(git rev-parse refs/heads/master)
144 type commit
145 tag series-A
147 An annotated tag without a tagger
149 test_expect_success 'A: verify tag/series-A' '
150 git cat-file tag tags/series-A >actual &&
151 test_cmp expect actual
154 cat >expect <<EOF
155 :2 `git rev-parse --verify master:file2`
156 :3 `git rev-parse --verify master:file3`
157 :4 `git rev-parse --verify master:file4`
158 :5 `git rev-parse --verify master^0`
160 test_expect_success \
161 'A: verify marks output' \
162 'test_cmp expect marks.out'
164 test_expect_success \
165 'A: verify marks import' \
166 'git fast-import \
167 --import-marks=marks.out \
168 --export-marks=marks.new \
169 </dev/null &&
170 test_cmp expect marks.new'
172 test_tick
173 cat >input <<INPUT_END
174 commit refs/heads/verify--import-marks
175 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
176 data <<COMMIT
177 recreate from :5
178 COMMIT
180 from :5
181 M 755 :2 copy-of-file2
183 INPUT_END
184 test_expect_success \
185 'A: verify marks import does not crash' \
186 'git fast-import --import-marks=marks.out <input &&
187 git whatchanged verify--import-marks'
188 test_expect_success \
189 'A: verify pack' \
190 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
191 cat >expect <<EOF
192 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
194 git diff-tree -M -r master verify--import-marks >actual
195 test_expect_success \
196 'A: verify diff' \
197 'compare_diff_raw expect actual &&
198 test `git rev-parse --verify master:file2` \
199 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
201 test_tick
202 mt=$(git hash-object --stdin < /dev/null)
203 : >input.blob
204 : >marks.exp
205 : >tree.exp
207 cat >input.commit <<EOF
208 commit refs/heads/verify--dump-marks
209 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
210 data <<COMMIT
211 test the sparse array dumping routines with exponentially growing marks
212 COMMIT
219 while test "$i" -lt 27; do
220 cat >>input.blob <<EOF
221 blob
222 mark :$l
223 data 0
224 blob
225 mark :$m
226 data 0
227 blob
228 mark :$n
229 data 0
231 echo "M 100644 :$l l$i" >>input.commit
232 echo "M 100644 :$m m$i" >>input.commit
233 echo "M 100644 :$n n$i" >>input.commit
235 echo ":$l $mt" >>marks.exp
236 echo ":$m $mt" >>marks.exp
237 echo ":$n $mt" >>marks.exp
239 printf "100644 blob $mt\tl$i\n" >>tree.exp
240 printf "100644 blob $mt\tm$i\n" >>tree.exp
241 printf "100644 blob $mt\tn$i\n" >>tree.exp
243 l=$(($l + $l))
244 m=$(($m + $m))
245 n=$(($l + $n))
247 i=$((1 + $i))
248 done
250 sort tree.exp > tree.exp_s
252 test_expect_success 'A: export marks with large values' '
253 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
254 git ls-tree refs/heads/verify--dump-marks >tree.out &&
255 test_cmp tree.exp_s tree.out &&
256 test_cmp marks.exp marks.large'
259 ### series B
262 test_tick
263 cat >input <<INPUT_END
264 commit refs/heads/branch
265 mark :1
266 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
267 data <<COMMIT
268 corrupt
269 COMMIT
271 from refs/heads/master
272 M 755 0000000000000000000000000000000000000001 zero1
274 INPUT_END
275 test_expect_success 'B: fail on invalid blob sha1' '
276 test_must_fail git fast-import <input
278 rm -f .git/objects/pack_* .git/objects/index_*
280 cat >input <<INPUT_END
281 commit .badbranchname
282 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
283 data <<COMMIT
284 corrupt
285 COMMIT
287 from refs/heads/master
289 INPUT_END
290 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
291 test_must_fail git fast-import <input
293 rm -f .git/objects/pack_* .git/objects/index_*
295 cat >input <<INPUT_END
296 commit bad[branch]name
297 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
298 data <<COMMIT
299 corrupt
300 COMMIT
302 from refs/heads/master
304 INPUT_END
305 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
306 test_must_fail git fast-import <input
308 rm -f .git/objects/pack_* .git/objects/index_*
310 cat >input <<INPUT_END
311 commit TEMP_TAG
312 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
313 data <<COMMIT
314 tag base
315 COMMIT
317 from refs/heads/master
319 INPUT_END
320 test_expect_success \
321 'B: accept branch name "TEMP_TAG"' \
322 'git fast-import <input &&
323 test -f .git/TEMP_TAG &&
324 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
325 rm -f .git/TEMP_TAG
328 ### series C
331 newf=`echo hi newf | git hash-object -w --stdin`
332 oldf=`git rev-parse --verify master:file2`
333 test_tick
334 cat >input <<INPUT_END
335 commit refs/heads/branch
336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
337 data <<COMMIT
338 second
339 COMMIT
341 from refs/heads/master
342 M 644 $oldf file2/oldf
343 M 755 $newf file2/newf
344 D file3
346 INPUT_END
347 test_expect_success \
348 'C: incremental import create pack from stdin' \
349 'git fast-import <input &&
350 git whatchanged branch'
351 test_expect_success \
352 'C: verify pack' \
353 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
354 test_expect_success \
355 'C: validate reuse existing blob' \
356 'test $newf = `git rev-parse --verify branch:file2/newf` &&
357 test $oldf = `git rev-parse --verify branch:file2/oldf`'
359 cat >expect <<EOF
360 parent `git rev-parse --verify master^0`
361 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
362 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
364 second
366 test_expect_success \
367 'C: verify commit' \
368 'git cat-file commit branch | sed 1d >actual &&
369 test_cmp expect actual'
371 cat >expect <<EOF
372 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
373 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
374 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
376 git diff-tree -M -r master branch >actual
377 test_expect_success \
378 'C: validate rename result' \
379 'compare_diff_raw expect actual'
382 ### series D
385 test_tick
386 cat >input <<INPUT_END
387 commit refs/heads/branch
388 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
389 data <<COMMIT
390 third
391 COMMIT
393 from refs/heads/branch^0
394 M 644 inline newdir/interesting
395 data <<EOF
396 $file5_data
399 M 755 inline newdir/exec.sh
400 data <<EOF
401 $file6_data
404 INPUT_END
405 test_expect_success \
406 'D: inline data in commit' \
407 'git fast-import <input &&
408 git whatchanged branch'
409 test_expect_success \
410 'D: verify pack' \
411 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
413 cat >expect <<EOF
414 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
415 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
417 git diff-tree -M -r branch^ branch >actual
418 test_expect_success \
419 'D: validate new files added' \
420 'compare_diff_raw expect actual'
422 echo "$file5_data" >expect
423 test_expect_success \
424 'D: verify file5' \
425 'git cat-file blob branch:newdir/interesting >actual &&
426 test_cmp expect actual'
428 echo "$file6_data" >expect
429 test_expect_success \
430 'D: verify file6' \
431 'git cat-file blob branch:newdir/exec.sh >actual &&
432 test_cmp expect actual'
435 ### series E
438 cat >input <<INPUT_END
439 commit refs/heads/branch
440 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
441 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
442 data <<COMMIT
443 RFC 2822 type date
444 COMMIT
446 from refs/heads/branch^0
448 INPUT_END
449 test_expect_success 'E: rfc2822 date, --date-format=raw' '
450 test_must_fail git fast-import --date-format=raw <input
452 test_expect_success \
453 'E: rfc2822 date, --date-format=rfc2822' \
454 'git fast-import --date-format=rfc2822 <input'
455 test_expect_success \
456 'E: verify pack' \
457 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
459 cat >expect <<EOF
460 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
461 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
463 RFC 2822 type date
465 test_expect_success \
466 'E: verify commit' \
467 'git cat-file commit branch | sed 1,2d >actual &&
468 test_cmp expect actual'
471 ### series F
474 old_branch=`git rev-parse --verify branch^0`
475 test_tick
476 cat >input <<INPUT_END
477 commit refs/heads/branch
478 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
479 data <<COMMIT
480 losing things already?
481 COMMIT
483 from refs/heads/branch~1
485 reset refs/heads/other
486 from refs/heads/branch
488 INPUT_END
489 test_expect_success \
490 'F: non-fast-forward update skips' \
491 'if git fast-import <input
492 then
493 echo BAD gfi did not fail
494 return 1
495 else
496 if test $old_branch = `git rev-parse --verify branch^0`
497 then
498 : branch unaffected and failure returned
499 return 0
500 else
501 echo BAD gfi changed branch $old_branch
502 return 1
506 test_expect_success \
507 'F: verify pack' \
508 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
510 cat >expect <<EOF
511 tree `git rev-parse branch~1^{tree}`
512 parent `git rev-parse branch~1`
513 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
514 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
516 losing things already?
518 test_expect_success \
519 'F: verify other commit' \
520 'git cat-file commit other >actual &&
521 test_cmp expect actual'
524 ### series G
527 old_branch=`git rev-parse --verify branch^0`
528 test_tick
529 cat >input <<INPUT_END
530 commit refs/heads/branch
531 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
532 data <<COMMIT
533 losing things already?
534 COMMIT
536 from refs/heads/branch~1
538 INPUT_END
539 test_expect_success \
540 'G: non-fast-forward update forced' \
541 'git fast-import --force <input'
542 test_expect_success \
543 'G: verify pack' \
544 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
545 test_expect_success \
546 'G: branch changed, but logged' \
547 'test $old_branch != `git rev-parse --verify branch^0` &&
548 test $old_branch = `git rev-parse --verify branch@{1}`'
551 ### series H
554 test_tick
555 cat >input <<INPUT_END
556 commit refs/heads/H
557 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
558 data <<COMMIT
559 third
560 COMMIT
562 from refs/heads/branch^0
563 M 644 inline i-will-die
564 data <<EOF
565 this file will never exist.
568 deleteall
569 M 644 inline h/e/l/lo
570 data <<EOF
571 $file5_data
574 INPUT_END
575 test_expect_success \
576 'H: deletall, add 1' \
577 'git fast-import <input &&
578 git whatchanged H'
579 test_expect_success \
580 'H: verify pack' \
581 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
583 cat >expect <<EOF
584 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
585 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
586 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
587 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
588 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
590 git diff-tree -M -r H^ H >actual
591 test_expect_success \
592 'H: validate old files removed, new files added' \
593 'compare_diff_raw expect actual'
595 echo "$file5_data" >expect
596 test_expect_success \
597 'H: verify file' \
598 'git cat-file blob H:h/e/l/lo >actual &&
599 test_cmp expect actual'
602 ### series I
605 cat >input <<INPUT_END
606 commit refs/heads/export-boundary
607 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
608 data <<COMMIT
609 we have a border. its only 40 characters wide.
610 COMMIT
612 from refs/heads/branch
614 INPUT_END
615 test_expect_success \
616 'I: export-pack-edges' \
617 'git fast-import --export-pack-edges=edges.list <input'
619 cat >expect <<EOF
620 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
622 test_expect_success \
623 'I: verify edge list' \
624 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
625 test_cmp expect actual'
628 ### series J
631 cat >input <<INPUT_END
632 commit refs/heads/J
633 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
634 data <<COMMIT
635 create J
636 COMMIT
638 from refs/heads/branch
640 reset refs/heads/J
642 commit refs/heads/J
643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
644 data <<COMMIT
645 initialize J
646 COMMIT
648 INPUT_END
649 test_expect_success \
650 'J: reset existing branch creates empty commit' \
651 'git fast-import <input'
652 test_expect_success \
653 'J: branch has 1 commit, empty tree' \
654 'test 1 = `git rev-list J | wc -l` &&
655 test 0 = `git ls-tree J | wc -l`'
658 ### series K
661 cat >input <<INPUT_END
662 commit refs/heads/K
663 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
664 data <<COMMIT
665 create K
666 COMMIT
668 from refs/heads/branch
670 commit refs/heads/K
671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
672 data <<COMMIT
673 redo K
674 COMMIT
676 from refs/heads/branch^1
678 INPUT_END
679 test_expect_success \
680 'K: reinit branch with from' \
681 'git fast-import <input'
682 test_expect_success \
683 'K: verify K^1 = branch^1' \
684 'test `git rev-parse --verify branch^1` \
685 = `git rev-parse --verify K^1`'
688 ### series L
691 cat >input <<INPUT_END
692 blob
693 mark :1
694 data <<EOF
695 some data
698 blob
699 mark :2
700 data <<EOF
701 other data
704 commit refs/heads/L
705 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
706 data <<COMMIT
707 create L
708 COMMIT
710 M 644 :1 b.
711 M 644 :1 b/other
712 M 644 :1 ba
714 commit refs/heads/L
715 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
716 data <<COMMIT
717 update L
718 COMMIT
720 M 644 :2 b.
721 M 644 :2 b/other
722 M 644 :2 ba
723 INPUT_END
725 cat >expect <<EXPECT_END
726 :100644 100644 4268632... 55d3a52... M b.
727 :040000 040000 0ae5cac... 443c768... M b
728 :100644 100644 4268632... 55d3a52... M ba
729 EXPECT_END
731 test_expect_success \
732 'L: verify internal tree sorting' \
733 'git fast-import <input &&
734 git diff-tree --abbrev --raw L^ L >output &&
735 test_cmp expect output'
738 ### series M
741 test_tick
742 cat >input <<INPUT_END
743 commit refs/heads/M1
744 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
745 data <<COMMIT
746 file rename
747 COMMIT
749 from refs/heads/branch^0
750 R file2/newf file2/n.e.w.f
752 INPUT_END
754 cat >expect <<EOF
755 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
757 test_expect_success \
758 'M: rename file in same subdirectory' \
759 'git fast-import <input &&
760 git diff-tree -M -r M1^ M1 >actual &&
761 compare_diff_raw expect actual'
763 cat >input <<INPUT_END
764 commit refs/heads/M2
765 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
766 data <<COMMIT
767 file rename
768 COMMIT
770 from refs/heads/branch^0
771 R file2/newf i/am/new/to/you
773 INPUT_END
775 cat >expect <<EOF
776 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
778 test_expect_success \
779 'M: rename file to new subdirectory' \
780 'git fast-import <input &&
781 git diff-tree -M -r M2^ M2 >actual &&
782 compare_diff_raw expect actual'
784 cat >input <<INPUT_END
785 commit refs/heads/M3
786 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
787 data <<COMMIT
788 file rename
789 COMMIT
791 from refs/heads/M2^0
792 R i other/sub
794 INPUT_END
796 cat >expect <<EOF
797 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
799 test_expect_success \
800 'M: rename subdirectory to new subdirectory' \
801 'git fast-import <input &&
802 git diff-tree -M -r M3^ M3 >actual &&
803 compare_diff_raw expect actual'
806 ### series N
809 test_tick
810 cat >input <<INPUT_END
811 commit refs/heads/N1
812 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
813 data <<COMMIT
814 file copy
815 COMMIT
817 from refs/heads/branch^0
818 C file2/newf file2/n.e.w.f
820 INPUT_END
822 cat >expect <<EOF
823 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
825 test_expect_success \
826 'N: copy file in same subdirectory' \
827 'git fast-import <input &&
828 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
829 compare_diff_raw expect actual'
831 cat >input <<INPUT_END
832 commit refs/heads/N2
833 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
834 data <<COMMIT
835 clean directory copy
836 COMMIT
838 from refs/heads/branch^0
839 C file2 file3
841 commit refs/heads/N2
842 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
843 data <<COMMIT
844 modify directory copy
845 COMMIT
847 M 644 inline file3/file5
848 data <<EOF
849 $file5_data
852 INPUT_END
854 cat >expect <<EOF
855 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
856 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
857 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
859 test_expect_success \
860 'N: copy then modify subdirectory' \
861 'git fast-import <input &&
862 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
863 compare_diff_raw expect actual'
865 cat >input <<INPUT_END
866 commit refs/heads/N3
867 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
868 data <<COMMIT
869 dirty directory copy
870 COMMIT
872 from refs/heads/branch^0
873 M 644 inline file2/file5
874 data <<EOF
875 $file5_data
878 C file2 file3
879 D file2/file5
881 INPUT_END
883 test_expect_success \
884 'N: copy dirty subdirectory' \
885 'git fast-import <input &&
886 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
888 test_expect_success \
889 'N: copy directory by id' \
890 'cat >expect <<-\EOF &&
891 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
892 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
894 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
895 cat >input <<-INPUT_END &&
896 commit refs/heads/N4
897 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
898 data <<COMMIT
899 copy by tree hash
900 COMMIT
902 from refs/heads/branch^0
903 M 040000 $subdir file3
904 INPUT_END
905 git fast-import <input &&
906 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
907 compare_diff_raw expect actual'
909 test_expect_success PIPE 'N: read and copy directory' '
910 cat >expect <<-\EOF
911 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
912 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
914 git update-ref -d refs/heads/N4 &&
915 rm -f backflow &&
916 mkfifo backflow &&
918 exec <backflow &&
919 cat <<-EOF &&
920 commit refs/heads/N4
921 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
922 data <<COMMIT
923 copy by tree hash, part 2
924 COMMIT
926 from refs/heads/branch^0
927 ls "file2"
929 read mode type tree filename &&
930 echo "M 040000 $tree file3"
932 git fast-import --cat-blob-fd=3 3>backflow &&
933 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
934 compare_diff_raw expect actual
937 test_expect_success PIPE 'N: empty directory reads as missing' '
938 cat <<-\EOF >expect &&
939 OBJNAME
940 :000000 100644 OBJNAME OBJNAME A unrelated
942 echo "missing src" >expect.response &&
943 git update-ref -d refs/heads/read-empty &&
944 rm -f backflow &&
945 mkfifo backflow &&
947 exec <backflow &&
948 cat <<-EOF &&
949 commit refs/heads/read-empty
950 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
951 data <<COMMIT
952 read "empty" (missing) directory
953 COMMIT
955 M 100644 inline src/greeting
956 data <<BLOB
957 hello
958 BLOB
959 C src/greeting dst1/non-greeting
960 C src/greeting unrelated
961 # leave behind "empty" src directory
962 D src/greeting
963 ls "src"
965 read -r line &&
966 printf "%s\n" "$line" >response &&
967 cat <<-\EOF
968 D dst1
969 D dst2
972 git fast-import --cat-blob-fd=3 3>backflow &&
973 test_cmp expect.response response &&
974 git rev-list read-empty |
975 git diff-tree -r --root --stdin |
976 sed "s/$_x40/OBJNAME/g" >actual &&
977 test_cmp expect actual
980 test_expect_success \
981 'N: copy root directory by tree hash' \
982 'cat >expect <<-\EOF &&
983 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
984 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
986 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
987 cat >input <<-INPUT_END &&
988 commit refs/heads/N6
989 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
990 data <<COMMIT
991 copy root directory by tree hash
992 COMMIT
994 from refs/heads/branch^0
995 M 040000 $root ""
996 INPUT_END
997 git fast-import <input &&
998 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
999 compare_diff_raw expect actual'
1001 test_expect_success \
1002 'N: delete directory by copying' \
1003 'cat >expect <<-\EOF &&
1004 OBJID
1005 :100644 000000 OBJID OBJID D foo/bar/qux
1006 OBJID
1007 :000000 100644 OBJID OBJID A foo/bar/baz
1008 :000000 100644 OBJID OBJID A foo/bar/qux
1010 empty_tree=$(git mktree </dev/null) &&
1011 cat >input <<-INPUT_END &&
1012 commit refs/heads/N-delete
1013 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1014 data <<COMMIT
1015 collect data to be deleted
1016 COMMIT
1018 deleteall
1019 M 100644 inline foo/bar/baz
1020 data <<DATA_END
1021 hello
1022 DATA_END
1023 C "foo/bar/baz" "foo/bar/qux"
1024 C "foo/bar/baz" "foo/bar/quux/1"
1025 C "foo/bar/baz" "foo/bar/quuux"
1026 M 040000 $empty_tree foo/bar/quux
1027 M 040000 $empty_tree foo/bar/quuux
1029 commit refs/heads/N-delete
1030 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1031 data <<COMMIT
1032 delete subdirectory
1033 COMMIT
1035 M 040000 $empty_tree foo/bar/qux
1036 INPUT_END
1037 git fast-import <input &&
1038 git rev-list N-delete |
1039 git diff-tree -r --stdin --root --always |
1040 sed -e "s/$_x40/OBJID/g" >actual &&
1041 test_cmp expect actual'
1043 test_expect_success \
1044 'N: modify copied tree' \
1045 'cat >expect <<-\EOF &&
1046 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1047 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1048 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1050 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1051 cat >input <<-INPUT_END &&
1052 commit refs/heads/N5
1053 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1054 data <<COMMIT
1055 copy by tree hash
1056 COMMIT
1058 from refs/heads/branch^0
1059 M 040000 $subdir file3
1061 commit refs/heads/N5
1062 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1063 data <<COMMIT
1064 modify directory copy
1065 COMMIT
1067 M 644 inline file3/file5
1068 data <<EOF
1069 $file5_data
1071 INPUT_END
1072 git fast-import <input &&
1073 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1074 compare_diff_raw expect actual'
1076 test_expect_success \
1077 'N: reject foo/ syntax' \
1078 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1079 test_must_fail git fast-import <<-INPUT_END
1080 commit refs/heads/N5B
1081 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1082 data <<COMMIT
1083 copy with invalid syntax
1084 COMMIT
1086 from refs/heads/branch^0
1087 M 040000 $subdir file3/
1088 INPUT_END'
1090 test_expect_success \
1091 'N: copy to root by id and modify' \
1092 'echo "hello, world" >expect.foo &&
1093 echo hello >expect.bar &&
1094 git fast-import <<-SETUP_END &&
1095 commit refs/heads/N7
1096 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1097 data <<COMMIT
1098 hello, tree
1099 COMMIT
1101 deleteall
1102 M 644 inline foo/bar
1103 data <<EOF
1104 hello
1106 SETUP_END
1108 tree=$(git rev-parse --verify N7:) &&
1109 git fast-import <<-INPUT_END &&
1110 commit refs/heads/N8
1111 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1112 data <<COMMIT
1113 copy to root by id and modify
1114 COMMIT
1116 M 040000 $tree ""
1117 M 644 inline foo/foo
1118 data <<EOF
1119 hello, world
1121 INPUT_END
1122 git show N8:foo/foo >actual.foo &&
1123 git show N8:foo/bar >actual.bar &&
1124 test_cmp expect.foo actual.foo &&
1125 test_cmp expect.bar actual.bar'
1127 test_expect_success \
1128 'N: extract subtree' \
1129 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1130 cat >input <<-INPUT_END &&
1131 commit refs/heads/N9
1132 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1133 data <<COMMIT
1134 extract subtree branch:newdir
1135 COMMIT
1137 M 040000 $branch ""
1138 C "newdir" ""
1139 INPUT_END
1140 git fast-import <input &&
1141 git diff --exit-code branch:newdir N9'
1143 test_expect_success \
1144 'N: modify subtree, extract it, and modify again' \
1145 'echo hello >expect.baz &&
1146 echo hello, world >expect.qux &&
1147 git fast-import <<-SETUP_END &&
1148 commit refs/heads/N10
1149 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1150 data <<COMMIT
1151 hello, tree
1152 COMMIT
1154 deleteall
1155 M 644 inline foo/bar/baz
1156 data <<EOF
1157 hello
1159 SETUP_END
1161 tree=$(git rev-parse --verify N10:) &&
1162 git fast-import <<-INPUT_END &&
1163 commit refs/heads/N11
1164 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1165 data <<COMMIT
1166 copy to root by id and modify
1167 COMMIT
1169 M 040000 $tree ""
1170 M 100644 inline foo/bar/qux
1171 data <<EOF
1172 hello, world
1174 R "foo" ""
1175 C "bar/qux" "bar/quux"
1176 INPUT_END
1177 git show N11:bar/baz >actual.baz &&
1178 git show N11:bar/qux >actual.qux &&
1179 git show N11:bar/quux >actual.quux &&
1180 test_cmp expect.baz actual.baz &&
1181 test_cmp expect.qux actual.qux &&
1182 test_cmp expect.qux actual.quux'
1185 ### series O
1188 cat >input <<INPUT_END
1189 #we will
1190 commit refs/heads/O1
1191 # -- ignore all of this text
1192 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1193 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1194 data <<COMMIT
1195 dirty directory copy
1196 COMMIT
1198 # don't forget the import blank line!
1200 # yes, we started from our usual base of branch^0.
1201 # i like branch^0.
1202 from refs/heads/branch^0
1203 # and we need to reuse file2/file5 from N3 above.
1204 M 644 inline file2/file5
1205 # otherwise the tree will be different
1206 data <<EOF
1207 $file5_data
1210 # don't forget to copy file2 to file3
1211 C file2 file3
1213 # or to delete file5 from file2.
1214 D file2/file5
1215 # are we done yet?
1217 INPUT_END
1219 test_expect_success \
1220 'O: comments are all skipped' \
1221 'git fast-import <input &&
1222 test `git rev-parse N3` = `git rev-parse O1`'
1224 cat >input <<INPUT_END
1225 commit refs/heads/O2
1226 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1227 data <<COMMIT
1228 dirty directory copy
1229 COMMIT
1230 from refs/heads/branch^0
1231 M 644 inline file2/file5
1232 data <<EOF
1233 $file5_data
1235 C file2 file3
1236 D file2/file5
1238 INPUT_END
1240 test_expect_success \
1241 'O: blank lines not necessary after data commands' \
1242 'git fast-import <input &&
1243 test `git rev-parse N3` = `git rev-parse O2`'
1245 test_expect_success \
1246 'O: repack before next test' \
1247 'git repack -a -d'
1249 cat >input <<INPUT_END
1250 commit refs/heads/O3
1251 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1252 data <<COMMIT
1253 zstring
1254 COMMIT
1255 commit refs/heads/O3
1256 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1257 data <<COMMIT
1259 COMMIT
1260 checkpoint
1261 commit refs/heads/O3
1262 mark :5
1263 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1264 data <<COMMIT
1265 zempty
1266 COMMIT
1267 checkpoint
1268 commit refs/heads/O3
1269 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1270 data <<COMMIT
1271 zcommits
1272 COMMIT
1273 reset refs/tags/O3-2nd
1274 from :5
1275 reset refs/tags/O3-3rd
1276 from :5
1277 INPUT_END
1279 cat >expect <<INPUT_END
1280 string
1282 empty
1283 commits
1284 INPUT_END
1285 test_expect_success \
1286 'O: blank lines not necessary after other commands' \
1287 'git fast-import <input &&
1288 test 8 = `find .git/objects/pack -type f | wc -l` &&
1289 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1290 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1291 test_cmp expect actual'
1293 cat >input <<INPUT_END
1294 commit refs/heads/O4
1295 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1296 data <<COMMIT
1297 zstring
1298 COMMIT
1299 commit refs/heads/O4
1300 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1301 data <<COMMIT
1303 COMMIT
1304 progress Two commits down, 2 to go!
1305 commit refs/heads/O4
1306 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1307 data <<COMMIT
1308 zempty
1309 COMMIT
1310 progress Three commits down, 1 to go!
1311 commit refs/heads/O4
1312 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1313 data <<COMMIT
1314 zcommits
1315 COMMIT
1316 progress I'm done!
1317 INPUT_END
1318 test_expect_success \
1319 'O: progress outputs as requested by input' \
1320 'git fast-import <input >actual &&
1321 grep "progress " <input >expect &&
1322 test_cmp expect actual'
1325 ### series P (gitlinks)
1328 cat >input <<INPUT_END
1329 blob
1330 mark :1
1331 data 10
1332 test file
1334 reset refs/heads/sub
1335 commit refs/heads/sub
1336 mark :2
1337 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1338 data 12
1339 sub_initial
1340 M 100644 :1 file
1342 blob
1343 mark :3
1344 data <<DATAEND
1345 [submodule "sub"]
1346 path = sub
1347 url = "`pwd`/sub"
1348 DATAEND
1350 commit refs/heads/subuse1
1351 mark :4
1352 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1353 data 8
1354 initial
1355 from refs/heads/master
1356 M 100644 :3 .gitmodules
1357 M 160000 :2 sub
1359 blob
1360 mark :5
1361 data 20
1362 test file
1363 more data
1365 commit refs/heads/sub
1366 mark :6
1367 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1368 data 11
1369 sub_second
1370 from :2
1371 M 100644 :5 file
1373 commit refs/heads/subuse1
1374 mark :7
1375 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1376 data 7
1377 second
1378 from :4
1379 M 160000 :6 sub
1381 INPUT_END
1383 test_expect_success \
1384 'P: supermodule & submodule mix' \
1385 'git fast-import <input &&
1386 git checkout subuse1 &&
1387 rm -rf sub && mkdir sub && (cd sub &&
1388 git init &&
1389 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1390 git checkout master) &&
1391 git submodule init &&
1392 git submodule update'
1394 SUBLAST=$(git rev-parse --verify sub)
1395 SUBPREV=$(git rev-parse --verify sub^)
1397 cat >input <<INPUT_END
1398 blob
1399 mark :1
1400 data <<DATAEND
1401 [submodule "sub"]
1402 path = sub
1403 url = "`pwd`/sub"
1404 DATAEND
1406 commit refs/heads/subuse2
1407 mark :2
1408 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1409 data 8
1410 initial
1411 from refs/heads/master
1412 M 100644 :1 .gitmodules
1413 M 160000 $SUBPREV sub
1415 commit refs/heads/subuse2
1416 mark :3
1417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418 data 7
1419 second
1420 from :2
1421 M 160000 $SUBLAST sub
1423 INPUT_END
1425 test_expect_success \
1426 'P: verbatim SHA gitlinks' \
1427 'git branch -D sub &&
1428 git gc && git prune &&
1429 git fast-import <input &&
1430 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1432 test_tick
1433 cat >input <<INPUT_END
1434 commit refs/heads/subuse3
1435 mark :1
1436 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1437 data <<COMMIT
1438 corrupt
1439 COMMIT
1441 from refs/heads/subuse2
1442 M 160000 inline sub
1443 data <<DATA
1444 $SUBPREV
1445 DATA
1447 INPUT_END
1449 test_expect_success 'P: fail on inline gitlink' '
1450 test_must_fail git fast-import <input'
1452 test_tick
1453 cat >input <<INPUT_END
1454 blob
1455 mark :1
1456 data <<DATA
1457 $SUBPREV
1458 DATA
1460 commit refs/heads/subuse3
1461 mark :2
1462 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1463 data <<COMMIT
1464 corrupt
1465 COMMIT
1467 from refs/heads/subuse2
1468 M 160000 :1 sub
1470 INPUT_END
1472 test_expect_success 'P: fail on blob mark in gitlink' '
1473 test_must_fail git fast-import <input'
1476 ### series Q (notes)
1479 note1_data="The first note for the first commit"
1480 note2_data="The first note for the second commit"
1481 note3_data="The first note for the third commit"
1482 note1b_data="The second note for the first commit"
1483 note1c_data="The third note for the first commit"
1484 note2b_data="The second note for the second commit"
1486 test_tick
1487 cat >input <<INPUT_END
1488 blob
1489 mark :2
1490 data <<EOF
1491 $file2_data
1494 commit refs/heads/notes-test
1495 mark :3
1496 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1497 data <<COMMIT
1498 first (:3)
1499 COMMIT
1501 M 644 :2 file2
1503 blob
1504 mark :4
1505 data $file4_len
1506 $file4_data
1507 commit refs/heads/notes-test
1508 mark :5
1509 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1510 data <<COMMIT
1511 second (:5)
1512 COMMIT
1514 M 644 :4 file4
1516 commit refs/heads/notes-test
1517 mark :6
1518 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1519 data <<COMMIT
1520 third (:6)
1521 COMMIT
1523 M 644 inline file5
1524 data <<EOF
1525 $file5_data
1528 M 755 inline file6
1529 data <<EOF
1530 $file6_data
1533 blob
1534 mark :7
1535 data <<EOF
1536 $note1_data
1539 blob
1540 mark :8
1541 data <<EOF
1542 $note2_data
1545 commit refs/notes/foobar
1546 mark :9
1547 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1548 data <<COMMIT
1549 notes (:9)
1550 COMMIT
1552 N :7 :3
1553 N :8 :5
1554 N inline :6
1555 data <<EOF
1556 $note3_data
1559 commit refs/notes/foobar
1560 mark :10
1561 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1562 data <<COMMIT
1563 notes (:10)
1564 COMMIT
1566 N inline :3
1567 data <<EOF
1568 $note1b_data
1571 commit refs/notes/foobar2
1572 mark :11
1573 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1574 data <<COMMIT
1575 notes (:11)
1576 COMMIT
1578 N inline :3
1579 data <<EOF
1580 $note1c_data
1583 commit refs/notes/foobar
1584 mark :12
1585 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1586 data <<COMMIT
1587 notes (:12)
1588 COMMIT
1590 deleteall
1591 N inline :5
1592 data <<EOF
1593 $note2b_data
1596 INPUT_END
1598 test_expect_success \
1599 'Q: commit notes' \
1600 'git fast-import <input &&
1601 git whatchanged notes-test'
1602 test_expect_success \
1603 'Q: verify pack' \
1604 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1606 commit1=$(git rev-parse notes-test~2)
1607 commit2=$(git rev-parse notes-test^)
1608 commit3=$(git rev-parse notes-test)
1610 cat >expect <<EOF
1611 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1614 first (:3)
1616 test_expect_success \
1617 'Q: verify first commit' \
1618 'git cat-file commit notes-test~2 | sed 1d >actual &&
1619 test_cmp expect actual'
1621 cat >expect <<EOF
1622 parent $commit1
1623 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1624 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1626 second (:5)
1628 test_expect_success \
1629 'Q: verify second commit' \
1630 'git cat-file commit notes-test^ | sed 1d >actual &&
1631 test_cmp expect actual'
1633 cat >expect <<EOF
1634 parent $commit2
1635 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1636 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1638 third (:6)
1640 test_expect_success \
1641 'Q: verify third commit' \
1642 'git cat-file commit notes-test | sed 1d >actual &&
1643 test_cmp expect actual'
1645 cat >expect <<EOF
1646 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1647 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1649 notes (:9)
1651 test_expect_success \
1652 'Q: verify first notes commit' \
1653 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1654 test_cmp expect actual'
1656 cat >expect.unsorted <<EOF
1657 100644 blob $commit1
1658 100644 blob $commit2
1659 100644 blob $commit3
1661 cat expect.unsorted | sort >expect
1662 test_expect_success \
1663 'Q: verify first notes tree' \
1664 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1665 test_cmp expect actual'
1667 echo "$note1_data" >expect
1668 test_expect_success \
1669 'Q: verify first note for first commit' \
1670 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1672 echo "$note2_data" >expect
1673 test_expect_success \
1674 'Q: verify first note for second commit' \
1675 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1677 echo "$note3_data" >expect
1678 test_expect_success \
1679 'Q: verify first note for third commit' \
1680 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1682 cat >expect <<EOF
1683 parent `git rev-parse --verify refs/notes/foobar~2`
1684 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1685 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1687 notes (:10)
1689 test_expect_success \
1690 'Q: verify second notes commit' \
1691 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1692 test_cmp expect actual'
1694 cat >expect.unsorted <<EOF
1695 100644 blob $commit1
1696 100644 blob $commit2
1697 100644 blob $commit3
1699 cat expect.unsorted | sort >expect
1700 test_expect_success \
1701 'Q: verify second notes tree' \
1702 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1703 test_cmp expect actual'
1705 echo "$note1b_data" >expect
1706 test_expect_success \
1707 'Q: verify second note for first commit' \
1708 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1710 echo "$note2_data" >expect
1711 test_expect_success \
1712 'Q: verify first note for second commit' \
1713 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1715 echo "$note3_data" >expect
1716 test_expect_success \
1717 'Q: verify first note for third commit' \
1718 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1720 cat >expect <<EOF
1721 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1724 notes (:11)
1726 test_expect_success \
1727 'Q: verify third notes commit' \
1728 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1729 test_cmp expect actual'
1731 cat >expect.unsorted <<EOF
1732 100644 blob $commit1
1734 cat expect.unsorted | sort >expect
1735 test_expect_success \
1736 'Q: verify third notes tree' \
1737 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1738 test_cmp expect actual'
1740 echo "$note1c_data" >expect
1741 test_expect_success \
1742 'Q: verify third note for first commit' \
1743 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1745 cat >expect <<EOF
1746 parent `git rev-parse --verify refs/notes/foobar^`
1747 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1748 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1750 notes (:12)
1752 test_expect_success \
1753 'Q: verify fourth notes commit' \
1754 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1755 test_cmp expect actual'
1757 cat >expect.unsorted <<EOF
1758 100644 blob $commit2
1760 cat expect.unsorted | sort >expect
1761 test_expect_success \
1762 'Q: verify fourth notes tree' \
1763 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1764 test_cmp expect actual'
1766 echo "$note2b_data" >expect
1767 test_expect_success \
1768 'Q: verify second note for second commit' \
1769 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1772 ### series R (feature and option)
1775 cat >input <<EOF
1776 feature no-such-feature-exists
1779 test_expect_success 'R: abort on unsupported feature' '
1780 test_must_fail git fast-import <input
1783 cat >input <<EOF
1784 feature date-format=now
1787 test_expect_success 'R: supported feature is accepted' '
1788 git fast-import <input
1791 cat >input << EOF
1792 blob
1793 data 3
1795 feature date-format=now
1798 test_expect_success 'R: abort on receiving feature after data command' '
1799 test_must_fail git fast-import <input
1802 cat >input << EOF
1803 feature import-marks=git.marks
1804 feature import-marks=git2.marks
1807 test_expect_success 'R: only one import-marks feature allowed per stream' '
1808 test_must_fail git fast-import <input
1811 cat >input << EOF
1812 feature export-marks=git.marks
1813 blob
1814 mark :1
1815 data 3
1820 test_expect_success \
1821 'R: export-marks feature results in a marks file being created' \
1822 'cat input | git fast-import &&
1823 grep :1 git.marks'
1825 test_expect_success \
1826 'R: export-marks options can be overriden by commandline options' \
1827 'cat input | git fast-import --export-marks=other.marks &&
1828 grep :1 other.marks'
1830 test_expect_success 'R: catch typo in marks file name' '
1831 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
1832 echo "feature import-marks=nonexistent.marks" |
1833 test_must_fail git fast-import
1836 test_expect_success 'R: import and output marks can be the same file' '
1837 rm -f io.marks &&
1838 blob=$(echo hi | git hash-object --stdin) &&
1839 cat >expect <<-EOF &&
1840 :1 $blob
1841 :2 $blob
1843 git fast-import --export-marks=io.marks <<-\EOF &&
1844 blob
1845 mark :1
1846 data 3
1850 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
1851 blob
1852 mark :2
1853 data 3
1857 test_cmp expect io.marks
1860 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
1861 rm -f io.marks &&
1862 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
1863 blob
1864 mark :1
1865 data 3
1871 test_expect_success 'R: --import-marks-if-exists' '
1872 rm -f io.marks &&
1873 blob=$(echo hi | git hash-object --stdin) &&
1874 echo ":1 $blob" >expect &&
1875 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
1876 blob
1877 mark :1
1878 data 3
1882 test_cmp expect io.marks
1885 cat >input << EOF
1886 feature import-marks=marks.out
1887 feature export-marks=marks.new
1890 test_expect_success \
1891 'R: import to output marks works without any content' \
1892 'cat input | git fast-import &&
1893 test_cmp marks.out marks.new'
1895 cat >input <<EOF
1896 feature import-marks=nonexistent.marks
1897 feature export-marks=marks.new
1900 test_expect_success \
1901 'R: import marks prefers commandline marks file over the stream' \
1902 'cat input | git fast-import --import-marks=marks.out &&
1903 test_cmp marks.out marks.new'
1906 cat >input <<EOF
1907 feature import-marks=nonexistent.marks
1908 feature export-marks=combined.marks
1911 test_expect_success 'R: multiple --import-marks= should be honoured' '
1912 head -n2 marks.out > one.marks &&
1913 tail -n +3 marks.out > two.marks &&
1914 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
1915 test_cmp marks.out combined.marks
1918 cat >input <<EOF
1919 feature relative-marks
1920 feature import-marks=relative.in
1921 feature export-marks=relative.out
1924 test_expect_success 'R: feature relative-marks should be honoured' '
1925 mkdir -p .git/info/fast-import/ &&
1926 cp marks.new .git/info/fast-import/relative.in &&
1927 git fast-import <input &&
1928 test_cmp marks.new .git/info/fast-import/relative.out
1931 cat >input <<EOF
1932 feature relative-marks
1933 feature import-marks=relative.in
1934 feature no-relative-marks
1935 feature export-marks=non-relative.out
1938 test_expect_success 'R: feature no-relative-marks should be honoured' '
1939 git fast-import <input &&
1940 test_cmp marks.new non-relative.out
1943 test_expect_success 'R: feature ls supported' '
1944 echo "feature ls" |
1945 git fast-import
1948 test_expect_success 'R: feature cat-blob supported' '
1949 echo "feature cat-blob" |
1950 git fast-import
1953 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
1954 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
1957 test_expect_success 'R: print old blob' '
1958 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
1959 cat >expect <<-EOF &&
1960 ${blob} blob 11
1961 yes it can
1964 echo "cat-blob $blob" |
1965 git fast-import --cat-blob-fd=6 6>actual &&
1966 test_cmp expect actual
1969 test_expect_success 'R: in-stream cat-blob-fd not respected' '
1970 echo hello >greeting &&
1971 blob=$(git hash-object -w greeting) &&
1972 cat >expect <<-EOF &&
1973 ${blob} blob 6
1974 hello
1977 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
1978 cat-blob $blob
1980 test_cmp expect actual.3 &&
1981 test_cmp empty actual.1 &&
1982 git fast-import 3>actual.3 >actual.1 <<-EOF &&
1983 option cat-blob-fd=3
1984 cat-blob $blob
1986 test_cmp empty actual.3 &&
1987 test_cmp expect actual.1
1990 test_expect_success 'R: print new blob' '
1991 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
1992 cat >expect <<-EOF &&
1993 ${blob} blob 12
1994 yep yep yep
1997 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
1998 blob
1999 mark :1
2000 data <<BLOB_END
2001 yep yep yep
2002 BLOB_END
2003 cat-blob :1
2005 test_cmp expect actual
2008 test_expect_success 'R: print new blob by sha1' '
2009 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2010 cat >expect <<-EOF &&
2011 ${blob} blob 25
2012 a new blob named by sha1
2015 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2016 blob
2017 data <<BLOB_END
2018 a new blob named by sha1
2019 BLOB_END
2020 cat-blob $blob
2022 test_cmp expect actual
2025 test_expect_success 'setup: big file' '
2027 echo "the quick brown fox jumps over the lazy dog" >big &&
2028 for i in 1 2 3
2030 cat big big big big >bigger &&
2031 cat bigger bigger bigger bigger >big ||
2032 exit
2033 done
2037 test_expect_success 'R: print two blobs to stdout' '
2038 blob1=$(git hash-object big) &&
2039 blob1_len=$(wc -c <big) &&
2040 blob2=$(echo hello | git hash-object --stdin) &&
2042 echo ${blob1} blob $blob1_len &&
2043 cat big &&
2044 cat <<-EOF
2046 ${blob2} blob 6
2047 hello
2050 } >expect &&
2052 cat <<-\END_PART1 &&
2053 blob
2054 mark :1
2055 data <<data_end
2056 END_PART1
2057 cat big &&
2058 cat <<-\EOF
2059 data_end
2060 blob
2061 mark :2
2062 data <<data_end
2063 hello
2064 data_end
2065 cat-blob :1
2066 cat-blob :2
2069 git fast-import >actual &&
2070 test_cmp expect actual
2073 test_expect_success PIPE 'R: copy using cat-file' '
2074 expect_id=$(git hash-object big) &&
2075 expect_len=$(wc -c <big) &&
2076 echo $expect_id blob $expect_len >expect.response &&
2078 rm -f blobs &&
2079 cat >frontend <<-\FRONTEND_END &&
2080 #!/bin/sh
2081 FRONTEND_END
2083 mkfifo blobs &&
2085 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2086 cat <<-\EOF &&
2087 feature cat-blob
2088 blob
2089 mark :1
2090 data <<BLOB
2092 cat big &&
2093 cat <<-\EOF &&
2094 BLOB
2095 cat-blob :1
2098 read blob_id type size <&3 &&
2099 echo "$blob_id $type $size" >response &&
2100 head_c $size >blob <&3 &&
2101 read newline <&3 &&
2103 cat <<-EOF &&
2104 commit refs/heads/copied
2105 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2106 data <<COMMIT
2107 copy big file as file3
2108 COMMIT
2109 M 644 inline file3
2110 data <<BLOB
2112 cat blob &&
2113 echo BLOB
2114 ) 3<blobs |
2115 git fast-import --cat-blob-fd=3 3>blobs &&
2116 git show copied:file3 >actual &&
2117 test_cmp expect.response response &&
2118 test_cmp big actual
2121 test_expect_success PIPE 'R: print blob mid-commit' '
2122 rm -f blobs &&
2123 echo "A blob from _before_ the commit." >expect &&
2124 mkfifo blobs &&
2126 exec 3<blobs &&
2127 cat <<-EOF &&
2128 feature cat-blob
2129 blob
2130 mark :1
2131 data <<BLOB
2132 A blob from _before_ the commit.
2133 BLOB
2134 commit refs/heads/temporary
2135 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2136 data <<COMMIT
2137 Empty commit
2138 COMMIT
2139 cat-blob :1
2142 read blob_id type size <&3 &&
2143 head_c $size >actual <&3 &&
2144 read newline <&3 &&
2146 echo
2148 git fast-import --cat-blob-fd=3 3>blobs &&
2149 test_cmp expect actual
2152 test_expect_success PIPE 'R: print staged blob within commit' '
2153 rm -f blobs &&
2154 echo "A blob from _within_ the commit." >expect &&
2155 mkfifo blobs &&
2157 exec 3<blobs &&
2158 cat <<-EOF &&
2159 feature cat-blob
2160 commit refs/heads/within
2161 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2162 data <<COMMIT
2163 Empty commit
2164 COMMIT
2165 M 644 inline within
2166 data <<BLOB
2167 A blob from _within_ the commit.
2168 BLOB
2171 to_get=$(
2172 echo "A blob from _within_ the commit." |
2173 git hash-object --stdin
2174 ) &&
2175 echo "cat-blob $to_get" &&
2177 read blob_id type size <&3 &&
2178 head_c $size >actual <&3 &&
2179 read newline <&3 &&
2181 echo deleteall
2183 git fast-import --cat-blob-fd=3 3>blobs &&
2184 test_cmp expect actual
2187 cat >input << EOF
2188 option git quiet
2189 blob
2190 data 3
2195 test_expect_success 'R: quiet option results in no stats being output' '
2196 cat input | git fast-import 2> output &&
2197 test_cmp empty output
2200 cat >input <<EOF
2201 option git non-existing-option
2204 test_expect_success 'R: die on unknown option' '
2205 test_must_fail git fast-import <input
2208 test_expect_success 'R: unknown commandline options are rejected' '\
2209 test_must_fail git fast-import --non-existing-option < /dev/null
2212 test_expect_success 'R: die on invalid option argument' '
2213 echo "option git active-branches=-5" |
2214 test_must_fail git fast-import &&
2215 echo "option git depth=" |
2216 test_must_fail git fast-import &&
2217 test_must_fail git fast-import --depth="5 elephants" </dev/null
2220 cat >input <<EOF
2221 option non-existing-vcs non-existing-option
2224 test_expect_success 'R: ignore non-git options' '
2225 git fast-import <input
2229 ## R: very large blobs
2231 blobsize=$((2*1024*1024 + 53))
2232 test-genrandom bar $blobsize >expect
2233 cat >input <<INPUT_END
2234 commit refs/heads/big-file
2235 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2236 data <<COMMIT
2237 R - big file
2238 COMMIT
2240 M 644 inline big1
2241 data $blobsize
2242 INPUT_END
2243 cat expect >>input
2244 cat >>input <<INPUT_END
2245 M 644 inline big2
2246 data $blobsize
2247 INPUT_END
2248 cat expect >>input
2249 echo >>input
2251 test_expect_success \
2252 'R: blob bigger than threshold' \
2253 'test_create_repo R &&
2254 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2255 test_expect_success \
2256 'R: verify created pack' \
2257 ': >verify &&
2258 for p in R/.git/objects/pack/*.pack;
2260 git verify-pack -v $p >>verify || exit;
2261 done'
2262 test_expect_success \
2263 'R: verify written objects' \
2264 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2265 test_cmp expect actual &&
2266 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2267 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2268 test $a = $b'
2269 test_expect_success \
2270 'R: blob appears only once' \
2271 'n=$(grep $a verify | wc -l) &&
2272 test 1 = $n'
2274 test_done