modernize t9300: mark here-doc words to ignore tab indentation
[git.git] / t / t9300-fast-import.sh
blob7586f41367632f33b744e70942020a2cf31069e6
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_tick
56 test_expect_success 'empty stream succeeds' '
57 git fast-import </dev/null
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 test_expect_success 'A: create pack from stdin' '
102 git fast-import --export-marks=marks.out <input &&
103 git whatchanged master
106 test_expect_success 'A: verify pack' '
107 verify_packs
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 test_expect_success 'A: verify commit' '
117 git cat-file commit master | sed 1d >actual &&
118 test_cmp expect actual
121 cat >expect <<-EOF &&
122 100644 blob file2
123 100644 blob file3
124 100755 blob file4
126 test_expect_success 'A: verify tree' '
127 git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
128 test_cmp expect actual
131 echo "$file2_data" >expect
132 test_expect_success 'A: verify file2' '
133 git cat-file blob master:file2 >actual &&
134 test_cmp expect actual
137 echo "$file3_data" >expect
138 test_expect_success 'A: verify file3' '
139 git cat-file blob master:file3 >actual &&
140 test_cmp expect actual
143 printf "$file4_data" >expect
144 test_expect_success 'A: verify file4' '
145 git cat-file blob master:file4 >actual &&
146 test_cmp expect actual
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 test_expect_success 'A: verify tag/series-A' '
157 git cat-file tag tags/series-A >actual &&
158 test_cmp expect actual
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 test_expect_success 'A: verify tag/series-A-blob' '
169 git cat-file tag tags/series-A-blob >actual &&
170 test_cmp expect actual
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_expect_success 'A: verify marks output' '
180 test_cmp expect marks.out
183 test_expect_success 'A: verify marks import' '
184 git fast-import \
185 --import-marks=marks.out \
186 --export-marks=marks.new \
187 </dev/null &&
188 test_cmp expect marks.new
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 test_expect_success 'A: tag blob by sha1' '
234 git fast-import <input &&
235 git cat-file tag tags/series-A-blob-2 >actual &&
236 git cat-file tag tags/series-A-blob-3 >>actual &&
237 test_cmp expect actual
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
252 test_expect_success 'A: verify marks import does not crash' '
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 cat >expect <<-EOF &&
262 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
264 git diff-tree -M -r master verify--import-marks >actual
265 test_expect_success 'A: verify diff' '
266 compare_diff_raw expect actual &&
267 test `git rev-parse --verify master:file2` \
268 = `git rev-parse --verify verify--import-marks:copy-of-file2`
271 test_tick
272 mt=$(git hash-object --stdin < /dev/null)
273 : >input.blob
274 : >marks.exp
275 : >tree.exp
277 cat >input.commit <<-EOF &&
278 commit refs/heads/verify--dump-marks
279 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
280 data <<COMMIT
281 test the sparse array dumping routines with exponentially growing marks
282 COMMIT
289 while test "$i" -lt 27; do
290 cat >>input.blob <<-EOF &&
291 blob
292 mark :$l
293 data 0
294 blob
295 mark :$m
296 data 0
297 blob
298 mark :$n
299 data 0
301 echo "M 100644 :$l l$i" >>input.commit
302 echo "M 100644 :$m m$i" >>input.commit
303 echo "M 100644 :$n n$i" >>input.commit
305 echo ":$l $mt" >>marks.exp
306 echo ":$m $mt" >>marks.exp
307 echo ":$n $mt" >>marks.exp
309 printf "100644 blob $mt\tl$i\n" >>tree.exp
310 printf "100644 blob $mt\tm$i\n" >>tree.exp
311 printf "100644 blob $mt\tn$i\n" >>tree.exp
313 l=$(($l + $l))
314 m=$(($m + $m))
315 n=$(($l + $n))
317 i=$((1 + $i))
318 done
320 sort tree.exp > tree.exp_s
322 test_expect_success 'A: export marks with large values' '
323 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
324 git ls-tree refs/heads/verify--dump-marks >tree.out &&
325 test_cmp tree.exp_s tree.out &&
326 test_cmp marks.exp marks.large
330 ### series B
333 test_tick
334 cat >input <<-INPUT_END &&
335 commit refs/heads/branch
336 mark :1
337 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
338 data <<COMMIT
339 corrupt
340 COMMIT
342 from refs/heads/master
343 M 755 0000000000000000000000000000000000000001 zero1
345 INPUT_END
346 test_expect_success 'B: fail on invalid blob sha1' '
347 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
348 test_must_fail git fast-import <input
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
361 test_expect_success 'B: accept branch name "TEMP_TAG"' '
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 cat >input <<-INPUT_END &&
371 commit refs/heads/empty-committer-1
372 committer <> $GIT_COMMITTER_DATE
373 data <<COMMIT
374 empty commit
375 COMMIT
376 INPUT_END
377 test_expect_success 'B: accept empty committer' '
378 test_when_finished "git update-ref -d refs/heads/empty-committer-1
379 git gc
380 git prune" &&
381 git fast-import <input &&
382 out=$(git fsck) &&
383 echo "$out" &&
384 test -z "$out"
387 cat >input <<-INPUT_END &&
388 commit refs/heads/empty-committer-2
389 committer <a@b.com> $GIT_COMMITTER_DATE
390 data <<COMMIT
391 empty commit
392 COMMIT
393 INPUT_END
394 test_expect_success 'B: accept and fixup committer with no name' '
395 test_when_finished "git update-ref -d refs/heads/empty-committer-2
396 git gc
397 git prune" &&
398 git fast-import <input &&
399 out=$(git fsck) &&
400 echo "$out" &&
401 test -z "$out"
404 cat >input <<-INPUT_END &&
405 commit refs/heads/invalid-committer
406 committer Name email> $GIT_COMMITTER_DATE
407 data <<COMMIT
408 empty commit
409 COMMIT
410 INPUT_END
411 test_expect_success 'B: fail on invalid committer (1)' '
412 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
413 test_must_fail git fast-import <input
416 cat >input <<-INPUT_END &&
417 commit refs/heads/invalid-committer
418 committer Name <e<mail> $GIT_COMMITTER_DATE
419 data <<COMMIT
420 empty commit
421 COMMIT
422 INPUT_END
423 test_expect_success 'B: fail on invalid committer (2)' '
424 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
425 test_must_fail git fast-import <input
428 cat >input <<-INPUT_END &&
429 commit refs/heads/invalid-committer
430 committer Name <email>> $GIT_COMMITTER_DATE
431 data <<COMMIT
432 empty commit
433 COMMIT
434 INPUT_END
435 test_expect_success 'B: fail on invalid committer (3)' '
436 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
437 test_must_fail git fast-import <input
440 cat >input <<-INPUT_END &&
441 commit refs/heads/invalid-committer
442 committer Name <email $GIT_COMMITTER_DATE
443 data <<COMMIT
444 empty commit
445 COMMIT
446 INPUT_END
447 test_expect_success 'B: fail on invalid committer (4)' '
448 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
449 test_must_fail git fast-import <input
452 cat >input <<-INPUT_END &&
453 commit refs/heads/invalid-committer
454 committer Name<email> $GIT_COMMITTER_DATE
455 data <<COMMIT
456 empty commit
457 COMMIT
458 INPUT_END
459 test_expect_success 'B: fail on invalid committer (5)' '
460 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
461 test_must_fail git fast-import <input
465 ### series C
468 newf=`echo hi newf | git hash-object -w --stdin`
469 oldf=`git rev-parse --verify master:file2`
470 test_tick
471 cat >input <<-INPUT_END &&
472 commit refs/heads/branch
473 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
474 data <<COMMIT
475 second
476 COMMIT
478 from refs/heads/master
479 M 644 $oldf file2/oldf
480 M 755 $newf file2/newf
481 D file3
483 INPUT_END
484 test_expect_success 'C: incremental import create pack from stdin' '
485 git fast-import <input &&
486 git whatchanged branch
489 test_expect_success 'C: verify pack' '
490 verify_packs
493 test_expect_success 'C: validate reuse existing blob' '
494 test $newf = `git rev-parse --verify branch:file2/newf` &&
495 test $oldf = `git rev-parse --verify branch:file2/oldf`
498 cat >expect <<-EOF &&
499 parent `git rev-parse --verify master^0`
500 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
501 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
503 second
505 test_expect_success 'C: verify commit' '
506 git cat-file commit branch | sed 1d >actual &&
507 test_cmp expect actual
510 cat >expect <<-EOF &&
511 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
512 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
513 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
515 git diff-tree -M -r master branch >actual
516 test_expect_success 'C: validate rename result' '
517 compare_diff_raw expect actual
521 ### series D
524 test_tick
525 cat >input <<-INPUT_END &&
526 commit refs/heads/branch
527 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
528 data <<COMMIT
529 third
530 COMMIT
532 from refs/heads/branch^0
533 M 644 inline newdir/interesting
534 data <<EOF
535 $file5_data
538 M 755 inline newdir/exec.sh
539 data <<EOF
540 $file6_data
543 INPUT_END
544 test_expect_success 'D: inline data in commit' '
545 git fast-import <input &&
546 git whatchanged branch
549 test_expect_success 'D: verify pack' '
550 verify_packs
553 cat >expect <<-EOF &&
554 :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
555 :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
557 git diff-tree -M -r branch^ branch >actual
558 test_expect_success 'D: validate new files added' '
559 compare_diff_raw expect actual
562 echo "$file5_data" >expect
563 test_expect_success 'D: verify file5' '
564 git cat-file blob branch:newdir/interesting >actual &&
565 test_cmp expect actual
568 echo "$file6_data" >expect
569 test_expect_success 'D: verify file6' '
570 git cat-file blob branch:newdir/exec.sh >actual &&
571 test_cmp expect actual
575 ### series E
578 cat >input <<-INPUT_END &&
579 commit refs/heads/branch
580 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
581 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
582 data <<COMMIT
583 RFC 2822 type date
584 COMMIT
586 from refs/heads/branch^0
588 INPUT_END
589 test_expect_success 'E: rfc2822 date, --date-format=raw' '
590 test_must_fail git fast-import --date-format=raw <input
592 test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
593 git fast-import --date-format=rfc2822 <input
596 test_expect_success 'E: verify pack' '
597 verify_packs
600 cat >expect <<-EOF &&
601 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
602 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
604 RFC 2822 type date
606 test_expect_success 'E: verify commit' '
607 git cat-file commit branch | sed 1,2d >actual &&
608 test_cmp expect actual
612 ### series F
615 old_branch=`git rev-parse --verify branch^0`
616 test_tick
617 cat >input <<-INPUT_END &&
618 commit refs/heads/branch
619 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
620 data <<COMMIT
621 losing things already?
622 COMMIT
624 from refs/heads/branch~1
626 reset refs/heads/other
627 from refs/heads/branch
629 INPUT_END
630 test_expect_success 'F: non-fast-forward update skips' '
631 test_must_fail git fast-import <input &&
632 # branch must remain unaffected
633 test $old_branch = `git rev-parse --verify branch^0`
636 test_expect_success 'F: verify pack' '
637 verify_packs
640 cat >expect <<-EOF &&
641 tree `git rev-parse branch~1^{tree}`
642 parent `git rev-parse branch~1`
643 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
644 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
646 losing things already?
648 test_expect_success 'F: verify other commit' '
649 git cat-file commit other >actual &&
650 test_cmp expect actual
654 ### series G
657 old_branch=`git rev-parse --verify branch^0`
658 test_tick
659 cat >input <<-INPUT_END &&
660 commit refs/heads/branch
661 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
662 data <<COMMIT
663 losing things already?
664 COMMIT
666 from refs/heads/branch~1
668 INPUT_END
669 test_expect_success 'G: non-fast-forward update forced' '
670 git fast-import --force <input
673 test_expect_success 'G: verify pack' '
674 verify_packs
677 test_expect_success 'G: branch changed, but logged' '
678 test $old_branch != `git rev-parse --verify branch^0` &&
679 test $old_branch = `git rev-parse --verify branch@{1}`
683 ### series H
686 test_tick
687 cat >input <<-INPUT_END &&
688 commit refs/heads/H
689 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 data <<COMMIT
691 third
692 COMMIT
694 from refs/heads/branch^0
695 M 644 inline i-will-die
696 data <<EOF
697 this file will never exist.
700 deleteall
701 M 644 inline h/e/l/lo
702 data <<EOF
703 $file5_data
706 INPUT_END
707 test_expect_success 'H: deletall, add 1' '
708 git fast-import <input &&
709 git whatchanged H
712 test_expect_success 'H: verify pack' '
713 verify_packs
716 cat >expect <<-EOF &&
717 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
718 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
719 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
720 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
721 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
723 git diff-tree -M -r H^ H >actual
724 test_expect_success 'H: validate old files removed, new files added' '
725 compare_diff_raw expect actual
728 echo "$file5_data" >expect
729 test_expect_success 'H: verify file' '
730 git cat-file blob H:h/e/l/lo >actual &&
731 test_cmp expect actual
735 ### series I
738 cat >input <<-INPUT_END &&
739 commit refs/heads/export-boundary
740 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
741 data <<COMMIT
742 we have a border. its only 40 characters wide.
743 COMMIT
745 from refs/heads/branch
747 INPUT_END
748 test_expect_success 'I: export-pack-edges' '
749 git fast-import --export-pack-edges=edges.list <input
752 cat >expect <<-EOF &&
753 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
755 test_expect_success 'I: verify edge list' '
756 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
757 test_cmp expect actual
761 ### series J
764 cat >input <<-INPUT_END &&
765 commit refs/heads/J
766 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
767 data <<COMMIT
768 create J
769 COMMIT
771 from refs/heads/branch
773 reset refs/heads/J
775 commit refs/heads/J
776 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
777 data <<COMMIT
778 initialize J
779 COMMIT
781 INPUT_END
782 test_expect_success 'J: reset existing branch creates empty commit' '
783 git fast-import <input
785 test_expect_success 'J: branch has 1 commit, empty tree' '
786 test 1 = `git rev-list J | wc -l` &&
787 test 0 = `git ls-tree J | wc -l`
790 cat >input <<-INPUT_END &&
791 reset refs/heads/J2
793 tag wrong_tag
794 from refs/heads/J2
795 data <<EOF
796 Tag branch that was reset.
798 INPUT_END
799 test_expect_success 'J: tag must fail on empty branch' '
800 test_must_fail git fast-import <input
803 ### series K
806 cat >input <<-INPUT_END &&
807 commit refs/heads/K
808 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
809 data <<COMMIT
810 create K
811 COMMIT
813 from refs/heads/branch
815 commit refs/heads/K
816 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
817 data <<COMMIT
818 redo K
819 COMMIT
821 from refs/heads/branch^1
823 INPUT_END
824 test_expect_success 'K: reinit branch with from' '
825 git fast-import <input
827 test_expect_success 'K: verify K^1 = branch^1' '
828 test `git rev-parse --verify branch^1` \
829 = `git rev-parse --verify K^1`
833 ### series L
836 cat >input <<-INPUT_END &&
837 blob
838 mark :1
839 data <<EOF
840 some data
843 blob
844 mark :2
845 data <<EOF
846 other data
849 commit refs/heads/L
850 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
851 data <<COMMIT
852 create L
853 COMMIT
855 M 644 :1 b.
856 M 644 :1 b/other
857 M 644 :1 ba
859 commit refs/heads/L
860 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
861 data <<COMMIT
862 update L
863 COMMIT
865 M 644 :2 b.
866 M 644 :2 b/other
867 M 644 :2 ba
868 INPUT_END
870 cat >expect <<-EXPECT_END &&
871 :100644 100644 4268632... 55d3a52... M b.
872 :040000 040000 0ae5cac... 443c768... M b
873 :100644 100644 4268632... 55d3a52... M ba
874 EXPECT_END
876 test_expect_success 'L: verify internal tree sorting' '
877 git fast-import <input &&
878 git diff-tree --abbrev --raw L^ L >output &&
879 test_cmp expect output
882 cat >input <<-INPUT_END &&
883 blob
884 mark :1
885 data <<EOF
886 the data
889 commit refs/heads/L2
890 committer C O Mitter <committer@example.com> 1112912473 -0700
891 data <<COMMIT
892 init L2
893 COMMIT
894 M 644 :1 a/b/c
895 M 644 :1 a/b/d
896 M 644 :1 a/e/f
898 commit refs/heads/L2
899 committer C O Mitter <committer@example.com> 1112912473 -0700
900 data <<COMMIT
901 update L2
902 COMMIT
903 C a g
904 C a/e g/b
905 M 644 :1 g/b/h
906 INPUT_END
908 cat <<-EOF >expect &&
909 g/b/f
910 g/b/h
913 test_expect_success 'L: nested tree copy does not corrupt deltas' '
914 test_when_finished "git update-ref -d refs/heads/L2" &&
915 git fast-import <input &&
916 git ls-tree L2 g/b/ >tmp &&
917 cat tmp | cut -f 2 >actual &&
918 test_cmp expect actual &&
919 git fsck `git rev-parse L2`
923 ### series M
926 test_tick
927 cat >input <<-INPUT_END &&
928 commit refs/heads/M1
929 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
930 data <<COMMIT
931 file rename
932 COMMIT
934 from refs/heads/branch^0
935 R file2/newf file2/n.e.w.f
937 INPUT_END
939 cat >expect <<-EOF &&
940 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
942 test_expect_success 'M: rename file in same subdirectory' '
943 git fast-import <input &&
944 git diff-tree -M -r M1^ M1 >actual &&
945 compare_diff_raw expect actual
948 cat >input <<-INPUT_END &&
949 commit refs/heads/M2
950 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
951 data <<COMMIT
952 file rename
953 COMMIT
955 from refs/heads/branch^0
956 R file2/newf i/am/new/to/you
958 INPUT_END
960 cat >expect <<-EOF &&
961 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
963 test_expect_success 'M: rename file to new subdirectory' '
964 git fast-import <input &&
965 git diff-tree -M -r M2^ M2 >actual &&
966 compare_diff_raw expect actual
969 cat >input <<-INPUT_END &&
970 commit refs/heads/M3
971 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
972 data <<COMMIT
973 file rename
974 COMMIT
976 from refs/heads/M2^0
977 R i other/sub
979 INPUT_END
981 cat >expect <<-EOF &&
982 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
984 test_expect_success 'M: rename subdirectory to new subdirectory' '
985 git fast-import <input &&
986 git diff-tree -M -r M3^ M3 >actual &&
987 compare_diff_raw expect actual
990 cat >input <<-INPUT_END &&
991 commit refs/heads/M4
992 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
993 data <<COMMIT
994 rename root
995 COMMIT
997 from refs/heads/M2^0
998 R "" sub
1000 INPUT_END
1002 cat >expect <<-EOF &&
1003 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1004 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1005 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1006 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1007 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1009 test_expect_success 'M: rename root to subdirectory' '
1010 git fast-import <input &&
1011 git diff-tree -M -r M4^ M4 >actual &&
1012 cat actual &&
1013 compare_diff_raw expect actual
1017 ### series N
1020 test_tick
1021 cat >input <<-INPUT_END &&
1022 commit refs/heads/N1
1023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1024 data <<COMMIT
1025 file copy
1026 COMMIT
1028 from refs/heads/branch^0
1029 C file2/newf file2/n.e.w.f
1031 INPUT_END
1033 cat >expect <<-EOF &&
1034 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1036 test_expect_success 'N: copy file in same subdirectory' '
1037 git fast-import <input &&
1038 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1039 compare_diff_raw expect actual
1042 cat >input <<-INPUT_END &&
1043 commit refs/heads/N2
1044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1045 data <<COMMIT
1046 clean directory copy
1047 COMMIT
1049 from refs/heads/branch^0
1050 C file2 file3
1052 commit refs/heads/N2
1053 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1054 data <<COMMIT
1055 modify directory copy
1056 COMMIT
1058 M 644 inline file3/file5
1059 data <<EOF
1060 $file5_data
1063 INPUT_END
1065 cat >expect <<-EOF &&
1066 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1067 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1068 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1070 test_expect_success 'N: copy then modify subdirectory' '
1071 git fast-import <input &&
1072 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1073 compare_diff_raw expect actual
1076 cat >input <<-INPUT_END &&
1077 commit refs/heads/N3
1078 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1079 data <<COMMIT
1080 dirty directory copy
1081 COMMIT
1083 from refs/heads/branch^0
1084 M 644 inline file2/file5
1085 data <<EOF
1086 $file5_data
1089 C file2 file3
1090 D file2/file5
1092 INPUT_END
1094 test_expect_success 'N: copy dirty subdirectory' '
1095 git fast-import <input &&
1096 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`
1099 test_expect_success 'N: copy directory by id' '
1100 cat >expect <<-\EOF &&
1101 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1102 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1104 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1105 cat >input <<-INPUT_END &&
1106 commit refs/heads/N4
1107 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1108 data <<COMMIT
1109 copy by tree hash
1110 COMMIT
1112 from refs/heads/branch^0
1113 M 040000 $subdir file3
1114 INPUT_END
1115 git fast-import <input &&
1116 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1117 compare_diff_raw expect actual
1120 test_expect_success PIPE 'N: read and copy directory' '
1121 cat >expect <<-\EOF &&
1122 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1123 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1125 git update-ref -d refs/heads/N4 &&
1126 rm -f backflow &&
1127 mkfifo backflow &&
1129 exec <backflow &&
1130 cat <<-EOF &&
1131 commit refs/heads/N4
1132 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1133 data <<COMMIT
1134 copy by tree hash, part 2
1135 COMMIT
1137 from refs/heads/branch^0
1138 ls "file2"
1140 read mode type tree filename &&
1141 echo "M 040000 $tree file3"
1143 git fast-import --cat-blob-fd=3 3>backflow &&
1144 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1145 compare_diff_raw expect actual
1148 test_expect_success PIPE 'N: empty directory reads as missing' '
1149 cat <<-\EOF >expect &&
1150 OBJNAME
1151 :000000 100644 OBJNAME OBJNAME A unrelated
1153 echo "missing src" >expect.response &&
1154 git update-ref -d refs/heads/read-empty &&
1155 rm -f backflow &&
1156 mkfifo backflow &&
1158 exec <backflow &&
1159 cat <<-EOF &&
1160 commit refs/heads/read-empty
1161 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1162 data <<COMMIT
1163 read "empty" (missing) directory
1164 COMMIT
1166 M 100644 inline src/greeting
1167 data <<BLOB
1168 hello
1169 BLOB
1170 C src/greeting dst1/non-greeting
1171 C src/greeting unrelated
1172 # leave behind "empty" src directory
1173 D src/greeting
1174 ls "src"
1176 read -r line &&
1177 printf "%s\n" "$line" >response &&
1178 cat <<-\EOF
1179 D dst1
1180 D dst2
1183 git fast-import --cat-blob-fd=3 3>backflow &&
1184 test_cmp expect.response response &&
1185 git rev-list read-empty |
1186 git diff-tree -r --root --stdin |
1187 sed "s/$_x40/OBJNAME/g" >actual &&
1188 test_cmp expect actual
1191 test_expect_success 'N: copy root directory by tree hash' '
1192 cat >expect <<-\EOF &&
1193 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1194 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1196 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1197 cat >input <<-INPUT_END &&
1198 commit refs/heads/N6
1199 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1200 data <<COMMIT
1201 copy root directory by tree hash
1202 COMMIT
1204 from refs/heads/branch^0
1205 M 040000 $root ""
1206 INPUT_END
1207 git fast-import <input &&
1208 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1209 compare_diff_raw expect actual
1212 test_expect_success 'N: copy root by path' '
1213 cat >expect <<-\EOF &&
1214 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1215 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1216 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1217 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1218 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1220 cat >input <<-INPUT_END &&
1221 commit refs/heads/N-copy-root-path
1222 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1223 data <<COMMIT
1224 copy root directory by (empty) path
1225 COMMIT
1227 from refs/heads/branch^0
1228 C "" oldroot
1229 INPUT_END
1230 git fast-import <input &&
1231 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1232 compare_diff_raw expect actual
1235 test_expect_success 'N: delete directory by copying' '
1236 cat >expect <<-\EOF &&
1237 OBJID
1238 :100644 000000 OBJID OBJID D foo/bar/qux
1239 OBJID
1240 :000000 100644 OBJID OBJID A foo/bar/baz
1241 :000000 100644 OBJID OBJID A foo/bar/qux
1243 empty_tree=$(git mktree </dev/null) &&
1244 cat >input <<-INPUT_END &&
1245 commit refs/heads/N-delete
1246 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1247 data <<COMMIT
1248 collect data to be deleted
1249 COMMIT
1251 deleteall
1252 M 100644 inline foo/bar/baz
1253 data <<DATA_END
1254 hello
1255 DATA_END
1256 C "foo/bar/baz" "foo/bar/qux"
1257 C "foo/bar/baz" "foo/bar/quux/1"
1258 C "foo/bar/baz" "foo/bar/quuux"
1259 M 040000 $empty_tree foo/bar/quux
1260 M 040000 $empty_tree foo/bar/quuux
1262 commit refs/heads/N-delete
1263 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1264 data <<COMMIT
1265 delete subdirectory
1266 COMMIT
1268 M 040000 $empty_tree foo/bar/qux
1269 INPUT_END
1270 git fast-import <input &&
1271 git rev-list N-delete |
1272 git diff-tree -r --stdin --root --always |
1273 sed -e "s/$_x40/OBJID/g" >actual &&
1274 test_cmp expect actual
1277 test_expect_success 'N: modify copied tree' '
1278 cat >expect <<-\EOF &&
1279 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1280 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1281 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1283 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1284 cat >input <<-INPUT_END &&
1285 commit refs/heads/N5
1286 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1287 data <<COMMIT
1288 copy by tree hash
1289 COMMIT
1291 from refs/heads/branch^0
1292 M 040000 $subdir file3
1294 commit refs/heads/N5
1295 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1296 data <<COMMIT
1297 modify directory copy
1298 COMMIT
1300 M 644 inline file3/file5
1301 data <<EOF
1302 $file5_data
1304 INPUT_END
1305 git fast-import <input &&
1306 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1307 compare_diff_raw expect actual
1310 test_expect_success 'N: reject foo/ syntax' '
1311 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1312 test_must_fail git fast-import <<-INPUT_END
1313 commit refs/heads/N5B
1314 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1315 data <<COMMIT
1316 copy with invalid syntax
1317 COMMIT
1319 from refs/heads/branch^0
1320 M 040000 $subdir file3/
1321 INPUT_END
1324 test_expect_success 'N: reject foo/ syntax in copy source' '
1325 test_must_fail git fast-import <<-INPUT_END
1326 commit refs/heads/N5C
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 C file2/ file3
1334 INPUT_END
1337 test_expect_success 'N: reject foo/ syntax in rename source' '
1338 test_must_fail git fast-import <<-INPUT_END
1339 commit refs/heads/N5D
1340 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1341 data <<COMMIT
1342 rename with invalid syntax
1343 COMMIT
1345 from refs/heads/branch^0
1346 R file2/ file3
1347 INPUT_END
1350 test_expect_success 'N: reject foo/ syntax in ls argument' '
1351 test_must_fail git fast-import <<-INPUT_END
1352 commit refs/heads/N5E
1353 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1354 data <<COMMIT
1355 copy with invalid syntax
1356 COMMIT
1358 from refs/heads/branch^0
1359 ls "file2/"
1360 INPUT_END
1363 test_expect_success 'N: copy to root by id and modify' '
1364 echo "hello, world" >expect.foo &&
1365 echo hello >expect.bar &&
1366 git fast-import <<-SETUP_END &&
1367 commit refs/heads/N7
1368 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1369 data <<COMMIT
1370 hello, tree
1371 COMMIT
1373 deleteall
1374 M 644 inline foo/bar
1375 data <<EOF
1376 hello
1378 SETUP_END
1380 tree=$(git rev-parse --verify N7:) &&
1381 git fast-import <<-INPUT_END &&
1382 commit refs/heads/N8
1383 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1384 data <<COMMIT
1385 copy to root by id and modify
1386 COMMIT
1388 M 040000 $tree ""
1389 M 644 inline foo/foo
1390 data <<EOF
1391 hello, world
1393 INPUT_END
1394 git show N8:foo/foo >actual.foo &&
1395 git show N8:foo/bar >actual.bar &&
1396 test_cmp expect.foo actual.foo &&
1397 test_cmp expect.bar actual.bar
1400 test_expect_success 'N: extract subtree' '
1401 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1402 cat >input <<-INPUT_END &&
1403 commit refs/heads/N9
1404 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1405 data <<COMMIT
1406 extract subtree branch:newdir
1407 COMMIT
1409 M 040000 $branch ""
1410 C "newdir" ""
1411 INPUT_END
1412 git fast-import <input &&
1413 git diff --exit-code branch:newdir N9
1416 test_expect_success 'N: modify subtree, extract it, and modify again' '
1417 echo hello >expect.baz &&
1418 echo hello, world >expect.qux &&
1419 git fast-import <<-SETUP_END &&
1420 commit refs/heads/N10
1421 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1422 data <<COMMIT
1423 hello, tree
1424 COMMIT
1426 deleteall
1427 M 644 inline foo/bar/baz
1428 data <<EOF
1429 hello
1431 SETUP_END
1433 tree=$(git rev-parse --verify N10:) &&
1434 git fast-import <<-INPUT_END &&
1435 commit refs/heads/N11
1436 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1437 data <<COMMIT
1438 copy to root by id and modify
1439 COMMIT
1441 M 040000 $tree ""
1442 M 100644 inline foo/bar/qux
1443 data <<EOF
1444 hello, world
1446 R "foo" ""
1447 C "bar/qux" "bar/quux"
1448 INPUT_END
1449 git show N11:bar/baz >actual.baz &&
1450 git show N11:bar/qux >actual.qux &&
1451 git show N11:bar/quux >actual.quux &&
1452 test_cmp expect.baz actual.baz &&
1453 test_cmp expect.qux actual.qux &&
1454 test_cmp expect.qux actual.quux'
1457 ### series O
1460 cat >input <<-INPUT_END &&
1461 #we will
1462 commit refs/heads/O1
1463 # -- ignore all of this text
1464 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1465 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1466 data <<COMMIT
1467 dirty directory copy
1468 COMMIT
1470 # don't forget the import blank line!
1472 # yes, we started from our usual base of branch^0.
1473 # i like branch^0.
1474 from refs/heads/branch^0
1475 # and we need to reuse file2/file5 from N3 above.
1476 M 644 inline file2/file5
1477 # otherwise the tree will be different
1478 data <<EOF
1479 $file5_data
1482 # don't forget to copy file2 to file3
1483 C file2 file3
1485 # or to delete file5 from file2.
1486 D file2/file5
1487 # are we done yet?
1489 INPUT_END
1491 test_expect_success 'O: comments are all skipped' '
1492 git fast-import <input &&
1493 test `git rev-parse N3` = `git rev-parse O1`
1496 cat >input <<-INPUT_END &&
1497 commit refs/heads/O2
1498 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1499 data <<COMMIT
1500 dirty directory copy
1501 COMMIT
1502 from refs/heads/branch^0
1503 M 644 inline file2/file5
1504 data <<EOF
1505 $file5_data
1507 C file2 file3
1508 D file2/file5
1510 INPUT_END
1512 test_expect_success 'O: blank lines not necessary after data commands' '
1513 git fast-import <input &&
1514 test `git rev-parse N3` = `git rev-parse O2`
1517 test_expect_success 'O: repack before next test' '
1518 git repack -a -d
1521 cat >input <<-INPUT_END &&
1522 commit refs/heads/O3
1523 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1524 data <<COMMIT
1525 zstring
1526 COMMIT
1527 commit refs/heads/O3
1528 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1529 data <<COMMIT
1531 COMMIT
1532 checkpoint
1533 commit refs/heads/O3
1534 mark :5
1535 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1536 data <<COMMIT
1537 zempty
1538 COMMIT
1539 checkpoint
1540 commit refs/heads/O3
1541 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1542 data <<COMMIT
1543 zcommits
1544 COMMIT
1545 reset refs/tags/O3-2nd
1546 from :5
1547 reset refs/tags/O3-3rd
1548 from :5
1549 INPUT_END
1551 cat >expect <<-INPUT_END &&
1552 string
1554 empty
1555 commits
1556 INPUT_END
1557 test_expect_success 'O: blank lines not necessary after other commands' '
1558 git fast-import <input &&
1559 test 8 = `find .git/objects/pack -type f | wc -l` &&
1560 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1561 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1562 test_cmp expect actual
1565 cat >input <<-INPUT_END &&
1566 commit refs/heads/O4
1567 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1568 data <<COMMIT
1569 zstring
1570 COMMIT
1571 commit refs/heads/O4
1572 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1573 data <<COMMIT
1575 COMMIT
1576 progress Two commits down, 2 to go!
1577 commit refs/heads/O4
1578 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1579 data <<COMMIT
1580 zempty
1581 COMMIT
1582 progress Three commits down, 1 to go!
1583 commit refs/heads/O4
1584 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1585 data <<COMMIT
1586 zcommits
1587 COMMIT
1588 progress I'm done!
1589 INPUT_END
1590 test_expect_success 'O: progress outputs as requested by input' '
1591 git fast-import <input >actual &&
1592 grep "progress " <input >expect &&
1593 test_cmp expect actual
1597 ### series P (gitlinks)
1600 cat >input <<-INPUT_END &&
1601 blob
1602 mark :1
1603 data 10
1604 test file
1606 reset refs/heads/sub
1607 commit refs/heads/sub
1608 mark :2
1609 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1610 data 12
1611 sub_initial
1612 M 100644 :1 file
1614 blob
1615 mark :3
1616 data <<DATAEND
1617 [submodule "sub"]
1618 path = sub
1619 url = "`pwd`/sub"
1620 DATAEND
1622 commit refs/heads/subuse1
1623 mark :4
1624 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625 data 8
1626 initial
1627 from refs/heads/master
1628 M 100644 :3 .gitmodules
1629 M 160000 :2 sub
1631 blob
1632 mark :5
1633 data 20
1634 test file
1635 more data
1637 commit refs/heads/sub
1638 mark :6
1639 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1640 data 11
1641 sub_second
1642 from :2
1643 M 100644 :5 file
1645 commit refs/heads/subuse1
1646 mark :7
1647 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1648 data 7
1649 second
1650 from :4
1651 M 160000 :6 sub
1653 INPUT_END
1655 test_expect_success 'P: superproject & submodule mix' '
1656 git fast-import <input &&
1657 git checkout subuse1 &&
1658 rm -rf sub &&
1659 mkdir sub &&
1661 cd sub &&
1662 git init &&
1663 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1664 git checkout master
1665 ) &&
1666 git submodule init &&
1667 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 'P: verbatim SHA gitlinks' '
1702 git branch -D sub &&
1703 git gc &&
1704 git prune &&
1705 git fast-import <input &&
1706 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1709 test_tick
1710 cat >input <<-INPUT_END &&
1711 commit refs/heads/subuse3
1712 mark :1
1713 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1714 data <<COMMIT
1715 corrupt
1716 COMMIT
1718 from refs/heads/subuse2
1719 M 160000 inline sub
1720 data <<DATA
1721 $SUBPREV
1722 DATA
1724 INPUT_END
1726 test_expect_success 'P: fail on inline gitlink' '
1727 test_must_fail git fast-import <input
1730 test_tick
1731 cat >input <<-INPUT_END &&
1732 blob
1733 mark :1
1734 data <<DATA
1735 $SUBPREV
1736 DATA
1738 commit refs/heads/subuse3
1739 mark :2
1740 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1741 data <<COMMIT
1742 corrupt
1743 COMMIT
1745 from refs/heads/subuse2
1746 M 160000 :1 sub
1748 INPUT_END
1750 test_expect_success 'P: fail on blob mark in gitlink' '
1751 test_must_fail git fast-import <input
1755 ### series Q (notes)
1758 note1_data="The first note for the first commit"
1759 note2_data="The first note for the second commit"
1760 note3_data="The first note for the third commit"
1761 note1b_data="The second note for the first commit"
1762 note1c_data="The third note for the first commit"
1763 note2b_data="The second note for the second commit"
1765 test_tick
1766 cat >input <<-INPUT_END &&
1767 blob
1768 mark :2
1769 data <<EOF
1770 $file2_data
1773 commit refs/heads/notes-test
1774 mark :3
1775 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1776 data <<COMMIT
1777 first (:3)
1778 COMMIT
1780 M 644 :2 file2
1782 blob
1783 mark :4
1784 data $file4_len
1785 $file4_data
1786 commit refs/heads/notes-test
1787 mark :5
1788 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1789 data <<COMMIT
1790 second (:5)
1791 COMMIT
1793 M 644 :4 file4
1795 commit refs/heads/notes-test
1796 mark :6
1797 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1798 data <<COMMIT
1799 third (:6)
1800 COMMIT
1802 M 644 inline file5
1803 data <<EOF
1804 $file5_data
1807 M 755 inline file6
1808 data <<EOF
1809 $file6_data
1812 blob
1813 mark :7
1814 data <<EOF
1815 $note1_data
1818 blob
1819 mark :8
1820 data <<EOF
1821 $note2_data
1824 commit refs/notes/foobar
1825 mark :9
1826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1827 data <<COMMIT
1828 notes (:9)
1829 COMMIT
1831 N :7 :3
1832 N :8 :5
1833 N inline :6
1834 data <<EOF
1835 $note3_data
1838 commit refs/notes/foobar
1839 mark :10
1840 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1841 data <<COMMIT
1842 notes (:10)
1843 COMMIT
1845 N inline :3
1846 data <<EOF
1847 $note1b_data
1850 commit refs/notes/foobar2
1851 mark :11
1852 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1853 data <<COMMIT
1854 notes (:11)
1855 COMMIT
1857 N inline :3
1858 data <<EOF
1859 $note1c_data
1862 commit refs/notes/foobar
1863 mark :12
1864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1865 data <<COMMIT
1866 notes (:12)
1867 COMMIT
1869 deleteall
1870 N inline :5
1871 data <<EOF
1872 $note2b_data
1875 INPUT_END
1877 test_expect_success 'Q: commit notes' '
1878 git fast-import <input &&
1879 git whatchanged notes-test
1882 test_expect_success 'Q: verify pack' '
1883 verify_packs
1886 commit1=$(git rev-parse notes-test~2)
1887 commit2=$(git rev-parse notes-test^)
1888 commit3=$(git rev-parse notes-test)
1890 cat >expect <<-EOF &&
1891 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1892 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1894 first (:3)
1896 test_expect_success 'Q: verify first commit' '
1897 git cat-file commit notes-test~2 | sed 1d >actual &&
1898 test_cmp expect actual
1901 cat >expect <<-EOF &&
1902 parent $commit1
1903 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1904 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1906 second (:5)
1908 test_expect_success 'Q: verify second commit' '
1909 git cat-file commit notes-test^ | sed 1d >actual &&
1910 test_cmp expect actual
1913 cat >expect <<-EOF &&
1914 parent $commit2
1915 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1916 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1918 third (:6)
1920 test_expect_success 'Q: verify third commit' '
1921 git cat-file commit notes-test | sed 1d >actual &&
1922 test_cmp expect actual
1925 cat >expect <<-EOF &&
1926 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1927 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1929 notes (:9)
1931 test_expect_success 'Q: verify first notes commit' '
1932 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1933 test_cmp expect actual
1936 cat >expect.unsorted <<-EOF &&
1937 100644 blob $commit1
1938 100644 blob $commit2
1939 100644 blob $commit3
1941 cat expect.unsorted | sort >expect
1942 test_expect_success 'Q: verify first notes tree' '
1943 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1944 test_cmp expect actual
1947 echo "$note1_data" >expect
1948 test_expect_success 'Q: verify first note for first commit' '
1949 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
1950 test_cmp expect actual
1953 echo "$note2_data" >expect
1954 test_expect_success 'Q: verify first note for second commit' '
1955 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
1956 test_cmp expect actual
1959 echo "$note3_data" >expect
1960 test_expect_success 'Q: verify first note for third commit' '
1961 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
1962 test_cmp expect actual
1965 cat >expect <<-EOF &&
1966 parent `git rev-parse --verify refs/notes/foobar~2`
1967 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1968 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1970 notes (:10)
1972 test_expect_success 'Q: verify second notes commit' '
1973 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1974 test_cmp expect actual
1977 cat >expect.unsorted <<-EOF &&
1978 100644 blob $commit1
1979 100644 blob $commit2
1980 100644 blob $commit3
1982 cat expect.unsorted | sort >expect
1983 test_expect_success 'Q: verify second notes tree' '
1984 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1985 test_cmp expect actual
1988 echo "$note1b_data" >expect
1989 test_expect_success 'Q: verify second note for first commit' '
1990 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
1991 test_cmp expect actual
1994 echo "$note2_data" >expect
1995 test_expect_success 'Q: verify first note for second commit' '
1996 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
1997 test_cmp expect actual
2000 echo "$note3_data" >expect
2001 test_expect_success 'Q: verify first note for third commit' '
2002 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2003 test_cmp expect actual
2006 cat >expect <<-EOF &&
2007 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2008 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2010 notes (:11)
2012 test_expect_success 'Q: verify third notes commit' '
2013 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2014 test_cmp expect actual
2017 cat >expect.unsorted <<-EOF &&
2018 100644 blob $commit1
2020 cat expect.unsorted | sort >expect
2021 test_expect_success 'Q: verify third notes tree' '
2022 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2023 test_cmp expect actual
2026 echo "$note1c_data" >expect
2027 test_expect_success 'Q: verify third note for first commit' '
2028 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2029 test_cmp expect actual
2032 cat >expect <<-EOF &&
2033 parent `git rev-parse --verify refs/notes/foobar^`
2034 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2035 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2037 notes (:12)
2039 test_expect_success 'Q: verify fourth notes commit' '
2040 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2041 test_cmp expect actual
2044 cat >expect.unsorted <<-EOF &&
2045 100644 blob $commit2
2047 cat expect.unsorted | sort >expect
2048 test_expect_success 'Q: verify fourth notes tree' '
2049 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2050 test_cmp expect actual
2053 echo "$note2b_data" >expect
2054 test_expect_success 'Q: verify second note for second commit' '
2055 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2056 test_cmp expect actual
2059 cat >input <<-EOF &&
2060 reset refs/heads/Q0
2062 commit refs/heads/note-Q0
2063 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2064 data <<COMMIT
2065 Note for an empty branch.
2066 COMMIT
2068 N inline refs/heads/Q0
2069 data <<NOTE
2070 some note
2071 NOTE
2073 test_expect_success 'Q: deny note on empty branch' '
2074 test_must_fail git fast-import <input
2077 ### series R (feature and option)
2080 cat >input <<-EOF &&
2081 feature no-such-feature-exists
2084 test_expect_success 'R: abort on unsupported feature' '
2085 test_must_fail git fast-import <input
2088 cat >input <<-EOF &&
2089 feature date-format=now
2092 test_expect_success 'R: supported feature is accepted' '
2093 git fast-import <input
2096 cat >input <<-EOF &&
2097 blob
2098 data 3
2100 feature date-format=now
2103 test_expect_success 'R: abort on receiving feature after data command' '
2104 test_must_fail git fast-import <input
2107 cat >input <<-EOF &&
2108 feature import-marks=git.marks
2109 feature import-marks=git2.marks
2112 test_expect_success 'R: only one import-marks feature allowed per stream' '
2113 test_must_fail git fast-import <input
2116 cat >input <<-EOF &&
2117 feature export-marks=git.marks
2118 blob
2119 mark :1
2120 data 3
2125 test_expect_success 'R: export-marks feature results in a marks file being created' '
2126 cat input | git fast-import &&
2127 grep :1 git.marks
2130 test_expect_success 'R: export-marks options can be overridden by commandline options' '
2131 cat input | git fast-import --export-marks=other.marks &&
2132 grep :1 other.marks
2135 test_expect_success 'R: catch typo in marks file name' '
2136 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2137 echo "feature import-marks=nonexistent.marks" |
2138 test_must_fail git fast-import
2141 test_expect_success 'R: import and output marks can be the same file' '
2142 rm -f io.marks &&
2143 blob=$(echo hi | git hash-object --stdin) &&
2144 cat >expect <<-EOF &&
2145 :1 $blob
2146 :2 $blob
2148 git fast-import --export-marks=io.marks <<-\EOF &&
2149 blob
2150 mark :1
2151 data 3
2155 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2156 blob
2157 mark :2
2158 data 3
2162 test_cmp expect io.marks
2165 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2166 rm -f io.marks &&
2167 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2168 blob
2169 mark :1
2170 data 3
2176 test_expect_success 'R: --import-marks-if-exists' '
2177 rm -f io.marks &&
2178 blob=$(echo hi | git hash-object --stdin) &&
2179 echo ":1 $blob" >expect &&
2180 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2181 blob
2182 mark :1
2183 data 3
2187 test_cmp expect io.marks
2190 test_expect_success 'R: feature import-marks-if-exists' '
2191 rm -f io.marks &&
2192 >expect &&
2194 git fast-import --export-marks=io.marks <<-\EOF &&
2195 feature import-marks-if-exists=not_io.marks
2197 test_cmp expect io.marks &&
2199 blob=$(echo hi | git hash-object --stdin) &&
2201 echo ":1 $blob" >io.marks &&
2202 echo ":1 $blob" >expect &&
2203 echo ":2 $blob" >>expect &&
2205 git fast-import --export-marks=io.marks <<-\EOF &&
2206 feature import-marks-if-exists=io.marks
2207 blob
2208 mark :2
2209 data 3
2213 test_cmp expect io.marks &&
2215 echo ":3 $blob" >>expect &&
2217 git fast-import --import-marks=io.marks \
2218 --export-marks=io.marks <<-\EOF &&
2219 feature import-marks-if-exists=not_io.marks
2220 blob
2221 mark :3
2222 data 3
2226 test_cmp expect io.marks &&
2228 >expect &&
2230 git fast-import --import-marks-if-exists=not_io.marks \
2231 --export-marks=io.marks <<-\EOF &&
2232 feature import-marks-if-exists=io.marks
2234 test_cmp expect io.marks
2237 cat >input <<-EOF &&
2238 feature import-marks=marks.out
2239 feature export-marks=marks.new
2242 test_expect_success 'R: import to output marks works without any content' '
2243 cat input | git fast-import &&
2244 test_cmp marks.out marks.new
2247 cat >input <<-EOF &&
2248 feature import-marks=nonexistent.marks
2249 feature export-marks=marks.new
2252 test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2253 cat input | git fast-import --import-marks=marks.out &&
2254 test_cmp marks.out marks.new
2258 cat >input <<-EOF &&
2259 feature import-marks=nonexistent.marks
2260 feature export-marks=combined.marks
2263 test_expect_success 'R: multiple --import-marks= should be honoured' '
2264 head -n2 marks.out > one.marks &&
2265 tail -n +3 marks.out > two.marks &&
2266 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2267 test_cmp marks.out combined.marks
2270 cat >input <<-EOF &&
2271 feature relative-marks
2272 feature import-marks=relative.in
2273 feature export-marks=relative.out
2276 test_expect_success 'R: feature relative-marks should be honoured' '
2277 mkdir -p .git/info/fast-import/ &&
2278 cp marks.new .git/info/fast-import/relative.in &&
2279 git fast-import <input &&
2280 test_cmp marks.new .git/info/fast-import/relative.out
2283 cat >input <<-EOF &&
2284 feature relative-marks
2285 feature import-marks=relative.in
2286 feature no-relative-marks
2287 feature export-marks=non-relative.out
2290 test_expect_success 'R: feature no-relative-marks should be honoured' '
2291 git fast-import <input &&
2292 test_cmp marks.new non-relative.out
2295 test_expect_success 'R: feature ls supported' '
2296 echo "feature ls" |
2297 git fast-import
2300 test_expect_success 'R: feature cat-blob supported' '
2301 echo "feature cat-blob" |
2302 git fast-import
2305 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2306 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2309 test_expect_success !MINGW 'R: print old blob' '
2310 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2311 cat >expect <<-EOF &&
2312 ${blob} blob 11
2313 yes it can
2316 echo "cat-blob $blob" |
2317 git fast-import --cat-blob-fd=6 6>actual &&
2318 test_cmp expect actual
2321 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2322 echo hello >greeting &&
2323 blob=$(git hash-object -w greeting) &&
2324 cat >expect <<-EOF &&
2325 ${blob} blob 6
2326 hello
2329 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2330 cat-blob $blob
2332 test_cmp expect actual.3 &&
2333 test_must_be_empty actual.1 &&
2334 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2335 option cat-blob-fd=3
2336 cat-blob $blob
2338 test_must_be_empty actual.3 &&
2339 test_cmp expect actual.1
2342 test_expect_success !MINGW 'R: print mark for new blob' '
2343 echo "effluentish" | git hash-object --stdin >expect &&
2344 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2345 blob
2346 mark :1
2347 data <<BLOB_END
2348 effluentish
2349 BLOB_END
2350 get-mark :1
2352 test_cmp expect actual
2355 test_expect_success !MINGW 'R: print new blob' '
2356 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2357 cat >expect <<-EOF &&
2358 ${blob} blob 12
2359 yep yep yep
2362 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2363 blob
2364 mark :1
2365 data <<BLOB_END
2366 yep yep yep
2367 BLOB_END
2368 cat-blob :1
2370 test_cmp expect actual
2373 test_expect_success !MINGW 'R: print new blob by sha1' '
2374 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2375 cat >expect <<-EOF &&
2376 ${blob} blob 25
2377 a new blob named by sha1
2380 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2381 blob
2382 data <<BLOB_END
2383 a new blob named by sha1
2384 BLOB_END
2385 cat-blob $blob
2387 test_cmp expect actual
2390 test_expect_success 'setup: big file' '
2392 echo "the quick brown fox jumps over the lazy dog" >big &&
2393 for i in 1 2 3
2395 cat big big big big >bigger &&
2396 cat bigger bigger bigger bigger >big ||
2397 exit
2398 done
2402 test_expect_success 'R: print two blobs to stdout' '
2403 blob1=$(git hash-object big) &&
2404 blob1_len=$(wc -c <big) &&
2405 blob2=$(echo hello | git hash-object --stdin) &&
2407 echo ${blob1} blob $blob1_len &&
2408 cat big &&
2409 cat <<-EOF
2411 ${blob2} blob 6
2412 hello
2415 } >expect &&
2417 cat <<-\END_PART1 &&
2418 blob
2419 mark :1
2420 data <<data_end
2421 END_PART1
2422 cat big &&
2423 cat <<-\EOF
2424 data_end
2425 blob
2426 mark :2
2427 data <<data_end
2428 hello
2429 data_end
2430 cat-blob :1
2431 cat-blob :2
2434 git fast-import >actual &&
2435 test_cmp expect actual
2438 test_expect_success PIPE 'R: copy using cat-file' '
2439 expect_id=$(git hash-object big) &&
2440 expect_len=$(wc -c <big) &&
2441 echo $expect_id blob $expect_len >expect.response &&
2443 rm -f blobs &&
2444 cat >frontend <<-\FRONTEND_END &&
2445 #!/bin/sh
2446 FRONTEND_END
2448 mkfifo blobs &&
2450 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2451 cat <<-\EOF &&
2452 feature cat-blob
2453 blob
2454 mark :1
2455 data <<BLOB
2457 cat big &&
2458 cat <<-\EOF &&
2459 BLOB
2460 cat-blob :1
2463 read blob_id type size <&3 &&
2464 echo "$blob_id $type $size" >response &&
2465 head_c $size >blob <&3 &&
2466 read newline <&3 &&
2468 cat <<-EOF &&
2469 commit refs/heads/copied
2470 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2471 data <<COMMIT
2472 copy big file as file3
2473 COMMIT
2474 M 644 inline file3
2475 data <<BLOB
2477 cat blob &&
2478 echo BLOB
2479 ) 3<blobs |
2480 git fast-import --cat-blob-fd=3 3>blobs &&
2481 git show copied:file3 >actual &&
2482 test_cmp expect.response response &&
2483 test_cmp big actual
2486 test_expect_success PIPE 'R: print blob mid-commit' '
2487 rm -f blobs &&
2488 echo "A blob from _before_ the commit." >expect &&
2489 mkfifo blobs &&
2491 exec 3<blobs &&
2492 cat <<-EOF &&
2493 feature cat-blob
2494 blob
2495 mark :1
2496 data <<BLOB
2497 A blob from _before_ the commit.
2498 BLOB
2499 commit refs/heads/temporary
2500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2501 data <<COMMIT
2502 Empty commit
2503 COMMIT
2504 cat-blob :1
2507 read blob_id type size <&3 &&
2508 head_c $size >actual <&3 &&
2509 read newline <&3 &&
2511 echo
2513 git fast-import --cat-blob-fd=3 3>blobs &&
2514 test_cmp expect actual
2517 test_expect_success PIPE 'R: print staged blob within commit' '
2518 rm -f blobs &&
2519 echo "A blob from _within_ the commit." >expect &&
2520 mkfifo blobs &&
2522 exec 3<blobs &&
2523 cat <<-EOF &&
2524 feature cat-blob
2525 commit refs/heads/within
2526 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2527 data <<COMMIT
2528 Empty commit
2529 COMMIT
2530 M 644 inline within
2531 data <<BLOB
2532 A blob from _within_ the commit.
2533 BLOB
2536 to_get=$(
2537 echo "A blob from _within_ the commit." |
2538 git hash-object --stdin
2539 ) &&
2540 echo "cat-blob $to_get" &&
2542 read blob_id type size <&3 &&
2543 head_c $size >actual <&3 &&
2544 read newline <&3 &&
2546 echo deleteall
2548 git fast-import --cat-blob-fd=3 3>blobs &&
2549 test_cmp expect actual
2552 cat >input <<-EOF &&
2553 option git quiet
2554 blob
2555 data 3
2560 test_expect_success 'R: quiet option results in no stats being output' '
2561 cat input | git fast-import 2> output &&
2562 test_must_be_empty output
2565 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2566 echo feature done | test_must_fail git fast-import &&
2567 test_must_fail git fast-import --done </dev/null
2570 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2571 git fast-import <<-\EOF &&
2572 feature done
2573 done
2574 trailing gibberish
2576 git fast-import <<-\EOF
2577 done
2578 more trailing gibberish
2582 test_expect_success 'R: terminating "done" within commit' '
2583 cat >expect <<-\EOF &&
2584 OBJID
2585 :000000 100644 OBJID OBJID A hello.c
2586 :000000 100644 OBJID OBJID A hello2.c
2588 git fast-import <<-EOF &&
2589 commit refs/heads/done-ends
2590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2591 data <<EOT
2592 Commit terminated by "done" command
2594 M 100644 inline hello.c
2595 data <<EOT
2596 Hello, world.
2598 C hello.c hello2.c
2599 done
2601 git rev-list done-ends |
2602 git diff-tree -r --stdin --root --always |
2603 sed -e "s/$_x40/OBJID/g" >actual &&
2604 test_cmp expect actual
2607 cat >input <<-EOF &&
2608 option git non-existing-option
2611 test_expect_success 'R: die on unknown option' '
2612 test_must_fail git fast-import <input
2615 test_expect_success 'R: unknown commandline options are rejected' '\
2616 test_must_fail git fast-import --non-existing-option < /dev/null
2619 test_expect_success 'R: die on invalid option argument' '
2620 echo "option git active-branches=-5" |
2621 test_must_fail git fast-import &&
2622 echo "option git depth=" |
2623 test_must_fail git fast-import &&
2624 test_must_fail git fast-import --depth="5 elephants" </dev/null
2627 cat >input <<-EOF &&
2628 option non-existing-vcs non-existing-option
2631 test_expect_success 'R: ignore non-git options' '
2632 git fast-import <input
2636 ## R: very large blobs
2638 blobsize=$((2*1024*1024 + 53))
2639 test-genrandom bar $blobsize >expect
2640 cat >input <<-INPUT_END &&
2641 commit refs/heads/big-file
2642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2643 data <<COMMIT
2644 R - big file
2645 COMMIT
2647 M 644 inline big1
2648 data $blobsize
2649 INPUT_END
2650 cat expect >>input
2651 cat >>input <<-INPUT_END &&
2652 M 644 inline big2
2653 data $blobsize
2654 INPUT_END
2655 cat expect >>input
2656 echo >>input
2658 test_expect_success 'R: blob bigger than threshold' '
2659 test_create_repo R &&
2660 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2663 test_expect_success 'R: verify created pack' '
2665 cd R &&
2666 verify_packs -v > ../verify
2670 test_expect_success 'R: verify written objects' '
2671 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2672 test_cmp_bin expect actual &&
2673 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2674 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2675 test $a = $b
2678 test_expect_success 'R: blob appears only once' '
2679 n=$(grep $a verify | wc -l) &&
2680 test 1 = $n
2684 ### series S
2687 # Make sure missing spaces and EOLs after mark references
2688 # cause errors.
2690 # Setup:
2692 # 1--2--4
2693 # \ /
2694 # -3-
2696 # commit marks: 301, 302, 303, 304
2697 # blob marks: 403, 404, resp.
2698 # note mark: 202
2700 # The error message when a space is missing not at the
2701 # end of the line is:
2703 # Missing space after ..
2705 # or when extra characters come after the mark at the end
2706 # of the line:
2708 # Garbage after ..
2710 # or when the dataref is neither "inline " or a known SHA1,
2712 # Invalid dataref ..
2714 test_tick
2716 cat >input <<-INPUT_END &&
2717 commit refs/heads/S
2718 mark :301
2719 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2720 data <<COMMIT
2721 commit 1
2722 COMMIT
2723 M 100644 inline hello.c
2724 data <<BLOB
2725 blob 1
2726 BLOB
2728 commit refs/heads/S
2729 mark :302
2730 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2731 data <<COMMIT
2732 commit 2
2733 COMMIT
2734 from :301
2735 M 100644 inline hello.c
2736 data <<BLOB
2737 blob 2
2738 BLOB
2740 blob
2741 mark :403
2742 data <<BLOB
2743 blob 3
2744 BLOB
2746 blob
2747 mark :202
2748 data <<BLOB
2749 note 2
2750 BLOB
2751 INPUT_END
2753 test_expect_success 'S: initialize for S tests' '
2754 git fast-import --export-marks=marks <input
2758 # filemodify, three datarefs
2760 test_expect_success 'S: filemodify with garbage after mark must fail' '
2761 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2762 commit refs/heads/S
2763 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2764 data <<COMMIT
2765 commit N
2766 COMMIT
2767 M 100644 :403x hello.c
2769 cat err &&
2770 test_i18ngrep "space after mark" err
2773 # inline is misspelled; fast-import thinks it is some unknown dataref
2774 test_expect_success 'S: filemodify with garbage after inline 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 inlineX hello.c
2782 data <<BLOB
2783 inline
2784 BLOB
2786 cat err &&
2787 test_i18ngrep "nvalid dataref" err
2790 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2791 sha1=$(grep :403 marks | cut -d\ -f2) &&
2792 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2793 commit refs/heads/S
2794 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2795 data <<COMMIT
2796 commit N
2797 COMMIT
2798 M 100644 ${sha1}x hello.c
2800 cat err &&
2801 test_i18ngrep "space after SHA1" err
2805 # notemodify, three ways to say dataref
2807 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2808 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2809 commit refs/heads/S
2810 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2811 data <<COMMIT
2812 commit S note dataref markref
2813 COMMIT
2814 N :202x :302
2816 cat err &&
2817 test_i18ngrep "space after mark" err
2820 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2821 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2822 commit refs/heads/S
2823 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2824 data <<COMMIT
2825 commit S note dataref inline
2826 COMMIT
2827 N inlineX :302
2828 data <<BLOB
2829 note blob
2830 BLOB
2832 cat err &&
2833 test_i18ngrep "nvalid dataref" err
2836 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2837 sha1=$(grep :202 marks | cut -d\ -f2) &&
2838 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2839 commit refs/heads/S
2840 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2841 data <<COMMIT
2842 commit S note dataref sha1
2843 COMMIT
2844 N ${sha1}x :302
2846 cat err &&
2847 test_i18ngrep "space after SHA1" err
2851 # notemodify, mark in commit-ish
2853 test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2854 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2855 commit refs/heads/Snotes
2856 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2857 data <<COMMIT
2858 commit S note commit-ish
2859 COMMIT
2860 N :202 :302x
2862 cat err &&
2863 test_i18ngrep "after mark" err
2867 # from
2869 test_expect_success 'S: from with garbage after mark must fail' '
2870 test_must_fail \
2871 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2872 commit refs/heads/S2
2873 mark :303
2874 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2875 data <<COMMIT
2876 commit 3
2877 COMMIT
2878 from :301x
2879 M 100644 :403 hello.c
2883 # go create the commit, need it for merge test
2884 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2885 commit refs/heads/S2
2886 mark :303
2887 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2888 data <<COMMIT
2889 commit 3
2890 COMMIT
2891 from :301
2892 M 100644 :403 hello.c
2895 # now evaluate the error
2896 cat err &&
2897 test_i18ngrep "after mark" err
2902 # merge
2904 test_expect_success 'S: merge with garbage after mark must fail' '
2905 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2906 commit refs/heads/S
2907 mark :304
2908 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2909 data <<COMMIT
2910 merge 4
2911 COMMIT
2912 from :302
2913 merge :303x
2914 M 100644 :403 hello.c
2916 cat err &&
2917 test_i18ngrep "after mark" err
2921 # tag, from markref
2923 test_expect_success 'S: tag with garbage after mark must fail' '
2924 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2925 tag refs/tags/Stag
2926 from :302x
2927 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2928 data <<TAG
2929 tag S
2932 cat err &&
2933 test_i18ngrep "after mark" err
2937 # cat-blob markref
2939 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2940 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2941 cat-blob :403x
2943 cat err &&
2944 test_i18ngrep "after mark" err
2948 # ls markref
2950 test_expect_success 'S: ls with garbage after mark must fail' '
2951 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2952 ls :302x hello.c
2954 cat err &&
2955 test_i18ngrep "space after mark" err
2958 test_expect_success 'S: ls with garbage after sha1 must fail' '
2959 sha1=$(grep :302 marks | cut -d\ -f2) &&
2960 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2961 ls ${sha1}x hello.c
2963 cat err &&
2964 test_i18ngrep "space after tree-ish" err
2968 ### series T (ls)
2970 # Setup is carried over from series S.
2972 test_expect_success 'T: ls root tree' '
2973 sed -e "s/Z\$//" >expect <<-EOF &&
2974 040000 tree $(git rev-parse S^{tree}) Z
2976 sha1=$(git rev-parse --verify S) &&
2977 git fast-import --import-marks=marks <<-EOF >actual &&
2978 ls $sha1 ""
2980 test_cmp expect actual
2983 test_expect_success 'T: delete branch' '
2984 git branch to-delete &&
2985 git fast-import <<-EOF &&
2986 reset refs/heads/to-delete
2987 from 0000000000000000000000000000000000000000
2989 test_must_fail git rev-parse --verify refs/heads/to-delete
2992 test_expect_success 'T: empty reset doesnt delete branch' '
2993 git branch not-to-delete &&
2994 git fast-import <<-EOF &&
2995 reset refs/heads/not-to-delete
2997 git show-ref &&
2998 git rev-parse --verify refs/heads/not-to-delete
3002 ### series U (filedelete)
3005 cat >input <<-INPUT_END &&
3006 commit refs/heads/U
3007 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3008 data <<COMMIT
3009 test setup
3010 COMMIT
3011 M 100644 inline hello.c
3012 data <<BLOB
3013 blob 1
3014 BLOB
3015 M 100644 inline good/night.txt
3016 data <<BLOB
3017 sleep well
3018 BLOB
3019 M 100644 inline good/bye.txt
3020 data <<BLOB
3021 au revoir
3022 BLOB
3024 INPUT_END
3026 test_expect_success 'U: initialize for U tests' '
3027 git fast-import <input
3030 cat >input <<-INPUT_END &&
3031 commit refs/heads/U
3032 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3033 data <<COMMIT
3034 delete good/night.txt
3035 COMMIT
3036 from refs/heads/U^0
3037 D good/night.txt
3039 INPUT_END
3041 test_expect_success 'U: filedelete file succeeds' '
3042 git fast-import <input
3045 cat >expect <<-EOF &&
3046 :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3049 git diff-tree -M -r U^1 U >actual
3051 test_expect_success 'U: validate file delete result' '
3052 compare_diff_raw expect actual
3055 cat >input <<-INPUT_END &&
3056 commit refs/heads/U
3057 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3058 data <<COMMIT
3059 delete good dir
3060 COMMIT
3061 from refs/heads/U^0
3062 D good
3064 INPUT_END
3066 test_expect_success 'U: filedelete directory succeeds' '
3067 git fast-import <input
3070 cat >expect <<-EOF &&
3071 :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3074 git diff-tree -M -r U^1 U >actual
3076 test_expect_success 'U: validate directory delete result' '
3077 compare_diff_raw expect actual
3080 cat >input <<-INPUT_END &&
3081 commit refs/heads/U
3082 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3083 data <<COMMIT
3084 must succeed
3085 COMMIT
3086 from refs/heads/U^0
3087 D ""
3089 INPUT_END
3091 test_expect_success 'U: filedelete root succeeds' '
3092 git fast-import <input
3095 cat >expect <<-EOF &&
3096 :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3099 git diff-tree -M -r U^1 U >actual
3101 test_expect_success 'U: validate root delete result' '
3102 compare_diff_raw expect actual
3105 test_done