3 # Copyright (c) 2007 Shawn Pearce
6 test_description
='test git fast-import utility'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 .
"$TEST_DIRECTORY"/lib-diff.sh
;# test-lib chdir's into trash
14 for p
in .git
/objects
/pack
/*.pack
16 git verify-pack
"$@" "$p" ||
return
30 file5_data
='an inline file.
31 we should see it later.'
40 test_expect_success
'empty stream succeeds' '
41 git config fastimport.unpackLimit 0 &&
42 git fast-import </dev/null
45 test_expect_success
'truncated stream complains' '
46 echo "tag foo" | test_must_fail git fast-import
49 test_expect_success
'A: create pack from stdin' '
51 cat >input <<-INPUT_END &&
68 commit refs/heads/main
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82 An annotated tag without a tagger
88 An annotated tag that annotates a blob.
94 Another annotated tag that annotates a blob.
97 reset refs/tags/to-be-deleted
104 Tag of our lovely commit
107 reset refs/tags/nested
114 Tag of tag of our lovely commit
122 git fast-import --export-marks=marks.out <input &&
126 test_expect_success
'A: verify pack' '
130 test_expect_success
'A: verify commit' '
131 cat >expect <<-EOF &&
132 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
137 git cat-file commit main | sed 1d >actual &&
138 test_cmp expect actual
141 test_expect_success
'A: verify tree' '
142 cat >expect <<-EOF &&
147 git cat-file -p main^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
148 test_cmp expect actual
151 test_expect_success
'A: verify file2' '
152 echo "$file2_data" >expect &&
153 git cat-file blob main:file2 >actual &&
154 test_cmp expect actual
157 test_expect_success
'A: verify file3' '
158 echo "$file3_data" >expect &&
159 git cat-file blob main:file3 >actual &&
160 test_cmp expect actual
163 test_expect_success
'A: verify file4' '
164 printf "$file4_data" >expect &&
165 git cat-file blob main:file4 >actual &&
166 test_cmp expect actual
169 test_expect_success
'A: verify tag/series-A' '
170 cat >expect <<-EOF &&
171 object $(git rev-parse refs/heads/main)
175 An annotated tag without a tagger
177 git cat-file tag tags/series-A >actual &&
178 test_cmp expect actual
181 test_expect_success
'A: verify tag/series-A-blob' '
182 cat >expect <<-EOF &&
183 object $(git rev-parse refs/heads/main:file3)
187 An annotated tag that annotates a blob.
189 git cat-file tag tags/series-A-blob >actual &&
190 test_cmp expect actual
193 test_expect_success
'A: verify tag deletion is successful' '
194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted
197 test_expect_success
'A: verify marks output' '
198 cat >expect <<-EOF &&
199 :2 $(git rev-parse --verify main:file2)
200 :3 $(git rev-parse --verify main:file3)
201 :4 $(git rev-parse --verify main:file4)
202 :5 $(git rev-parse --verify main^0)
203 :6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
204 :7 $(git rev-parse --verify nested)
205 :8 $(git rev-parse --verify main^0)
207 test_cmp expect marks.out
210 test_expect_success
'A: verify marks import' '
212 --import-marks=marks.out \
213 --export-marks=marks.new \
215 test_cmp expect marks.new
218 test_expect_success
'A: tag blob by sha1' '
220 new_blob=$(echo testing | git hash-object --stdin) &&
221 cat >input <<-INPUT_END &&
223 from $(git rev-parse refs/heads/main:file3)
234 commit refs/heads/new_blob
238 #pretend we got sha1 from fast-import
248 cat >expect <<-EOF &&
249 object $(git rev-parse refs/heads/main:file3)
261 git fast-import <input &&
262 git cat-file tag tags/series-A-blob-2 >actual &&
263 git cat-file tag tags/series-A-blob-3 >>actual &&
264 test_cmp expect actual
267 test_expect_success
'A: verify marks import does not crash' '
269 cat >input <<-INPUT_END &&
270 commit refs/heads/verify--import-marks
271 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
277 M 755 :2 copy-of-file2
281 git fast-import --import-marks=marks.out <input &&
282 git whatchanged verify--import-marks
285 test_expect_success
'A: verify pack' '
289 test_expect_success
'A: verify diff' '
290 copy=$(git rev-parse --verify main:file2) &&
291 cat >expect <<-EOF &&
292 :000000 100755 $ZERO_OID $copy A copy-of-file2
294 git diff-tree -M -r main verify--import-marks >actual &&
295 compare_diff_raw expect actual &&
296 test $(git rev-parse --verify main:file2) \
297 = $(git rev-parse --verify verify--import-marks:copy-of-file2)
300 test_expect_success
'A: export marks with large values' '
302 mt=$(git hash-object --stdin < /dev/null) &&
307 cat >input.commit <<-EOF &&
308 commit refs/heads/verify--dump-marks
309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
311 test the sparse array dumping routines with exponentially growing marks
316 while test "$i" -lt 27
318 cat >>input.blob <<-EOF &&
329 echo "M 100644 :$l l$i" >>input.commit &&
330 echo "M 100644 :$m m$i" >>input.commit &&
331 echo "M 100644 :$n n$i" >>input.commit &&
333 echo ":$l $mt" >>marks.exp &&
334 echo ":$m $mt" >>marks.exp &&
335 echo ":$n $mt" >>marks.exp &&
337 printf "100644 blob $mt\tl$i\n" >>tree.exp &&
338 printf "100644 blob $mt\tm$i\n" >>tree.exp &&
339 printf "100644 blob $mt\tn$i\n" >>tree.exp &&
345 i=$((1 + $i)) || return 1
348 sort tree.exp > tree.exp_s &&
350 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
351 git ls-tree refs/heads/verify--dump-marks >tree.out &&
352 test_cmp tree.exp_s tree.out &&
353 test_cmp marks.exp marks.large
360 test_expect_success
'B: fail on invalid blob sha1' '
362 cat >input <<-INPUT_END &&
363 commit refs/heads/branch
365 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
371 M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
375 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
376 test_must_fail git fast-import <input
379 test_expect_success
'B: accept branch name "TEMP_TAG"' '
380 cat >input <<-INPUT_END &&
382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
391 test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" &&
392 git fast-import <input &&
393 test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
394 test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
397 test_expect_success
'B: accept empty committer' '
398 cat >input <<-INPUT_END &&
399 commit refs/heads/empty-committer-1
400 committer <> $GIT_COMMITTER_DATE
406 test_when_finished "git update-ref -d refs/heads/empty-committer-1
407 git gc --prune=now" &&
408 git fast-import <input &&
414 test_expect_success
'B: reject invalid timezone' '
415 cat >input <<-INPUT_END &&
416 commit refs/heads/invalid-timezone
417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
423 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
424 test_must_fail git fast-import <input
427 test_expect_success
'B: accept invalid timezone with raw-permissive' '
428 cat >input <<-INPUT_END &&
429 commit refs/heads/invalid-timezone
430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
436 git init invalid-timezone &&
437 git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
438 git -C invalid-timezone cat-file -p invalid-timezone >out &&
439 grep "1234567890 [+]051800" out
442 test_expect_success
'B: accept and fixup committer with no name' '
443 cat >input <<-INPUT_END &&
444 commit refs/heads/empty-committer-2
445 committer <a@b.com> $GIT_COMMITTER_DATE
451 test_when_finished "git update-ref -d refs/heads/empty-committer-2
452 git gc --prune=now" &&
453 git fast-import <input &&
459 test_expect_success
'B: fail on invalid committer (1)' '
460 cat >input <<-INPUT_END &&
461 commit refs/heads/invalid-committer
462 committer Name email> $GIT_COMMITTER_DATE
468 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
469 test_must_fail git fast-import <input
472 test_expect_success
'B: fail on invalid committer (2)' '
473 cat >input <<-INPUT_END &&
474 commit refs/heads/invalid-committer
475 committer Name <e<mail> $GIT_COMMITTER_DATE
481 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
482 test_must_fail git fast-import <input
485 test_expect_success
'B: fail on invalid committer (3)' '
486 cat >input <<-INPUT_END &&
487 commit refs/heads/invalid-committer
488 committer Name <email>> $GIT_COMMITTER_DATE
494 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
495 test_must_fail git fast-import <input
498 test_expect_success
'B: fail on invalid committer (4)' '
499 cat >input <<-INPUT_END &&
500 commit refs/heads/invalid-committer
501 committer Name <email $GIT_COMMITTER_DATE
507 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
508 test_must_fail git fast-import <input
511 test_expect_success
'B: fail on invalid committer (5)' '
512 cat >input <<-INPUT_END &&
513 commit refs/heads/invalid-committer
514 committer Name<email> $GIT_COMMITTER_DATE
520 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
521 test_must_fail git fast-import <input
528 test_expect_success
'C: incremental import create pack from stdin' '
529 newf=$(echo hi newf | git hash-object -w --stdin) &&
530 oldf=$(git rev-parse --verify main:file2) &&
531 thrf=$(git rev-parse --verify main:file3) &&
533 cat >input <<-INPUT_END &&
534 commit refs/heads/branch
535 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
541 M 644 $oldf file2/oldf
542 M 755 $newf file2/newf
547 git fast-import <input &&
548 git whatchanged branch
551 test_expect_success
'C: verify pack' '
555 test_expect_success
'C: validate reuse existing blob' '
556 test $newf = $(git rev-parse --verify branch:file2/newf) &&
557 test $oldf = $(git rev-parse --verify branch:file2/oldf)
560 test_expect_success
'C: verify commit' '
561 cat >expect <<-EOF &&
562 parent $(git rev-parse --verify main^0)
563 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
569 git cat-file commit branch | sed 1d >actual &&
570 test_cmp expect actual
573 test_expect_success
'C: validate rename result' '
575 cat >expect <<-EOF &&
576 :000000 100755 $zero $newf A file2/newf
577 :100644 100644 $oldf $oldf R100 file2 file2/oldf
578 :100644 000000 $thrf $zero D file3
580 git diff-tree -M -r main branch >actual &&
581 compare_diff_raw expect actual
588 test_expect_success
'D: inline data in commit' '
590 cat >input <<-INPUT_END &&
591 commit refs/heads/branch
592 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
597 from refs/heads/branch^0
598 M 644 inline newdir/interesting
603 M 755 inline newdir/exec.sh
610 git fast-import <input &&
611 git whatchanged branch
614 test_expect_success
'D: verify pack' '
618 test_expect_success
'D: validate new files added' '
619 f5id=$(echo "$file5_data" | git hash-object --stdin) &&
620 f6id=$(echo "$file6_data" | git hash-object --stdin) &&
621 cat >expect <<-EOF &&
622 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh
623 :000000 100644 $ZERO_OID $f5id A newdir/interesting
625 git diff-tree -M -r branch^ branch >actual &&
626 compare_diff_raw expect actual
629 test_expect_success
'D: verify file5' '
630 echo "$file5_data" >expect &&
631 git cat-file blob branch:newdir/interesting >actual &&
632 test_cmp expect actual
635 test_expect_success
'D: verify file6' '
636 echo "$file6_data" >expect &&
637 git cat-file blob branch:newdir/exec.sh >actual &&
638 test_cmp expect actual
645 test_expect_success
'E: rfc2822 date, --date-format=raw' '
646 cat >input <<-INPUT_END &&
647 commit refs/heads/branch
648 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
649 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
654 from refs/heads/branch^0
658 test_must_fail git fast-import --date-format=raw <input
660 test_expect_success
'E: rfc2822 date, --date-format=rfc2822' '
661 git fast-import --date-format=rfc2822 <input
664 test_expect_success
'E: verify pack' '
668 test_expect_success
'E: verify commit' '
669 cat >expect <<-EOF &&
670 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
675 git cat-file commit branch | sed 1,2d >actual &&
676 test_cmp expect actual
683 test_expect_success
'F: non-fast-forward update skips' '
684 old_branch=$(git rev-parse --verify branch^0) &&
686 cat >input <<-INPUT_END &&
687 commit refs/heads/branch
688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 losing things already?
693 from refs/heads/branch~1
695 reset refs/heads/other
696 from refs/heads/branch
700 test_must_fail git fast-import <input &&
701 # branch must remain unaffected
702 test $old_branch = $(git rev-parse --verify branch^0)
705 test_expect_success
'F: verify pack' '
709 test_expect_success
'F: verify other commit' '
710 cat >expect <<-EOF &&
711 tree $(git rev-parse branch~1^{tree})
712 parent $(git rev-parse branch~1)
713 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
716 losing things already?
718 git cat-file commit other >actual &&
719 test_cmp expect actual
726 test_expect_success
'G: non-fast-forward update forced' '
727 old_branch=$(git rev-parse --verify branch^0) &&
729 cat >input <<-INPUT_END &&
730 commit refs/heads/branch
731 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
733 losing things already?
736 from refs/heads/branch~1
739 git fast-import --force <input
742 test_expect_success
'G: verify pack' '
746 test_expect_success
'G: branch changed, but logged' '
747 test $old_branch != $(git rev-parse --verify branch^0) &&
748 test $old_branch = $(git rev-parse --verify branch@{1})
755 test_expect_success
'H: deletall, add 1' '
757 cat >input <<-INPUT_END &&
759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
764 from refs/heads/branch^0
765 M 644 inline i-will-die
767 this file will never exist.
771 M 644 inline h/e/l/lo
777 git fast-import <input &&
781 test_expect_success
'H: verify pack' '
785 test_expect_success
'H: validate old files removed, new files added' '
786 f4id=$(git rev-parse HEAD:file4) &&
787 cat >expect <<-EOF &&
788 :100755 000000 $newf $zero D file2/newf
789 :100644 000000 $oldf $zero D file2/oldf
790 :100755 000000 $f4id $zero D file4
791 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo
792 :100755 000000 $f6id $zero D newdir/exec.sh
794 git diff-tree -M -r H^ H >actual &&
795 compare_diff_raw expect actual
798 test_expect_success
'H: verify file' '
799 echo "$file5_data" >expect &&
800 git cat-file blob H:h/e/l/lo >actual &&
801 test_cmp expect actual
808 test_expect_success
'I: export-pack-edges' '
809 cat >input <<-INPUT_END &&
810 commit refs/heads/export-boundary
811 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
813 we have a border. its only 40 characters wide.
816 from refs/heads/branch
819 git fast-import --export-pack-edges=edges.list <input
822 test_expect_success
'I: verify edge list' '
823 cat >expect <<-EOF &&
824 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
826 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
827 test_cmp expect actual
834 test_expect_success
'J: reset existing branch creates empty commit' '
835 cat >input <<-INPUT_END &&
837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
842 from refs/heads/branch
847 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
853 git fast-import <input
855 test_expect_success
'J: branch has 1 commit, empty tree' '
856 test 1 = $(git rev-list J | wc -l) &&
857 test 0 = $(git ls-tree J | wc -l)
860 test_expect_success
'J: tag must fail on empty branch' '
861 cat >input <<-INPUT_END &&
867 Tag branch that was reset.
870 test_must_fail git fast-import <input
877 test_expect_success
'K: reinit branch with from' '
878 cat >input <<-INPUT_END &&
880 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
885 from refs/heads/branch
888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
893 from refs/heads/branch^1
896 git fast-import <input
898 test_expect_success
'K: verify K^1 = branch^1' '
899 test $(git rev-parse --verify branch^1) \
900 = $(git rev-parse --verify K^1)
907 test_expect_success
'L: verify internal tree sorting' '
908 cat >input <<-INPUT_END &&
922 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
932 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
942 cat >expect <<-EXPECT_END &&
948 git fast-import <input &&
949 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
950 cut -d" " -f1,2,5 output >actual &&
951 test_cmp expect actual
954 test_expect_success
'L: nested tree copy does not corrupt deltas' '
955 cat >input <<-INPUT_END &&
963 committer C O Mitter <committer@example.com> 1112912473 -0700
972 committer C O Mitter <committer@example.com> 1112912473 -0700
981 cat >expect <<-\EOF &&
986 test_when_finished "git update-ref -d refs/heads/L2" &&
987 git fast-import <input &&
988 git ls-tree L2 g/b/ >tmp &&
989 cut -f 2 <tmp >actual &&
990 test_cmp expect actual &&
991 git fsck $(git rev-parse L2)
998 test_expect_success
'M: rename file in same subdirectory' '
1000 cat >input <<-INPUT_END &&
1001 commit refs/heads/M1
1002 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007 from refs/heads/branch^0
1008 R file2/newf file2/n.e.w.f
1012 cat >expect <<-EOF &&
1013 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f
1015 git fast-import <input &&
1016 git diff-tree -M -r M1^ M1 >actual &&
1017 compare_diff_raw expect actual
1020 test_expect_success
'M: rename file to new subdirectory' '
1021 cat >input <<-INPUT_END &&
1022 commit refs/heads/M2
1023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1028 from refs/heads/branch^0
1029 R file2/newf i/am/new/to/you
1033 cat >expect <<-EOF &&
1034 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you
1036 git fast-import <input &&
1037 git diff-tree -M -r M2^ M2 >actual &&
1038 compare_diff_raw expect actual
1041 test_expect_success
'M: rename subdirectory to new subdirectory' '
1042 cat >input <<-INPUT_END &&
1043 commit refs/heads/M3
1044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1049 from refs/heads/M2^0
1054 cat >expect <<-EOF &&
1055 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you
1057 git fast-import <input &&
1058 git diff-tree -M -r M3^ M3 >actual &&
1059 compare_diff_raw expect actual
1064 test_expect_success
"M: rename root ($root) to subdirectory" '
1065 cat >input <<-INPUT_END &&
1066 commit refs/heads/M4
1067 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1072 from refs/heads/M2^0
1077 cat >expect <<-EOF &&
1078 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1079 :100755 100755 $f4id $f4id R100 file4 sub/file4
1080 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1081 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1082 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
1084 git fast-import <input &&
1085 git diff-tree -M -r M4^ M4 >actual &&
1086 compare_diff_raw expect actual
1094 test_expect_success
'N: copy file in same subdirectory' '
1096 cat >input <<-INPUT_END &&
1097 commit refs/heads/N1
1098 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1103 from refs/heads/branch^0
1104 C file2/newf file2/n.e.w.f
1108 cat >expect <<-EOF &&
1109 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
1111 git fast-import <input &&
1112 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1113 compare_diff_raw expect actual
1116 test_expect_success
'N: copy then modify subdirectory' '
1117 cat >input <<-INPUT_END &&
1118 commit refs/heads/N2
1119 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1121 clean directory copy
1124 from refs/heads/branch^0
1127 commit refs/heads/N2
1128 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1130 modify directory copy
1133 M 644 inline file3/file5
1140 cat >expect <<-EOF &&
1141 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1142 :100755 100755 $newf $newf C100 file2/newf file3/newf
1143 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1145 git fast-import <input &&
1146 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1147 compare_diff_raw expect actual
1150 test_expect_success
'N: copy dirty subdirectory' '
1151 cat >input <<-INPUT_END &&
1152 commit refs/heads/N3
1153 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1155 dirty directory copy
1158 from refs/heads/branch^0
1159 M 644 inline file2/file5
1169 git fast-import <input &&
1170 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1173 test_expect_success
'N: copy directory by id' '
1174 cat >expect <<-EOF &&
1175 :100755 100755 $newf $newf C100 file2/newf file3/newf
1176 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1178 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1179 cat >input <<-INPUT_END &&
1180 commit refs/heads/N4
1181 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1186 from refs/heads/branch^0
1187 M 040000 $subdir file3
1189 git fast-import <input &&
1190 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1191 compare_diff_raw expect actual
1194 test_expect_success PIPE
'N: read and copy directory' '
1195 cat >expect <<-EOF &&
1196 :100755 100755 $newf $newf C100 file2/newf file3/newf
1197 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1199 git update-ref -d refs/heads/N4 &&
1205 commit refs/heads/N4
1206 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1208 copy by tree hash, part 2
1211 from refs/heads/branch^0
1214 read mode type tree filename &&
1215 echo "M 040000 $tree file3"
1217 git fast-import --cat-blob-fd=3 3>backflow &&
1218 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1219 compare_diff_raw expect actual
1222 test_expect_success PIPE
'N: empty directory reads as missing' '
1223 cat <<-\EOF >expect &&
1225 :000000 100644 OBJNAME OBJNAME A unrelated
1227 echo "missing src" >expect.response &&
1228 git update-ref -d refs/heads/read-empty &&
1234 commit refs/heads/read-empty
1235 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1237 read "empty" (missing) directory
1240 M 100644 inline src/greeting
1244 C src/greeting dst1/non-greeting
1245 C src/greeting unrelated
1246 # leave behind "empty" src directory
1251 printf "%s\n" "$line" >response &&
1257 git fast-import --cat-blob-fd=3 3>backflow &&
1258 test_cmp expect.response response &&
1259 git rev-list read-empty |
1260 git diff-tree -r --root --stdin |
1261 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
1262 test_cmp expect actual
1267 test_expect_success
"N: copy root ($root) by tree hash" '
1268 cat >expect <<-EOF &&
1269 :100755 000000 $newf $zero D file3/newf
1270 :100644 000000 $oldf $zero D file3/oldf
1272 root_tree=$(git rev-parse refs/heads/branch^0^{tree}) &&
1273 cat >input <<-INPUT_END &&
1274 commit refs/heads/N6
1275 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1277 copy root directory by tree hash
1280 from refs/heads/branch^0
1281 M 040000 $root_tree $root
1283 git fast-import <input &&
1284 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1285 compare_diff_raw expect actual
1288 test_expect_success
"N: copy root ($root) by path" '
1289 cat >expect <<-EOF &&
1290 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1291 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1292 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1293 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1294 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
1296 cat >input <<-INPUT_END &&
1297 commit refs/heads/N-copy-root-path
1298 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1300 copy root directory by (empty) path
1303 from refs/heads/branch^0
1306 git fast-import <input &&
1307 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1308 compare_diff_raw expect actual
1312 test_expect_success
'N: delete directory by copying' '
1313 cat >expect <<-\EOF &&
1315 :100644 000000 OBJID OBJID D foo/bar/qux
1317 :000000 100644 OBJID OBJID A foo/bar/baz
1318 :000000 100644 OBJID OBJID A foo/bar/qux
1320 empty_tree=$(git mktree </dev/null) &&
1321 cat >input <<-INPUT_END &&
1322 commit refs/heads/N-delete
1323 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1325 collect data to be deleted
1329 M 100644 inline foo/bar/baz
1333 C "foo/bar/baz" "foo/bar/qux"
1334 C "foo/bar/baz" "foo/bar/quux/1"
1335 C "foo/bar/baz" "foo/bar/quuux"
1336 M 040000 $empty_tree foo/bar/quux
1337 M 040000 $empty_tree foo/bar/quuux
1339 commit refs/heads/N-delete
1340 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1345 M 040000 $empty_tree foo/bar/qux
1347 git fast-import <input &&
1348 git rev-list N-delete |
1349 git diff-tree -r --stdin --root --always |
1350 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
1351 test_cmp expect actual
1354 test_expect_success
'N: modify copied tree' '
1355 cat >expect <<-EOF &&
1356 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1357 :100755 100755 $newf $newf C100 file2/newf file3/newf
1358 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1360 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1361 cat >input <<-INPUT_END &&
1362 commit refs/heads/N5
1363 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1368 from refs/heads/branch^0
1369 M 040000 $subdir file3
1371 commit refs/heads/N5
1372 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1374 modify directory copy
1377 M 644 inline file3/file5
1382 git fast-import <input &&
1383 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1384 compare_diff_raw expect actual
1387 test_expect_success
'N: reject foo/ syntax' '
1388 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1389 test_must_fail git fast-import <<-INPUT_END
1390 commit refs/heads/N5B
1391 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1393 copy with invalid syntax
1396 from refs/heads/branch^0
1397 M 040000 $subdir file3/
1401 test_expect_success
'N: reject foo/ syntax in copy source' '
1402 test_must_fail git fast-import <<-INPUT_END
1403 commit refs/heads/N5C
1404 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1406 copy with invalid syntax
1409 from refs/heads/branch^0
1414 test_expect_success
'N: reject foo/ syntax in rename source' '
1415 test_must_fail git fast-import <<-INPUT_END
1416 commit refs/heads/N5D
1417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1419 rename with invalid syntax
1422 from refs/heads/branch^0
1427 test_expect_success
'N: reject foo/ syntax in ls argument' '
1428 test_must_fail git fast-import <<-INPUT_END
1429 commit refs/heads/N5E
1430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1432 copy with invalid syntax
1435 from refs/heads/branch^0
1442 test_expect_success
"N: copy to root ($root) by id and modify" '
1443 echo "hello, world" >expect.foo &&
1444 echo hello >expect.bar &&
1445 git fast-import <<-SETUP_END &&
1446 commit refs/heads/N7
1447 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1453 M 644 inline foo/bar
1459 tree=$(git rev-parse --verify N7:) &&
1460 git fast-import <<-INPUT_END &&
1461 commit refs/heads/N8
1462 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1464 copy to root by id and modify
1467 M 040000 $tree $root
1468 M 644 inline foo/foo
1473 git show N8:foo/foo >actual.foo &&
1474 git show N8:foo/bar >actual.bar &&
1475 test_cmp expect.foo actual.foo &&
1476 test_cmp expect.bar actual.bar
1479 test_expect_success
"N: extract subtree to the root ($root)" '
1480 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1481 cat >input <<-INPUT_END &&
1482 commit refs/heads/N9
1483 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1485 extract subtree branch:newdir
1488 M 040000 $branch $root
1491 git fast-import <input &&
1492 git diff --exit-code branch:newdir N9
1495 test_expect_success
"N: modify subtree, extract it to the root ($root), and modify again" '
1496 echo hello >expect.baz &&
1497 echo hello, world >expect.qux &&
1498 git fast-import <<-SETUP_END &&
1499 commit refs/heads/N10
1500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1506 M 644 inline foo/bar/baz
1512 tree=$(git rev-parse --verify N10:) &&
1513 git fast-import <<-INPUT_END &&
1514 commit refs/heads/N11
1515 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1517 copy to root by id and modify
1520 M 040000 $tree $root
1521 M 100644 inline foo/bar/qux
1526 C "bar/qux" "bar/quux"
1528 git show N11:bar/baz >actual.baz &&
1529 git show N11:bar/qux >actual.qux &&
1530 git show N11:bar/quux >actual.quux &&
1531 test_cmp expect.baz actual.baz &&
1532 test_cmp expect.qux actual.qux &&
1533 test_cmp expect.qux actual.quux
1541 test_expect_success
'O: comments are all skipped' '
1542 cat >input <<-INPUT_END &&
1544 commit refs/heads/O1
1545 # -- ignore all of this text
1546 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1548 dirty directory copy
1551 # do not forget the import blank line!
1553 # yes, we started from our usual base of branch^0.
1555 from refs/heads/branch^0
1556 # and we need to reuse file2/file5 from N3 above.
1557 M 644 inline file2/file5
1558 # otherwise the tree will be different
1563 # do not forget to copy file2 to file3
1566 # or to delete file5 from file2.
1572 git fast-import <input &&
1573 test $(git rev-parse N3) = $(git rev-parse O1)
1576 test_expect_success
'O: blank lines not necessary after data commands' '
1577 cat >input <<-INPUT_END &&
1578 commit refs/heads/O2
1579 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1581 dirty directory copy
1583 from refs/heads/branch^0
1584 M 644 inline file2/file5
1593 git fast-import <input &&
1594 test $(git rev-parse N3) = $(git rev-parse O2)
1597 test_expect_success
'O: repack before next test' '
1601 test_expect_success
'O: blank lines not necessary after other commands' '
1602 cat >input <<-INPUT_END &&
1603 commit refs/heads/O3
1604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1608 commit refs/heads/O3
1609 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1614 commit refs/heads/O3
1616 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1621 commit refs/heads/O3
1622 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1626 reset refs/tags/O3-2nd
1628 reset refs/tags/O3-3rd
1632 cat >expect <<-INPUT_END &&
1639 git fast-import <input &&
1640 ls -la .git/objects/pack/pack-*.pack >packlist &&
1641 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1642 test_line_count = 4 idxlist &&
1643 test_line_count = 4 packlist &&
1644 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1645 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1646 test_cmp expect actual
1649 test_expect_success
'O: progress outputs as requested by input' '
1650 cat >input <<-INPUT_END &&
1651 commit refs/heads/O4
1652 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1656 commit refs/heads/O4
1657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1661 progress Two commits down, 2 to go!
1662 commit refs/heads/O4
1663 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1667 progress Three commits down, 1 to go!
1668 commit refs/heads/O4
1669 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1675 git fast-import <input >actual &&
1676 grep "progress " <input >expect &&
1677 test_cmp expect actual
1681 ### series P (gitlinks)
1684 test_expect_success
'P: superproject & submodule mix' '
1685 cat >input <<-INPUT_END &&
1691 reset refs/heads/sub
1692 commit refs/heads/sub
1694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1707 commit refs/heads/subuse1
1709 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1712 from refs/heads/main
1713 M 100644 :3 .gitmodules
1722 commit refs/heads/sub
1724 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1730 commit refs/heads/subuse1
1732 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1740 git fast-import <input &&
1741 git checkout subuse1 &&
1747 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1750 git submodule init &&
1751 git submodule update
1754 test_expect_success
'P: verbatim SHA gitlinks' '
1755 SUBLAST=$(git rev-parse --verify sub) &&
1756 SUBPREV=$(git rev-parse --verify sub^) &&
1758 cat >input <<-INPUT_END &&
1767 commit refs/heads/subuse2
1769 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1772 from refs/heads/main
1773 M 100644 :1 .gitmodules
1774 M 160000 $SUBPREV sub
1776 commit refs/heads/subuse2
1778 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1782 M 160000 $SUBLAST sub
1786 git branch -D sub &&
1787 git gc --prune=now &&
1788 git fast-import <input &&
1789 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1792 test_expect_success
'P: fail on inline gitlink' '
1794 cat >input <<-INPUT_END &&
1795 commit refs/heads/subuse3
1797 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1802 from refs/heads/subuse2
1810 test_must_fail git fast-import <input
1813 test_expect_success
'P: fail on blob mark in gitlink' '
1815 cat >input <<-INPUT_END &&
1822 commit refs/heads/subuse3
1824 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1829 from refs/heads/subuse2
1834 test_must_fail git fast-import <input
1838 ### series Q (notes)
1841 test_expect_success
'Q: commit notes' '
1842 note1_data="The first note for the first commit" &&
1843 note2_data="The first note for the second commit" &&
1844 note3_data="The first note for the third commit" &&
1845 note1b_data="The second note for the first commit" &&
1846 note1c_data="The third note for the first commit" &&
1847 note2b_data="The second note for the second commit" &&
1850 cat >input <<-INPUT_END &&
1857 commit refs/heads/notes-test
1859 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1870 commit refs/heads/notes-test
1872 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1879 commit refs/heads/notes-test
1881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1908 commit refs/notes/foobar
1910 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1922 commit refs/notes/foobar
1924 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1934 commit refs/notes/foobar2
1936 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1946 commit refs/notes/foobar
1948 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1961 git fast-import <input &&
1962 git whatchanged notes-test
1965 test_expect_success
'Q: verify pack' '
1969 test_expect_success
'Q: verify first commit' '
1970 commit1=$(git rev-parse notes-test~2) &&
1971 commit2=$(git rev-parse notes-test^) &&
1972 commit3=$(git rev-parse notes-test) &&
1974 cat >expect <<-EOF &&
1975 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1976 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1980 git cat-file commit notes-test~2 | sed 1d >actual &&
1981 test_cmp expect actual
1984 test_expect_success
'Q: verify second commit' '
1985 cat >expect <<-EOF &&
1987 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1988 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1992 git cat-file commit notes-test^ | sed 1d >actual &&
1993 test_cmp expect actual
1996 test_expect_success
'Q: verify third commit' '
1997 cat >expect <<-EOF &&
1999 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2000 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2004 git cat-file commit notes-test | sed 1d >actual &&
2005 test_cmp expect actual
2008 test_expect_success
'Q: verify first notes commit' '
2009 cat >expect <<-EOF &&
2010 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2011 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2015 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2016 test_cmp expect actual
2019 test_expect_success
'Q: verify first notes tree' '
2020 sort >expect <<-EOF &&
2021 100644 blob $commit1
2022 100644 blob $commit2
2023 100644 blob $commit3
2025 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2026 test_cmp expect actual
2029 test_expect_success
'Q: verify first note for first commit' '
2030 echo "$note1_data" >expect &&
2031 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2032 test_cmp expect actual
2035 test_expect_success
'Q: verify first note for second commit' '
2036 echo "$note2_data" >expect &&
2037 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2038 test_cmp expect actual
2041 test_expect_success
'Q: verify first note for third commit' '
2042 echo "$note3_data" >expect &&
2043 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2044 test_cmp expect actual
2047 test_expect_success
'Q: verify second notes commit' '
2048 cat >expect <<-EOF &&
2049 parent $(git rev-parse --verify refs/notes/foobar~2)
2050 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2051 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2055 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2056 test_cmp expect actual
2059 test_expect_success
'Q: verify second notes tree' '
2060 sort >expect <<-EOF &&
2061 100644 blob $commit1
2062 100644 blob $commit2
2063 100644 blob $commit3
2065 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2066 test_cmp expect actual
2069 test_expect_success
'Q: verify second note for first commit' '
2070 echo "$note1b_data" >expect &&
2071 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2072 test_cmp expect actual
2075 test_expect_success
'Q: verify first note for second commit' '
2076 echo "$note2_data" >expect &&
2077 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2078 test_cmp expect actual
2081 test_expect_success
'Q: verify first note for third commit' '
2082 echo "$note3_data" >expect &&
2083 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2084 test_cmp expect actual
2087 test_expect_success
'Q: verify third notes commit' '
2088 cat >expect <<-EOF &&
2089 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2090 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2094 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2095 test_cmp expect actual
2098 test_expect_success
'Q: verify third notes tree' '
2099 sort >expect <<-EOF &&
2100 100644 blob $commit1
2102 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2103 test_cmp expect actual
2106 test_expect_success
'Q: verify third note for first commit' '
2107 echo "$note1c_data" >expect &&
2108 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2109 test_cmp expect actual
2112 test_expect_success
'Q: verify fourth notes commit' '
2113 cat >expect <<-EOF &&
2114 parent $(git rev-parse --verify refs/notes/foobar^)
2115 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2116 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2120 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2121 test_cmp expect actual
2124 test_expect_success
'Q: verify fourth notes tree' '
2125 sort >expect <<-EOF &&
2126 100644 blob $commit2
2128 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2129 test_cmp expect actual
2132 test_expect_success
'Q: verify second note for second commit' '
2133 echo "$note2b_data" >expect &&
2134 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2135 test_cmp expect actual
2138 test_expect_success
'Q: deny note on empty branch' '
2139 cat >input <<-EOF &&
2142 commit refs/heads/note-Q0
2143 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2145 Note for an empty branch.
2148 N inline refs/heads/Q0
2153 test_must_fail git fast-import <input
2157 ### series R (feature and option)
2160 test_expect_success
'R: abort on unsupported feature' '
2161 cat >input <<-EOF &&
2162 feature no-such-feature-exists
2165 test_must_fail git fast-import <input
2168 test_expect_success
'R: supported feature is accepted' '
2169 cat >input <<-EOF &&
2170 feature date-format=now
2173 git fast-import <input
2176 test_expect_success
'R: abort on receiving feature after data command' '
2177 cat >input <<-EOF &&
2181 feature date-format=now
2184 test_must_fail git fast-import <input
2187 test_expect_success
'R: import-marks features forbidden by default' '
2189 echo "feature import-marks=git.marks" >input &&
2190 test_must_fail git fast-import <input &&
2191 echo "feature import-marks-if-exists=git.marks" >input &&
2192 test_must_fail git fast-import <input
2195 test_expect_success
'R: only one import-marks feature allowed per stream' '
2198 cat >input <<-EOF &&
2199 feature import-marks=git.marks
2200 feature import-marks=git2.marks
2203 test_must_fail git fast-import --allow-unsafe-features <input
2206 test_expect_success
'R: export-marks feature forbidden by default' '
2207 echo "feature export-marks=git.marks" >input &&
2208 test_must_fail git fast-import <input
2211 test_expect_success
'R: export-marks feature results in a marks file being created' '
2212 cat >input <<-EOF &&
2213 feature export-marks=git.marks
2221 git fast-import --allow-unsafe-features <input &&
2225 test_expect_success
'R: export-marks options can be overridden by commandline options' '
2226 cat >input <<-\EOF &&
2227 feature export-marks=feature-sub/git.marks
2234 git fast-import --allow-unsafe-features \
2235 --export-marks=cmdline-sub/other.marks <input &&
2236 grep :1 cmdline-sub/other.marks &&
2237 test_path_is_missing feature-sub
2240 test_expect_success
'R: catch typo in marks file name' '
2241 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2242 echo "feature import-marks=nonexistent.marks" |
2243 test_must_fail git fast-import --allow-unsafe-features
2246 test_expect_success
'R: import and output marks can be the same file' '
2248 blob=$(echo hi | git hash-object --stdin) &&
2249 cat >expect <<-EOF &&
2253 git fast-import --export-marks=io.marks <<-\EOF &&
2260 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2267 test_cmp expect io.marks
2270 test_expect_success
'R: --import-marks=foo --output-marks=foo to create foo fails' '
2272 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2281 test_expect_success
'R: --import-marks-if-exists' '
2283 blob=$(echo hi | git hash-object --stdin) &&
2284 echo ":1 $blob" >expect &&
2285 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2292 test_cmp expect io.marks
2295 test_expect_success
'R: feature import-marks-if-exists' '
2298 git fast-import --export-marks=io.marks \
2299 --allow-unsafe-features <<-\EOF &&
2300 feature import-marks-if-exists=not_io.marks
2302 test_must_be_empty io.marks &&
2304 blob=$(echo hi | git hash-object --stdin) &&
2306 echo ":1 $blob" >io.marks &&
2307 echo ":1 $blob" >expect &&
2308 echo ":2 $blob" >>expect &&
2310 git fast-import --export-marks=io.marks \
2311 --allow-unsafe-features <<-\EOF &&
2312 feature import-marks-if-exists=io.marks
2319 test_cmp expect io.marks &&
2321 echo ":3 $blob" >>expect &&
2323 git fast-import --import-marks=io.marks \
2324 --export-marks=io.marks \
2325 --allow-unsafe-features <<-\EOF &&
2326 feature import-marks-if-exists=not_io.marks
2333 test_cmp expect io.marks &&
2335 git fast-import --import-marks-if-exists=not_io.marks \
2336 --export-marks=io.marks \
2337 --allow-unsafe-features <<-\EOF &&
2338 feature import-marks-if-exists=io.marks
2340 test_must_be_empty io.marks
2343 test_expect_success
'R: import to output marks works without any content' '
2344 cat >input <<-EOF &&
2345 feature import-marks=marks.out
2346 feature export-marks=marks.new
2349 git fast-import --allow-unsafe-features <input &&
2350 test_cmp marks.out marks.new
2353 test_expect_success
'R: import marks prefers commandline marks file over the stream' '
2354 cat >input <<-EOF &&
2355 feature import-marks=nonexistent.marks
2356 feature export-marks=marks.new
2359 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
2360 test_cmp marks.out marks.new
2364 test_expect_success
'R: multiple --import-marks= should be honoured' '
2365 cat >input <<-EOF &&
2366 feature import-marks=nonexistent.marks
2367 feature export-marks=combined.marks
2370 head -n2 marks.out > one.marks &&
2371 tail -n +3 marks.out > two.marks &&
2372 git fast-import --import-marks=one.marks --import-marks=two.marks \
2373 --allow-unsafe-features <input &&
2374 test_cmp marks.out combined.marks
2377 test_expect_success
'R: feature relative-marks should be honoured' '
2378 cat >input <<-EOF &&
2379 feature relative-marks
2380 feature import-marks=relative.in
2381 feature export-marks=relative.out
2384 mkdir -p .git/info/fast-import/ &&
2385 cp marks.new .git/info/fast-import/relative.in &&
2386 git fast-import --allow-unsafe-features <input &&
2387 test_cmp marks.new .git/info/fast-import/relative.out
2390 test_expect_success
'R: feature no-relative-marks should be honoured' '
2391 cat >input <<-EOF &&
2392 feature relative-marks
2393 feature import-marks=relative.in
2394 feature no-relative-marks
2395 feature export-marks=non-relative.out
2398 git fast-import --allow-unsafe-features <input &&
2399 test_cmp marks.new non-relative.out
2402 test_expect_success
'R: feature ls supported' '
2407 test_expect_success
'R: feature cat-blob supported' '
2408 echo "feature cat-blob" |
2412 test_expect_success
'R: cat-blob-fd must be a nonnegative integer' '
2413 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2416 test_expect_success
!MINGW
'R: print old blob' '
2417 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2418 cat >expect <<-EOF &&
2423 echo "cat-blob $blob" |
2424 git fast-import --cat-blob-fd=6 6>actual &&
2425 test_cmp expect actual
2428 test_expect_success
!MINGW
'R: in-stream cat-blob-fd not respected' '
2429 echo hello >greeting &&
2430 blob=$(git hash-object -w greeting) &&
2431 cat >expect <<-EOF &&
2436 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2439 test_cmp expect actual.3 &&
2440 test_must_be_empty actual.1 &&
2441 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2442 option cat-blob-fd=3
2445 test_must_be_empty actual.3 &&
2446 test_cmp expect actual.1
2449 test_expect_success
!MINGW
'R: print mark for new blob' '
2450 echo "effluentish" | git hash-object --stdin >expect &&
2451 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2459 test_cmp expect actual
2462 test_expect_success
!MINGW
'R: print new blob' '
2463 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2464 cat >expect <<-EOF &&
2469 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2477 test_cmp expect actual
2480 test_expect_success
!MINGW
'R: print new blob by sha1' '
2481 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2482 cat >expect <<-EOF &&
2484 a new blob named by sha1
2487 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2490 a new blob named by sha1
2494 test_cmp expect actual
2497 test_expect_success
'setup: big file' '
2499 echo "the quick brown fox jumps over the lazy dog" >big &&
2502 cat big big big big >bigger &&
2503 cat bigger bigger bigger bigger >big ||
2509 test_expect_success
'R: print two blobs to stdout' '
2510 blob1=$(git hash-object big) &&
2511 blob1_len=$(wc -c <big) &&
2512 blob2=$(echo hello | git hash-object --stdin) &&
2514 echo ${blob1} blob $blob1_len &&
2524 cat <<-\END_PART1 &&
2541 git fast-import >actual &&
2542 test_cmp expect actual
2545 test_expect_success PIPE
'R: copy using cat-file' '
2546 expect_id=$(git hash-object big) &&
2547 expect_len=$(wc -c <big) &&
2548 echo $expect_id blob $expect_len >expect.response &&
2554 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2567 read blob_id type size <&3 &&
2568 echo "$blob_id $type $size" >response &&
2569 test_copy_bytes $size >blob <&3 &&
2573 commit refs/heads/copied
2574 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2576 copy big file as file3
2584 git fast-import --cat-blob-fd=3 3>blobs &&
2585 git show copied:file3 >actual &&
2586 test_cmp expect.response response &&
2590 test_expect_success PIPE
'R: print blob mid-commit' '
2592 echo "A blob from _before_ the commit." >expect &&
2601 A blob from _before_ the commit.
2603 commit refs/heads/temporary
2604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2611 read blob_id type size <&3 &&
2612 test_copy_bytes $size >actual <&3 &&
2617 git fast-import --cat-blob-fd=3 3>blobs &&
2618 test_cmp expect actual
2621 test_expect_success PIPE
'R: print staged blob within commit' '
2623 echo "A blob from _within_ the commit." >expect &&
2629 commit refs/heads/within
2630 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2636 A blob from _within_ the commit.
2641 echo "A blob from _within_ the commit." |
2642 git hash-object --stdin
2644 echo "cat-blob $to_get" &&
2646 read blob_id type size <&3 &&
2647 test_copy_bytes $size >actual <&3 &&
2652 git fast-import --cat-blob-fd=3 3>blobs &&
2653 test_cmp expect actual
2656 test_expect_success
'R: quiet option results in no stats being output' '
2657 cat >input <<-EOF &&
2665 git fast-import 2>output <input &&
2666 test_must_be_empty output
2669 test_expect_success
'R: feature done means terminating "done" is mandatory' '
2670 echo feature done | test_must_fail git fast-import &&
2671 test_must_fail git fast-import --done </dev/null
2674 test_expect_success
'R: terminating "done" with trailing gibberish is ok' '
2675 git fast-import <<-\EOF &&
2680 git fast-import <<-\EOF
2682 more trailing gibberish
2686 test_expect_success
'R: terminating "done" within commit' '
2687 cat >expect <<-\EOF &&
2689 :000000 100644 OBJID OBJID A hello.c
2690 :000000 100644 OBJID OBJID A hello2.c
2692 git fast-import <<-EOF &&
2693 commit refs/heads/done-ends
2694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2696 Commit terminated by "done" command
2698 M 100644 inline hello.c
2705 git rev-list done-ends |
2706 git diff-tree -r --stdin --root --always |
2707 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
2708 test_cmp expect actual
2711 test_expect_success
'R: die on unknown option' '
2712 cat >input <<-EOF &&
2713 option git non-existing-option
2716 test_must_fail git fast-import <input
2719 test_expect_success
'R: unknown commandline options are rejected' '\
2720 test_must_fail git fast-import --non-existing-option < /dev/null
2723 test_expect_success
'R: die on invalid option argument' '
2724 echo "option git active-branches=-5" |
2725 test_must_fail git fast-import &&
2726 echo "option git depth=" |
2727 test_must_fail git fast-import &&
2728 test_must_fail git fast-import --depth="5 elephants" </dev/null
2731 test_expect_success
'R: ignore non-git options' '
2732 cat >input <<-EOF &&
2733 option non-existing-vcs non-existing-option
2736 git fast-import <input
2739 test_expect_success
'R: corrupt lines do not mess marks file' '
2741 blob=$(echo hi | git hash-object --stdin) &&
2742 cat >expect <<-EOF &&
2747 cp expect io.marks &&
2748 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2751 test_cmp expect io.marks
2755 ## R: very large blobs
2757 test_expect_success
'R: blob bigger than threshold' '
2758 blobsize=$((2*1024*1024 + 53)) &&
2759 test-tool genrandom bar $blobsize >expect &&
2760 cat >input <<-INPUT_END &&
2761 commit refs/heads/big-file
2762 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2770 cat expect >>input &&
2771 cat >>input <<-INPUT_END &&
2775 cat expect >>input &&
2778 test_create_repo R &&
2779 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
2780 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2783 test_expect_success
'R: verify created pack' '
2786 verify_packs -v > ../verify
2790 test_expect_success
'R: verify written objects' '
2791 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2792 test_cmp_bin expect actual &&
2793 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2794 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2798 test_expect_success
'R: blob appears only once' '
2799 n=$(grep $a verify | wc -l) &&
2804 ### series S (mark and path parsing)
2807 # Make sure missing spaces and EOLs after mark references
2816 # commit marks: 301, 302, 303, 304
2817 # blob marks: 403, 404, resp.
2820 # The error message when a space is missing not at the
2821 # end of the line is:
2823 # Missing space after ..
2825 # or when extra characters come after the mark at the end
2830 # or when the dataref is neither "inline " or a known SHA1,
2832 # Invalid dataref ..
2834 test_expect_success
'S: initialize for S tests' '
2837 cat >input <<-INPUT_END &&
2840 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2844 M 100644 inline hello.c
2851 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2856 M 100644 inline hello.c
2874 git fast-import --export-marks=marks <input
2878 # filemodify, three datarefs
2880 test_expect_success
'S: filemodify with garbage after mark must fail' '
2881 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2883 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2887 M 100644 :403x hello.c
2889 test_grep "space after mark" err
2892 # inline is misspelled; fast-import thinks it is some unknown dataref
2893 test_expect_success
'S: filemodify with garbage after inline must fail' '
2894 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2896 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2900 M 100644 inlineX hello.c
2905 test_grep "nvalid dataref" err
2908 test_expect_success
'S: filemodify with garbage after sha1 must fail' '
2909 sha1=$(grep :403 marks | cut -d\ -f2) &&
2910 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2912 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2916 M 100644 ${sha1}x hello.c
2918 test_grep "space after SHA1" err
2922 # notemodify, three ways to say dataref
2924 test_expect_success
'S: notemodify with garbage after mark dataref must fail' '
2925 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2927 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2929 commit S note dataref markref
2933 test_grep "space after mark" err
2936 test_expect_success
'S: notemodify with garbage after inline dataref must fail' '
2937 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2939 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2941 commit S note dataref inline
2948 test_grep "nvalid dataref" err
2951 test_expect_success
'S: notemodify with garbage after sha1 dataref must fail' '
2952 sha1=$(grep :202 marks | cut -d\ -f2) &&
2953 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2955 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2957 commit S note dataref sha1
2961 test_grep "space after SHA1" err
2965 # notemodify, mark in commit-ish
2967 test_expect_success
'S: notemodify with garbage after mark commit-ish must fail' '
2968 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2969 commit refs/heads/Snotes
2970 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2972 commit S note commit-ish
2976 test_grep "after mark" err
2982 test_expect_success
'S: from with garbage after mark must fail' '
2984 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2985 commit refs/heads/S2
2987 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2992 M 100644 :403 hello.c
2996 # go create the commit, need it for merge test
2997 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2998 commit refs/heads/S2
3000 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3005 M 100644 :403 hello.c
3008 # now evaluate the error
3009 test_grep "after mark" err
3016 test_expect_success
'S: merge with garbage after mark must fail' '
3017 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3020 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3026 M 100644 :403 hello.c
3028 test_grep "after mark" err
3034 test_expect_success
'S: tag with garbage after mark must fail' '
3035 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3038 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3043 test_grep "after mark" err
3049 test_expect_success
'S: cat-blob with garbage after mark must fail' '
3050 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3053 test_grep "after mark" err
3059 test_expect_success
'S: ls with garbage after mark must fail' '
3060 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3063 test_grep "space after mark" err
3066 test_expect_success
'S: ls with garbage after sha1 must fail' '
3067 sha1=$(grep :302 marks | cut -d\ -f2) &&
3068 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3071 test_grep "space after tree-ish" err
3077 # There are two sorts of ways a path can be parsed, depending on whether it is
3078 # the last field on the line. Additionally, ls without a <dataref> has a special
3079 # case. Test every occurrence of <path> in the grammar against every error case.
3080 # Paths for the root (empty strings) are tested elsewhere.
3084 # Valid paths at the end of a line: filemodify, filedelete, filecopy (dest),
3085 # filerename (dest), and ls.
3087 # commit :301 from root -- modify hello.c (for setup)
3088 # commit :302 from :301 -- modify $path
3089 # commit :303 from :302 -- delete $path
3090 # commit :304 from :301 -- copy hello.c $path
3091 # commit :305 from :301 -- rename hello.c $path
3094 test_path_eol_success
() {
3095 local test="$1" path
="$2" unquoted_path
="$3"
3096 test_expect_success
"S: paths at EOL with $test must work" '
3097 test_when_finished "git branch -D S-path-eol" &&
3099 git fast-import --export-marks=marks.out <<-EOF >out 2>err &&
3112 commit refs/heads/S-path-eol
3114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3118 M 100644 :401 hello.c
3120 commit refs/heads/S-path-eol
3122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3129 commit refs/heads/S-path-eol
3131 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3138 commit refs/heads/S-path-eol
3140 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3142 commit filecopy dest
3147 commit refs/heads/S-path-eol
3149 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3151 commit filerename dest
3159 commit_m=$(grep :302 marks.out | cut -d\ -f2) &&
3160 commit_d=$(grep :303 marks.out | cut -d\ -f2) &&
3161 commit_c=$(grep :304 marks.out | cut -d\ -f2) &&
3162 commit_r=$(grep :305 marks.out | cut -d\ -f2) &&
3163 blob1=$(grep :401 marks.out | cut -d\ -f2) &&
3164 blob2=$(grep :402 marks.out | cut -d\ -f2) &&
3167 printf "100644 blob $blob2\t$unquoted_path\n" &&
3168 printf "100644 blob $blob1\thello.c\n"
3169 ) | sort >tree_m.exp &&
3170 git ls-tree $commit_m | sort >tree_m.out &&
3171 test_cmp tree_m.exp tree_m.out &&
3173 printf "100644 blob $blob1\thello.c\n" >tree_d.exp &&
3174 git ls-tree $commit_d >tree_d.out &&
3175 test_cmp tree_d.exp tree_d.out &&
3178 printf "100644 blob $blob1\t$unquoted_path\n" &&
3179 printf "100644 blob $blob1\thello.c\n"
3180 ) | sort >tree_c.exp &&
3181 git ls-tree $commit_c | sort >tree_c.out &&
3182 test_cmp tree_c.exp tree_c.out &&
3184 printf "100644 blob $blob1\t$unquoted_path\n" >tree_r.exp &&
3185 git ls-tree $commit_r >tree_r.out &&
3186 test_cmp tree_r.exp tree_r.out &&
3188 test_cmp out tree_r.exp
3192 test_path_eol_success
'quoted spaces' '" hello world.c "' ' hello world.c '
3193 test_path_eol_success
'unquoted spaces' ' hello world.c ' ' hello world.c '
3194 test_path_eol_success
'octal escapes' '"\150\151\056\143"' 'hi.c'
3197 # Valid paths before a space: filecopy (source) and filerename (source).
3199 # commit :301 from root -- modify $path (for setup)
3200 # commit :302 from :301 -- copy $path hello2.c
3201 # commit :303 from :301 -- rename $path hello2.c
3203 test_path_space_success
() {
3204 local test="$1" path
="$2" unquoted_path
="$3"
3205 test_expect_success
"S: paths before space with $test must work" '
3206 test_when_finished "git branch -D S-path-space" &&
3208 git fast-import --export-marks=marks.out <<-EOF 2>err &&
3215 commit refs/heads/S-path-space
3217 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3223 commit refs/heads/S-path-space
3225 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3227 commit filecopy source
3232 commit refs/heads/S-path-space
3234 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3236 commit filerename source
3243 commit_c=$(grep :302 marks.out | cut -d\ -f2) &&
3244 commit_r=$(grep :303 marks.out | cut -d\ -f2) &&
3245 blob=$(grep :401 marks.out | cut -d\ -f2) &&
3248 printf "100644 blob $blob\t$unquoted_path\n" &&
3249 printf "100644 blob $blob\thello2.c\n"
3250 ) | sort >tree_c.exp &&
3251 git ls-tree $commit_c | sort >tree_c.out &&
3252 test_cmp tree_c.exp tree_c.out &&
3254 printf "100644 blob $blob\thello2.c\n" >tree_r.exp &&
3255 git ls-tree $commit_r >tree_r.out &&
3256 test_cmp tree_r.exp tree_r.out
3260 test_path_space_success
'quoted spaces' '" hello world.c "' ' hello world.c '
3261 test_path_space_success
'no unquoted spaces' 'hello_world.c' 'hello_world.c'
3262 test_path_space_success
'octal escapes' '"\150\151\056\143"' 'hi.c'
3265 # Test a single commit change with an invalid path. Run it with all occurrences
3266 # of <path> in the grammar against all error kinds.
3269 local change
="$1" what
="$2" prefix
="$3" path
="$4" suffix
="$5" err_grep
="$6"
3270 test_expect_success
"S: $change with $what must fail" '
3271 test_must_fail git fast-import <<-EOF 2>err &&
3278 commit refs/heads/S-path-fail
3280 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3286 commit refs/heads/S-path-fail
3287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3289 commit with bad path
3295 test_grep "$err_grep" err
3299 test_path_base_fail
() {
3300 local change
="$1" prefix
="$2" field
="$3" suffix
="$4"
3301 test_path_fail
"$change" 'unclosed " in '"$field" "$prefix" '"hello.c' "$suffix" "Invalid $field"
3302 test_path_fail
"$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "Invalid $field"
3303 test_path_fail
"$change" "escaped NUL in quoted $field" "$prefix" '"hello\000"' "$suffix" "NUL in $field"
3305 test_path_eol_quoted_fail
() {
3306 local change
="$1" prefix
="$2" field
="$3"
3307 test_path_base_fail
"$change" "$prefix" "$field" ''
3308 test_path_fail
"$change" "garbage after quoted $field" "$prefix" '"hello.c"' 'x' "Garbage after $field"
3309 test_path_fail
"$change" "space after quoted $field" "$prefix" '"hello.c"' ' ' "Garbage after $field"
3311 test_path_eol_fail
() {
3312 local change
="$1" prefix
="$2" field
="$3"
3313 test_path_eol_quoted_fail
"$change" "$prefix" "$field"
3315 test_path_space_fail
() {
3316 local change
="$1" prefix
="$2" field
="$3"
3317 test_path_base_fail
"$change" "$prefix" "$field" ' world.c'
3318 test_path_fail
"$change" "missing space after quoted $field" "$prefix" '"hello.c"' 'x world.c' "Missing space after $field"
3319 test_path_fail
"$change" "missing space after unquoted $field" "$prefix" 'hello.c' '' "Missing space after $field"
3322 test_path_eol_fail filemodify
'M 100644 :1 ' path
3323 test_path_eol_fail filedelete
'D ' path
3324 test_path_space_fail filecopy
'C ' source
3325 test_path_eol_fail filecopy
'C hello.c ' dest
3326 test_path_space_fail filerename
'R ' source
3327 test_path_eol_fail filerename
'R hello.c ' dest
3328 test_path_eol_fail
'ls (in commit)' 'ls :2 ' path
3330 # When 'ls' has no <dataref>, the <path> must be quoted.
3331 test_path_eol_quoted_fail
'ls (without dataref in commit)' 'ls ' path
3336 # Setup is carried over from series S.
3340 test_expect_success
"T: ls root ($root) tree" '
3341 sed -e "s/Z\$//" >expect <<-EOF &&
3342 040000 tree $(git rev-parse S^{tree}) Z
3344 sha1=$(git rev-parse --verify S) &&
3345 git fast-import --import-marks=marks <<-EOF >actual &&
3348 test_cmp expect actual
3352 test_expect_success
'T: delete branch' '
3353 git branch to-delete &&
3354 git fast-import <<-EOF &&
3355 reset refs/heads/to-delete
3358 test_must_fail git rev-parse --verify refs/heads/to-delete
3361 test_expect_success
'T: empty reset doesnt delete branch' '
3362 git branch not-to-delete &&
3363 git fast-import <<-EOF &&
3364 reset refs/heads/not-to-delete
3367 git rev-parse --verify refs/heads/not-to-delete
3371 ### series U (filedelete)
3374 test_expect_success
'U: initialize for U tests' '
3375 cat >input <<-INPUT_END &&
3377 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3381 M 100644 inline hello.c
3385 M 100644 inline good/night.txt
3389 M 100644 inline good/bye.txt
3396 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3397 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3398 f9id=$(echo "au revoir" | git hash-object --stdin) &&
3399 git fast-import <input
3402 test_expect_success
'U: filedelete file succeeds' '
3403 cat >input <<-INPUT_END &&
3405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3407 delete good/night.txt
3414 git fast-import <input
3417 test_expect_success
'U: validate file delete result' '
3418 cat >expect <<-EOF &&
3419 :100644 000000 $f8id $ZERO_OID D good/night.txt
3422 git diff-tree -M -r U^1 U >actual &&
3424 compare_diff_raw expect actual
3427 test_expect_success
'U: filedelete directory succeeds' '
3428 cat >input <<-INPUT_END &&
3430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3439 git fast-import <input
3442 test_expect_success
'U: validate directory delete result' '
3443 cat >expect <<-EOF &&
3444 :100644 000000 $f9id $ZERO_OID D good/bye.txt
3447 git diff-tree -M -r U^1 U >actual &&
3449 compare_diff_raw expect actual
3454 test_expect_success
"U: filedelete root ($root) succeeds" '
3455 cat >input <<-INPUT_END &&
3456 commit refs/heads/U-delete-root
3457 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3466 git fast-import <input
3469 test_expect_success
"U: validate root ($root) delete result" '
3470 cat >expect <<-EOF &&
3471 :100644 000000 $f7id $ZERO_OID D hello.c
3474 git diff-tree -M -r U U-delete-root >actual &&
3476 compare_diff_raw expect actual
3481 ### series V (checkpoint)
3484 # The commands in input_file should not produce any output on the file
3485 # descriptor set with --cat-blob-fd (or stdout if unspecified).
3487 # To make sure you're observing the side effects of checkpoint *before*
3488 # fast-import terminates (and thus writes out its state), check that the
3489 # fast-import process is still running using background_import_still_running
3490 # *after* evaluating the test conditions.
3491 background_import_then_checkpoint
() {
3504 git fast-import
$options <&8 >&9 &
3507 echo >&2 "background fast-import terminated too early with exit code $?"
3508 # Un-block the read loop in the main shell process.
3513 # We don't mind if fast-import has already died by the time the test
3515 test_when_finished
"
3516 exec 8>&-; exec 9>&-;
3517 kill $sh_pid && wait $sh_pid
3518 kill $fi_pid && wait $fi_pid
3521 # Start in the background to ensure we adhere strictly to (blocking)
3522 # pipes writing sequence. We want to assume that the write below could
3523 # block, e.g. if fast-import blocks writing its own output to &9
3524 # because there is no reader on &9 yet.
3528 echo "progress checkpoint"
3531 error
=1 ;# assume the worst
3532 while read output
<&9
3534 if test "$output" = "progress checkpoint"
3538 elif test "$output" = "UNEXPECTED"
3542 # otherwise ignore cruft
3543 echo >&2 "cruft: $output"
3546 if test $error -eq 1
3552 background_import_still_running
() {
3553 if ! kill -0 "$fi_pid"
3555 echo >&2 "background fast-import terminated too early"
3560 test_expect_success PIPE
'V: checkpoint helper does not get stuck with extra output' '
3561 cat >input <<-INPUT_END &&
3567 background_import_then_checkpoint "" input &&
3568 background_import_still_running
3571 test_expect_success PIPE
'V: checkpoint updates refs after reset' '
3572 cat >input <<-\INPUT_END &&
3578 background_import_then_checkpoint "" input &&
3579 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3580 background_import_still_running
3583 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit' '
3584 cat >input <<-INPUT_END &&
3587 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3593 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3595 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3597 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3598 test_cmp marks.expected marks.actual &&
3599 background_import_still_running
3602 # Re-create the exact same commit, but on a different branch: no new object is
3603 # created in the database, but the refs and marks still need to be updated.
3604 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit (no new objects)' '
3605 cat >input <<-INPUT_END &&
3606 commit refs/heads/V2
3608 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3614 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3616 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3618 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3619 test_cmp marks.expected marks.actual &&
3620 background_import_still_running
3623 test_expect_success PIPE
'V: checkpoint updates tags after tag' '
3624 cat >input <<-INPUT_END &&
3627 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3632 background_import_then_checkpoint "" input &&
3633 git show-ref -d Vtag &&
3634 background_import_still_running
3638 ### series W (get-mark and empty orphan commits)
3641 cat >>W-input
<<-W_INPUT_END
3642 commit refs/heads/W-branch
3644 author Full Name <user@company.tld> 1000000000 +0100
3645 committer Full Name <user@company.tld> 1000000000 +0100
3647 Intentionally empty commit
3651 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with no newlines' '
3652 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3655 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with one newline' '
3656 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3659 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with ugly second newline' '
3660 # Technically, this should fail as it has too many linefeeds
3661 # according to the grammar in fast-import.txt. But, for whatever
3662 # reason, it works. Since using the correct number of newlines
3663 # does not work with older (pre-2.22) versions of git, allow apps
3664 # that used this second-newline workaround to keep working by
3665 # checking it with this test...
3666 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3669 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with erroneous third newline' '
3670 # ...but do NOT allow more empty lines than that (see previous test).
3671 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3675 ### series X (other new features)
3678 test_expect_success
'X: handling encoding' '
3680 cat >input <<-INPUT_END &&
3681 commit refs/heads/encoding
3682 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3687 printf "Pi: \360\nCOMMIT\n" >>input &&
3689 git fast-import <input &&
3690 git cat-file -p encoding | grep $(printf "\360") &&
3691 git log -1 --format=%B encoding | grep $(printf "\317\200")
3695 ### series Y (submodules and hash algorithms)
3698 cat >Y-sub-input
<<\Y_INPUT_END
3704 reset refs
/heads
/main
3705 commit refs
/heads
/main
3707 author Full Name
<user@company.tld
> 1000000000 +0100
3708 committer Full Name
<user@company.tld
> 1000000000 +0100
3710 Test submodule commit
1
3719 commit refs
/heads
/main
3721 author Full Name
<user@company.tld
> 1000000001 +0100
3722 committer Full Name
<user@company.tld
> 1000000001 +0100
3724 Test submodule commit
2
3729 # Note that the submodule object IDs are intentionally not translated.
3730 cat >Y-main-input
<<\Y_INPUT_END
3736 reset refs
/heads
/main
3737 commit refs
/heads
/main
3739 author Full Name
<user@company.tld
> 2000000000 +0100
3740 committer Full Name
<user@company.tld
> 2000000000 +0100
3750 url
= https
://void.example.com
/main.git
3752 commit refs
/heads
/main
3754 author Full Name
<user@company.tld
> 2000000001 +0100
3755 committer Full Name
<user@company.tld
> 2000000001 +0100
3759 M
100644 :3 .gitmodules
3760 M
160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3768 commit refs
/heads
/main
3770 author Full Name
<user@company.tld
> 2000000002 +0100
3771 committer Full Name
<user@company.tld
> 2000000002 +0100
3776 M
160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3779 cat >Y-marks
<<\Y_INPUT_END
3780 :2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3781 :4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3784 test_expect_success
'Y: setup' '
3785 test_oid_cache <<-EOF
3786 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3787 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
3791 test_expect_success
'Y: rewrite submodules' '
3796 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3797 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3798 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
3799 test "$(git rev-parse main)" = "$(test_oid Ymain)"