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
394 git fast-import <input &&
395 test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
396 test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
399 test_expect_success
'B: accept empty committer' '
400 cat >input <<-INPUT_END &&
401 commit refs/heads/empty-committer-1
402 committer <> $GIT_COMMITTER_DATE
408 test_when_finished "git update-ref -d refs/heads/empty-committer-1
411 git fast-import <input &&
417 test_expect_success
'B: reject invalid timezone' '
418 cat >input <<-INPUT_END &&
419 commit refs/heads/invalid-timezone
420 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
426 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
427 test_must_fail git fast-import <input
430 test_expect_success
'B: accept invalid timezone with raw-permissive' '
431 cat >input <<-INPUT_END &&
432 commit refs/heads/invalid-timezone
433 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
439 git init invalid-timezone &&
440 git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
441 git -C invalid-timezone cat-file -p invalid-timezone >out &&
442 grep "1234567890 [+]051800" out
445 test_expect_success
'B: accept and fixup committer with no name' '
446 cat >input <<-INPUT_END &&
447 commit refs/heads/empty-committer-2
448 committer <a@b.com> $GIT_COMMITTER_DATE
454 test_when_finished "git update-ref -d refs/heads/empty-committer-2
457 git fast-import <input &&
463 test_expect_success
'B: fail on invalid committer (1)' '
464 cat >input <<-INPUT_END &&
465 commit refs/heads/invalid-committer
466 committer Name email> $GIT_COMMITTER_DATE
472 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
473 test_must_fail git fast-import <input
476 test_expect_success
'B: fail on invalid committer (2)' '
477 cat >input <<-INPUT_END &&
478 commit refs/heads/invalid-committer
479 committer Name <e<mail> $GIT_COMMITTER_DATE
485 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
486 test_must_fail git fast-import <input
489 test_expect_success
'B: fail on invalid committer (3)' '
490 cat >input <<-INPUT_END &&
491 commit refs/heads/invalid-committer
492 committer Name <email>> $GIT_COMMITTER_DATE
498 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
499 test_must_fail git fast-import <input
502 test_expect_success
'B: fail on invalid committer (4)' '
503 cat >input <<-INPUT_END &&
504 commit refs/heads/invalid-committer
505 committer Name <email $GIT_COMMITTER_DATE
511 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
512 test_must_fail git fast-import <input
515 test_expect_success
'B: fail on invalid committer (5)' '
516 cat >input <<-INPUT_END &&
517 commit refs/heads/invalid-committer
518 committer Name<email> $GIT_COMMITTER_DATE
524 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
525 test_must_fail git fast-import <input
532 test_expect_success
'C: incremental import create pack from stdin' '
533 newf=$(echo hi newf | git hash-object -w --stdin) &&
534 oldf=$(git rev-parse --verify main:file2) &&
535 thrf=$(git rev-parse --verify main:file3) &&
537 cat >input <<-INPUT_END &&
538 commit refs/heads/branch
539 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
545 M 644 $oldf file2/oldf
546 M 755 $newf file2/newf
551 git fast-import <input &&
552 git whatchanged branch
555 test_expect_success
'C: verify pack' '
559 test_expect_success
'C: validate reuse existing blob' '
560 test $newf = $(git rev-parse --verify branch:file2/newf) &&
561 test $oldf = $(git rev-parse --verify branch:file2/oldf)
564 test_expect_success
'C: verify commit' '
565 cat >expect <<-EOF &&
566 parent $(git rev-parse --verify main^0)
567 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
568 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
573 git cat-file commit branch | sed 1d >actual &&
574 test_cmp expect actual
577 test_expect_success
'C: validate rename result' '
579 cat >expect <<-EOF &&
580 :000000 100755 $zero $newf A file2/newf
581 :100644 100644 $oldf $oldf R100 file2 file2/oldf
582 :100644 000000 $thrf $zero D file3
584 git diff-tree -M -r main branch >actual &&
585 compare_diff_raw expect actual
592 test_expect_success
'D: inline data in commit' '
594 cat >input <<-INPUT_END &&
595 commit refs/heads/branch
596 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
601 from refs/heads/branch^0
602 M 644 inline newdir/interesting
607 M 755 inline newdir/exec.sh
614 git fast-import <input &&
615 git whatchanged branch
618 test_expect_success
'D: verify pack' '
622 test_expect_success
'D: validate new files added' '
623 f5id=$(echo "$file5_data" | git hash-object --stdin) &&
624 f6id=$(echo "$file6_data" | git hash-object --stdin) &&
625 cat >expect <<-EOF &&
626 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh
627 :000000 100644 $ZERO_OID $f5id A newdir/interesting
629 git diff-tree -M -r branch^ branch >actual &&
630 compare_diff_raw expect actual
633 test_expect_success
'D: verify file5' '
634 echo "$file5_data" >expect &&
635 git cat-file blob branch:newdir/interesting >actual &&
636 test_cmp expect actual
639 test_expect_success
'D: verify file6' '
640 echo "$file6_data" >expect &&
641 git cat-file blob branch:newdir/exec.sh >actual &&
642 test_cmp expect actual
649 test_expect_success
'E: rfc2822 date, --date-format=raw' '
650 cat >input <<-INPUT_END &&
651 commit refs/heads/branch
652 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
658 from refs/heads/branch^0
662 test_must_fail git fast-import --date-format=raw <input
664 test_expect_success
'E: rfc2822 date, --date-format=rfc2822' '
665 git fast-import --date-format=rfc2822 <input
668 test_expect_success
'E: verify pack' '
672 test_expect_success
'E: verify commit' '
673 cat >expect <<-EOF &&
674 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
675 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
679 git cat-file commit branch | sed 1,2d >actual &&
680 test_cmp expect actual
687 test_expect_success
'F: non-fast-forward update skips' '
688 old_branch=$(git rev-parse --verify branch^0) &&
690 cat >input <<-INPUT_END &&
691 commit refs/heads/branch
692 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
694 losing things already?
697 from refs/heads/branch~1
699 reset refs/heads/other
700 from refs/heads/branch
704 test_must_fail git fast-import <input &&
705 # branch must remain unaffected
706 test $old_branch = $(git rev-parse --verify branch^0)
709 test_expect_success
'F: verify pack' '
713 test_expect_success
'F: verify other commit' '
714 cat >expect <<-EOF &&
715 tree $(git rev-parse branch~1^{tree})
716 parent $(git rev-parse branch~1)
717 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
718 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
720 losing things already?
722 git cat-file commit other >actual &&
723 test_cmp expect actual
730 test_expect_success
'G: non-fast-forward update forced' '
731 old_branch=$(git rev-parse --verify branch^0) &&
733 cat >input <<-INPUT_END &&
734 commit refs/heads/branch
735 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
737 losing things already?
740 from refs/heads/branch~1
743 git fast-import --force <input
746 test_expect_success
'G: verify pack' '
750 test_expect_success
'G: branch changed, but logged' '
751 test $old_branch != $(git rev-parse --verify branch^0) &&
752 test $old_branch = $(git rev-parse --verify branch@{1})
759 test_expect_success
'H: deletall, add 1' '
761 cat >input <<-INPUT_END &&
763 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
768 from refs/heads/branch^0
769 M 644 inline i-will-die
771 this file will never exist.
775 M 644 inline h/e/l/lo
781 git fast-import <input &&
785 test_expect_success
'H: verify pack' '
789 test_expect_success
'H: validate old files removed, new files added' '
790 f4id=$(git rev-parse HEAD:file4) &&
791 cat >expect <<-EOF &&
792 :100755 000000 $newf $zero D file2/newf
793 :100644 000000 $oldf $zero D file2/oldf
794 :100755 000000 $f4id $zero D file4
795 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo
796 :100755 000000 $f6id $zero D newdir/exec.sh
798 git diff-tree -M -r H^ H >actual &&
799 compare_diff_raw expect actual
802 test_expect_success
'H: verify file' '
803 echo "$file5_data" >expect &&
804 git cat-file blob H:h/e/l/lo >actual &&
805 test_cmp expect actual
812 test_expect_success
'I: export-pack-edges' '
813 cat >input <<-INPUT_END &&
814 commit refs/heads/export-boundary
815 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
817 we have a border. its only 40 characters wide.
820 from refs/heads/branch
823 git fast-import --export-pack-edges=edges.list <input
826 test_expect_success
'I: verify edge list' '
827 cat >expect <<-EOF &&
828 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
830 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
831 test_cmp expect actual
838 test_expect_success
'J: reset existing branch creates empty commit' '
839 cat >input <<-INPUT_END &&
841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
846 from refs/heads/branch
851 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
857 git fast-import <input
859 test_expect_success
'J: branch has 1 commit, empty tree' '
860 test 1 = $(git rev-list J | wc -l) &&
861 test 0 = $(git ls-tree J | wc -l)
864 test_expect_success
'J: tag must fail on empty branch' '
865 cat >input <<-INPUT_END &&
871 Tag branch that was reset.
874 test_must_fail git fast-import <input
881 test_expect_success
'K: reinit branch with from' '
882 cat >input <<-INPUT_END &&
884 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
889 from refs/heads/branch
892 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
897 from refs/heads/branch^1
900 git fast-import <input
902 test_expect_success
'K: verify K^1 = branch^1' '
903 test $(git rev-parse --verify branch^1) \
904 = $(git rev-parse --verify K^1)
911 test_expect_success
'L: verify internal tree sorting' '
912 cat >input <<-INPUT_END &&
926 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
936 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
946 cat >expect <<-EXPECT_END &&
952 git fast-import <input &&
953 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
954 cut -d" " -f1,2,5 output >actual &&
955 test_cmp expect actual
958 test_expect_success
'L: nested tree copy does not corrupt deltas' '
959 cat >input <<-INPUT_END &&
967 committer C O Mitter <committer@example.com> 1112912473 -0700
976 committer C O Mitter <committer@example.com> 1112912473 -0700
985 cat >expect <<-\EOF &&
990 test_when_finished "git update-ref -d refs/heads/L2" &&
991 git fast-import <input &&
992 git ls-tree L2 g/b/ >tmp &&
993 cat tmp | cut -f 2 >actual &&
994 test_cmp expect actual &&
995 git fsck $(git rev-parse L2)
1002 test_expect_success
'M: rename file in same subdirectory' '
1004 cat >input <<-INPUT_END &&
1005 commit refs/heads/M1
1006 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1011 from refs/heads/branch^0
1012 R file2/newf file2/n.e.w.f
1016 cat >expect <<-EOF &&
1017 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f
1019 git fast-import <input &&
1020 git diff-tree -M -r M1^ M1 >actual &&
1021 compare_diff_raw expect actual
1024 test_expect_success
'M: rename file to new subdirectory' '
1025 cat >input <<-INPUT_END &&
1026 commit refs/heads/M2
1027 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1032 from refs/heads/branch^0
1033 R file2/newf i/am/new/to/you
1037 cat >expect <<-EOF &&
1038 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you
1040 git fast-import <input &&
1041 git diff-tree -M -r M2^ M2 >actual &&
1042 compare_diff_raw expect actual
1045 test_expect_success
'M: rename subdirectory to new subdirectory' '
1046 cat >input <<-INPUT_END &&
1047 commit refs/heads/M3
1048 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1053 from refs/heads/M2^0
1058 cat >expect <<-EOF &&
1059 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you
1061 git fast-import <input &&
1062 git diff-tree -M -r M3^ M3 >actual &&
1063 compare_diff_raw expect actual
1066 test_expect_success
'M: rename root to subdirectory' '
1067 cat >input <<-INPUT_END &&
1068 commit refs/heads/M4
1069 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1074 from refs/heads/M2^0
1079 cat >expect <<-EOF &&
1080 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1081 :100755 100755 $f4id $f4id R100 file4 sub/file4
1082 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1083 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1084 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
1086 git fast-import <input &&
1087 git diff-tree -M -r M4^ M4 >actual &&
1088 compare_diff_raw expect actual
1095 test_expect_success
'N: copy file in same subdirectory' '
1097 cat >input <<-INPUT_END &&
1098 commit refs/heads/N1
1099 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1104 from refs/heads/branch^0
1105 C file2/newf file2/n.e.w.f
1109 cat >expect <<-EOF &&
1110 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
1112 git fast-import <input &&
1113 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1114 compare_diff_raw expect actual
1117 test_expect_success
'N: copy then modify subdirectory' '
1118 cat >input <<-INPUT_END &&
1119 commit refs/heads/N2
1120 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1122 clean directory copy
1125 from refs/heads/branch^0
1128 commit refs/heads/N2
1129 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1131 modify directory copy
1134 M 644 inline file3/file5
1141 cat >expect <<-EOF &&
1142 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1143 :100755 100755 $newf $newf C100 file2/newf file3/newf
1144 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1146 git fast-import <input &&
1147 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1148 compare_diff_raw expect actual
1151 test_expect_success
'N: copy dirty subdirectory' '
1152 cat >input <<-INPUT_END &&
1153 commit refs/heads/N3
1154 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1156 dirty directory copy
1159 from refs/heads/branch^0
1160 M 644 inline file2/file5
1170 git fast-import <input &&
1171 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1174 test_expect_success
'N: copy directory by id' '
1175 cat >expect <<-EOF &&
1176 :100755 100755 $newf $newf C100 file2/newf file3/newf
1177 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1179 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1180 cat >input <<-INPUT_END &&
1181 commit refs/heads/N4
1182 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1187 from refs/heads/branch^0
1188 M 040000 $subdir file3
1190 git fast-import <input &&
1191 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1192 compare_diff_raw expect actual
1195 test_expect_success PIPE
'N: read and copy directory' '
1196 cat >expect <<-EOF &&
1197 :100755 100755 $newf $newf C100 file2/newf file3/newf
1198 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1200 git update-ref -d refs/heads/N4 &&
1206 commit refs/heads/N4
1207 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1209 copy by tree hash, part 2
1212 from refs/heads/branch^0
1215 read mode type tree filename &&
1216 echo "M 040000 $tree file3"
1218 git fast-import --cat-blob-fd=3 3>backflow &&
1219 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1220 compare_diff_raw expect actual
1223 test_expect_success PIPE
'N: empty directory reads as missing' '
1224 cat <<-\EOF >expect &&
1226 :000000 100644 OBJNAME OBJNAME A unrelated
1228 echo "missing src" >expect.response &&
1229 git update-ref -d refs/heads/read-empty &&
1235 commit refs/heads/read-empty
1236 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1238 read "empty" (missing) directory
1241 M 100644 inline src/greeting
1245 C src/greeting dst1/non-greeting
1246 C src/greeting unrelated
1247 # leave behind "empty" src directory
1252 printf "%s\n" "$line" >response &&
1258 git fast-import --cat-blob-fd=3 3>backflow &&
1259 test_cmp expect.response response &&
1260 git rev-list read-empty |
1261 git diff-tree -r --root --stdin |
1262 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
1263 test_cmp expect actual
1266 test_expect_success
'N: copy root directory by tree hash' '
1267 cat >expect <<-EOF &&
1268 :100755 000000 $newf $zero D file3/newf
1269 :100644 000000 $oldf $zero D file3/oldf
1271 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1272 cat >input <<-INPUT_END &&
1273 commit refs/heads/N6
1274 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1276 copy root directory by tree hash
1279 from refs/heads/branch^0
1282 git fast-import <input &&
1283 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1284 compare_diff_raw expect actual
1287 test_expect_success
'N: copy root by path' '
1288 cat >expect <<-EOF &&
1289 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1290 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1291 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1292 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1293 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
1295 cat >input <<-INPUT_END &&
1296 commit refs/heads/N-copy-root-path
1297 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1299 copy root directory by (empty) path
1302 from refs/heads/branch^0
1305 git fast-import <input &&
1306 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1307 compare_diff_raw expect actual
1310 test_expect_success
'N: delete directory by copying' '
1311 cat >expect <<-\EOF &&
1313 :100644 000000 OBJID OBJID D foo/bar/qux
1315 :000000 100644 OBJID OBJID A foo/bar/baz
1316 :000000 100644 OBJID OBJID A foo/bar/qux
1318 empty_tree=$(git mktree </dev/null) &&
1319 cat >input <<-INPUT_END &&
1320 commit refs/heads/N-delete
1321 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1323 collect data to be deleted
1327 M 100644 inline foo/bar/baz
1331 C "foo/bar/baz" "foo/bar/qux"
1332 C "foo/bar/baz" "foo/bar/quux/1"
1333 C "foo/bar/baz" "foo/bar/quuux"
1334 M 040000 $empty_tree foo/bar/quux
1335 M 040000 $empty_tree foo/bar/quuux
1337 commit refs/heads/N-delete
1338 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1343 M 040000 $empty_tree foo/bar/qux
1345 git fast-import <input &&
1346 git rev-list N-delete |
1347 git diff-tree -r --stdin --root --always |
1348 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
1349 test_cmp expect actual
1352 test_expect_success
'N: modify copied tree' '
1353 cat >expect <<-EOF &&
1354 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1355 :100755 100755 $newf $newf C100 file2/newf file3/newf
1356 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1358 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1359 cat >input <<-INPUT_END &&
1360 commit refs/heads/N5
1361 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1366 from refs/heads/branch^0
1367 M 040000 $subdir file3
1369 commit refs/heads/N5
1370 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1372 modify directory copy
1375 M 644 inline file3/file5
1380 git fast-import <input &&
1381 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1382 compare_diff_raw expect actual
1385 test_expect_success
'N: reject foo/ syntax' '
1386 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1387 test_must_fail git fast-import <<-INPUT_END
1388 commit refs/heads/N5B
1389 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1391 copy with invalid syntax
1394 from refs/heads/branch^0
1395 M 040000 $subdir file3/
1399 test_expect_success
'N: reject foo/ syntax in copy source' '
1400 test_must_fail git fast-import <<-INPUT_END
1401 commit refs/heads/N5C
1402 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1404 copy with invalid syntax
1407 from refs/heads/branch^0
1412 test_expect_success
'N: reject foo/ syntax in rename source' '
1413 test_must_fail git fast-import <<-INPUT_END
1414 commit refs/heads/N5D
1415 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1417 rename with invalid syntax
1420 from refs/heads/branch^0
1425 test_expect_success
'N: reject foo/ syntax in ls argument' '
1426 test_must_fail git fast-import <<-INPUT_END
1427 commit refs/heads/N5E
1428 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1430 copy with invalid syntax
1433 from refs/heads/branch^0
1438 test_expect_success
'N: copy to root by id and modify' '
1439 echo "hello, world" >expect.foo &&
1440 echo hello >expect.bar &&
1441 git fast-import <<-SETUP_END &&
1442 commit refs/heads/N7
1443 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1449 M 644 inline foo/bar
1455 tree=$(git rev-parse --verify N7:) &&
1456 git fast-import <<-INPUT_END &&
1457 commit refs/heads/N8
1458 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1460 copy to root by id and modify
1464 M 644 inline foo/foo
1469 git show N8:foo/foo >actual.foo &&
1470 git show N8:foo/bar >actual.bar &&
1471 test_cmp expect.foo actual.foo &&
1472 test_cmp expect.bar actual.bar
1475 test_expect_success
'N: extract subtree' '
1476 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1477 cat >input <<-INPUT_END &&
1478 commit refs/heads/N9
1479 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1481 extract subtree branch:newdir
1487 git fast-import <input &&
1488 git diff --exit-code branch:newdir N9
1491 test_expect_success
'N: modify subtree, extract it, and modify again' '
1492 echo hello >expect.baz &&
1493 echo hello, world >expect.qux &&
1494 git fast-import <<-SETUP_END &&
1495 commit refs/heads/N10
1496 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1502 M 644 inline foo/bar/baz
1508 tree=$(git rev-parse --verify N10:) &&
1509 git fast-import <<-INPUT_END &&
1510 commit refs/heads/N11
1511 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1513 copy to root by id and modify
1517 M 100644 inline foo/bar/qux
1522 C "bar/qux" "bar/quux"
1524 git show N11:bar/baz >actual.baz &&
1525 git show N11:bar/qux >actual.qux &&
1526 git show N11:bar/quux >actual.quux &&
1527 test_cmp expect.baz actual.baz &&
1528 test_cmp expect.qux actual.qux &&
1529 test_cmp expect.qux actual.quux'
1535 test_expect_success
'O: comments are all skipped' '
1536 cat >input <<-INPUT_END &&
1538 commit refs/heads/O1
1539 # -- ignore all of this text
1540 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1542 dirty directory copy
1545 # do not forget the import blank line!
1547 # yes, we started from our usual base of branch^0.
1549 from refs/heads/branch^0
1550 # and we need to reuse file2/file5 from N3 above.
1551 M 644 inline file2/file5
1552 # otherwise the tree will be different
1557 # do not forget to copy file2 to file3
1560 # or to delete file5 from file2.
1566 git fast-import <input &&
1567 test $(git rev-parse N3) = $(git rev-parse O1)
1570 test_expect_success
'O: blank lines not necessary after data commands' '
1571 cat >input <<-INPUT_END &&
1572 commit refs/heads/O2
1573 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575 dirty directory copy
1577 from refs/heads/branch^0
1578 M 644 inline file2/file5
1587 git fast-import <input &&
1588 test $(git rev-parse N3) = $(git rev-parse O2)
1591 test_expect_success
'O: repack before next test' '
1595 test_expect_success
'O: blank lines not necessary after other commands' '
1596 cat >input <<-INPUT_END &&
1597 commit refs/heads/O3
1598 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1602 commit refs/heads/O3
1603 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1608 commit refs/heads/O3
1610 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1615 commit refs/heads/O3
1616 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1620 reset refs/tags/O3-2nd
1622 reset refs/tags/O3-3rd
1626 cat >expect <<-INPUT_END &&
1633 git fast-import <input &&
1634 ls -la .git/objects/pack/pack-*.pack >packlist &&
1635 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1636 test_line_count = 4 idxlist &&
1637 test_line_count = 4 packlist &&
1638 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1639 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1640 test_cmp expect actual
1643 test_expect_success
'O: progress outputs as requested by input' '
1644 cat >input <<-INPUT_END &&
1645 commit refs/heads/O4
1646 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1650 commit refs/heads/O4
1651 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655 progress Two commits down, 2 to go!
1656 commit refs/heads/O4
1657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1661 progress Three commits down, 1 to go!
1662 commit refs/heads/O4
1663 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1669 git fast-import <input >actual &&
1670 grep "progress " <input >expect &&
1671 test_cmp expect actual
1675 ### series P (gitlinks)
1678 test_expect_success
'P: superproject & submodule mix' '
1679 cat >input <<-INPUT_END &&
1685 reset refs/heads/sub
1686 commit refs/heads/sub
1688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1701 commit refs/heads/subuse1
1703 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1706 from refs/heads/main
1707 M 100644 :3 .gitmodules
1716 commit refs/heads/sub
1718 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1724 commit refs/heads/subuse1
1726 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1734 git fast-import <input &&
1735 git checkout subuse1 &&
1741 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1744 git submodule init &&
1745 git submodule update
1748 test_expect_success
'P: verbatim SHA gitlinks' '
1749 SUBLAST=$(git rev-parse --verify sub) &&
1750 SUBPREV=$(git rev-parse --verify sub^) &&
1752 cat >input <<-INPUT_END &&
1761 commit refs/heads/subuse2
1763 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1766 from refs/heads/main
1767 M 100644 :1 .gitmodules
1768 M 160000 $SUBPREV sub
1770 commit refs/heads/subuse2
1772 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1776 M 160000 $SUBLAST sub
1780 git branch -D sub &&
1783 git fast-import <input &&
1784 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1787 test_expect_success
'P: fail on inline gitlink' '
1789 cat >input <<-INPUT_END &&
1790 commit refs/heads/subuse3
1792 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1797 from refs/heads/subuse2
1805 test_must_fail git fast-import <input
1808 test_expect_success
'P: fail on blob mark in gitlink' '
1810 cat >input <<-INPUT_END &&
1817 commit refs/heads/subuse3
1819 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1824 from refs/heads/subuse2
1829 test_must_fail git fast-import <input
1833 ### series Q (notes)
1836 test_expect_success
'Q: commit notes' '
1837 note1_data="The first note for the first commit" &&
1838 note2_data="The first note for the second commit" &&
1839 note3_data="The first note for the third commit" &&
1840 note1b_data="The second note for the first commit" &&
1841 note1c_data="The third note for the first commit" &&
1842 note2b_data="The second note for the second commit" &&
1845 cat >input <<-INPUT_END &&
1852 commit refs/heads/notes-test
1854 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1865 commit refs/heads/notes-test
1867 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1874 commit refs/heads/notes-test
1876 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1903 commit refs/notes/foobar
1905 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1917 commit refs/notes/foobar
1919 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1929 commit refs/notes/foobar2
1931 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1941 commit refs/notes/foobar
1943 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1956 git fast-import <input &&
1957 git whatchanged notes-test
1960 test_expect_success
'Q: verify pack' '
1964 test_expect_success
'Q: verify first commit' '
1965 commit1=$(git rev-parse notes-test~2) &&
1966 commit2=$(git rev-parse notes-test^) &&
1967 commit3=$(git rev-parse notes-test) &&
1969 cat >expect <<-EOF &&
1970 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1971 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1975 git cat-file commit notes-test~2 | sed 1d >actual &&
1976 test_cmp expect actual
1979 test_expect_success
'Q: verify second commit' '
1980 cat >expect <<-EOF &&
1982 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1983 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1987 git cat-file commit notes-test^ | sed 1d >actual &&
1988 test_cmp expect actual
1991 test_expect_success
'Q: verify third commit' '
1992 cat >expect <<-EOF &&
1994 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1995 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1999 git cat-file commit notes-test | sed 1d >actual &&
2000 test_cmp expect actual
2003 test_expect_success
'Q: verify first notes commit' '
2004 cat >expect <<-EOF &&
2005 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2006 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2010 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2011 test_cmp expect actual
2014 test_expect_success
'Q: verify first notes tree' '
2015 cat >expect.unsorted <<-EOF &&
2016 100644 blob $commit1
2017 100644 blob $commit2
2018 100644 blob $commit3
2020 cat expect.unsorted | sort >expect &&
2021 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2022 test_cmp expect actual
2025 test_expect_success
'Q: verify first note for first commit' '
2026 echo "$note1_data" >expect &&
2027 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2028 test_cmp expect actual
2031 test_expect_success
'Q: verify first note for second commit' '
2032 echo "$note2_data" >expect &&
2033 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2034 test_cmp expect actual
2037 test_expect_success
'Q: verify first note for third commit' '
2038 echo "$note3_data" >expect &&
2039 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2040 test_cmp expect actual
2043 test_expect_success
'Q: verify second notes commit' '
2044 cat >expect <<-EOF &&
2045 parent $(git rev-parse --verify refs/notes/foobar~2)
2046 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2047 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2051 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2052 test_cmp expect actual
2055 test_expect_success
'Q: verify second notes tree' '
2056 cat >expect.unsorted <<-EOF &&
2057 100644 blob $commit1
2058 100644 blob $commit2
2059 100644 blob $commit3
2061 cat expect.unsorted | sort >expect &&
2062 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2063 test_cmp expect actual
2066 test_expect_success
'Q: verify second note for first commit' '
2067 echo "$note1b_data" >expect &&
2068 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2069 test_cmp expect actual
2072 test_expect_success
'Q: verify first note for second commit' '
2073 echo "$note2_data" >expect &&
2074 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2075 test_cmp expect actual
2078 test_expect_success
'Q: verify first note for third commit' '
2079 echo "$note3_data" >expect &&
2080 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2081 test_cmp expect actual
2084 test_expect_success
'Q: verify third notes commit' '
2085 cat >expect <<-EOF &&
2086 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2087 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2091 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2092 test_cmp expect actual
2095 test_expect_success
'Q: verify third notes tree' '
2096 cat >expect.unsorted <<-EOF &&
2097 100644 blob $commit1
2099 cat expect.unsorted | sort >expect &&
2100 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2101 test_cmp expect actual
2104 test_expect_success
'Q: verify third note for first commit' '
2105 echo "$note1c_data" >expect &&
2106 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2107 test_cmp expect actual
2110 test_expect_success
'Q: verify fourth notes commit' '
2111 cat >expect <<-EOF &&
2112 parent $(git rev-parse --verify refs/notes/foobar^)
2113 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2118 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2119 test_cmp expect actual
2122 test_expect_success
'Q: verify fourth notes tree' '
2123 cat >expect.unsorted <<-EOF &&
2124 100644 blob $commit2
2126 cat expect.unsorted | sort >expect &&
2127 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2128 test_cmp expect actual
2131 test_expect_success
'Q: verify second note for second commit' '
2132 echo "$note2b_data" >expect &&
2133 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2134 test_cmp expect actual
2137 test_expect_success
'Q: deny note on empty branch' '
2138 cat >input <<-EOF &&
2141 commit refs/heads/note-Q0
2142 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2144 Note for an empty branch.
2147 N inline refs/heads/Q0
2152 test_must_fail git fast-import <input
2155 ### series R (feature and option)
2158 test_expect_success
'R: abort on unsupported feature' '
2159 cat >input <<-EOF &&
2160 feature no-such-feature-exists
2163 test_must_fail git fast-import <input
2166 test_expect_success
'R: supported feature is accepted' '
2167 cat >input <<-EOF &&
2168 feature date-format=now
2171 git fast-import <input
2174 test_expect_success
'R: abort on receiving feature after data command' '
2175 cat >input <<-EOF &&
2179 feature date-format=now
2182 test_must_fail git fast-import <input
2185 test_expect_success
'R: import-marks features forbidden by default' '
2187 echo "feature import-marks=git.marks" >input &&
2188 test_must_fail git fast-import <input &&
2189 echo "feature import-marks-if-exists=git.marks" >input &&
2190 test_must_fail git fast-import <input
2193 test_expect_success
'R: only one import-marks feature allowed per stream' '
2196 cat >input <<-EOF &&
2197 feature import-marks=git.marks
2198 feature import-marks=git2.marks
2201 test_must_fail git fast-import --allow-unsafe-features <input
2204 test_expect_success
'R: export-marks feature forbidden by default' '
2205 echo "feature export-marks=git.marks" >input &&
2206 test_must_fail git fast-import <input
2209 test_expect_success
'R: export-marks feature results in a marks file being created' '
2210 cat >input <<-EOF &&
2211 feature export-marks=git.marks
2219 git fast-import --allow-unsafe-features <input &&
2223 test_expect_success
'R: export-marks options can be overridden by commandline options' '
2224 cat >input <<-\EOF &&
2225 feature export-marks=feature-sub/git.marks
2232 git fast-import --allow-unsafe-features \
2233 --export-marks=cmdline-sub/other.marks <input &&
2234 grep :1 cmdline-sub/other.marks &&
2235 test_path_is_missing feature-sub
2238 test_expect_success
'R: catch typo in marks file name' '
2239 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2240 echo "feature import-marks=nonexistent.marks" |
2241 test_must_fail git fast-import --allow-unsafe-features
2244 test_expect_success
'R: import and output marks can be the same file' '
2246 blob=$(echo hi | git hash-object --stdin) &&
2247 cat >expect <<-EOF &&
2251 git fast-import --export-marks=io.marks <<-\EOF &&
2258 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2265 test_cmp expect io.marks
2268 test_expect_success
'R: --import-marks=foo --output-marks=foo to create foo fails' '
2270 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2279 test_expect_success
'R: --import-marks-if-exists' '
2281 blob=$(echo hi | git hash-object --stdin) &&
2282 echo ":1 $blob" >expect &&
2283 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2290 test_cmp expect io.marks
2293 test_expect_success
'R: feature import-marks-if-exists' '
2296 git fast-import --export-marks=io.marks \
2297 --allow-unsafe-features <<-\EOF &&
2298 feature import-marks-if-exists=not_io.marks
2300 test_must_be_empty io.marks &&
2302 blob=$(echo hi | git hash-object --stdin) &&
2304 echo ":1 $blob" >io.marks &&
2305 echo ":1 $blob" >expect &&
2306 echo ":2 $blob" >>expect &&
2308 git fast-import --export-marks=io.marks \
2309 --allow-unsafe-features <<-\EOF &&
2310 feature import-marks-if-exists=io.marks
2317 test_cmp expect io.marks &&
2319 echo ":3 $blob" >>expect &&
2321 git fast-import --import-marks=io.marks \
2322 --export-marks=io.marks \
2323 --allow-unsafe-features <<-\EOF &&
2324 feature import-marks-if-exists=not_io.marks
2331 test_cmp expect io.marks &&
2333 git fast-import --import-marks-if-exists=not_io.marks \
2334 --export-marks=io.marks \
2335 --allow-unsafe-features <<-\EOF &&
2336 feature import-marks-if-exists=io.marks
2338 test_must_be_empty io.marks
2341 test_expect_success
'R: import to output marks works without any content' '
2342 cat >input <<-EOF &&
2343 feature import-marks=marks.out
2344 feature export-marks=marks.new
2347 git fast-import --allow-unsafe-features <input &&
2348 test_cmp marks.out marks.new
2351 test_expect_success
'R: import marks prefers commandline marks file over the stream' '
2352 cat >input <<-EOF &&
2353 feature import-marks=nonexistent.marks
2354 feature export-marks=marks.new
2357 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
2358 test_cmp marks.out marks.new
2362 test_expect_success
'R: multiple --import-marks= should be honoured' '
2363 cat >input <<-EOF &&
2364 feature import-marks=nonexistent.marks
2365 feature export-marks=combined.marks
2368 head -n2 marks.out > one.marks &&
2369 tail -n +3 marks.out > two.marks &&
2370 git fast-import --import-marks=one.marks --import-marks=two.marks \
2371 --allow-unsafe-features <input &&
2372 test_cmp marks.out combined.marks
2375 test_expect_success
'R: feature relative-marks should be honoured' '
2376 cat >input <<-EOF &&
2377 feature relative-marks
2378 feature import-marks=relative.in
2379 feature export-marks=relative.out
2382 mkdir -p .git/info/fast-import/ &&
2383 cp marks.new .git/info/fast-import/relative.in &&
2384 git fast-import --allow-unsafe-features <input &&
2385 test_cmp marks.new .git/info/fast-import/relative.out
2388 test_expect_success
'R: feature no-relative-marks should be honoured' '
2389 cat >input <<-EOF &&
2390 feature relative-marks
2391 feature import-marks=relative.in
2392 feature no-relative-marks
2393 feature export-marks=non-relative.out
2396 git fast-import --allow-unsafe-features <input &&
2397 test_cmp marks.new non-relative.out
2400 test_expect_success
'R: feature ls supported' '
2405 test_expect_success
'R: feature cat-blob supported' '
2406 echo "feature cat-blob" |
2410 test_expect_success
'R: cat-blob-fd must be a nonnegative integer' '
2411 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2414 test_expect_success
!MINGW
'R: print old blob' '
2415 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2416 cat >expect <<-EOF &&
2421 echo "cat-blob $blob" |
2422 git fast-import --cat-blob-fd=6 6>actual &&
2423 test_cmp expect actual
2426 test_expect_success
!MINGW
'R: in-stream cat-blob-fd not respected' '
2427 echo hello >greeting &&
2428 blob=$(git hash-object -w greeting) &&
2429 cat >expect <<-EOF &&
2434 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2437 test_cmp expect actual.3 &&
2438 test_must_be_empty actual.1 &&
2439 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2440 option cat-blob-fd=3
2443 test_must_be_empty actual.3 &&
2444 test_cmp expect actual.1
2447 test_expect_success
!MINGW
'R: print mark for new blob' '
2448 echo "effluentish" | git hash-object --stdin >expect &&
2449 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2457 test_cmp expect actual
2460 test_expect_success
!MINGW
'R: print new blob' '
2461 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2462 cat >expect <<-EOF &&
2467 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2475 test_cmp expect actual
2478 test_expect_success
!MINGW
'R: print new blob by sha1' '
2479 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2480 cat >expect <<-EOF &&
2482 a new blob named by sha1
2485 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2488 a new blob named by sha1
2492 test_cmp expect actual
2495 test_expect_success
'setup: big file' '
2497 echo "the quick brown fox jumps over the lazy dog" >big &&
2500 cat big big big big >bigger &&
2501 cat bigger bigger bigger bigger >big ||
2507 test_expect_success
'R: print two blobs to stdout' '
2508 blob1=$(git hash-object big) &&
2509 blob1_len=$(wc -c <big) &&
2510 blob2=$(echo hello | git hash-object --stdin) &&
2512 echo ${blob1} blob $blob1_len &&
2522 cat <<-\END_PART1 &&
2539 git fast-import >actual &&
2540 test_cmp expect actual
2543 test_expect_success PIPE
'R: copy using cat-file' '
2544 expect_id=$(git hash-object big) &&
2545 expect_len=$(wc -c <big) &&
2546 echo $expect_id blob $expect_len >expect.response &&
2552 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2565 read blob_id type size <&3 &&
2566 echo "$blob_id $type $size" >response &&
2567 test_copy_bytes $size >blob <&3 &&
2571 commit refs/heads/copied
2572 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2574 copy big file as file3
2582 git fast-import --cat-blob-fd=3 3>blobs &&
2583 git show copied:file3 >actual &&
2584 test_cmp expect.response response &&
2588 test_expect_success PIPE
'R: print blob mid-commit' '
2590 echo "A blob from _before_ the commit." >expect &&
2599 A blob from _before_ the commit.
2601 commit refs/heads/temporary
2602 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2609 read blob_id type size <&3 &&
2610 test_copy_bytes $size >actual <&3 &&
2615 git fast-import --cat-blob-fd=3 3>blobs &&
2616 test_cmp expect actual
2619 test_expect_success PIPE
'R: print staged blob within commit' '
2621 echo "A blob from _within_ the commit." >expect &&
2627 commit refs/heads/within
2628 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2634 A blob from _within_ the commit.
2639 echo "A blob from _within_ the commit." |
2640 git hash-object --stdin
2642 echo "cat-blob $to_get" &&
2644 read blob_id type size <&3 &&
2645 test_copy_bytes $size >actual <&3 &&
2650 git fast-import --cat-blob-fd=3 3>blobs &&
2651 test_cmp expect actual
2654 test_expect_success
'R: quiet option results in no stats being output' '
2655 cat >input <<-EOF &&
2663 git fast-import 2>output <input &&
2664 test_must_be_empty output
2667 test_expect_success
'R: feature done means terminating "done" is mandatory' '
2668 echo feature done | test_must_fail git fast-import &&
2669 test_must_fail git fast-import --done </dev/null
2672 test_expect_success
'R: terminating "done" with trailing gibberish is ok' '
2673 git fast-import <<-\EOF &&
2678 git fast-import <<-\EOF
2680 more trailing gibberish
2684 test_expect_success
'R: terminating "done" within commit' '
2685 cat >expect <<-\EOF &&
2687 :000000 100644 OBJID OBJID A hello.c
2688 :000000 100644 OBJID OBJID A hello2.c
2690 git fast-import <<-EOF &&
2691 commit refs/heads/done-ends
2692 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2694 Commit terminated by "done" command
2696 M 100644 inline hello.c
2703 git rev-list done-ends |
2704 git diff-tree -r --stdin --root --always |
2705 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
2706 test_cmp expect actual
2709 test_expect_success
'R: die on unknown option' '
2710 cat >input <<-EOF &&
2711 option git non-existing-option
2714 test_must_fail git fast-import <input
2717 test_expect_success
'R: unknown commandline options are rejected' '\
2718 test_must_fail git fast-import --non-existing-option < /dev/null
2721 test_expect_success
'R: die on invalid option argument' '
2722 echo "option git active-branches=-5" |
2723 test_must_fail git fast-import &&
2724 echo "option git depth=" |
2725 test_must_fail git fast-import &&
2726 test_must_fail git fast-import --depth="5 elephants" </dev/null
2729 test_expect_success
'R: ignore non-git options' '
2730 cat >input <<-EOF &&
2731 option non-existing-vcs non-existing-option
2734 git fast-import <input
2737 test_expect_success
'R: corrupt lines do not mess marks file' '
2739 blob=$(echo hi | git hash-object --stdin) &&
2740 cat >expect <<-EOF &&
2745 cp expect io.marks &&
2746 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2749 test_cmp expect io.marks
2753 ## R: very large blobs
2755 test_expect_success
'R: blob bigger than threshold' '
2756 blobsize=$((2*1024*1024 + 53)) &&
2757 test-tool genrandom bar $blobsize >expect &&
2758 cat >input <<-INPUT_END &&
2759 commit refs/heads/big-file
2760 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2768 cat expect >>input &&
2769 cat >>input <<-INPUT_END &&
2773 cat expect >>input &&
2776 test_create_repo R &&
2777 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
2778 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2781 test_expect_success
'R: verify created pack' '
2784 verify_packs -v > ../verify
2788 test_expect_success
'R: verify written objects' '
2789 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2790 test_cmp_bin expect actual &&
2791 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2792 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2796 test_expect_success
'R: blob appears only once' '
2797 n=$(grep $a verify | wc -l) &&
2805 # Make sure missing spaces and EOLs after mark references
2814 # commit marks: 301, 302, 303, 304
2815 # blob marks: 403, 404, resp.
2818 # The error message when a space is missing not at the
2819 # end of the line is:
2821 # Missing space after ..
2823 # or when extra characters come after the mark at the end
2828 # or when the dataref is neither "inline " or a known SHA1,
2830 # Invalid dataref ..
2832 test_expect_success
'S: initialize for S tests' '
2835 cat >input <<-INPUT_END &&
2838 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842 M 100644 inline hello.c
2849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2854 M 100644 inline hello.c
2872 git fast-import --export-marks=marks <input
2876 # filemodify, three datarefs
2878 test_expect_success
'S: filemodify with garbage after mark must fail' '
2879 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2881 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2885 M 100644 :403x hello.c
2887 test_i18ngrep "space after mark" err
2890 # inline is misspelled; fast-import thinks it is some unknown dataref
2891 test_expect_success
'S: filemodify with garbage after inline must fail' '
2892 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2894 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2898 M 100644 inlineX hello.c
2903 test_i18ngrep "nvalid dataref" err
2906 test_expect_success
'S: filemodify with garbage after sha1 must fail' '
2907 sha1=$(grep :403 marks | cut -d\ -f2) &&
2908 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2910 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2914 M 100644 ${sha1}x hello.c
2916 test_i18ngrep "space after SHA1" err
2920 # notemodify, three ways to say dataref
2922 test_expect_success
'S: notemodify with garbage after mark dataref must fail' '
2923 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2925 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2927 commit S note dataref markref
2931 test_i18ngrep "space after mark" err
2934 test_expect_success
'S: notemodify with garbage after inline dataref must fail' '
2935 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2937 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2939 commit S note dataref inline
2946 test_i18ngrep "nvalid dataref" err
2949 test_expect_success
'S: notemodify with garbage after sha1 dataref must fail' '
2950 sha1=$(grep :202 marks | cut -d\ -f2) &&
2951 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2953 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2955 commit S note dataref sha1
2959 test_i18ngrep "space after SHA1" err
2963 # notemodify, mark in commit-ish
2965 test_expect_success
'S: notemodify with garbage after mark commit-ish must fail' '
2966 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2967 commit refs/heads/Snotes
2968 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2970 commit S note commit-ish
2974 test_i18ngrep "after mark" err
2980 test_expect_success
'S: from with garbage after mark must fail' '
2982 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2983 commit refs/heads/S2
2985 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2990 M 100644 :403 hello.c
2994 # go create the commit, need it for merge test
2995 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2996 commit refs/heads/S2
2998 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3003 M 100644 :403 hello.c
3006 # now evaluate the error
3007 test_i18ngrep "after mark" err
3014 test_expect_success
'S: merge with garbage after mark must fail' '
3015 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3018 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3024 M 100644 :403 hello.c
3026 test_i18ngrep "after mark" err
3032 test_expect_success
'S: tag with garbage after mark must fail' '
3033 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3036 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3041 test_i18ngrep "after mark" err
3047 test_expect_success
'S: cat-blob with garbage after mark must fail' '
3048 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3051 test_i18ngrep "after mark" err
3057 test_expect_success
'S: ls with garbage after mark must fail' '
3058 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3061 test_i18ngrep "space after mark" err
3064 test_expect_success
'S: ls with garbage after sha1 must fail' '
3065 sha1=$(grep :302 marks | cut -d\ -f2) &&
3066 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3069 test_i18ngrep "space after tree-ish" err
3075 # Setup is carried over from series S.
3077 test_expect_success
'T: ls root tree' '
3078 sed -e "s/Z\$//" >expect <<-EOF &&
3079 040000 tree $(git rev-parse S^{tree}) Z
3081 sha1=$(git rev-parse --verify S) &&
3082 git fast-import --import-marks=marks <<-EOF >actual &&
3085 test_cmp expect actual
3088 test_expect_success
'T: delete branch' '
3089 git branch to-delete &&
3090 git fast-import <<-EOF &&
3091 reset refs/heads/to-delete
3094 test_must_fail git rev-parse --verify refs/heads/to-delete
3097 test_expect_success
'T: empty reset doesnt delete branch' '
3098 git branch not-to-delete &&
3099 git fast-import <<-EOF &&
3100 reset refs/heads/not-to-delete
3103 git rev-parse --verify refs/heads/not-to-delete
3107 ### series U (filedelete)
3110 test_expect_success
'U: initialize for U tests' '
3111 cat >input <<-INPUT_END &&
3113 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3117 M 100644 inline hello.c
3121 M 100644 inline good/night.txt
3125 M 100644 inline good/bye.txt
3132 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3133 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3134 f9id=$(echo "au revoir" | git hash-object --stdin) &&
3135 git fast-import <input
3138 test_expect_success
'U: filedelete file succeeds' '
3139 cat >input <<-INPUT_END &&
3141 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3143 delete good/night.txt
3150 git fast-import <input
3153 test_expect_success
'U: validate file delete result' '
3154 cat >expect <<-EOF &&
3155 :100644 000000 $f8id $ZERO_OID D good/night.txt
3158 git diff-tree -M -r U^1 U >actual &&
3160 compare_diff_raw expect actual
3163 test_expect_success
'U: filedelete directory succeeds' '
3164 cat >input <<-INPUT_END &&
3166 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3175 git fast-import <input
3178 test_expect_success
'U: validate directory delete result' '
3179 cat >expect <<-EOF &&
3180 :100644 000000 $f9id $ZERO_OID D good/bye.txt
3183 git diff-tree -M -r U^1 U >actual &&
3185 compare_diff_raw expect actual
3188 test_expect_success
'U: filedelete root succeeds' '
3189 cat >input <<-INPUT_END &&
3191 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3200 git fast-import <input
3203 test_expect_success
'U: validate root delete result' '
3204 cat >expect <<-EOF &&
3205 :100644 000000 $f7id $ZERO_OID D hello.c
3208 git diff-tree -M -r U^1 U >actual &&
3210 compare_diff_raw expect actual
3214 ### series V (checkpoint)
3217 # The commands in input_file should not produce any output on the file
3218 # descriptor set with --cat-blob-fd (or stdout if unspecified).
3220 # To make sure you're observing the side effects of checkpoint *before*
3221 # fast-import terminates (and thus writes out its state), check that the
3222 # fast-import process is still running using background_import_still_running
3223 # *after* evaluating the test conditions.
3224 background_import_then_checkpoint
() {
3237 git fast-import
$options <&8 >&9 &
3240 echo >&2 "background fast-import terminated too early with exit code $?"
3241 # Un-block the read loop in the main shell process.
3246 # We don't mind if fast-import has already died by the time the test
3248 test_when_finished
"
3249 exec 8>&-; exec 9>&-;
3250 kill $sh_pid && wait $sh_pid
3251 kill $fi_pid && wait $fi_pid
3254 # Start in the background to ensure we adhere strictly to (blocking)
3255 # pipes writing sequence. We want to assume that the write below could
3256 # block, e.g. if fast-import blocks writing its own output to &9
3257 # because there is no reader on &9 yet.
3261 echo "progress checkpoint"
3264 error
=1 ;# assume the worst
3265 while read output
<&9
3267 if test "$output" = "progress checkpoint"
3271 elif test "$output" = "UNEXPECTED"
3275 # otherwise ignore cruft
3276 echo >&2 "cruft: $output"
3279 if test $error -eq 1
3285 background_import_still_running
() {
3286 if ! kill -0 "$fi_pid"
3288 echo >&2 "background fast-import terminated too early"
3293 test_expect_success PIPE
'V: checkpoint helper does not get stuck with extra output' '
3294 cat >input <<-INPUT_END &&
3300 background_import_then_checkpoint "" input &&
3301 background_import_still_running
3304 test_expect_success PIPE
'V: checkpoint updates refs after reset' '
3305 cat >input <<-\INPUT_END &&
3311 background_import_then_checkpoint "" input &&
3312 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3313 background_import_still_running
3316 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit' '
3317 cat >input <<-INPUT_END &&
3320 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3326 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3328 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3330 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3331 test_cmp marks.expected marks.actual &&
3332 background_import_still_running
3335 # Re-create the exact same commit, but on a different branch: no new object is
3336 # created in the database, but the refs and marks still need to be updated.
3337 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit (no new objects)' '
3338 cat >input <<-INPUT_END &&
3339 commit refs/heads/V2
3341 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3347 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3349 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3351 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3352 test_cmp marks.expected marks.actual &&
3353 background_import_still_running
3356 test_expect_success PIPE
'V: checkpoint updates tags after tag' '
3357 cat >input <<-INPUT_END &&
3360 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3365 background_import_then_checkpoint "" input &&
3366 git show-ref -d Vtag &&
3367 background_import_still_running
3371 ### series W (get-mark and empty orphan commits)
3374 cat >>W-input
<<-W_INPUT_END
3375 commit refs/heads/W-branch
3377 author Full Name <user@company.tld> 1000000000 +0100
3378 committer Full Name <user@company.tld> 1000000000 +0100
3380 Intentionally empty commit
3384 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with no newlines' '
3385 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3388 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with one newline' '
3389 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3392 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with ugly second newline' '
3393 # Technically, this should fail as it has too many linefeeds
3394 # according to the grammar in fast-import.txt. But, for whatever
3395 # reason, it works. Since using the correct number of newlines
3396 # does not work with older (pre-2.22) versions of git, allow apps
3397 # that used this second-newline workaround to keep working by
3398 # checking it with this test...
3399 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3402 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with erroneous third newline' '
3403 # ...but do NOT allow more empty lines than that (see previous test).
3404 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3408 ### series X (other new features)
3411 test_expect_success
'X: handling encoding' '
3413 cat >input <<-INPUT_END &&
3414 commit refs/heads/encoding
3415 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3420 printf "Pi: \360\nCOMMIT\n" >>input &&
3422 git fast-import <input &&
3423 git cat-file -p encoding | grep $(printf "\360") &&
3424 git log -1 --format=%B encoding | grep $(printf "\317\200")
3428 ### series Y (submodules and hash algorithms)
3431 cat >Y-sub-input
<<\Y_INPUT_END
3437 reset refs
/heads
/main
3438 commit refs
/heads
/main
3440 author Full Name
<user@company.tld
> 1000000000 +0100
3441 committer Full Name
<user@company.tld
> 1000000000 +0100
3443 Test submodule commit
1
3452 commit refs
/heads
/main
3454 author Full Name
<user@company.tld
> 1000000001 +0100
3455 committer Full Name
<user@company.tld
> 1000000001 +0100
3457 Test submodule commit
2
3462 # Note that the submodule object IDs are intentionally not translated.
3463 cat >Y-main-input
<<\Y_INPUT_END
3469 reset refs
/heads
/main
3470 commit refs
/heads
/main
3472 author Full Name
<user@company.tld
> 2000000000 +0100
3473 committer Full Name
<user@company.tld
> 2000000000 +0100
3483 url
= https
://void.example.com
/main.git
3485 commit refs
/heads
/main
3487 author Full Name
<user@company.tld
> 2000000001 +0100
3488 committer Full Name
<user@company.tld
> 2000000001 +0100
3492 M
100644 :3 .gitmodules
3493 M
160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3501 commit refs
/heads
/main
3503 author Full Name
<user@company.tld
> 2000000002 +0100
3504 committer Full Name
<user@company.tld
> 2000000002 +0100
3509 M
160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3512 cat >Y-marks
<<\Y_INPUT_END
3513 :2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3514 :4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3517 test_expect_success
'Y: setup' '
3518 test_oid_cache <<-EOF
3519 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3520 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
3524 test_expect_success
'Y: rewrite submodules' '
3529 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3530 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3531 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
3532 test "$(git rev-parse main)" = "$(test_oid Ymain)"