Merge branch 'da/user-useconfigonly'
[git/debian.git] / t / t9300-fast-import.sh
blob4c5f3c9d418bf6f85f1067b2cb1481bf941ff954
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 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 ###
51 ### series A
52 ###
54 test_expect_success 'empty stream succeeds' '
55 git fast-import </dev/null
58 test_expect_success 'A: create pack from stdin' '
59 test_tick &&
60 cat >input <<-INPUT_END &&
61 blob
62 mark :2
63 data <<EOF
64 $file2_data
65 EOF
67 blob
68 mark :3
69 data <<END
70 $file3_data
71 END
73 blob
74 mark :4
75 data $file4_len
76 $file4_data
77 commit refs/heads/master
78 mark :5
79 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
80 data <<COMMIT
81 initial
82 COMMIT
84 M 644 :2 file2
85 M 644 :3 file3
86 M 755 :4 file4
88 tag series-A
89 from :5
90 data <<EOF
91 An annotated tag without a tagger
92 EOF
94 tag series-A-blob
95 from :3
96 data <<EOF
97 An annotated tag that annotates a blob.
98 EOF
100 INPUT_END
101 git fast-import --export-marks=marks.out <input &&
102 git whatchanged master
105 test_expect_success 'A: verify pack' '
106 verify_packs
109 test_expect_success 'A: verify commit' '
110 cat >expect <<-EOF &&
111 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
112 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 initial
116 git cat-file commit master | sed 1d >actual &&
117 test_cmp expect actual
120 test_expect_success 'A: verify tree' '
121 cat >expect <<-EOF &&
122 100644 blob file2
123 100644 blob file3
124 100755 blob file4
126 git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
127 test_cmp expect actual
130 test_expect_success 'A: verify file2' '
131 echo "$file2_data" >expect &&
132 git cat-file blob master:file2 >actual &&
133 test_cmp expect actual
136 test_expect_success 'A: verify file3' '
137 echo "$file3_data" >expect &&
138 git cat-file blob master:file3 >actual &&
139 test_cmp expect actual
142 test_expect_success 'A: verify file4' '
143 printf "$file4_data" >expect &&
144 git cat-file blob master:file4 >actual &&
145 test_cmp expect actual
148 test_expect_success 'A: verify tag/series-A' '
149 cat >expect <<-EOF &&
150 object $(git rev-parse refs/heads/master)
151 type commit
152 tag series-A
154 An annotated tag without a tagger
156 git cat-file tag tags/series-A >actual &&
157 test_cmp expect actual
160 test_expect_success 'A: verify tag/series-A-blob' '
161 cat >expect <<-EOF &&
162 object $(git rev-parse refs/heads/master:file3)
163 type blob
164 tag series-A-blob
166 An annotated tag that annotates a blob.
168 git cat-file tag tags/series-A-blob >actual &&
169 test_cmp expect actual
172 test_expect_success 'A: verify marks output' '
173 cat >expect <<-EOF &&
174 :2 $(git rev-parse --verify master:file2)
175 :3 $(git rev-parse --verify master:file3)
176 :4 $(git rev-parse --verify master:file4)
177 :5 $(git rev-parse --verify master^0)
179 test_cmp expect marks.out
182 test_expect_success 'A: verify marks import' '
183 git fast-import \
184 --import-marks=marks.out \
185 --export-marks=marks.new \
186 </dev/null &&
187 test_cmp expect marks.new
190 test_expect_success 'A: tag blob by sha1' '
191 test_tick &&
192 new_blob=$(echo testing | git hash-object --stdin) &&
193 cat >input <<-INPUT_END &&
194 tag series-A-blob-2
195 from $(git rev-parse refs/heads/master:file3)
196 data <<EOF
197 Tag blob by sha1.
200 blob
201 mark :6
202 data <<EOF
203 testing
206 commit refs/heads/new_blob
207 committer <> 0 +0000
208 data 0
209 M 644 :6 new_blob
210 #pretend we got sha1 from fast-import
211 ls "new_blob"
213 tag series-A-blob-3
214 from $new_blob
215 data <<EOF
216 Tag new_blob.
218 INPUT_END
220 cat >expect <<-EOF &&
221 object $(git rev-parse refs/heads/master:file3)
222 type blob
223 tag series-A-blob-2
225 Tag blob by sha1.
226 object $new_blob
227 type blob
228 tag series-A-blob-3
230 Tag new_blob.
233 git fast-import <input &&
234 git cat-file tag tags/series-A-blob-2 >actual &&
235 git cat-file tag tags/series-A-blob-3 >>actual &&
236 test_cmp expect actual
239 test_expect_success 'A: verify marks import does not crash' '
240 test_tick &&
241 cat >input <<-INPUT_END &&
242 commit refs/heads/verify--import-marks
243 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
244 data <<COMMIT
245 recreate from :5
246 COMMIT
248 from :5
249 M 755 :2 copy-of-file2
251 INPUT_END
253 git fast-import --import-marks=marks.out <input &&
254 git whatchanged verify--import-marks
257 test_expect_success 'A: verify pack' '
258 verify_packs
261 test_expect_success 'A: verify diff' '
262 cat >expect <<-EOF &&
263 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
265 git diff-tree -M -r master verify--import-marks >actual &&
266 compare_diff_raw expect actual &&
267 test $(git rev-parse --verify master:file2) \
268 = $(git rev-parse --verify verify--import-marks:copy-of-file2)
271 test_expect_success 'A: export marks with large values' '
272 test_tick &&
273 mt=$(git hash-object --stdin < /dev/null) &&
274 >input.blob &&
275 >marks.exp &&
276 >tree.exp &&
278 cat >input.commit <<-EOF &&
279 commit refs/heads/verify--dump-marks
280 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
281 data <<COMMIT
282 test the sparse array dumping routines with exponentially growing marks
283 COMMIT
286 i=0 l=4 m=6 n=7 &&
287 while test "$i" -lt 27
289 cat >>input.blob <<-EOF &&
290 blob
291 mark :$l
292 data 0
293 blob
294 mark :$m
295 data 0
296 blob
297 mark :$n
298 data 0
300 echo "M 100644 :$l l$i" >>input.commit &&
301 echo "M 100644 :$m m$i" >>input.commit &&
302 echo "M 100644 :$n n$i" >>input.commit &&
304 echo ":$l $mt" >>marks.exp &&
305 echo ":$m $mt" >>marks.exp &&
306 echo ":$n $mt" >>marks.exp &&
308 printf "100644 blob $mt\tl$i\n" >>tree.exp &&
309 printf "100644 blob $mt\tm$i\n" >>tree.exp &&
310 printf "100644 blob $mt\tn$i\n" >>tree.exp &&
312 l=$(($l + $l)) &&
313 m=$(($m + $m)) &&
314 n=$(($l + $n)) &&
316 i=$((1 + $i)) || return 1
317 done &&
319 sort tree.exp > tree.exp_s &&
321 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
322 git ls-tree refs/heads/verify--dump-marks >tree.out &&
323 test_cmp tree.exp_s tree.out &&
324 test_cmp marks.exp marks.large
328 ### series B
331 test_expect_success 'B: fail on invalid blob sha1' '
332 test_tick &&
333 cat >input <<-INPUT_END &&
334 commit refs/heads/branch
335 mark :1
336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
337 data <<COMMIT
338 corrupt
339 COMMIT
341 from refs/heads/master
342 M 755 0000000000000000000000000000000000000001 zero1
344 INPUT_END
346 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
347 test_must_fail git fast-import <input
350 test_expect_success 'B: accept branch name "TEMP_TAG"' '
351 cat >input <<-INPUT_END &&
352 commit TEMP_TAG
353 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
354 data <<COMMIT
355 tag base
356 COMMIT
358 from refs/heads/master
360 INPUT_END
362 test_when_finished "rm -f .git/TEMP_TAG
363 git gc
364 git prune" &&
365 git fast-import <input &&
366 test -f .git/TEMP_TAG &&
367 test $(git rev-parse master) = $(git rev-parse TEMP_TAG^)
370 test_expect_success 'B: accept empty committer' '
371 cat >input <<-INPUT_END &&
372 commit refs/heads/empty-committer-1
373 committer <> $GIT_COMMITTER_DATE
374 data <<COMMIT
375 empty commit
376 COMMIT
377 INPUT_END
379 test_when_finished "git update-ref -d refs/heads/empty-committer-1
380 git gc
381 git prune" &&
382 git fast-import <input &&
383 out=$(git fsck) &&
384 echo "$out" &&
385 test -z "$out"
388 test_expect_success 'B: accept and fixup committer with no name' '
389 cat >input <<-INPUT_END &&
390 commit refs/heads/empty-committer-2
391 committer <a@b.com> $GIT_COMMITTER_DATE
392 data <<COMMIT
393 empty commit
394 COMMIT
395 INPUT_END
397 test_when_finished "git update-ref -d refs/heads/empty-committer-2
398 git gc
399 git prune" &&
400 git fast-import <input &&
401 out=$(git fsck) &&
402 echo "$out" &&
403 test -z "$out"
406 test_expect_success 'B: fail on invalid committer (1)' '
407 cat >input <<-INPUT_END &&
408 commit refs/heads/invalid-committer
409 committer Name email> $GIT_COMMITTER_DATE
410 data <<COMMIT
411 empty commit
412 COMMIT
413 INPUT_END
415 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
416 test_must_fail git fast-import <input
419 test_expect_success 'B: fail on invalid committer (2)' '
420 cat >input <<-INPUT_END &&
421 commit refs/heads/invalid-committer
422 committer Name <e<mail> $GIT_COMMITTER_DATE
423 data <<COMMIT
424 empty commit
425 COMMIT
426 INPUT_END
428 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
429 test_must_fail git fast-import <input
432 test_expect_success 'B: fail on invalid committer (3)' '
433 cat >input <<-INPUT_END &&
434 commit refs/heads/invalid-committer
435 committer Name <email>> $GIT_COMMITTER_DATE
436 data <<COMMIT
437 empty commit
438 COMMIT
439 INPUT_END
441 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
442 test_must_fail git fast-import <input
445 test_expect_success 'B: fail on invalid committer (4)' '
446 cat >input <<-INPUT_END &&
447 commit refs/heads/invalid-committer
448 committer Name <email $GIT_COMMITTER_DATE
449 data <<COMMIT
450 empty commit
451 COMMIT
452 INPUT_END
454 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
455 test_must_fail git fast-import <input
458 test_expect_success 'B: fail on invalid committer (5)' '
459 cat >input <<-INPUT_END &&
460 commit refs/heads/invalid-committer
461 committer Name<email> $GIT_COMMITTER_DATE
462 data <<COMMIT
463 empty commit
464 COMMIT
465 INPUT_END
467 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
468 test_must_fail git fast-import <input
472 ### series C
475 test_expect_success 'C: incremental import create pack from stdin' '
476 newf=$(echo hi newf | git hash-object -w --stdin) &&
477 oldf=$(git rev-parse --verify master:file2) &&
478 test_tick &&
479 cat >input <<-INPUT_END &&
480 commit refs/heads/branch
481 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
482 data <<COMMIT
483 second
484 COMMIT
486 from refs/heads/master
487 M 644 $oldf file2/oldf
488 M 755 $newf file2/newf
489 D file3
491 INPUT_END
493 git fast-import <input &&
494 git whatchanged branch
497 test_expect_success 'C: verify pack' '
498 verify_packs
501 test_expect_success 'C: validate reuse existing blob' '
502 test $newf = $(git rev-parse --verify branch:file2/newf) &&
503 test $oldf = $(git rev-parse --verify branch:file2/oldf)
506 test_expect_success 'C: verify commit' '
507 cat >expect <<-EOF &&
508 parent $(git rev-parse --verify master^0)
509 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
510 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
512 second
515 git cat-file commit branch | sed 1d >actual &&
516 test_cmp expect actual
519 test_expect_success 'C: validate rename result' '
520 cat >expect <<-EOF &&
521 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
522 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
523 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
525 git diff-tree -M -r master branch >actual &&
526 compare_diff_raw expect actual
530 ### series D
533 test_expect_success 'D: inline data in commit' '
534 test_tick &&
535 cat >input <<-INPUT_END &&
536 commit refs/heads/branch
537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
538 data <<COMMIT
539 third
540 COMMIT
542 from refs/heads/branch^0
543 M 644 inline newdir/interesting
544 data <<EOF
545 $file5_data
548 M 755 inline newdir/exec.sh
549 data <<EOF
550 $file6_data
553 INPUT_END
555 git fast-import <input &&
556 git whatchanged branch
559 test_expect_success 'D: verify pack' '
560 verify_packs
563 test_expect_success 'D: validate new files added' '
564 cat >expect <<-EOF &&
565 :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
566 :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
568 git diff-tree -M -r branch^ branch >actual &&
569 compare_diff_raw expect actual
572 test_expect_success 'D: verify file5' '
573 echo "$file5_data" >expect &&
574 git cat-file blob branch:newdir/interesting >actual &&
575 test_cmp expect actual
578 test_expect_success 'D: verify file6' '
579 echo "$file6_data" >expect &&
580 git cat-file blob branch:newdir/exec.sh >actual &&
581 test_cmp expect actual
585 ### series E
588 test_expect_success 'E: rfc2822 date, --date-format=raw' '
589 cat >input <<-INPUT_END &&
590 commit refs/heads/branch
591 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
592 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
593 data <<COMMIT
594 RFC 2822 type date
595 COMMIT
597 from refs/heads/branch^0
599 INPUT_END
601 test_must_fail git fast-import --date-format=raw <input
603 test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
604 git fast-import --date-format=rfc2822 <input
607 test_expect_success 'E: verify pack' '
608 verify_packs
611 test_expect_success 'E: verify commit' '
612 cat >expect <<-EOF &&
613 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
614 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
616 RFC 2822 type date
618 git cat-file commit branch | sed 1,2d >actual &&
619 test_cmp expect actual
623 ### series F
626 test_expect_success 'F: non-fast-forward update skips' '
627 old_branch=$(git rev-parse --verify branch^0) &&
628 test_tick &&
629 cat >input <<-INPUT_END &&
630 commit refs/heads/branch
631 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
632 data <<COMMIT
633 losing things already?
634 COMMIT
636 from refs/heads/branch~1
638 reset refs/heads/other
639 from refs/heads/branch
641 INPUT_END
643 test_must_fail git fast-import <input &&
644 # branch must remain unaffected
645 test $old_branch = $(git rev-parse --verify branch^0)
648 test_expect_success 'F: verify pack' '
649 verify_packs
652 test_expect_success 'F: verify other commit' '
653 cat >expect <<-EOF &&
654 tree $(git rev-parse branch~1^{tree})
655 parent $(git rev-parse branch~1)
656 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
659 losing things already?
661 git cat-file commit other >actual &&
662 test_cmp expect actual
666 ### series G
669 test_expect_success 'G: non-fast-forward update forced' '
670 old_branch=$(git rev-parse --verify branch^0) &&
671 test_tick &&
672 cat >input <<-INPUT_END &&
673 commit refs/heads/branch
674 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
675 data <<COMMIT
676 losing things already?
677 COMMIT
679 from refs/heads/branch~1
681 INPUT_END
682 git fast-import --force <input
685 test_expect_success 'G: verify pack' '
686 verify_packs
689 test_expect_success 'G: branch changed, but logged' '
690 test $old_branch != $(git rev-parse --verify branch^0) &&
691 test $old_branch = $(git rev-parse --verify branch@{1})
695 ### series H
698 test_expect_success 'H: deletall, add 1' '
699 test_tick &&
700 cat >input <<-INPUT_END &&
701 commit refs/heads/H
702 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
703 data <<COMMIT
704 third
705 COMMIT
707 from refs/heads/branch^0
708 M 644 inline i-will-die
709 data <<EOF
710 this file will never exist.
713 deleteall
714 M 644 inline h/e/l/lo
715 data <<EOF
716 $file5_data
719 INPUT_END
720 git fast-import <input &&
721 git whatchanged H
724 test_expect_success 'H: verify pack' '
725 verify_packs
728 test_expect_success 'H: validate old files removed, new files added' '
729 cat >expect <<-EOF &&
730 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
731 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
732 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
733 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
734 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
736 git diff-tree -M -r H^ H >actual &&
737 compare_diff_raw expect actual
740 test_expect_success 'H: verify file' '
741 echo "$file5_data" >expect &&
742 git cat-file blob H:h/e/l/lo >actual &&
743 test_cmp expect actual
747 ### series I
750 test_expect_success 'I: export-pack-edges' '
751 cat >input <<-INPUT_END &&
752 commit refs/heads/export-boundary
753 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
754 data <<COMMIT
755 we have a border. its only 40 characters wide.
756 COMMIT
758 from refs/heads/branch
760 INPUT_END
761 git fast-import --export-pack-edges=edges.list <input
764 test_expect_success 'I: verify edge list' '
765 cat >expect <<-EOF &&
766 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
768 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
769 test_cmp expect actual
773 ### series J
776 test_expect_success 'J: reset existing branch creates empty commit' '
777 cat >input <<-INPUT_END &&
778 commit refs/heads/J
779 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
780 data <<COMMIT
781 create J
782 COMMIT
784 from refs/heads/branch
786 reset refs/heads/J
788 commit refs/heads/J
789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
790 data <<COMMIT
791 initialize J
792 COMMIT
794 INPUT_END
795 git fast-import <input
797 test_expect_success 'J: branch has 1 commit, empty tree' '
798 test 1 = $(git rev-list J | wc -l) &&
799 test 0 = $(git ls-tree J | wc -l)
802 test_expect_success 'J: tag must fail on empty branch' '
803 cat >input <<-INPUT_END &&
804 reset refs/heads/J2
806 tag wrong_tag
807 from refs/heads/J2
808 data <<EOF
809 Tag branch that was reset.
811 INPUT_END
812 test_must_fail git fast-import <input
816 ### series K
819 test_expect_success 'K: reinit branch with from' '
820 cat >input <<-INPUT_END &&
821 commit refs/heads/K
822 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
823 data <<COMMIT
824 create K
825 COMMIT
827 from refs/heads/branch
829 commit refs/heads/K
830 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
831 data <<COMMIT
832 redo K
833 COMMIT
835 from refs/heads/branch^1
837 INPUT_END
838 git fast-import <input
840 test_expect_success 'K: verify K^1 = branch^1' '
841 test $(git rev-parse --verify branch^1) \
842 = $(git rev-parse --verify K^1)
846 ### series L
849 test_expect_success 'L: verify internal tree sorting' '
850 cat >input <<-INPUT_END &&
851 blob
852 mark :1
853 data <<EOF
854 some data
857 blob
858 mark :2
859 data <<EOF
860 other data
863 commit refs/heads/L
864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
865 data <<COMMIT
866 create L
867 COMMIT
869 M 644 :1 b.
870 M 644 :1 b/other
871 M 644 :1 ba
873 commit refs/heads/L
874 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
875 data <<COMMIT
876 update L
877 COMMIT
879 M 644 :2 b.
880 M 644 :2 b/other
881 M 644 :2 ba
882 INPUT_END
884 cat >expect <<-EXPECT_END &&
885 :100644 100644 4268632... 55d3a52... M b.
886 :040000 040000 0ae5cac... 443c768... M b
887 :100644 100644 4268632... 55d3a52... M ba
888 EXPECT_END
890 git fast-import <input &&
891 git diff-tree --abbrev --raw L^ L >output &&
892 test_cmp expect output
895 test_expect_success 'L: nested tree copy does not corrupt deltas' '
896 cat >input <<-INPUT_END &&
897 blob
898 mark :1
899 data <<EOF
900 the data
903 commit refs/heads/L2
904 committer C O Mitter <committer@example.com> 1112912473 -0700
905 data <<COMMIT
906 init L2
907 COMMIT
908 M 644 :1 a/b/c
909 M 644 :1 a/b/d
910 M 644 :1 a/e/f
912 commit refs/heads/L2
913 committer C O Mitter <committer@example.com> 1112912473 -0700
914 data <<COMMIT
915 update L2
916 COMMIT
917 C a g
918 C a/e g/b
919 M 644 :1 g/b/h
920 INPUT_END
922 cat >expect <<-\EOF &&
923 g/b/f
924 g/b/h
927 test_when_finished "git update-ref -d refs/heads/L2" &&
928 git fast-import <input &&
929 git ls-tree L2 g/b/ >tmp &&
930 cat tmp | cut -f 2 >actual &&
931 test_cmp expect actual &&
932 git fsck $(git rev-parse L2)
936 ### series M
939 test_expect_success 'M: rename file in same subdirectory' '
940 test_tick &&
941 cat >input <<-INPUT_END &&
942 commit refs/heads/M1
943 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
944 data <<COMMIT
945 file rename
946 COMMIT
948 from refs/heads/branch^0
949 R file2/newf file2/n.e.w.f
951 INPUT_END
953 cat >expect <<-EOF &&
954 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
956 git fast-import <input &&
957 git diff-tree -M -r M1^ M1 >actual &&
958 compare_diff_raw expect actual
961 test_expect_success 'M: rename file to new subdirectory' '
962 cat >input <<-INPUT_END &&
963 commit refs/heads/M2
964 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
965 data <<COMMIT
966 file rename
967 COMMIT
969 from refs/heads/branch^0
970 R file2/newf i/am/new/to/you
972 INPUT_END
974 cat >expect <<-EOF &&
975 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
977 git fast-import <input &&
978 git diff-tree -M -r M2^ M2 >actual &&
979 compare_diff_raw expect actual
982 test_expect_success 'M: rename subdirectory to new subdirectory' '
983 cat >input <<-INPUT_END &&
984 commit refs/heads/M3
985 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
986 data <<COMMIT
987 file rename
988 COMMIT
990 from refs/heads/M2^0
991 R i other/sub
993 INPUT_END
995 cat >expect <<-EOF &&
996 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
998 git fast-import <input &&
999 git diff-tree -M -r M3^ M3 >actual &&
1000 compare_diff_raw expect actual
1003 test_expect_success 'M: rename root to subdirectory' '
1004 cat >input <<-INPUT_END &&
1005 commit refs/heads/M4
1006 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007 data <<COMMIT
1008 rename root
1009 COMMIT
1011 from refs/heads/M2^0
1012 R "" sub
1014 INPUT_END
1016 cat >expect <<-EOF &&
1017 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1018 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1019 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1020 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1021 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1023 git fast-import <input &&
1024 git diff-tree -M -r M4^ M4 >actual &&
1025 cat actual &&
1026 compare_diff_raw expect actual
1030 ### series N
1033 test_expect_success 'N: copy file in same subdirectory' '
1034 test_tick &&
1035 cat >input <<-INPUT_END &&
1036 commit refs/heads/N1
1037 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1038 data <<COMMIT
1039 file copy
1040 COMMIT
1042 from refs/heads/branch^0
1043 C file2/newf file2/n.e.w.f
1045 INPUT_END
1047 cat >expect <<-EOF &&
1048 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1050 git fast-import <input &&
1051 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1052 compare_diff_raw expect actual
1055 test_expect_success 'N: copy then modify subdirectory' '
1056 cat >input <<-INPUT_END &&
1057 commit refs/heads/N2
1058 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1059 data <<COMMIT
1060 clean directory copy
1061 COMMIT
1063 from refs/heads/branch^0
1064 C file2 file3
1066 commit refs/heads/N2
1067 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068 data <<COMMIT
1069 modify directory copy
1070 COMMIT
1072 M 644 inline file3/file5
1073 data <<EOF
1074 $file5_data
1077 INPUT_END
1079 cat >expect <<-EOF &&
1080 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1081 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1082 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1084 git fast-import <input &&
1085 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1086 compare_diff_raw expect actual
1089 test_expect_success 'N: copy dirty subdirectory' '
1090 cat >input <<-INPUT_END &&
1091 commit refs/heads/N3
1092 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1093 data <<COMMIT
1094 dirty directory copy
1095 COMMIT
1097 from refs/heads/branch^0
1098 M 644 inline file2/file5
1099 data <<EOF
1100 $file5_data
1103 C file2 file3
1104 D file2/file5
1106 INPUT_END
1108 git fast-import <input &&
1109 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1112 test_expect_success 'N: copy directory by id' '
1113 cat >expect <<-\EOF &&
1114 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1115 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1117 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1118 cat >input <<-INPUT_END &&
1119 commit refs/heads/N4
1120 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1121 data <<COMMIT
1122 copy by tree hash
1123 COMMIT
1125 from refs/heads/branch^0
1126 M 040000 $subdir file3
1127 INPUT_END
1128 git fast-import <input &&
1129 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1130 compare_diff_raw expect actual
1133 test_expect_success PIPE 'N: read and copy directory' '
1134 cat >expect <<-\EOF &&
1135 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1136 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1138 git update-ref -d refs/heads/N4 &&
1139 rm -f backflow &&
1140 mkfifo backflow &&
1142 exec <backflow &&
1143 cat <<-EOF &&
1144 commit refs/heads/N4
1145 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1146 data <<COMMIT
1147 copy by tree hash, part 2
1148 COMMIT
1150 from refs/heads/branch^0
1151 ls "file2"
1153 read mode type tree filename &&
1154 echo "M 040000 $tree file3"
1156 git fast-import --cat-blob-fd=3 3>backflow &&
1157 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1158 compare_diff_raw expect actual
1161 test_expect_success PIPE 'N: empty directory reads as missing' '
1162 cat <<-\EOF >expect &&
1163 OBJNAME
1164 :000000 100644 OBJNAME OBJNAME A unrelated
1166 echo "missing src" >expect.response &&
1167 git update-ref -d refs/heads/read-empty &&
1168 rm -f backflow &&
1169 mkfifo backflow &&
1171 exec <backflow &&
1172 cat <<-EOF &&
1173 commit refs/heads/read-empty
1174 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1175 data <<COMMIT
1176 read "empty" (missing) directory
1177 COMMIT
1179 M 100644 inline src/greeting
1180 data <<BLOB
1181 hello
1182 BLOB
1183 C src/greeting dst1/non-greeting
1184 C src/greeting unrelated
1185 # leave behind "empty" src directory
1186 D src/greeting
1187 ls "src"
1189 read -r line &&
1190 printf "%s\n" "$line" >response &&
1191 cat <<-\EOF
1192 D dst1
1193 D dst2
1196 git fast-import --cat-blob-fd=3 3>backflow &&
1197 test_cmp expect.response response &&
1198 git rev-list read-empty |
1199 git diff-tree -r --root --stdin |
1200 sed "s/$_x40/OBJNAME/g" >actual &&
1201 test_cmp expect actual
1204 test_expect_success 'N: copy root directory by tree hash' '
1205 cat >expect <<-\EOF &&
1206 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1207 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1209 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1210 cat >input <<-INPUT_END &&
1211 commit refs/heads/N6
1212 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1213 data <<COMMIT
1214 copy root directory by tree hash
1215 COMMIT
1217 from refs/heads/branch^0
1218 M 040000 $root ""
1219 INPUT_END
1220 git fast-import <input &&
1221 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1222 compare_diff_raw expect actual
1225 test_expect_success 'N: copy root by path' '
1226 cat >expect <<-\EOF &&
1227 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1228 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1229 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1230 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1231 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1233 cat >input <<-INPUT_END &&
1234 commit refs/heads/N-copy-root-path
1235 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1236 data <<COMMIT
1237 copy root directory by (empty) path
1238 COMMIT
1240 from refs/heads/branch^0
1241 C "" oldroot
1242 INPUT_END
1243 git fast-import <input &&
1244 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1245 compare_diff_raw expect actual
1248 test_expect_success 'N: delete directory by copying' '
1249 cat >expect <<-\EOF &&
1250 OBJID
1251 :100644 000000 OBJID OBJID D foo/bar/qux
1252 OBJID
1253 :000000 100644 OBJID OBJID A foo/bar/baz
1254 :000000 100644 OBJID OBJID A foo/bar/qux
1256 empty_tree=$(git mktree </dev/null) &&
1257 cat >input <<-INPUT_END &&
1258 commit refs/heads/N-delete
1259 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1260 data <<COMMIT
1261 collect data to be deleted
1262 COMMIT
1264 deleteall
1265 M 100644 inline foo/bar/baz
1266 data <<DATA_END
1267 hello
1268 DATA_END
1269 C "foo/bar/baz" "foo/bar/qux"
1270 C "foo/bar/baz" "foo/bar/quux/1"
1271 C "foo/bar/baz" "foo/bar/quuux"
1272 M 040000 $empty_tree foo/bar/quux
1273 M 040000 $empty_tree foo/bar/quuux
1275 commit refs/heads/N-delete
1276 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1277 data <<COMMIT
1278 delete subdirectory
1279 COMMIT
1281 M 040000 $empty_tree foo/bar/qux
1282 INPUT_END
1283 git fast-import <input &&
1284 git rev-list N-delete |
1285 git diff-tree -r --stdin --root --always |
1286 sed -e "s/$_x40/OBJID/g" >actual &&
1287 test_cmp expect actual
1290 test_expect_success 'N: modify copied tree' '
1291 cat >expect <<-\EOF &&
1292 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1293 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1294 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1296 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1297 cat >input <<-INPUT_END &&
1298 commit refs/heads/N5
1299 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1300 data <<COMMIT
1301 copy by tree hash
1302 COMMIT
1304 from refs/heads/branch^0
1305 M 040000 $subdir file3
1307 commit refs/heads/N5
1308 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1309 data <<COMMIT
1310 modify directory copy
1311 COMMIT
1313 M 644 inline file3/file5
1314 data <<EOF
1315 $file5_data
1317 INPUT_END
1318 git fast-import <input &&
1319 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1320 compare_diff_raw expect actual
1323 test_expect_success 'N: reject foo/ syntax' '
1324 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1325 test_must_fail git fast-import <<-INPUT_END
1326 commit refs/heads/N5B
1327 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1328 data <<COMMIT
1329 copy with invalid syntax
1330 COMMIT
1332 from refs/heads/branch^0
1333 M 040000 $subdir file3/
1334 INPUT_END
1337 test_expect_success 'N: reject foo/ syntax in copy source' '
1338 test_must_fail git fast-import <<-INPUT_END
1339 commit refs/heads/N5C
1340 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1341 data <<COMMIT
1342 copy with invalid syntax
1343 COMMIT
1345 from refs/heads/branch^0
1346 C file2/ file3
1347 INPUT_END
1350 test_expect_success 'N: reject foo/ syntax in rename source' '
1351 test_must_fail git fast-import <<-INPUT_END
1352 commit refs/heads/N5D
1353 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1354 data <<COMMIT
1355 rename with invalid syntax
1356 COMMIT
1358 from refs/heads/branch^0
1359 R file2/ file3
1360 INPUT_END
1363 test_expect_success 'N: reject foo/ syntax in ls argument' '
1364 test_must_fail git fast-import <<-INPUT_END
1365 commit refs/heads/N5E
1366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1367 data <<COMMIT
1368 copy with invalid syntax
1369 COMMIT
1371 from refs/heads/branch^0
1372 ls "file2/"
1373 INPUT_END
1376 test_expect_success 'N: copy to root by id and modify' '
1377 echo "hello, world" >expect.foo &&
1378 echo hello >expect.bar &&
1379 git fast-import <<-SETUP_END &&
1380 commit refs/heads/N7
1381 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1382 data <<COMMIT
1383 hello, tree
1384 COMMIT
1386 deleteall
1387 M 644 inline foo/bar
1388 data <<EOF
1389 hello
1391 SETUP_END
1393 tree=$(git rev-parse --verify N7:) &&
1394 git fast-import <<-INPUT_END &&
1395 commit refs/heads/N8
1396 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1397 data <<COMMIT
1398 copy to root by id and modify
1399 COMMIT
1401 M 040000 $tree ""
1402 M 644 inline foo/foo
1403 data <<EOF
1404 hello, world
1406 INPUT_END
1407 git show N8:foo/foo >actual.foo &&
1408 git show N8:foo/bar >actual.bar &&
1409 test_cmp expect.foo actual.foo &&
1410 test_cmp expect.bar actual.bar
1413 test_expect_success 'N: extract subtree' '
1414 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1415 cat >input <<-INPUT_END &&
1416 commit refs/heads/N9
1417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418 data <<COMMIT
1419 extract subtree branch:newdir
1420 COMMIT
1422 M 040000 $branch ""
1423 C "newdir" ""
1424 INPUT_END
1425 git fast-import <input &&
1426 git diff --exit-code branch:newdir N9
1429 test_expect_success 'N: modify subtree, extract it, and modify again' '
1430 echo hello >expect.baz &&
1431 echo hello, world >expect.qux &&
1432 git fast-import <<-SETUP_END &&
1433 commit refs/heads/N10
1434 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1435 data <<COMMIT
1436 hello, tree
1437 COMMIT
1439 deleteall
1440 M 644 inline foo/bar/baz
1441 data <<EOF
1442 hello
1444 SETUP_END
1446 tree=$(git rev-parse --verify N10:) &&
1447 git fast-import <<-INPUT_END &&
1448 commit refs/heads/N11
1449 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1450 data <<COMMIT
1451 copy to root by id and modify
1452 COMMIT
1454 M 040000 $tree ""
1455 M 100644 inline foo/bar/qux
1456 data <<EOF
1457 hello, world
1459 R "foo" ""
1460 C "bar/qux" "bar/quux"
1461 INPUT_END
1462 git show N11:bar/baz >actual.baz &&
1463 git show N11:bar/qux >actual.qux &&
1464 git show N11:bar/quux >actual.quux &&
1465 test_cmp expect.baz actual.baz &&
1466 test_cmp expect.qux actual.qux &&
1467 test_cmp expect.qux actual.quux'
1470 ### series O
1473 test_expect_success 'O: comments are all skipped' '
1474 cat >input <<-INPUT_END &&
1475 #we will
1476 commit refs/heads/O1
1477 # -- ignore all of this text
1478 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1479 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1480 data <<COMMIT
1481 dirty directory copy
1482 COMMIT
1484 # do not forget the import blank line!
1486 # yes, we started from our usual base of branch^0.
1487 # i like branch^0.
1488 from refs/heads/branch^0
1489 # and we need to reuse file2/file5 from N3 above.
1490 M 644 inline file2/file5
1491 # otherwise the tree will be different
1492 data <<EOF
1493 $file5_data
1496 # do not forget to copy file2 to file3
1497 C file2 file3
1499 # or to delete file5 from file2.
1500 D file2/file5
1501 # are we done yet?
1503 INPUT_END
1505 git fast-import <input &&
1506 test $(git rev-parse N3) = $(git rev-parse O1)
1509 test_expect_success 'O: blank lines not necessary after data commands' '
1510 cat >input <<-INPUT_END &&
1511 commit refs/heads/O2
1512 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1513 data <<COMMIT
1514 dirty directory copy
1515 COMMIT
1516 from refs/heads/branch^0
1517 M 644 inline file2/file5
1518 data <<EOF
1519 $file5_data
1521 C file2 file3
1522 D file2/file5
1524 INPUT_END
1526 git fast-import <input &&
1527 test $(git rev-parse N3) = $(git rev-parse O2)
1530 test_expect_success 'O: repack before next test' '
1531 git repack -a -d
1534 test_expect_success 'O: blank lines not necessary after other commands' '
1535 cat >input <<-INPUT_END &&
1536 commit refs/heads/O3
1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 data <<COMMIT
1539 zstring
1540 COMMIT
1541 commit refs/heads/O3
1542 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1543 data <<COMMIT
1545 COMMIT
1546 checkpoint
1547 commit refs/heads/O3
1548 mark :5
1549 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1550 data <<COMMIT
1551 zempty
1552 COMMIT
1553 checkpoint
1554 commit refs/heads/O3
1555 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1556 data <<COMMIT
1557 zcommits
1558 COMMIT
1559 reset refs/tags/O3-2nd
1560 from :5
1561 reset refs/tags/O3-3rd
1562 from :5
1563 INPUT_END
1565 cat >expect <<-INPUT_END &&
1566 string
1568 empty
1569 commits
1570 INPUT_END
1572 git fast-import <input &&
1573 test 8 = $(find .git/objects/pack -type f | wc -l) &&
1574 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1575 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1576 test_cmp expect actual
1579 test_expect_success 'O: progress outputs as requested by input' '
1580 cat >input <<-INPUT_END &&
1581 commit refs/heads/O4
1582 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583 data <<COMMIT
1584 zstring
1585 COMMIT
1586 commit refs/heads/O4
1587 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1588 data <<COMMIT
1590 COMMIT
1591 progress Two commits down, 2 to go!
1592 commit refs/heads/O4
1593 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1594 data <<COMMIT
1595 zempty
1596 COMMIT
1597 progress Three commits down, 1 to go!
1598 commit refs/heads/O4
1599 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1600 data <<COMMIT
1601 zcommits
1602 COMMIT
1603 progress done!
1604 INPUT_END
1605 git fast-import <input >actual &&
1606 grep "progress " <input >expect &&
1607 test_cmp expect actual
1611 ### series P (gitlinks)
1614 test_expect_success 'P: superproject & submodule mix' '
1615 cat >input <<-INPUT_END &&
1616 blob
1617 mark :1
1618 data 10
1619 test file
1621 reset refs/heads/sub
1622 commit refs/heads/sub
1623 mark :2
1624 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625 data 12
1626 sub_initial
1627 M 100644 :1 file
1629 blob
1630 mark :3
1631 data <<DATAEND
1632 [submodule "sub"]
1633 path = sub
1634 url = "$(pwd)/sub"
1635 DATAEND
1637 commit refs/heads/subuse1
1638 mark :4
1639 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1640 data 8
1641 initial
1642 from refs/heads/master
1643 M 100644 :3 .gitmodules
1644 M 160000 :2 sub
1646 blob
1647 mark :5
1648 data 20
1649 test file
1650 more data
1652 commit refs/heads/sub
1653 mark :6
1654 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655 data 11
1656 sub_second
1657 from :2
1658 M 100644 :5 file
1660 commit refs/heads/subuse1
1661 mark :7
1662 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1663 data 7
1664 second
1665 from :4
1666 M 160000 :6 sub
1668 INPUT_END
1670 git fast-import <input &&
1671 git checkout subuse1 &&
1672 rm -rf sub &&
1673 mkdir sub &&
1675 cd sub &&
1676 git init &&
1677 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1678 git checkout master
1679 ) &&
1680 git submodule init &&
1681 git submodule update
1684 test_expect_success 'P: verbatim SHA gitlinks' '
1685 SUBLAST=$(git rev-parse --verify sub) &&
1686 SUBPREV=$(git rev-parse --verify sub^) &&
1688 cat >input <<-INPUT_END &&
1689 blob
1690 mark :1
1691 data <<DATAEND
1692 [submodule "sub"]
1693 path = sub
1694 url = "$(pwd)/sub"
1695 DATAEND
1697 commit refs/heads/subuse2
1698 mark :2
1699 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1700 data 8
1701 initial
1702 from refs/heads/master
1703 M 100644 :1 .gitmodules
1704 M 160000 $SUBPREV sub
1706 commit refs/heads/subuse2
1707 mark :3
1708 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1709 data 7
1710 second
1711 from :2
1712 M 160000 $SUBLAST sub
1714 INPUT_END
1716 git branch -D sub &&
1717 git gc &&
1718 git prune &&
1719 git fast-import <input &&
1720 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1723 test_expect_success 'P: fail on inline gitlink' '
1724 test_tick &&
1725 cat >input <<-INPUT_END &&
1726 commit refs/heads/subuse3
1727 mark :1
1728 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1729 data <<COMMIT
1730 corrupt
1731 COMMIT
1733 from refs/heads/subuse2
1734 M 160000 inline sub
1735 data <<DATA
1736 $SUBPREV
1737 DATA
1739 INPUT_END
1741 test_must_fail git fast-import <input
1744 test_expect_success 'P: fail on blob mark in gitlink' '
1745 test_tick &&
1746 cat >input <<-INPUT_END &&
1747 blob
1748 mark :1
1749 data <<DATA
1750 $SUBPREV
1751 DATA
1753 commit refs/heads/subuse3
1754 mark :2
1755 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1756 data <<COMMIT
1757 corrupt
1758 COMMIT
1760 from refs/heads/subuse2
1761 M 160000 :1 sub
1763 INPUT_END
1765 test_must_fail git fast-import <input
1769 ### series Q (notes)
1772 test_expect_success 'Q: commit notes' '
1773 note1_data="The first note for the first commit" &&
1774 note2_data="The first note for the second commit" &&
1775 note3_data="The first note for the third commit" &&
1776 note1b_data="The second note for the first commit" &&
1777 note1c_data="The third note for the first commit" &&
1778 note2b_data="The second note for the second commit" &&
1780 test_tick &&
1781 cat >input <<-INPUT_END &&
1782 blob
1783 mark :2
1784 data <<EOF
1785 $file2_data
1788 commit refs/heads/notes-test
1789 mark :3
1790 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1791 data <<COMMIT
1792 first (:3)
1793 COMMIT
1795 M 644 :2 file2
1797 blob
1798 mark :4
1799 data $file4_len
1800 $file4_data
1801 commit refs/heads/notes-test
1802 mark :5
1803 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1804 data <<COMMIT
1805 second (:5)
1806 COMMIT
1808 M 644 :4 file4
1810 commit refs/heads/notes-test
1811 mark :6
1812 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1813 data <<COMMIT
1814 third (:6)
1815 COMMIT
1817 M 644 inline file5
1818 data <<EOF
1819 $file5_data
1822 M 755 inline file6
1823 data <<EOF
1824 $file6_data
1827 blob
1828 mark :7
1829 data <<EOF
1830 $note1_data
1833 blob
1834 mark :8
1835 data <<EOF
1836 $note2_data
1839 commit refs/notes/foobar
1840 mark :9
1841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842 data <<COMMIT
1843 notes (:9)
1844 COMMIT
1846 N :7 :3
1847 N :8 :5
1848 N inline :6
1849 data <<EOF
1850 $note3_data
1853 commit refs/notes/foobar
1854 mark :10
1855 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1856 data <<COMMIT
1857 notes (:10)
1858 COMMIT
1860 N inline :3
1861 data <<EOF
1862 $note1b_data
1865 commit refs/notes/foobar2
1866 mark :11
1867 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1868 data <<COMMIT
1869 notes (:11)
1870 COMMIT
1872 N inline :3
1873 data <<EOF
1874 $note1c_data
1877 commit refs/notes/foobar
1878 mark :12
1879 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1880 data <<COMMIT
1881 notes (:12)
1882 COMMIT
1884 deleteall
1885 N inline :5
1886 data <<EOF
1887 $note2b_data
1890 INPUT_END
1892 git fast-import <input &&
1893 git whatchanged notes-test
1896 test_expect_success 'Q: verify pack' '
1897 verify_packs
1900 test_expect_success 'Q: verify first commit' '
1901 commit1=$(git rev-parse notes-test~2) &&
1902 commit2=$(git rev-parse notes-test^) &&
1903 commit3=$(git rev-parse notes-test) &&
1905 cat >expect <<-EOF &&
1906 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1907 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1909 first (:3)
1911 git cat-file commit notes-test~2 | sed 1d >actual &&
1912 test_cmp expect actual
1915 test_expect_success 'Q: verify second commit' '
1916 cat >expect <<-EOF &&
1917 parent $commit1
1918 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1919 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1921 second (:5)
1923 git cat-file commit notes-test^ | sed 1d >actual &&
1924 test_cmp expect actual
1927 test_expect_success 'Q: verify third commit' '
1928 cat >expect <<-EOF &&
1929 parent $commit2
1930 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1931 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1933 third (:6)
1935 git cat-file commit notes-test | sed 1d >actual &&
1936 test_cmp expect actual
1939 test_expect_success 'Q: verify first notes commit' '
1940 cat >expect <<-EOF &&
1941 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1942 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1944 notes (:9)
1946 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1947 test_cmp expect actual
1950 test_expect_success 'Q: verify first notes tree' '
1951 cat >expect.unsorted <<-EOF &&
1952 100644 blob $commit1
1953 100644 blob $commit2
1954 100644 blob $commit3
1956 cat expect.unsorted | sort >expect &&
1957 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1958 test_cmp expect actual
1961 test_expect_success 'Q: verify first note for first commit' '
1962 echo "$note1_data" >expect &&
1963 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
1964 test_cmp expect actual
1967 test_expect_success 'Q: verify first note for second commit' '
1968 echo "$note2_data" >expect &&
1969 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
1970 test_cmp expect actual
1973 test_expect_success 'Q: verify first note for third commit' '
1974 echo "$note3_data" >expect &&
1975 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
1976 test_cmp expect actual
1979 test_expect_success 'Q: verify second notes commit' '
1980 cat >expect <<-EOF &&
1981 parent $(git rev-parse --verify refs/notes/foobar~2)
1982 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1983 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1985 notes (:10)
1987 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1988 test_cmp expect actual
1991 test_expect_success 'Q: verify second notes tree' '
1992 cat >expect.unsorted <<-EOF &&
1993 100644 blob $commit1
1994 100644 blob $commit2
1995 100644 blob $commit3
1997 cat expect.unsorted | sort >expect &&
1998 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1999 test_cmp expect actual
2002 test_expect_success 'Q: verify second note for first commit' '
2003 echo "$note1b_data" >expect &&
2004 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2005 test_cmp expect actual
2008 test_expect_success 'Q: verify first note for second commit' '
2009 echo "$note2_data" >expect &&
2010 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2011 test_cmp expect actual
2014 test_expect_success 'Q: verify first note for third commit' '
2015 echo "$note3_data" >expect &&
2016 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2017 test_cmp expect actual
2020 test_expect_success 'Q: verify third notes commit' '
2021 cat >expect <<-EOF &&
2022 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2025 notes (:11)
2027 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2028 test_cmp expect actual
2031 test_expect_success 'Q: verify third notes tree' '
2032 cat >expect.unsorted <<-EOF &&
2033 100644 blob $commit1
2035 cat expect.unsorted | sort >expect &&
2036 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2037 test_cmp expect actual
2040 test_expect_success 'Q: verify third note for first commit' '
2041 echo "$note1c_data" >expect &&
2042 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2043 test_cmp expect actual
2046 test_expect_success 'Q: verify fourth notes commit' '
2047 cat >expect <<-EOF &&
2048 parent $(git rev-parse --verify refs/notes/foobar^)
2049 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2050 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2052 notes (:12)
2054 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2055 test_cmp expect actual
2058 test_expect_success 'Q: verify fourth notes tree' '
2059 cat >expect.unsorted <<-EOF &&
2060 100644 blob $commit2
2062 cat expect.unsorted | sort >expect &&
2063 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2064 test_cmp expect actual
2067 test_expect_success 'Q: verify second note for second commit' '
2068 echo "$note2b_data" >expect &&
2069 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2070 test_cmp expect actual
2073 test_expect_success 'Q: deny note on empty branch' '
2074 cat >input <<-EOF &&
2075 reset refs/heads/Q0
2077 commit refs/heads/note-Q0
2078 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2079 data <<COMMIT
2080 Note for an empty branch.
2081 COMMIT
2083 N inline refs/heads/Q0
2084 data <<NOTE
2085 some note
2086 NOTE
2088 test_must_fail git fast-import <input
2091 ### series R (feature and option)
2094 test_expect_success 'R: abort on unsupported feature' '
2095 cat >input <<-EOF &&
2096 feature no-such-feature-exists
2099 test_must_fail git fast-import <input
2102 test_expect_success 'R: supported feature is accepted' '
2103 cat >input <<-EOF &&
2104 feature date-format=now
2107 git fast-import <input
2110 test_expect_success 'R: abort on receiving feature after data command' '
2111 cat >input <<-EOF &&
2112 blob
2113 data 3
2115 feature date-format=now
2118 test_must_fail git fast-import <input
2121 test_expect_success 'R: only one import-marks feature allowed per stream' '
2122 cat >input <<-EOF &&
2123 feature import-marks=git.marks
2124 feature import-marks=git2.marks
2127 test_must_fail git fast-import <input
2130 test_expect_success 'R: export-marks feature results in a marks file being created' '
2131 cat >input <<-EOF &&
2132 feature export-marks=git.marks
2133 blob
2134 mark :1
2135 data 3
2140 cat input | git fast-import &&
2141 grep :1 git.marks
2144 test_expect_success 'R: export-marks options can be overridden by commandline options' '
2145 cat input | git fast-import --export-marks=other.marks &&
2146 grep :1 other.marks
2149 test_expect_success 'R: catch typo in marks file name' '
2150 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2151 echo "feature import-marks=nonexistent.marks" |
2152 test_must_fail git fast-import
2155 test_expect_success 'R: import and output marks can be the same file' '
2156 rm -f io.marks &&
2157 blob=$(echo hi | git hash-object --stdin) &&
2158 cat >expect <<-EOF &&
2159 :1 $blob
2160 :2 $blob
2162 git fast-import --export-marks=io.marks <<-\EOF &&
2163 blob
2164 mark :1
2165 data 3
2169 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2170 blob
2171 mark :2
2172 data 3
2176 test_cmp expect io.marks
2179 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2180 rm -f io.marks &&
2181 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2182 blob
2183 mark :1
2184 data 3
2190 test_expect_success 'R: --import-marks-if-exists' '
2191 rm -f io.marks &&
2192 blob=$(echo hi | git hash-object --stdin) &&
2193 echo ":1 $blob" >expect &&
2194 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2195 blob
2196 mark :1
2197 data 3
2201 test_cmp expect io.marks
2204 test_expect_success 'R: feature import-marks-if-exists' '
2205 rm -f io.marks &&
2206 >expect &&
2208 git fast-import --export-marks=io.marks <<-\EOF &&
2209 feature import-marks-if-exists=not_io.marks
2211 test_cmp expect io.marks &&
2213 blob=$(echo hi | git hash-object --stdin) &&
2215 echo ":1 $blob" >io.marks &&
2216 echo ":1 $blob" >expect &&
2217 echo ":2 $blob" >>expect &&
2219 git fast-import --export-marks=io.marks <<-\EOF &&
2220 feature import-marks-if-exists=io.marks
2221 blob
2222 mark :2
2223 data 3
2227 test_cmp expect io.marks &&
2229 echo ":3 $blob" >>expect &&
2231 git fast-import --import-marks=io.marks \
2232 --export-marks=io.marks <<-\EOF &&
2233 feature import-marks-if-exists=not_io.marks
2234 blob
2235 mark :3
2236 data 3
2240 test_cmp expect io.marks &&
2242 >expect &&
2244 git fast-import --import-marks-if-exists=not_io.marks \
2245 --export-marks=io.marks <<-\EOF &&
2246 feature import-marks-if-exists=io.marks
2248 test_cmp expect io.marks
2251 test_expect_success 'R: import to output marks works without any content' '
2252 cat >input <<-EOF &&
2253 feature import-marks=marks.out
2254 feature export-marks=marks.new
2257 cat input | git fast-import &&
2258 test_cmp marks.out marks.new
2261 test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2262 cat >input <<-EOF &&
2263 feature import-marks=nonexistent.marks
2264 feature export-marks=marks.new
2267 cat input | git fast-import --import-marks=marks.out &&
2268 test_cmp marks.out marks.new
2272 test_expect_success 'R: multiple --import-marks= should be honoured' '
2273 cat >input <<-EOF &&
2274 feature import-marks=nonexistent.marks
2275 feature export-marks=combined.marks
2278 head -n2 marks.out > one.marks &&
2279 tail -n +3 marks.out > two.marks &&
2280 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2281 test_cmp marks.out combined.marks
2284 test_expect_success 'R: feature relative-marks should be honoured' '
2285 cat >input <<-EOF &&
2286 feature relative-marks
2287 feature import-marks=relative.in
2288 feature export-marks=relative.out
2291 mkdir -p .git/info/fast-import/ &&
2292 cp marks.new .git/info/fast-import/relative.in &&
2293 git fast-import <input &&
2294 test_cmp marks.new .git/info/fast-import/relative.out
2297 test_expect_success 'R: feature no-relative-marks should be honoured' '
2298 cat >input <<-EOF &&
2299 feature relative-marks
2300 feature import-marks=relative.in
2301 feature no-relative-marks
2302 feature export-marks=non-relative.out
2305 git fast-import <input &&
2306 test_cmp marks.new non-relative.out
2309 test_expect_success 'R: feature ls supported' '
2310 echo "feature ls" |
2311 git fast-import
2314 test_expect_success 'R: feature cat-blob supported' '
2315 echo "feature cat-blob" |
2316 git fast-import
2319 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2320 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2323 test_expect_success !MINGW 'R: print old blob' '
2324 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2325 cat >expect <<-EOF &&
2326 ${blob} blob 11
2327 yes it can
2330 echo "cat-blob $blob" |
2331 git fast-import --cat-blob-fd=6 6>actual &&
2332 test_cmp expect actual
2335 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2336 echo hello >greeting &&
2337 blob=$(git hash-object -w greeting) &&
2338 cat >expect <<-EOF &&
2339 ${blob} blob 6
2340 hello
2343 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2344 cat-blob $blob
2346 test_cmp expect actual.3 &&
2347 test_must_be_empty actual.1 &&
2348 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2349 option cat-blob-fd=3
2350 cat-blob $blob
2352 test_must_be_empty actual.3 &&
2353 test_cmp expect actual.1
2356 test_expect_success !MINGW 'R: print mark for new blob' '
2357 echo "effluentish" | git hash-object --stdin >expect &&
2358 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2359 blob
2360 mark :1
2361 data <<BLOB_END
2362 effluentish
2363 BLOB_END
2364 get-mark :1
2366 test_cmp expect actual
2369 test_expect_success !MINGW 'R: print new blob' '
2370 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2371 cat >expect <<-EOF &&
2372 ${blob} blob 12
2373 yep yep yep
2376 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2377 blob
2378 mark :1
2379 data <<BLOB_END
2380 yep yep yep
2381 BLOB_END
2382 cat-blob :1
2384 test_cmp expect actual
2387 test_expect_success !MINGW 'R: print new blob by sha1' '
2388 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2389 cat >expect <<-EOF &&
2390 ${blob} blob 25
2391 a new blob named by sha1
2394 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2395 blob
2396 data <<BLOB_END
2397 a new blob named by sha1
2398 BLOB_END
2399 cat-blob $blob
2401 test_cmp expect actual
2404 test_expect_success 'setup: big file' '
2406 echo "the quick brown fox jumps over the lazy dog" >big &&
2407 for i in 1 2 3
2409 cat big big big big >bigger &&
2410 cat bigger bigger bigger bigger >big ||
2411 exit
2412 done
2416 test_expect_success 'R: print two blobs to stdout' '
2417 blob1=$(git hash-object big) &&
2418 blob1_len=$(wc -c <big) &&
2419 blob2=$(echo hello | git hash-object --stdin) &&
2421 echo ${blob1} blob $blob1_len &&
2422 cat big &&
2423 cat <<-EOF
2425 ${blob2} blob 6
2426 hello
2429 } >expect &&
2431 cat <<-\END_PART1 &&
2432 blob
2433 mark :1
2434 data <<data_end
2435 END_PART1
2436 cat big &&
2437 cat <<-\EOF
2438 data_end
2439 blob
2440 mark :2
2441 data <<data_end
2442 hello
2443 data_end
2444 cat-blob :1
2445 cat-blob :2
2448 git fast-import >actual &&
2449 test_cmp expect actual
2452 test_expect_success PIPE 'R: copy using cat-file' '
2453 expect_id=$(git hash-object big) &&
2454 expect_len=$(wc -c <big) &&
2455 echo $expect_id blob $expect_len >expect.response &&
2457 rm -f blobs &&
2458 cat >frontend <<-\FRONTEND_END &&
2459 #!/bin/sh
2460 FRONTEND_END
2462 mkfifo blobs &&
2464 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2465 cat <<-\EOF &&
2466 feature cat-blob
2467 blob
2468 mark :1
2469 data <<BLOB
2471 cat big &&
2472 cat <<-\EOF &&
2473 BLOB
2474 cat-blob :1
2477 read blob_id type size <&3 &&
2478 echo "$blob_id $type $size" >response &&
2479 head_c $size >blob <&3 &&
2480 read newline <&3 &&
2482 cat <<-EOF &&
2483 commit refs/heads/copied
2484 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2485 data <<COMMIT
2486 copy big file as file3
2487 COMMIT
2488 M 644 inline file3
2489 data <<BLOB
2491 cat blob &&
2492 echo BLOB
2493 ) 3<blobs |
2494 git fast-import --cat-blob-fd=3 3>blobs &&
2495 git show copied:file3 >actual &&
2496 test_cmp expect.response response &&
2497 test_cmp big actual
2500 test_expect_success PIPE 'R: print blob mid-commit' '
2501 rm -f blobs &&
2502 echo "A blob from _before_ the commit." >expect &&
2503 mkfifo blobs &&
2505 exec 3<blobs &&
2506 cat <<-EOF &&
2507 feature cat-blob
2508 blob
2509 mark :1
2510 data <<BLOB
2511 A blob from _before_ the commit.
2512 BLOB
2513 commit refs/heads/temporary
2514 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2515 data <<COMMIT
2516 Empty commit
2517 COMMIT
2518 cat-blob :1
2521 read blob_id type size <&3 &&
2522 head_c $size >actual <&3 &&
2523 read newline <&3 &&
2525 echo
2527 git fast-import --cat-blob-fd=3 3>blobs &&
2528 test_cmp expect actual
2531 test_expect_success PIPE 'R: print staged blob within commit' '
2532 rm -f blobs &&
2533 echo "A blob from _within_ the commit." >expect &&
2534 mkfifo blobs &&
2536 exec 3<blobs &&
2537 cat <<-EOF &&
2538 feature cat-blob
2539 commit refs/heads/within
2540 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2541 data <<COMMIT
2542 Empty commit
2543 COMMIT
2544 M 644 inline within
2545 data <<BLOB
2546 A blob from _within_ the commit.
2547 BLOB
2550 to_get=$(
2551 echo "A blob from _within_ the commit." |
2552 git hash-object --stdin
2553 ) &&
2554 echo "cat-blob $to_get" &&
2556 read blob_id type size <&3 &&
2557 head_c $size >actual <&3 &&
2558 read newline <&3 &&
2560 echo deleteall
2562 git fast-import --cat-blob-fd=3 3>blobs &&
2563 test_cmp expect actual
2566 test_expect_success 'R: quiet option results in no stats being output' '
2567 cat >input <<-EOF &&
2568 option git quiet
2569 blob
2570 data 3
2575 cat input | git fast-import 2> output &&
2576 test_must_be_empty output
2579 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2580 echo feature done | test_must_fail git fast-import &&
2581 test_must_fail git fast-import --done </dev/null
2584 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2585 git fast-import <<-\EOF &&
2586 feature done
2587 done
2588 trailing gibberish
2590 git fast-import <<-\EOF
2591 done
2592 more trailing gibberish
2596 test_expect_success 'R: terminating "done" within commit' '
2597 cat >expect <<-\EOF &&
2598 OBJID
2599 :000000 100644 OBJID OBJID A hello.c
2600 :000000 100644 OBJID OBJID A hello2.c
2602 git fast-import <<-EOF &&
2603 commit refs/heads/done-ends
2604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2605 data <<EOT
2606 Commit terminated by "done" command
2608 M 100644 inline hello.c
2609 data <<EOT
2610 Hello, world.
2612 C hello.c hello2.c
2613 done
2615 git rev-list done-ends |
2616 git diff-tree -r --stdin --root --always |
2617 sed -e "s/$_x40/OBJID/g" >actual &&
2618 test_cmp expect actual
2621 test_expect_success 'R: die on unknown option' '
2622 cat >input <<-EOF &&
2623 option git non-existing-option
2626 test_must_fail git fast-import <input
2629 test_expect_success 'R: unknown commandline options are rejected' '\
2630 test_must_fail git fast-import --non-existing-option < /dev/null
2633 test_expect_success 'R: die on invalid option argument' '
2634 echo "option git active-branches=-5" |
2635 test_must_fail git fast-import &&
2636 echo "option git depth=" |
2637 test_must_fail git fast-import &&
2638 test_must_fail git fast-import --depth="5 elephants" </dev/null
2641 test_expect_success 'R: ignore non-git options' '
2642 cat >input <<-EOF &&
2643 option non-existing-vcs non-existing-option
2646 git fast-import <input
2650 ## R: very large blobs
2652 test_expect_success 'R: blob bigger than threshold' '
2653 blobsize=$((2*1024*1024 + 53)) &&
2654 test-genrandom bar $blobsize >expect &&
2655 cat >input <<-INPUT_END &&
2656 commit refs/heads/big-file
2657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2658 data <<COMMIT
2659 R - big file
2660 COMMIT
2662 M 644 inline big1
2663 data $blobsize
2664 INPUT_END
2665 cat expect >>input &&
2666 cat >>input <<-INPUT_END &&
2667 M 644 inline big2
2668 data $blobsize
2669 INPUT_END
2670 cat expect >>input &&
2671 echo >>input &&
2673 test_create_repo R &&
2674 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2677 test_expect_success 'R: verify created pack' '
2679 cd R &&
2680 verify_packs -v > ../verify
2684 test_expect_success 'R: verify written objects' '
2685 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2686 test_cmp_bin expect actual &&
2687 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2688 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2689 test $a = $b
2692 test_expect_success 'R: blob appears only once' '
2693 n=$(grep $a verify | wc -l) &&
2694 test 1 = $n
2698 ### series S
2701 # Make sure missing spaces and EOLs after mark references
2702 # cause errors.
2704 # Setup:
2706 # 1--2--4
2707 # \ /
2708 # -3-
2710 # commit marks: 301, 302, 303, 304
2711 # blob marks: 403, 404, resp.
2712 # note mark: 202
2714 # The error message when a space is missing not at the
2715 # end of the line is:
2717 # Missing space after ..
2719 # or when extra characters come after the mark at the end
2720 # of the line:
2722 # Garbage after ..
2724 # or when the dataref is neither "inline " or a known SHA1,
2726 # Invalid dataref ..
2728 test_expect_success 'S: initialize for S tests' '
2729 test_tick &&
2731 cat >input <<-INPUT_END &&
2732 commit refs/heads/S
2733 mark :301
2734 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2735 data <<COMMIT
2736 commit 1
2737 COMMIT
2738 M 100644 inline hello.c
2739 data <<BLOB
2740 blob 1
2741 BLOB
2743 commit refs/heads/S
2744 mark :302
2745 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2746 data <<COMMIT
2747 commit 2
2748 COMMIT
2749 from :301
2750 M 100644 inline hello.c
2751 data <<BLOB
2752 blob 2
2753 BLOB
2755 blob
2756 mark :403
2757 data <<BLOB
2758 blob 3
2759 BLOB
2761 blob
2762 mark :202
2763 data <<BLOB
2764 note 2
2765 BLOB
2766 INPUT_END
2768 git fast-import --export-marks=marks <input
2772 # filemodify, three datarefs
2774 test_expect_success 'S: filemodify with garbage after mark must fail' '
2775 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2776 commit refs/heads/S
2777 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2778 data <<COMMIT
2779 commit N
2780 COMMIT
2781 M 100644 :403x hello.c
2783 cat err &&
2784 test_i18ngrep "space after mark" err
2787 # inline is misspelled; fast-import thinks it is some unknown dataref
2788 test_expect_success 'S: filemodify with garbage after inline must fail' '
2789 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2790 commit refs/heads/S
2791 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2792 data <<COMMIT
2793 commit N
2794 COMMIT
2795 M 100644 inlineX hello.c
2796 data <<BLOB
2797 inline
2798 BLOB
2800 cat err &&
2801 test_i18ngrep "nvalid dataref" err
2804 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2805 sha1=$(grep :403 marks | cut -d\ -f2) &&
2806 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2807 commit refs/heads/S
2808 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2809 data <<COMMIT
2810 commit N
2811 COMMIT
2812 M 100644 ${sha1}x hello.c
2814 cat err &&
2815 test_i18ngrep "space after SHA1" err
2819 # notemodify, three ways to say dataref
2821 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2822 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2823 commit refs/heads/S
2824 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2825 data <<COMMIT
2826 commit S note dataref markref
2827 COMMIT
2828 N :202x :302
2830 cat err &&
2831 test_i18ngrep "space after mark" err
2834 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2835 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2836 commit refs/heads/S
2837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2838 data <<COMMIT
2839 commit S note dataref inline
2840 COMMIT
2841 N inlineX :302
2842 data <<BLOB
2843 note blob
2844 BLOB
2846 cat err &&
2847 test_i18ngrep "nvalid dataref" err
2850 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2851 sha1=$(grep :202 marks | cut -d\ -f2) &&
2852 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2853 commit refs/heads/S
2854 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2855 data <<COMMIT
2856 commit S note dataref sha1
2857 COMMIT
2858 N ${sha1}x :302
2860 cat err &&
2861 test_i18ngrep "space after SHA1" err
2865 # notemodify, mark in commit-ish
2867 test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2868 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2869 commit refs/heads/Snotes
2870 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2871 data <<COMMIT
2872 commit S note commit-ish
2873 COMMIT
2874 N :202 :302x
2876 cat err &&
2877 test_i18ngrep "after mark" err
2881 # from
2883 test_expect_success 'S: from with garbage after mark must fail' '
2884 test_must_fail \
2885 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2886 commit refs/heads/S2
2887 mark :303
2888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2889 data <<COMMIT
2890 commit 3
2891 COMMIT
2892 from :301x
2893 M 100644 :403 hello.c
2897 # go create the commit, need it for merge test
2898 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2899 commit refs/heads/S2
2900 mark :303
2901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2902 data <<COMMIT
2903 commit 3
2904 COMMIT
2905 from :301
2906 M 100644 :403 hello.c
2909 # now evaluate the error
2910 cat err &&
2911 test_i18ngrep "after mark" err
2916 # merge
2918 test_expect_success 'S: merge with garbage after mark must fail' '
2919 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2920 commit refs/heads/S
2921 mark :304
2922 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2923 data <<COMMIT
2924 merge 4
2925 COMMIT
2926 from :302
2927 merge :303x
2928 M 100644 :403 hello.c
2930 cat err &&
2931 test_i18ngrep "after mark" err
2935 # tag, from markref
2937 test_expect_success 'S: tag with garbage after mark must fail' '
2938 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2939 tag refs/tags/Stag
2940 from :302x
2941 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2942 data <<TAG
2943 tag S
2946 cat err &&
2947 test_i18ngrep "after mark" err
2951 # cat-blob markref
2953 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2954 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2955 cat-blob :403x
2957 cat err &&
2958 test_i18ngrep "after mark" err
2962 # ls markref
2964 test_expect_success 'S: ls with garbage after mark must fail' '
2965 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2966 ls :302x hello.c
2968 cat err &&
2969 test_i18ngrep "space after mark" err
2972 test_expect_success 'S: ls with garbage after sha1 must fail' '
2973 sha1=$(grep :302 marks | cut -d\ -f2) &&
2974 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2975 ls ${sha1}x hello.c
2977 cat err &&
2978 test_i18ngrep "space after tree-ish" err
2982 ### series T (ls)
2984 # Setup is carried over from series S.
2986 test_expect_success 'T: ls root tree' '
2987 sed -e "s/Z\$//" >expect <<-EOF &&
2988 040000 tree $(git rev-parse S^{tree}) Z
2990 sha1=$(git rev-parse --verify S) &&
2991 git fast-import --import-marks=marks <<-EOF >actual &&
2992 ls $sha1 ""
2994 test_cmp expect actual
2997 test_expect_success 'T: delete branch' '
2998 git branch to-delete &&
2999 git fast-import <<-EOF &&
3000 reset refs/heads/to-delete
3001 from 0000000000000000000000000000000000000000
3003 test_must_fail git rev-parse --verify refs/heads/to-delete
3006 test_expect_success 'T: empty reset doesnt delete branch' '
3007 git branch not-to-delete &&
3008 git fast-import <<-EOF &&
3009 reset refs/heads/not-to-delete
3011 git show-ref &&
3012 git rev-parse --verify refs/heads/not-to-delete
3016 ### series U (filedelete)
3019 test_expect_success 'U: initialize for U tests' '
3020 cat >input <<-INPUT_END &&
3021 commit refs/heads/U
3022 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3023 data <<COMMIT
3024 test setup
3025 COMMIT
3026 M 100644 inline hello.c
3027 data <<BLOB
3028 blob 1
3029 BLOB
3030 M 100644 inline good/night.txt
3031 data <<BLOB
3032 sleep well
3033 BLOB
3034 M 100644 inline good/bye.txt
3035 data <<BLOB
3036 au revoir
3037 BLOB
3039 INPUT_END
3041 git fast-import <input
3044 test_expect_success 'U: filedelete file succeeds' '
3045 cat >input <<-INPUT_END &&
3046 commit refs/heads/U
3047 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3048 data <<COMMIT
3049 delete good/night.txt
3050 COMMIT
3051 from refs/heads/U^0
3052 D good/night.txt
3054 INPUT_END
3056 git fast-import <input
3059 test_expect_success 'U: validate file delete result' '
3060 cat >expect <<-EOF &&
3061 :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3064 git diff-tree -M -r U^1 U >actual &&
3066 compare_diff_raw expect actual
3069 test_expect_success 'U: filedelete directory succeeds' '
3070 cat >input <<-INPUT_END &&
3071 commit refs/heads/U
3072 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3073 data <<COMMIT
3074 delete good dir
3075 COMMIT
3076 from refs/heads/U^0
3077 D good
3079 INPUT_END
3081 git fast-import <input
3084 test_expect_success 'U: validate directory delete result' '
3085 cat >expect <<-EOF &&
3086 :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3089 git diff-tree -M -r U^1 U >actual &&
3091 compare_diff_raw expect actual
3094 test_expect_success 'U: filedelete root succeeds' '
3095 cat >input <<-INPUT_END &&
3096 commit refs/heads/U
3097 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3098 data <<COMMIT
3099 must succeed
3100 COMMIT
3101 from refs/heads/U^0
3102 D ""
3104 INPUT_END
3106 git fast-import <input
3109 test_expect_success 'U: validate root delete result' '
3110 cat >expect <<-EOF &&
3111 :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3114 git diff-tree -M -r U^1 U >actual &&
3116 compare_diff_raw expect actual
3119 test_done