t0050: Use TAB for indentation
[git/jnareb-git.git] / t / t9300-fast-import.sh
blob2fcf2694696fedb5e7e3d57c869f7dbbbf23dbec
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
10 # Print $1 bytes from stdin to stdout.
12 # This could be written as "head -c $1", but IRIX "head" does not
13 # support the -c option.
14 head_c () {
15 "$PERL_PATH" -e '
16 my $len = $ARGV[1];
17 while ($len > 0) {
18 my $s;
19 my $nread = sysread(STDIN, $s, $len);
20 die "cannot read: $!" unless defined($nread);
21 print $s;
22 $len -= $nread;
24 ' - "$1"
27 verify_packs () {
28 for p in .git/objects/pack/*.pack
30 git verify-pack "$@" "$p" || return
31 done
34 file2_data='file2
35 second line of EOF'
37 file3_data='EOF
38 in 3rd file
39 END'
41 file4_data=abcd
42 file4_len=4
44 file5_data='an inline file.
45 we should see it later.'
47 file6_data='#!/bin/sh
48 echo "$@"'
50 >empty
52 test_expect_success 'setup: have pipes?' '
53 rm -f frob &&
54 if mkfifo frob
55 then
56 test_set_prereq PIPE
60 ###
61 ### series A
62 ###
64 test_tick
66 test_expect_success 'empty stream succeeds' '
67 git fast-import </dev/null
70 cat >input <<INPUT_END
71 blob
72 mark :2
73 data <<EOF
74 $file2_data
75 EOF
77 blob
78 mark :3
79 data <<END
80 $file3_data
81 END
83 blob
84 mark :4
85 data $file4_len
86 $file4_data
87 commit refs/heads/master
88 mark :5
89 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
90 data <<COMMIT
91 initial
92 COMMIT
94 M 644 :2 file2
95 M 644 :3 file3
96 M 755 :4 file4
98 tag series-A
99 from :5
100 data <<EOF
101 An annotated tag without a tagger
104 tag series-A-blob
105 from :3
106 data <<EOF
107 An annotated tag that annotates a blob.
110 INPUT_END
111 test_expect_success \
112 'A: create pack from stdin' \
113 'git fast-import --export-marks=marks.out <input &&
114 git whatchanged master'
116 test_expect_success 'A: verify pack' '
117 verify_packs
120 cat >expect <<EOF
121 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
124 initial
126 test_expect_success \
127 'A: verify commit' \
128 'git cat-file commit master | sed 1d >actual &&
129 test_cmp expect actual'
131 cat >expect <<EOF
132 100644 blob file2
133 100644 blob file3
134 100755 blob file4
136 test_expect_success \
137 'A: verify tree' \
138 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
139 test_cmp expect actual'
141 echo "$file2_data" >expect
142 test_expect_success \
143 'A: verify file2' \
144 'git cat-file blob master:file2 >actual && test_cmp expect actual'
146 echo "$file3_data" >expect
147 test_expect_success \
148 'A: verify file3' \
149 'git cat-file blob master:file3 >actual && test_cmp expect actual'
151 printf "$file4_data" >expect
152 test_expect_success \
153 'A: verify file4' \
154 'git cat-file blob master:file4 >actual && test_cmp expect actual'
156 cat >expect <<EOF
157 object $(git rev-parse refs/heads/master)
158 type commit
159 tag series-A
161 An annotated tag without a tagger
163 test_expect_success 'A: verify tag/series-A' '
164 git cat-file tag tags/series-A >actual &&
165 test_cmp expect actual
168 cat >expect <<EOF
169 object $(git rev-parse refs/heads/master:file3)
170 type blob
171 tag series-A-blob
173 An annotated tag that annotates a blob.
175 test_expect_success 'A: verify tag/series-A-blob' '
176 git cat-file tag tags/series-A-blob >actual &&
177 test_cmp expect actual
180 cat >expect <<EOF
181 :2 `git rev-parse --verify master:file2`
182 :3 `git rev-parse --verify master:file3`
183 :4 `git rev-parse --verify master:file4`
184 :5 `git rev-parse --verify master^0`
186 test_expect_success \
187 'A: verify marks output' \
188 'test_cmp expect marks.out'
190 test_expect_success \
191 'A: verify marks import' \
192 'git fast-import \
193 --import-marks=marks.out \
194 --export-marks=marks.new \
195 </dev/null &&
196 test_cmp expect marks.new'
198 test_tick
199 new_blob=$(echo testing | git hash-object --stdin)
200 cat >input <<INPUT_END
201 tag series-A-blob-2
202 from $(git rev-parse refs/heads/master:file3)
203 data <<EOF
204 Tag blob by sha1.
207 blob
208 mark :6
209 data <<EOF
210 testing
213 commit refs/heads/new_blob
214 committer <> 0 +0000
215 data 0
216 M 644 :6 new_blob
217 #pretend we got sha1 from fast-import
218 ls "new_blob"
220 tag series-A-blob-3
221 from $new_blob
222 data <<EOF
223 Tag new_blob.
225 INPUT_END
227 cat >expect <<EOF
228 object $(git rev-parse refs/heads/master:file3)
229 type blob
230 tag series-A-blob-2
232 Tag blob by sha1.
233 object $new_blob
234 type blob
235 tag series-A-blob-3
237 Tag new_blob.
240 test_expect_success \
241 'A: tag blob by sha1' \
242 'git fast-import <input &&
243 git cat-file tag tags/series-A-blob-2 >actual &&
244 git cat-file tag tags/series-A-blob-3 >>actual &&
245 test_cmp expect actual'
247 test_tick
248 cat >input <<INPUT_END
249 commit refs/heads/verify--import-marks
250 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
251 data <<COMMIT
252 recreate from :5
253 COMMIT
255 from :5
256 M 755 :2 copy-of-file2
258 INPUT_END
259 test_expect_success \
260 'A: verify marks import does not crash' \
261 'git fast-import --import-marks=marks.out <input &&
262 git whatchanged verify--import-marks'
264 test_expect_success 'A: verify pack' '
265 verify_packs
268 cat >expect <<EOF
269 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
271 git diff-tree -M -r master verify--import-marks >actual
272 test_expect_success \
273 'A: verify diff' \
274 'compare_diff_raw expect actual &&
275 test `git rev-parse --verify master:file2` \
276 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
278 test_tick
279 mt=$(git hash-object --stdin < /dev/null)
280 : >input.blob
281 : >marks.exp
282 : >tree.exp
284 cat >input.commit <<EOF
285 commit refs/heads/verify--dump-marks
286 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
287 data <<COMMIT
288 test the sparse array dumping routines with exponentially growing marks
289 COMMIT
296 while test "$i" -lt 27; do
297 cat >>input.blob <<EOF
298 blob
299 mark :$l
300 data 0
301 blob
302 mark :$m
303 data 0
304 blob
305 mark :$n
306 data 0
308 echo "M 100644 :$l l$i" >>input.commit
309 echo "M 100644 :$m m$i" >>input.commit
310 echo "M 100644 :$n n$i" >>input.commit
312 echo ":$l $mt" >>marks.exp
313 echo ":$m $mt" >>marks.exp
314 echo ":$n $mt" >>marks.exp
316 printf "100644 blob $mt\tl$i\n" >>tree.exp
317 printf "100644 blob $mt\tm$i\n" >>tree.exp
318 printf "100644 blob $mt\tn$i\n" >>tree.exp
320 l=$(($l + $l))
321 m=$(($m + $m))
322 n=$(($l + $n))
324 i=$((1 + $i))
325 done
327 sort tree.exp > tree.exp_s
329 test_expect_success 'A: export marks with large values' '
330 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
331 git ls-tree refs/heads/verify--dump-marks >tree.out &&
332 test_cmp tree.exp_s tree.out &&
333 test_cmp marks.exp marks.large'
336 ### series B
339 test_tick
340 cat >input <<INPUT_END
341 commit refs/heads/branch
342 mark :1
343 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
344 data <<COMMIT
345 corrupt
346 COMMIT
348 from refs/heads/master
349 M 755 0000000000000000000000000000000000000001 zero1
351 INPUT_END
352 test_expect_success 'B: fail on invalid blob sha1' '
353 test_must_fail git fast-import <input
355 rm -f .git/objects/pack_* .git/objects/index_*
357 cat >input <<INPUT_END
358 commit .badbranchname
359 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
360 data <<COMMIT
361 corrupt
362 COMMIT
364 from refs/heads/master
366 INPUT_END
367 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
368 test_must_fail git fast-import <input
370 rm -f .git/objects/pack_* .git/objects/index_*
372 cat >input <<INPUT_END
373 commit bad[branch]name
374 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
375 data <<COMMIT
376 corrupt
377 COMMIT
379 from refs/heads/master
381 INPUT_END
382 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
383 test_must_fail git fast-import <input
385 rm -f .git/objects/pack_* .git/objects/index_*
387 cat >input <<INPUT_END
388 commit TEMP_TAG
389 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
390 data <<COMMIT
391 tag base
392 COMMIT
394 from refs/heads/master
396 INPUT_END
397 test_expect_success \
398 'B: accept branch name "TEMP_TAG"' \
399 'git fast-import <input &&
400 test -f .git/TEMP_TAG &&
401 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
402 rm -f .git/TEMP_TAG
404 git gc 2>/dev/null >/dev/null
405 git prune 2>/dev/null >/dev/null
407 cat >input <<INPUT_END
408 commit refs/heads/empty-committer-1
409 committer <> $GIT_COMMITTER_DATE
410 data <<COMMIT
411 empty commit
412 COMMIT
413 INPUT_END
414 test_expect_success 'B: accept empty committer' '
415 git fast-import <input &&
416 out=$(git fsck) &&
417 echo "$out" &&
418 test -z "$out"
420 git update-ref -d refs/heads/empty-committer-1 || true
422 git gc 2>/dev/null >/dev/null
423 git prune 2>/dev/null >/dev/null
425 cat >input <<INPUT_END
426 commit refs/heads/empty-committer-2
427 committer <a@b.com> $GIT_COMMITTER_DATE
428 data <<COMMIT
429 empty commit
430 COMMIT
431 INPUT_END
432 test_expect_success 'B: accept and fixup committer with no name' '
433 git fast-import <input &&
434 out=$(git fsck) &&
435 echo "$out" &&
436 test -z "$out"
438 git update-ref -d refs/heads/empty-committer-2 || true
440 git gc 2>/dev/null >/dev/null
441 git prune 2>/dev/null >/dev/null
443 cat >input <<INPUT_END
444 commit refs/heads/invalid-committer
445 committer Name email> $GIT_COMMITTER_DATE
446 data <<COMMIT
447 empty commit
448 COMMIT
449 INPUT_END
450 test_expect_success 'B: fail on invalid committer (1)' '
451 test_must_fail git fast-import <input
453 git update-ref -d refs/heads/invalid-committer || true
455 cat >input <<INPUT_END
456 commit refs/heads/invalid-committer
457 committer Name <e<mail> $GIT_COMMITTER_DATE
458 data <<COMMIT
459 empty commit
460 COMMIT
461 INPUT_END
462 test_expect_success 'B: fail on invalid committer (2)' '
463 test_must_fail git fast-import <input
465 git update-ref -d refs/heads/invalid-committer || true
467 cat >input <<INPUT_END
468 commit refs/heads/invalid-committer
469 committer Name <email>> $GIT_COMMITTER_DATE
470 data <<COMMIT
471 empty commit
472 COMMIT
473 INPUT_END
474 test_expect_success 'B: fail on invalid committer (3)' '
475 test_must_fail git fast-import <input
477 git update-ref -d refs/heads/invalid-committer || true
479 cat >input <<INPUT_END
480 commit refs/heads/invalid-committer
481 committer Name <email $GIT_COMMITTER_DATE
482 data <<COMMIT
483 empty commit
484 COMMIT
485 INPUT_END
486 test_expect_success 'B: fail on invalid committer (4)' '
487 test_must_fail git fast-import <input
489 git update-ref -d refs/heads/invalid-committer || true
491 cat >input <<INPUT_END
492 commit refs/heads/invalid-committer
493 committer Name<email> $GIT_COMMITTER_DATE
494 data <<COMMIT
495 empty commit
496 COMMIT
497 INPUT_END
498 test_expect_success 'B: fail on invalid committer (5)' '
499 test_must_fail git fast-import <input
501 git update-ref -d refs/heads/invalid-committer || true
504 ### series C
507 newf=`echo hi newf | git hash-object -w --stdin`
508 oldf=`git rev-parse --verify master:file2`
509 test_tick
510 cat >input <<INPUT_END
511 commit refs/heads/branch
512 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
513 data <<COMMIT
514 second
515 COMMIT
517 from refs/heads/master
518 M 644 $oldf file2/oldf
519 M 755 $newf file2/newf
520 D file3
522 INPUT_END
523 test_expect_success \
524 'C: incremental import create pack from stdin' \
525 'git fast-import <input &&
526 git whatchanged branch'
528 test_expect_success 'C: verify pack' '
529 verify_packs
532 test_expect_success \
533 'C: validate reuse existing blob' \
534 'test $newf = `git rev-parse --verify branch:file2/newf` &&
535 test $oldf = `git rev-parse --verify branch:file2/oldf`'
537 cat >expect <<EOF
538 parent `git rev-parse --verify master^0`
539 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
540 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
542 second
544 test_expect_success \
545 'C: verify commit' \
546 'git cat-file commit branch | sed 1d >actual &&
547 test_cmp expect actual'
549 cat >expect <<EOF
550 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
551 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
552 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
554 git diff-tree -M -r master branch >actual
555 test_expect_success \
556 'C: validate rename result' \
557 'compare_diff_raw expect actual'
560 ### series D
563 test_tick
564 cat >input <<INPUT_END
565 commit refs/heads/branch
566 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
567 data <<COMMIT
568 third
569 COMMIT
571 from refs/heads/branch^0
572 M 644 inline newdir/interesting
573 data <<EOF
574 $file5_data
577 M 755 inline newdir/exec.sh
578 data <<EOF
579 $file6_data
582 INPUT_END
583 test_expect_success \
584 'D: inline data in commit' \
585 'git fast-import <input &&
586 git whatchanged branch'
588 test_expect_success 'D: verify pack' '
589 verify_packs
592 cat >expect <<EOF
593 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
594 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
596 git diff-tree -M -r branch^ branch >actual
597 test_expect_success \
598 'D: validate new files added' \
599 'compare_diff_raw expect actual'
601 echo "$file5_data" >expect
602 test_expect_success \
603 'D: verify file5' \
604 'git cat-file blob branch:newdir/interesting >actual &&
605 test_cmp expect actual'
607 echo "$file6_data" >expect
608 test_expect_success \
609 'D: verify file6' \
610 'git cat-file blob branch:newdir/exec.sh >actual &&
611 test_cmp expect actual'
614 ### series E
617 cat >input <<INPUT_END
618 commit refs/heads/branch
619 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
620 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
621 data <<COMMIT
622 RFC 2822 type date
623 COMMIT
625 from refs/heads/branch^0
627 INPUT_END
628 test_expect_success 'E: rfc2822 date, --date-format=raw' '
629 test_must_fail git fast-import --date-format=raw <input
631 test_expect_success \
632 'E: rfc2822 date, --date-format=rfc2822' \
633 'git fast-import --date-format=rfc2822 <input'
635 test_expect_success 'E: verify pack' '
636 verify_packs
639 cat >expect <<EOF
640 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
641 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
643 RFC 2822 type date
645 test_expect_success \
646 'E: verify commit' \
647 'git cat-file commit branch | sed 1,2d >actual &&
648 test_cmp expect actual'
651 ### series F
654 old_branch=`git rev-parse --verify branch^0`
655 test_tick
656 cat >input <<INPUT_END
657 commit refs/heads/branch
658 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
659 data <<COMMIT
660 losing things already?
661 COMMIT
663 from refs/heads/branch~1
665 reset refs/heads/other
666 from refs/heads/branch
668 INPUT_END
669 test_expect_success \
670 'F: non-fast-forward update skips' \
671 'if git fast-import <input
672 then
673 echo BAD gfi did not fail
674 return 1
675 else
676 if test $old_branch = `git rev-parse --verify branch^0`
677 then
678 : branch unaffected and failure returned
679 return 0
680 else
681 echo BAD gfi changed branch $old_branch
682 return 1
687 test_expect_success 'F: verify pack' '
688 verify_packs
691 cat >expect <<EOF
692 tree `git rev-parse branch~1^{tree}`
693 parent `git rev-parse branch~1`
694 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
695 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
697 losing things already?
699 test_expect_success \
700 'F: verify other commit' \
701 'git cat-file commit other >actual &&
702 test_cmp expect actual'
705 ### series G
708 old_branch=`git rev-parse --verify branch^0`
709 test_tick
710 cat >input <<INPUT_END
711 commit refs/heads/branch
712 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
713 data <<COMMIT
714 losing things already?
715 COMMIT
717 from refs/heads/branch~1
719 INPUT_END
720 test_expect_success \
721 'G: non-fast-forward update forced' \
722 'git fast-import --force <input'
724 test_expect_success 'G: verify pack' '
725 verify_packs
728 test_expect_success \
729 'G: branch changed, but logged' \
730 'test $old_branch != `git rev-parse --verify branch^0` &&
731 test $old_branch = `git rev-parse --verify branch@{1}`'
734 ### series H
737 test_tick
738 cat >input <<INPUT_END
739 commit refs/heads/H
740 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
741 data <<COMMIT
742 third
743 COMMIT
745 from refs/heads/branch^0
746 M 644 inline i-will-die
747 data <<EOF
748 this file will never exist.
751 deleteall
752 M 644 inline h/e/l/lo
753 data <<EOF
754 $file5_data
757 INPUT_END
758 test_expect_success \
759 'H: deletall, add 1' \
760 'git fast-import <input &&
761 git whatchanged H'
763 test_expect_success 'H: verify pack' '
764 verify_packs
767 cat >expect <<EOF
768 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
769 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
770 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
771 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
772 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
774 git diff-tree -M -r H^ H >actual
775 test_expect_success \
776 'H: validate old files removed, new files added' \
777 'compare_diff_raw expect actual'
779 echo "$file5_data" >expect
780 test_expect_success \
781 'H: verify file' \
782 'git cat-file blob H:h/e/l/lo >actual &&
783 test_cmp expect actual'
786 ### series I
789 cat >input <<INPUT_END
790 commit refs/heads/export-boundary
791 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
792 data <<COMMIT
793 we have a border. its only 40 characters wide.
794 COMMIT
796 from refs/heads/branch
798 INPUT_END
799 test_expect_success \
800 'I: export-pack-edges' \
801 'git fast-import --export-pack-edges=edges.list <input'
803 cat >expect <<EOF
804 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
806 test_expect_success \
807 'I: verify edge list' \
808 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
809 test_cmp expect actual'
812 ### series J
815 cat >input <<INPUT_END
816 commit refs/heads/J
817 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
818 data <<COMMIT
819 create J
820 COMMIT
822 from refs/heads/branch
824 reset refs/heads/J
826 commit refs/heads/J
827 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
828 data <<COMMIT
829 initialize J
830 COMMIT
832 INPUT_END
833 test_expect_success \
834 'J: reset existing branch creates empty commit' \
835 'git fast-import <input'
836 test_expect_success \
837 'J: branch has 1 commit, empty tree' \
838 'test 1 = `git rev-list J | wc -l` &&
839 test 0 = `git ls-tree J | wc -l`'
841 cat >input <<INPUT_END
842 reset refs/heads/J2
844 tag wrong_tag
845 from refs/heads/J2
846 data <<EOF
847 Tag branch that was reset.
849 INPUT_END
850 test_expect_success \
851 'J: tag must fail on empty branch' \
852 'test_must_fail git fast-import <input'
854 ### series K
857 cat >input <<INPUT_END
858 commit refs/heads/K
859 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
860 data <<COMMIT
861 create K
862 COMMIT
864 from refs/heads/branch
866 commit refs/heads/K
867 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
868 data <<COMMIT
869 redo K
870 COMMIT
872 from refs/heads/branch^1
874 INPUT_END
875 test_expect_success \
876 'K: reinit branch with from' \
877 'git fast-import <input'
878 test_expect_success \
879 'K: verify K^1 = branch^1' \
880 'test `git rev-parse --verify branch^1` \
881 = `git rev-parse --verify K^1`'
884 ### series L
887 cat >input <<INPUT_END
888 blob
889 mark :1
890 data <<EOF
891 some data
894 blob
895 mark :2
896 data <<EOF
897 other data
900 commit refs/heads/L
901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
902 data <<COMMIT
903 create L
904 COMMIT
906 M 644 :1 b.
907 M 644 :1 b/other
908 M 644 :1 ba
910 commit refs/heads/L
911 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
912 data <<COMMIT
913 update L
914 COMMIT
916 M 644 :2 b.
917 M 644 :2 b/other
918 M 644 :2 ba
919 INPUT_END
921 cat >expect <<EXPECT_END
922 :100644 100644 4268632... 55d3a52... M b.
923 :040000 040000 0ae5cac... 443c768... M b
924 :100644 100644 4268632... 55d3a52... M ba
925 EXPECT_END
927 test_expect_success \
928 'L: verify internal tree sorting' \
929 'git fast-import <input &&
930 git diff-tree --abbrev --raw L^ L >output &&
931 test_cmp expect output'
933 cat >input <<INPUT_END
934 blob
935 mark :1
936 data <<EOF
937 the data
940 commit refs/heads/L2
941 committer C O Mitter <committer@example.com> 1112912473 -0700
942 data <<COMMIT
943 init L2
944 COMMIT
945 M 644 :1 a/b/c
946 M 644 :1 a/b/d
947 M 644 :1 a/e/f
949 commit refs/heads/L2
950 committer C O Mitter <committer@example.com> 1112912473 -0700
951 data <<COMMIT
952 update L2
953 COMMIT
954 C a g
955 C a/e g/b
956 M 644 :1 g/b/h
957 INPUT_END
959 cat <<EOF >expect
960 g/b/f
961 g/b/h
964 test_expect_success \
965 'L: nested tree copy does not corrupt deltas' \
966 'git fast-import <input &&
967 git ls-tree L2 g/b/ >tmp &&
968 cat tmp | cut -f 2 >actual &&
969 test_cmp expect actual &&
970 git fsck `git rev-parse L2`'
972 git update-ref -d refs/heads/L2
975 ### series M
978 test_tick
979 cat >input <<INPUT_END
980 commit refs/heads/M1
981 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
982 data <<COMMIT
983 file rename
984 COMMIT
986 from refs/heads/branch^0
987 R file2/newf file2/n.e.w.f
989 INPUT_END
991 cat >expect <<EOF
992 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
994 test_expect_success \
995 'M: rename file in same subdirectory' \
996 'git fast-import <input &&
997 git diff-tree -M -r M1^ M1 >actual &&
998 compare_diff_raw expect actual'
1000 cat >input <<INPUT_END
1001 commit refs/heads/M2
1002 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1003 data <<COMMIT
1004 file rename
1005 COMMIT
1007 from refs/heads/branch^0
1008 R file2/newf i/am/new/to/you
1010 INPUT_END
1012 cat >expect <<EOF
1013 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
1015 test_expect_success \
1016 'M: rename file to new subdirectory' \
1017 'git fast-import <input &&
1018 git diff-tree -M -r M2^ M2 >actual &&
1019 compare_diff_raw expect actual'
1021 cat >input <<INPUT_END
1022 commit refs/heads/M3
1023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1024 data <<COMMIT
1025 file rename
1026 COMMIT
1028 from refs/heads/M2^0
1029 R i other/sub
1031 INPUT_END
1033 cat >expect <<EOF
1034 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
1036 test_expect_success \
1037 'M: rename subdirectory to new subdirectory' \
1038 'git fast-import <input &&
1039 git diff-tree -M -r M3^ M3 >actual &&
1040 compare_diff_raw expect actual'
1043 ### series N
1046 test_tick
1047 cat >input <<INPUT_END
1048 commit refs/heads/N1
1049 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1050 data <<COMMIT
1051 file copy
1052 COMMIT
1054 from refs/heads/branch^0
1055 C file2/newf file2/n.e.w.f
1057 INPUT_END
1059 cat >expect <<EOF
1060 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1062 test_expect_success \
1063 'N: copy file in same subdirectory' \
1064 'git fast-import <input &&
1065 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1066 compare_diff_raw expect actual'
1068 cat >input <<INPUT_END
1069 commit refs/heads/N2
1070 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1071 data <<COMMIT
1072 clean directory copy
1073 COMMIT
1075 from refs/heads/branch^0
1076 C file2 file3
1078 commit refs/heads/N2
1079 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1080 data <<COMMIT
1081 modify directory copy
1082 COMMIT
1084 M 644 inline file3/file5
1085 data <<EOF
1086 $file5_data
1089 INPUT_END
1091 cat >expect <<EOF
1092 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1093 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1094 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1096 test_expect_success \
1097 'N: copy then modify subdirectory' \
1098 'git fast-import <input &&
1099 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1100 compare_diff_raw expect actual'
1102 cat >input <<INPUT_END
1103 commit refs/heads/N3
1104 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1105 data <<COMMIT
1106 dirty directory copy
1107 COMMIT
1109 from refs/heads/branch^0
1110 M 644 inline file2/file5
1111 data <<EOF
1112 $file5_data
1115 C file2 file3
1116 D file2/file5
1118 INPUT_END
1120 test_expect_success \
1121 'N: copy dirty subdirectory' \
1122 'git fast-import <input &&
1123 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1125 test_expect_success \
1126 'N: copy directory by id' \
1127 'cat >expect <<-\EOF &&
1128 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1129 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1131 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1132 cat >input <<-INPUT_END &&
1133 commit refs/heads/N4
1134 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1135 data <<COMMIT
1136 copy by tree hash
1137 COMMIT
1139 from refs/heads/branch^0
1140 M 040000 $subdir file3
1141 INPUT_END
1142 git fast-import <input &&
1143 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1144 compare_diff_raw expect actual'
1146 test_expect_success PIPE 'N: read and copy directory' '
1147 cat >expect <<-\EOF
1148 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1149 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1151 git update-ref -d refs/heads/N4 &&
1152 rm -f backflow &&
1153 mkfifo backflow &&
1155 exec <backflow &&
1156 cat <<-EOF &&
1157 commit refs/heads/N4
1158 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1159 data <<COMMIT
1160 copy by tree hash, part 2
1161 COMMIT
1163 from refs/heads/branch^0
1164 ls "file2"
1166 read mode type tree filename &&
1167 echo "M 040000 $tree file3"
1169 git fast-import --cat-blob-fd=3 3>backflow &&
1170 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1171 compare_diff_raw expect actual
1174 test_expect_success PIPE 'N: empty directory reads as missing' '
1175 cat <<-\EOF >expect &&
1176 OBJNAME
1177 :000000 100644 OBJNAME OBJNAME A unrelated
1179 echo "missing src" >expect.response &&
1180 git update-ref -d refs/heads/read-empty &&
1181 rm -f backflow &&
1182 mkfifo backflow &&
1184 exec <backflow &&
1185 cat <<-EOF &&
1186 commit refs/heads/read-empty
1187 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1188 data <<COMMIT
1189 read "empty" (missing) directory
1190 COMMIT
1192 M 100644 inline src/greeting
1193 data <<BLOB
1194 hello
1195 BLOB
1196 C src/greeting dst1/non-greeting
1197 C src/greeting unrelated
1198 # leave behind "empty" src directory
1199 D src/greeting
1200 ls "src"
1202 read -r line &&
1203 printf "%s\n" "$line" >response &&
1204 cat <<-\EOF
1205 D dst1
1206 D dst2
1209 git fast-import --cat-blob-fd=3 3>backflow &&
1210 test_cmp expect.response response &&
1211 git rev-list read-empty |
1212 git diff-tree -r --root --stdin |
1213 sed "s/$_x40/OBJNAME/g" >actual &&
1214 test_cmp expect actual
1217 test_expect_success \
1218 'N: copy root directory by tree hash' \
1219 'cat >expect <<-\EOF &&
1220 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1221 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1223 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1224 cat >input <<-INPUT_END &&
1225 commit refs/heads/N6
1226 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1227 data <<COMMIT
1228 copy root directory by tree hash
1229 COMMIT
1231 from refs/heads/branch^0
1232 M 040000 $root ""
1233 INPUT_END
1234 git fast-import <input &&
1235 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1236 compare_diff_raw expect actual'
1238 test_expect_success \
1239 'N: delete directory by copying' \
1240 'cat >expect <<-\EOF &&
1241 OBJID
1242 :100644 000000 OBJID OBJID D foo/bar/qux
1243 OBJID
1244 :000000 100644 OBJID OBJID A foo/bar/baz
1245 :000000 100644 OBJID OBJID A foo/bar/qux
1247 empty_tree=$(git mktree </dev/null) &&
1248 cat >input <<-INPUT_END &&
1249 commit refs/heads/N-delete
1250 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1251 data <<COMMIT
1252 collect data to be deleted
1253 COMMIT
1255 deleteall
1256 M 100644 inline foo/bar/baz
1257 data <<DATA_END
1258 hello
1259 DATA_END
1260 C "foo/bar/baz" "foo/bar/qux"
1261 C "foo/bar/baz" "foo/bar/quux/1"
1262 C "foo/bar/baz" "foo/bar/quuux"
1263 M 040000 $empty_tree foo/bar/quux
1264 M 040000 $empty_tree foo/bar/quuux
1266 commit refs/heads/N-delete
1267 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1268 data <<COMMIT
1269 delete subdirectory
1270 COMMIT
1272 M 040000 $empty_tree foo/bar/qux
1273 INPUT_END
1274 git fast-import <input &&
1275 git rev-list N-delete |
1276 git diff-tree -r --stdin --root --always |
1277 sed -e "s/$_x40/OBJID/g" >actual &&
1278 test_cmp expect actual'
1280 test_expect_success \
1281 'N: modify copied tree' \
1282 'cat >expect <<-\EOF &&
1283 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1284 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1285 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1287 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1288 cat >input <<-INPUT_END &&
1289 commit refs/heads/N5
1290 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1291 data <<COMMIT
1292 copy by tree hash
1293 COMMIT
1295 from refs/heads/branch^0
1296 M 040000 $subdir file3
1298 commit refs/heads/N5
1299 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1300 data <<COMMIT
1301 modify directory copy
1302 COMMIT
1304 M 644 inline file3/file5
1305 data <<EOF
1306 $file5_data
1308 INPUT_END
1309 git fast-import <input &&
1310 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1311 compare_diff_raw expect actual'
1313 test_expect_success \
1314 'N: reject foo/ syntax' \
1315 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1316 test_must_fail git fast-import <<-INPUT_END
1317 commit refs/heads/N5B
1318 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1319 data <<COMMIT
1320 copy with invalid syntax
1321 COMMIT
1323 from refs/heads/branch^0
1324 M 040000 $subdir file3/
1325 INPUT_END'
1327 test_expect_success \
1328 'N: reject foo/ syntax in copy source' \
1329 'test_must_fail git fast-import <<-INPUT_END
1330 commit refs/heads/N5C
1331 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1332 data <<COMMIT
1333 copy with invalid syntax
1334 COMMIT
1336 from refs/heads/branch^0
1337 C file2/ file3
1338 INPUT_END'
1340 test_expect_success \
1341 'N: reject foo/ syntax in rename source' \
1342 'test_must_fail git fast-import <<-INPUT_END
1343 commit refs/heads/N5D
1344 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1345 data <<COMMIT
1346 rename with invalid syntax
1347 COMMIT
1349 from refs/heads/branch^0
1350 R file2/ file3
1351 INPUT_END'
1353 test_expect_success \
1354 'N: reject foo/ syntax in ls argument' \
1355 'test_must_fail git fast-import <<-INPUT_END
1356 commit refs/heads/N5E
1357 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1358 data <<COMMIT
1359 copy with invalid syntax
1360 COMMIT
1362 from refs/heads/branch^0
1363 ls "file2/"
1364 INPUT_END'
1366 test_expect_success \
1367 'N: copy to root by id and modify' \
1368 'echo "hello, world" >expect.foo &&
1369 echo hello >expect.bar &&
1370 git fast-import <<-SETUP_END &&
1371 commit refs/heads/N7
1372 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1373 data <<COMMIT
1374 hello, tree
1375 COMMIT
1377 deleteall
1378 M 644 inline foo/bar
1379 data <<EOF
1380 hello
1382 SETUP_END
1384 tree=$(git rev-parse --verify N7:) &&
1385 git fast-import <<-INPUT_END &&
1386 commit refs/heads/N8
1387 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1388 data <<COMMIT
1389 copy to root by id and modify
1390 COMMIT
1392 M 040000 $tree ""
1393 M 644 inline foo/foo
1394 data <<EOF
1395 hello, world
1397 INPUT_END
1398 git show N8:foo/foo >actual.foo &&
1399 git show N8:foo/bar >actual.bar &&
1400 test_cmp expect.foo actual.foo &&
1401 test_cmp expect.bar actual.bar'
1403 test_expect_success \
1404 'N: extract subtree' \
1405 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1406 cat >input <<-INPUT_END &&
1407 commit refs/heads/N9
1408 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1409 data <<COMMIT
1410 extract subtree branch:newdir
1411 COMMIT
1413 M 040000 $branch ""
1414 C "newdir" ""
1415 INPUT_END
1416 git fast-import <input &&
1417 git diff --exit-code branch:newdir N9'
1419 test_expect_success \
1420 'N: modify subtree, extract it, and modify again' \
1421 'echo hello >expect.baz &&
1422 echo hello, world >expect.qux &&
1423 git fast-import <<-SETUP_END &&
1424 commit refs/heads/N10
1425 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1426 data <<COMMIT
1427 hello, tree
1428 COMMIT
1430 deleteall
1431 M 644 inline foo/bar/baz
1432 data <<EOF
1433 hello
1435 SETUP_END
1437 tree=$(git rev-parse --verify N10:) &&
1438 git fast-import <<-INPUT_END &&
1439 commit refs/heads/N11
1440 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1441 data <<COMMIT
1442 copy to root by id and modify
1443 COMMIT
1445 M 040000 $tree ""
1446 M 100644 inline foo/bar/qux
1447 data <<EOF
1448 hello, world
1450 R "foo" ""
1451 C "bar/qux" "bar/quux"
1452 INPUT_END
1453 git show N11:bar/baz >actual.baz &&
1454 git show N11:bar/qux >actual.qux &&
1455 git show N11:bar/quux >actual.quux &&
1456 test_cmp expect.baz actual.baz &&
1457 test_cmp expect.qux actual.qux &&
1458 test_cmp expect.qux actual.quux'
1461 ### series O
1464 cat >input <<INPUT_END
1465 #we will
1466 commit refs/heads/O1
1467 # -- ignore all of this text
1468 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1469 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1470 data <<COMMIT
1471 dirty directory copy
1472 COMMIT
1474 # don't forget the import blank line!
1476 # yes, we started from our usual base of branch^0.
1477 # i like branch^0.
1478 from refs/heads/branch^0
1479 # and we need to reuse file2/file5 from N3 above.
1480 M 644 inline file2/file5
1481 # otherwise the tree will be different
1482 data <<EOF
1483 $file5_data
1486 # don't forget to copy file2 to file3
1487 C file2 file3
1489 # or to delete file5 from file2.
1490 D file2/file5
1491 # are we done yet?
1493 INPUT_END
1495 test_expect_success \
1496 'O: comments are all skipped' \
1497 'git fast-import <input &&
1498 test `git rev-parse N3` = `git rev-parse O1`'
1500 cat >input <<INPUT_END
1501 commit refs/heads/O2
1502 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1503 data <<COMMIT
1504 dirty directory copy
1505 COMMIT
1506 from refs/heads/branch^0
1507 M 644 inline file2/file5
1508 data <<EOF
1509 $file5_data
1511 C file2 file3
1512 D file2/file5
1514 INPUT_END
1516 test_expect_success \
1517 'O: blank lines not necessary after data commands' \
1518 'git fast-import <input &&
1519 test `git rev-parse N3` = `git rev-parse O2`'
1521 test_expect_success \
1522 'O: repack before next test' \
1523 'git repack -a -d'
1525 cat >input <<INPUT_END
1526 commit refs/heads/O3
1527 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1528 data <<COMMIT
1529 zstring
1530 COMMIT
1531 commit refs/heads/O3
1532 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1533 data <<COMMIT
1535 COMMIT
1536 checkpoint
1537 commit refs/heads/O3
1538 mark :5
1539 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1540 data <<COMMIT
1541 zempty
1542 COMMIT
1543 checkpoint
1544 commit refs/heads/O3
1545 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1546 data <<COMMIT
1547 zcommits
1548 COMMIT
1549 reset refs/tags/O3-2nd
1550 from :5
1551 reset refs/tags/O3-3rd
1552 from :5
1553 INPUT_END
1555 cat >expect <<INPUT_END
1556 string
1558 empty
1559 commits
1560 INPUT_END
1561 test_expect_success \
1562 'O: blank lines not necessary after other commands' \
1563 'git fast-import <input &&
1564 test 8 = `find .git/objects/pack -type f | wc -l` &&
1565 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1566 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1567 test_cmp expect actual'
1569 cat >input <<INPUT_END
1570 commit refs/heads/O4
1571 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1572 data <<COMMIT
1573 zstring
1574 COMMIT
1575 commit refs/heads/O4
1576 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1577 data <<COMMIT
1579 COMMIT
1580 progress Two commits down, 2 to go!
1581 commit refs/heads/O4
1582 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583 data <<COMMIT
1584 zempty
1585 COMMIT
1586 progress Three commits down, 1 to go!
1587 commit refs/heads/O4
1588 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1589 data <<COMMIT
1590 zcommits
1591 COMMIT
1592 progress I'm done!
1593 INPUT_END
1594 test_expect_success \
1595 'O: progress outputs as requested by input' \
1596 'git fast-import <input >actual &&
1597 grep "progress " <input >expect &&
1598 test_cmp expect actual'
1601 ### series P (gitlinks)
1604 cat >input <<INPUT_END
1605 blob
1606 mark :1
1607 data 10
1608 test file
1610 reset refs/heads/sub
1611 commit refs/heads/sub
1612 mark :2
1613 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1614 data 12
1615 sub_initial
1616 M 100644 :1 file
1618 blob
1619 mark :3
1620 data <<DATAEND
1621 [submodule "sub"]
1622 path = sub
1623 url = "`pwd`/sub"
1624 DATAEND
1626 commit refs/heads/subuse1
1627 mark :4
1628 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1629 data 8
1630 initial
1631 from refs/heads/master
1632 M 100644 :3 .gitmodules
1633 M 160000 :2 sub
1635 blob
1636 mark :5
1637 data 20
1638 test file
1639 more data
1641 commit refs/heads/sub
1642 mark :6
1643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644 data 11
1645 sub_second
1646 from :2
1647 M 100644 :5 file
1649 commit refs/heads/subuse1
1650 mark :7
1651 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1652 data 7
1653 second
1654 from :4
1655 M 160000 :6 sub
1657 INPUT_END
1659 test_expect_success \
1660 'P: superproject & submodule mix' \
1661 'git fast-import <input &&
1662 git checkout subuse1 &&
1663 rm -rf sub && mkdir sub && (cd sub &&
1664 git init &&
1665 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1666 git checkout master) &&
1667 git submodule init &&
1668 git submodule update'
1670 SUBLAST=$(git rev-parse --verify sub)
1671 SUBPREV=$(git rev-parse --verify sub^)
1673 cat >input <<INPUT_END
1674 blob
1675 mark :1
1676 data <<DATAEND
1677 [submodule "sub"]
1678 path = sub
1679 url = "`pwd`/sub"
1680 DATAEND
1682 commit refs/heads/subuse2
1683 mark :2
1684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1685 data 8
1686 initial
1687 from refs/heads/master
1688 M 100644 :1 .gitmodules
1689 M 160000 $SUBPREV sub
1691 commit refs/heads/subuse2
1692 mark :3
1693 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1694 data 7
1695 second
1696 from :2
1697 M 160000 $SUBLAST sub
1699 INPUT_END
1701 test_expect_success \
1702 'P: verbatim SHA gitlinks' \
1703 'git branch -D sub &&
1704 git gc && git prune &&
1705 git fast-import <input &&
1706 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1708 test_tick
1709 cat >input <<INPUT_END
1710 commit refs/heads/subuse3
1711 mark :1
1712 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1713 data <<COMMIT
1714 corrupt
1715 COMMIT
1717 from refs/heads/subuse2
1718 M 160000 inline sub
1719 data <<DATA
1720 $SUBPREV
1721 DATA
1723 INPUT_END
1725 test_expect_success 'P: fail on inline gitlink' '
1726 test_must_fail git fast-import <input'
1728 test_tick
1729 cat >input <<INPUT_END
1730 blob
1731 mark :1
1732 data <<DATA
1733 $SUBPREV
1734 DATA
1736 commit refs/heads/subuse3
1737 mark :2
1738 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1739 data <<COMMIT
1740 corrupt
1741 COMMIT
1743 from refs/heads/subuse2
1744 M 160000 :1 sub
1746 INPUT_END
1748 test_expect_success 'P: fail on blob mark in gitlink' '
1749 test_must_fail git fast-import <input'
1752 ### series Q (notes)
1755 note1_data="The first note for the first commit"
1756 note2_data="The first note for the second commit"
1757 note3_data="The first note for the third commit"
1758 note1b_data="The second note for the first commit"
1759 note1c_data="The third note for the first commit"
1760 note2b_data="The second note for the second commit"
1762 test_tick
1763 cat >input <<INPUT_END
1764 blob
1765 mark :2
1766 data <<EOF
1767 $file2_data
1770 commit refs/heads/notes-test
1771 mark :3
1772 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1773 data <<COMMIT
1774 first (:3)
1775 COMMIT
1777 M 644 :2 file2
1779 blob
1780 mark :4
1781 data $file4_len
1782 $file4_data
1783 commit refs/heads/notes-test
1784 mark :5
1785 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1786 data <<COMMIT
1787 second (:5)
1788 COMMIT
1790 M 644 :4 file4
1792 commit refs/heads/notes-test
1793 mark :6
1794 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1795 data <<COMMIT
1796 third (:6)
1797 COMMIT
1799 M 644 inline file5
1800 data <<EOF
1801 $file5_data
1804 M 755 inline file6
1805 data <<EOF
1806 $file6_data
1809 blob
1810 mark :7
1811 data <<EOF
1812 $note1_data
1815 blob
1816 mark :8
1817 data <<EOF
1818 $note2_data
1821 commit refs/notes/foobar
1822 mark :9
1823 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1824 data <<COMMIT
1825 notes (:9)
1826 COMMIT
1828 N :7 :3
1829 N :8 :5
1830 N inline :6
1831 data <<EOF
1832 $note3_data
1835 commit refs/notes/foobar
1836 mark :10
1837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1838 data <<COMMIT
1839 notes (:10)
1840 COMMIT
1842 N inline :3
1843 data <<EOF
1844 $note1b_data
1847 commit refs/notes/foobar2
1848 mark :11
1849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1850 data <<COMMIT
1851 notes (:11)
1852 COMMIT
1854 N inline :3
1855 data <<EOF
1856 $note1c_data
1859 commit refs/notes/foobar
1860 mark :12
1861 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1862 data <<COMMIT
1863 notes (:12)
1864 COMMIT
1866 deleteall
1867 N inline :5
1868 data <<EOF
1869 $note2b_data
1872 INPUT_END
1874 test_expect_success \
1875 'Q: commit notes' \
1876 'git fast-import <input &&
1877 git whatchanged notes-test'
1879 test_expect_success 'Q: verify pack' '
1880 verify_packs
1883 commit1=$(git rev-parse notes-test~2)
1884 commit2=$(git rev-parse notes-test^)
1885 commit3=$(git rev-parse notes-test)
1887 cat >expect <<EOF
1888 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1889 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1891 first (:3)
1893 test_expect_success \
1894 'Q: verify first commit' \
1895 'git cat-file commit notes-test~2 | sed 1d >actual &&
1896 test_cmp expect actual'
1898 cat >expect <<EOF
1899 parent $commit1
1900 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1903 second (:5)
1905 test_expect_success \
1906 'Q: verify second commit' \
1907 'git cat-file commit notes-test^ | sed 1d >actual &&
1908 test_cmp expect actual'
1910 cat >expect <<EOF
1911 parent $commit2
1912 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1913 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1915 third (:6)
1917 test_expect_success \
1918 'Q: verify third commit' \
1919 'git cat-file commit notes-test | sed 1d >actual &&
1920 test_cmp expect actual'
1922 cat >expect <<EOF
1923 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1924 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1926 notes (:9)
1928 test_expect_success \
1929 'Q: verify first notes commit' \
1930 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1931 test_cmp expect actual'
1933 cat >expect.unsorted <<EOF
1934 100644 blob $commit1
1935 100644 blob $commit2
1936 100644 blob $commit3
1938 cat expect.unsorted | sort >expect
1939 test_expect_success \
1940 'Q: verify first notes tree' \
1941 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1942 test_cmp expect actual'
1944 echo "$note1_data" >expect
1945 test_expect_success \
1946 'Q: verify first note for first commit' \
1947 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1949 echo "$note2_data" >expect
1950 test_expect_success \
1951 'Q: verify first note for second commit' \
1952 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1954 echo "$note3_data" >expect
1955 test_expect_success \
1956 'Q: verify first note for third commit' \
1957 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1959 cat >expect <<EOF
1960 parent `git rev-parse --verify refs/notes/foobar~2`
1961 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1962 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1964 notes (:10)
1966 test_expect_success \
1967 'Q: verify second notes commit' \
1968 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1969 test_cmp expect actual'
1971 cat >expect.unsorted <<EOF
1972 100644 blob $commit1
1973 100644 blob $commit2
1974 100644 blob $commit3
1976 cat expect.unsorted | sort >expect
1977 test_expect_success \
1978 'Q: verify second notes tree' \
1979 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1980 test_cmp expect actual'
1982 echo "$note1b_data" >expect
1983 test_expect_success \
1984 'Q: verify second note for first commit' \
1985 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1987 echo "$note2_data" >expect
1988 test_expect_success \
1989 'Q: verify first note for second commit' \
1990 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1992 echo "$note3_data" >expect
1993 test_expect_success \
1994 'Q: verify first note for third commit' \
1995 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1997 cat >expect <<EOF
1998 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1999 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2001 notes (:11)
2003 test_expect_success \
2004 'Q: verify third notes commit' \
2005 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2006 test_cmp expect actual'
2008 cat >expect.unsorted <<EOF
2009 100644 blob $commit1
2011 cat expect.unsorted | sort >expect
2012 test_expect_success \
2013 'Q: verify third notes tree' \
2014 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2015 test_cmp expect actual'
2017 echo "$note1c_data" >expect
2018 test_expect_success \
2019 'Q: verify third note for first commit' \
2020 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2022 cat >expect <<EOF
2023 parent `git rev-parse --verify refs/notes/foobar^`
2024 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2025 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2027 notes (:12)
2029 test_expect_success \
2030 'Q: verify fourth notes commit' \
2031 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2032 test_cmp expect actual'
2034 cat >expect.unsorted <<EOF
2035 100644 blob $commit2
2037 cat expect.unsorted | sort >expect
2038 test_expect_success \
2039 'Q: verify fourth notes tree' \
2040 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2041 test_cmp expect actual'
2043 echo "$note2b_data" >expect
2044 test_expect_success \
2045 'Q: verify second note for second commit' \
2046 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2048 cat >input <<EOF
2049 reset refs/heads/Q0
2051 commit refs/heads/note-Q0
2052 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2053 data <<COMMIT
2054 Note for an empty branch.
2055 COMMIT
2057 N inline refs/heads/Q0
2058 data <<NOTE
2059 some note
2060 NOTE
2062 test_expect_success \
2063 'Q: deny note on empty branch' \
2064 'test_must_fail git fast-import <input'
2066 ### series R (feature and option)
2069 cat >input <<EOF
2070 feature no-such-feature-exists
2073 test_expect_success 'R: abort on unsupported feature' '
2074 test_must_fail git fast-import <input
2077 cat >input <<EOF
2078 feature date-format=now
2081 test_expect_success 'R: supported feature is accepted' '
2082 git fast-import <input
2085 cat >input << EOF
2086 blob
2087 data 3
2089 feature date-format=now
2092 test_expect_success 'R: abort on receiving feature after data command' '
2093 test_must_fail git fast-import <input
2096 cat >input << EOF
2097 feature import-marks=git.marks
2098 feature import-marks=git2.marks
2101 test_expect_success 'R: only one import-marks feature allowed per stream' '
2102 test_must_fail git fast-import <input
2105 cat >input << EOF
2106 feature export-marks=git.marks
2107 blob
2108 mark :1
2109 data 3
2114 test_expect_success \
2115 'R: export-marks feature results in a marks file being created' \
2116 'cat input | git fast-import &&
2117 grep :1 git.marks'
2119 test_expect_success \
2120 'R: export-marks options can be overridden by commandline options' \
2121 'cat input | git fast-import --export-marks=other.marks &&
2122 grep :1 other.marks'
2124 test_expect_success 'R: catch typo in marks file name' '
2125 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2126 echo "feature import-marks=nonexistent.marks" |
2127 test_must_fail git fast-import
2130 test_expect_success 'R: import and output marks can be the same file' '
2131 rm -f io.marks &&
2132 blob=$(echo hi | git hash-object --stdin) &&
2133 cat >expect <<-EOF &&
2134 :1 $blob
2135 :2 $blob
2137 git fast-import --export-marks=io.marks <<-\EOF &&
2138 blob
2139 mark :1
2140 data 3
2144 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2145 blob
2146 mark :2
2147 data 3
2151 test_cmp expect io.marks
2154 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2155 rm -f io.marks &&
2156 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2157 blob
2158 mark :1
2159 data 3
2165 test_expect_success 'R: --import-marks-if-exists' '
2166 rm -f io.marks &&
2167 blob=$(echo hi | git hash-object --stdin) &&
2168 echo ":1 $blob" >expect &&
2169 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2170 blob
2171 mark :1
2172 data 3
2176 test_cmp expect io.marks
2179 test_expect_success 'R: feature import-marks-if-exists' '
2180 rm -f io.marks &&
2181 >expect &&
2183 git fast-import --export-marks=io.marks <<-\EOF &&
2184 feature import-marks-if-exists=not_io.marks
2186 test_cmp expect io.marks &&
2188 blob=$(echo hi | git hash-object --stdin) &&
2190 echo ":1 $blob" >io.marks &&
2191 echo ":1 $blob" >expect &&
2192 echo ":2 $blob" >>expect &&
2194 git fast-import --export-marks=io.marks <<-\EOF &&
2195 feature import-marks-if-exists=io.marks
2196 blob
2197 mark :2
2198 data 3
2202 test_cmp expect io.marks &&
2204 echo ":3 $blob" >>expect &&
2206 git fast-import --import-marks=io.marks \
2207 --export-marks=io.marks <<-\EOF &&
2208 feature import-marks-if-exists=not_io.marks
2209 blob
2210 mark :3
2211 data 3
2215 test_cmp expect io.marks &&
2217 >expect &&
2219 git fast-import --import-marks-if-exists=not_io.marks \
2220 --export-marks=io.marks <<-\EOF
2221 feature import-marks-if-exists=io.marks
2223 test_cmp expect io.marks
2226 cat >input << EOF
2227 feature import-marks=marks.out
2228 feature export-marks=marks.new
2231 test_expect_success \
2232 'R: import to output marks works without any content' \
2233 'cat input | git fast-import &&
2234 test_cmp marks.out marks.new'
2236 cat >input <<EOF
2237 feature import-marks=nonexistent.marks
2238 feature export-marks=marks.new
2241 test_expect_success \
2242 'R: import marks prefers commandline marks file over the stream' \
2243 'cat input | git fast-import --import-marks=marks.out &&
2244 test_cmp marks.out marks.new'
2247 cat >input <<EOF
2248 feature import-marks=nonexistent.marks
2249 feature export-marks=combined.marks
2252 test_expect_success 'R: multiple --import-marks= should be honoured' '
2253 head -n2 marks.out > one.marks &&
2254 tail -n +3 marks.out > two.marks &&
2255 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2256 test_cmp marks.out combined.marks
2259 cat >input <<EOF
2260 feature relative-marks
2261 feature import-marks=relative.in
2262 feature export-marks=relative.out
2265 test_expect_success 'R: feature relative-marks should be honoured' '
2266 mkdir -p .git/info/fast-import/ &&
2267 cp marks.new .git/info/fast-import/relative.in &&
2268 git fast-import <input &&
2269 test_cmp marks.new .git/info/fast-import/relative.out
2272 cat >input <<EOF
2273 feature relative-marks
2274 feature import-marks=relative.in
2275 feature no-relative-marks
2276 feature export-marks=non-relative.out
2279 test_expect_success 'R: feature no-relative-marks should be honoured' '
2280 git fast-import <input &&
2281 test_cmp marks.new non-relative.out
2284 test_expect_success 'R: feature ls supported' '
2285 echo "feature ls" |
2286 git fast-import
2289 test_expect_success 'R: feature cat-blob supported' '
2290 echo "feature cat-blob" |
2291 git fast-import
2294 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2295 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2298 test_expect_success NOT_MINGW 'R: print old blob' '
2299 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2300 cat >expect <<-EOF &&
2301 ${blob} blob 11
2302 yes it can
2305 echo "cat-blob $blob" |
2306 git fast-import --cat-blob-fd=6 6>actual &&
2307 test_cmp expect actual
2310 test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' '
2311 echo hello >greeting &&
2312 blob=$(git hash-object -w greeting) &&
2313 cat >expect <<-EOF &&
2314 ${blob} blob 6
2315 hello
2318 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2319 cat-blob $blob
2321 test_cmp expect actual.3 &&
2322 test_cmp empty actual.1 &&
2323 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2324 option cat-blob-fd=3
2325 cat-blob $blob
2327 test_cmp empty actual.3 &&
2328 test_cmp expect actual.1
2331 test_expect_success NOT_MINGW 'R: print new blob' '
2332 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2333 cat >expect <<-EOF &&
2334 ${blob} blob 12
2335 yep yep yep
2338 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2339 blob
2340 mark :1
2341 data <<BLOB_END
2342 yep yep yep
2343 BLOB_END
2344 cat-blob :1
2346 test_cmp expect actual
2349 test_expect_success NOT_MINGW 'R: print new blob by sha1' '
2350 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2351 cat >expect <<-EOF &&
2352 ${blob} blob 25
2353 a new blob named by sha1
2356 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2357 blob
2358 data <<BLOB_END
2359 a new blob named by sha1
2360 BLOB_END
2361 cat-blob $blob
2363 test_cmp expect actual
2366 test_expect_success 'setup: big file' '
2368 echo "the quick brown fox jumps over the lazy dog" >big &&
2369 for i in 1 2 3
2371 cat big big big big >bigger &&
2372 cat bigger bigger bigger bigger >big ||
2373 exit
2374 done
2378 test_expect_success 'R: print two blobs to stdout' '
2379 blob1=$(git hash-object big) &&
2380 blob1_len=$(wc -c <big) &&
2381 blob2=$(echo hello | git hash-object --stdin) &&
2383 echo ${blob1} blob $blob1_len &&
2384 cat big &&
2385 cat <<-EOF
2387 ${blob2} blob 6
2388 hello
2391 } >expect &&
2393 cat <<-\END_PART1 &&
2394 blob
2395 mark :1
2396 data <<data_end
2397 END_PART1
2398 cat big &&
2399 cat <<-\EOF
2400 data_end
2401 blob
2402 mark :2
2403 data <<data_end
2404 hello
2405 data_end
2406 cat-blob :1
2407 cat-blob :2
2410 git fast-import >actual &&
2411 test_cmp expect actual
2414 test_expect_success PIPE 'R: copy using cat-file' '
2415 expect_id=$(git hash-object big) &&
2416 expect_len=$(wc -c <big) &&
2417 echo $expect_id blob $expect_len >expect.response &&
2419 rm -f blobs &&
2420 cat >frontend <<-\FRONTEND_END &&
2421 #!/bin/sh
2422 FRONTEND_END
2424 mkfifo blobs &&
2426 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2427 cat <<-\EOF &&
2428 feature cat-blob
2429 blob
2430 mark :1
2431 data <<BLOB
2433 cat big &&
2434 cat <<-\EOF &&
2435 BLOB
2436 cat-blob :1
2439 read blob_id type size <&3 &&
2440 echo "$blob_id $type $size" >response &&
2441 head_c $size >blob <&3 &&
2442 read newline <&3 &&
2444 cat <<-EOF &&
2445 commit refs/heads/copied
2446 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2447 data <<COMMIT
2448 copy big file as file3
2449 COMMIT
2450 M 644 inline file3
2451 data <<BLOB
2453 cat blob &&
2454 echo BLOB
2455 ) 3<blobs |
2456 git fast-import --cat-blob-fd=3 3>blobs &&
2457 git show copied:file3 >actual &&
2458 test_cmp expect.response response &&
2459 test_cmp big actual
2462 test_expect_success PIPE 'R: print blob mid-commit' '
2463 rm -f blobs &&
2464 echo "A blob from _before_ the commit." >expect &&
2465 mkfifo blobs &&
2467 exec 3<blobs &&
2468 cat <<-EOF &&
2469 feature cat-blob
2470 blob
2471 mark :1
2472 data <<BLOB
2473 A blob from _before_ the commit.
2474 BLOB
2475 commit refs/heads/temporary
2476 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2477 data <<COMMIT
2478 Empty commit
2479 COMMIT
2480 cat-blob :1
2483 read blob_id type size <&3 &&
2484 head_c $size >actual <&3 &&
2485 read newline <&3 &&
2487 echo
2489 git fast-import --cat-blob-fd=3 3>blobs &&
2490 test_cmp expect actual
2493 test_expect_success PIPE 'R: print staged blob within commit' '
2494 rm -f blobs &&
2495 echo "A blob from _within_ the commit." >expect &&
2496 mkfifo blobs &&
2498 exec 3<blobs &&
2499 cat <<-EOF &&
2500 feature cat-blob
2501 commit refs/heads/within
2502 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2503 data <<COMMIT
2504 Empty commit
2505 COMMIT
2506 M 644 inline within
2507 data <<BLOB
2508 A blob from _within_ the commit.
2509 BLOB
2512 to_get=$(
2513 echo "A blob from _within_ the commit." |
2514 git hash-object --stdin
2515 ) &&
2516 echo "cat-blob $to_get" &&
2518 read blob_id type size <&3 &&
2519 head_c $size >actual <&3 &&
2520 read newline <&3 &&
2522 echo deleteall
2524 git fast-import --cat-blob-fd=3 3>blobs &&
2525 test_cmp expect actual
2528 cat >input << EOF
2529 option git quiet
2530 blob
2531 data 3
2536 test_expect_success 'R: quiet option results in no stats being output' '
2537 cat input | git fast-import 2> output &&
2538 test_cmp empty output
2541 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2542 echo feature done | test_must_fail git fast-import &&
2543 test_must_fail git fast-import --done </dev/null
2546 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2547 git fast-import <<-\EOF &&
2548 feature done
2549 done
2550 trailing gibberish
2552 git fast-import <<-\EOF
2553 done
2554 more trailing gibberish
2558 test_expect_success 'R: terminating "done" within commit' '
2559 cat >expect <<-\EOF &&
2560 OBJID
2561 :000000 100644 OBJID OBJID A hello.c
2562 :000000 100644 OBJID OBJID A hello2.c
2564 git fast-import <<-EOF &&
2565 commit refs/heads/done-ends
2566 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2567 data <<EOT
2568 Commit terminated by "done" command
2570 M 100644 inline hello.c
2571 data <<EOT
2572 Hello, world.
2574 C hello.c hello2.c
2575 done
2577 git rev-list done-ends |
2578 git diff-tree -r --stdin --root --always |
2579 sed -e "s/$_x40/OBJID/g" >actual &&
2580 test_cmp expect actual
2583 cat >input <<EOF
2584 option git non-existing-option
2587 test_expect_success 'R: die on unknown option' '
2588 test_must_fail git fast-import <input
2591 test_expect_success 'R: unknown commandline options are rejected' '\
2592 test_must_fail git fast-import --non-existing-option < /dev/null
2595 test_expect_success 'R: die on invalid option argument' '
2596 echo "option git active-branches=-5" |
2597 test_must_fail git fast-import &&
2598 echo "option git depth=" |
2599 test_must_fail git fast-import &&
2600 test_must_fail git fast-import --depth="5 elephants" </dev/null
2603 cat >input <<EOF
2604 option non-existing-vcs non-existing-option
2607 test_expect_success 'R: ignore non-git options' '
2608 git fast-import <input
2612 ## R: very large blobs
2614 blobsize=$((2*1024*1024 + 53))
2615 test-genrandom bar $blobsize >expect
2616 cat >input <<INPUT_END
2617 commit refs/heads/big-file
2618 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2619 data <<COMMIT
2620 R - big file
2621 COMMIT
2623 M 644 inline big1
2624 data $blobsize
2625 INPUT_END
2626 cat expect >>input
2627 cat >>input <<INPUT_END
2628 M 644 inline big2
2629 data $blobsize
2630 INPUT_END
2631 cat expect >>input
2632 echo >>input
2634 test_expect_success \
2635 'R: blob bigger than threshold' \
2636 'test_create_repo R &&
2637 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2639 test_expect_success 'R: verify created pack' '
2641 cd R &&
2642 verify_packs -v > ../verify
2646 test_expect_success \
2647 'R: verify written objects' \
2648 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2649 test_cmp expect actual &&
2650 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2651 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2652 test $a = $b'
2653 test_expect_success \
2654 'R: blob appears only once' \
2655 'n=$(grep $a verify | wc -l) &&
2656 test 1 = $n'
2659 ### series S
2662 # Make sure missing spaces and EOLs after mark references
2663 # cause errors.
2665 # Setup:
2667 # 1--2--4
2668 # \ /
2669 # -3-
2671 # commit marks: 301, 302, 303, 304
2672 # blob marks: 403, 404, resp.
2673 # note mark: 202
2675 # The error message when a space is missing not at the
2676 # end of the line is:
2678 # Missing space after ..
2680 # or when extra characters come after the mark at the end
2681 # of the line:
2683 # Garbage after ..
2685 # or when the dataref is neither "inline " or a known SHA1,
2687 # Invalid dataref ..
2689 test_tick
2691 cat >input <<INPUT_END
2692 commit refs/heads/S
2693 mark :301
2694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2695 data <<COMMIT
2696 commit 1
2697 COMMIT
2698 M 100644 inline hello.c
2699 data <<BLOB
2700 blob 1
2701 BLOB
2703 commit refs/heads/S
2704 mark :302
2705 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2706 data <<COMMIT
2707 commit 2
2708 COMMIT
2709 from :301
2710 M 100644 inline hello.c
2711 data <<BLOB
2712 blob 2
2713 BLOB
2715 blob
2716 mark :403
2717 data <<BLOB
2718 blob 3
2719 BLOB
2721 blob
2722 mark :202
2723 data <<BLOB
2724 note 2
2725 BLOB
2726 INPUT_END
2728 test_expect_success 'S: initialize for S tests' '
2729 git fast-import --export-marks=marks <input
2733 # filemodify, three datarefs
2735 test_expect_success 'S: filemodify with garbage after mark must fail' '
2736 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2737 commit refs/heads/S
2738 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2739 data <<COMMIT
2740 commit N
2741 COMMIT
2742 M 100644 :403x hello.c
2744 cat err &&
2745 test_i18ngrep "space after mark" err
2748 # inline is misspelled; fast-import thinks it is some unknown dataref
2749 test_expect_success 'S: filemodify with garbage after inline must fail' '
2750 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2751 commit refs/heads/S
2752 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2753 data <<COMMIT
2754 commit N
2755 COMMIT
2756 M 100644 inlineX hello.c
2757 data <<BLOB
2758 inline
2759 BLOB
2761 cat err &&
2762 test_i18ngrep "nvalid dataref" err
2765 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2766 sha1=$(grep :403 marks | cut -d\ -f2) &&
2767 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2768 commit refs/heads/S
2769 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2770 data <<COMMIT
2771 commit N
2772 COMMIT
2773 M 100644 ${sha1}x hello.c
2775 cat err &&
2776 test_i18ngrep "space after SHA1" err
2780 # notemodify, three ways to say dataref
2782 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2783 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2784 commit refs/heads/S
2785 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2786 data <<COMMIT
2787 commit S note dataref markref
2788 COMMIT
2789 N :202x :302
2791 cat err &&
2792 test_i18ngrep "space after mark" err
2795 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2796 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2797 commit refs/heads/S
2798 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2799 data <<COMMIT
2800 commit S note dataref inline
2801 COMMIT
2802 N inlineX :302
2803 data <<BLOB
2804 note blob
2805 BLOB
2807 cat err &&
2808 test_i18ngrep "nvalid dataref" err
2811 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2812 sha1=$(grep :202 marks | cut -d\ -f2) &&
2813 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2814 commit refs/heads/S
2815 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2816 data <<COMMIT
2817 commit S note dataref sha1
2818 COMMIT
2819 N ${sha1}x :302
2821 cat err &&
2822 test_i18ngrep "space after SHA1" err
2826 # notemodify, mark in committish
2828 test_expect_success 'S: notemodify with garbarge after mark committish must fail' '
2829 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2830 commit refs/heads/Snotes
2831 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2832 data <<COMMIT
2833 commit S note committish
2834 COMMIT
2835 N :202 :302x
2837 cat err &&
2838 test_i18ngrep "after mark" err
2842 # from
2844 test_expect_success 'S: from with garbage after mark must fail' '
2845 # no &&
2846 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err
2847 commit refs/heads/S2
2848 mark :303
2849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2850 data <<COMMIT
2851 commit 3
2852 COMMIT
2853 from :301x
2854 M 100644 :403 hello.c
2857 ret=$? &&
2858 echo returned $ret &&
2859 test $ret -ne 0 && # failed, but it created the commit
2861 # go create the commit, need it for merge test
2862 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2863 commit refs/heads/S2
2864 mark :303
2865 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2866 data <<COMMIT
2867 commit 3
2868 COMMIT
2869 from :301
2870 M 100644 :403 hello.c
2873 # now evaluate the error
2874 cat err &&
2875 test_i18ngrep "after mark" err
2880 # merge
2882 test_expect_success 'S: merge with garbage after mark must fail' '
2883 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2884 commit refs/heads/S
2885 mark :304
2886 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2887 data <<COMMIT
2888 merge 4
2889 COMMIT
2890 from :302
2891 merge :303x
2892 M 100644 :403 hello.c
2894 cat err &&
2895 test_i18ngrep "after mark" err
2899 # tag, from markref
2901 test_expect_success 'S: tag with garbage after mark must fail' '
2902 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2903 tag refs/tags/Stag
2904 from :302x
2905 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2906 data <<TAG
2907 tag S
2910 cat err &&
2911 test_i18ngrep "after mark" err
2915 # cat-blob markref
2917 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2918 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2919 cat-blob :403x
2921 cat err &&
2922 test_i18ngrep "after mark" err
2926 # ls markref
2928 test_expect_success 'S: ls with garbage after mark must fail' '
2929 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2930 ls :302x hello.c
2932 cat err &&
2933 test_i18ngrep "space after mark" err
2936 test_expect_success 'S: ls with garbage after sha1 must fail' '
2937 sha1=$(grep :302 marks | cut -d\ -f2) &&
2938 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2939 ls ${sha1}x hello.c
2941 cat err &&
2942 test_i18ngrep "space after tree-ish" err
2945 test_done