Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t9300-fast-import.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t9300-fast-import.sh` 4038 lines ยท 92479 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2007 Shawn Pearce 4 # 5 6 test_description='test git fast-import utility' 7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 9 10 . ./test-lib.sh 11 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash 12 13 verify_packs () { 14 for p in .git/objects/pack/*.pack 15 do 16 git verify-pack "$@" "$p" || return 17 done 18 } 19 20 file2_data='file2 21 second line of EOF' 22 23 file3_data='EOF 24 in 3rd file 25 END' 26 27 file4_data=abcd 28 file4_len=4 29 30 file5_data='an inline file. 31 we should see it later.' 32 33 file6_data='#!/bin/sh 34 echo "$@"' 35 36 ### 37 ### series A 38 ### 39 40 test_expect_success 'empty stream succeeds' ' 41 git config fastimport.unpackLimit 0 && 42 git fast-import input <<-INPUT_END && 52 blob 53 mark :2 54 data < $GIT_COMMITTER_DATE 71 data <expect <<-EOF && 132 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 134 135 initial 136 EOF 137 git cat-file commit main | sed 1d >actual && 138 test_cmp expect actual 139 ' 140 141 test_expect_success 'A: verify tree' ' 142 cat >expect <<-EOF && 143 100644 blob file2 144 100644 blob file3 145 100755 blob file4 146 EOF 147 git cat-file -p main^{tree} | sed "s/ [0-9a-f]* / /" >actual && 148 test_cmp expect actual 149 ' 150 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 155 ' 156 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 161 ' 162 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 167 ' 168 169 test_expect_success 'A: verify tag/series-A' ' 170 cat >expect <<-EOF && 171 object $(git rev-parse refs/heads/main) 172 type commit 173 tag series-A 174 175 An annotated tag without a tagger 176 EOF 177 git cat-file tag tags/series-A >actual && 178 test_cmp expect actual 179 ' 180 181 test_expect_success 'A: verify tag/series-A-blob' ' 182 cat >expect <<-EOF && 183 object $(git rev-parse refs/heads/main:file3) 184 type blob 185 tag series-A-blob 186 187 An annotated tag that annotates a blob. 188 EOF 189 git cat-file tag tags/series-A-blob >actual && 190 test_cmp expect actual 191 ' 192 193 test_expect_success 'A: verify tag deletion is successful' ' 194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted 195 ' 196 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) 206 EOF 207 test_cmp expect marks.out 208 ' 209 210 test_expect_success 'A: verify marks import' ' 211 git fast-import \ 212 --import-marks=marks.out \ 213 --export-marks=marks.new \ 214 input <<-INPUT_END && 222 tag series-A-blob-2 223 from $(git rev-parse refs/heads/main:file3) 224 data < 0 +0000 236 data 0 237 M 644 :6 new_blob 238 #pretend we got sha1 from fast-import 239 ls "new_blob" 240 241 tag series-A-blob-3 242 from $new_blob 243 data <expect <<-EOF && 249 object $(git rev-parse refs/heads/main:file3) 250 type blob 251 tag series-A-blob-2 252 253 Tag blob by sha1. 254 object $new_blob 255 type blob 256 tag series-A-blob-3 257 258 Tag new_blob. 259 EOF 260 261 git fast-import actual && 263 git cat-file tag tags/series-A-blob-3 >>actual && 264 test_cmp expect actual 265 ' 266 267 test_expect_success 'A: verify marks import does not crash' ' 268 test_tick && 269 cat >input <<-INPUT_END && 270 commit refs/heads/verify--import-marks 271 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 272 data <expect <<-EOF && 292 :000000 100755 $ZERO_OID $copy A copy-of-file2 293 EOF 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) 298 ' 299 300 test_expect_success 'A: export marks with large values' ' 301 test_tick && 302 mt=$(git hash-object --stdin < /dev/null) && 303 >input.blob && 304 >marks.exp && 305 >tree.exp && 306 307 cat >input.commit <<-EOF && 308 commit refs/heads/verify--dump-marks 309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 310 data <>input.blob <<-EOF && 319 blob 320 mark :$l 321 data 0 322 blob 323 mark :$m 324 data 0 325 blob 326 mark :$n 327 data 0 328 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 && 332 333 echo ":$l $mt" >>marks.exp && 334 echo ":$m $mt" >>marks.exp && 335 echo ":$n $mt" >>marks.exp && 336 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 && 340 341 l=$(($l + $l)) && 342 m=$(($m + $m)) && 343 n=$(($l + $n)) && 344 345 i=$((1 + $i)) || return 1 346 done && 347 348 sort tree.exp > tree.exp_s && 349 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 354 ' 355 356 ### 357 ### series B 358 ### 359 360 test_expect_success 'B: fail on invalid blob sha1' ' 361 test_tick && 362 cat >input <<-INPUT_END && 363 commit refs/heads/branch 364 mark :1 365 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 366 data <input <<-INPUT_END && 381 commit TEMP_TAG 382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 383 data <input <<-INPUT_END && 399 commit refs/heads/empty-committer-1 400 committer <> $GIT_COMMITTER_DATE 401 data <input <<-INPUT_END && 416 commit refs/heads/invalid-timezone 417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1234567890` +051800 418 data <input <<-INPUT_END && 429 commit refs/heads/invalid-timezone 430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1234567890` +051800 431 data <out && 439 test_grep "`1234567890` [+]051800" out 440 ' 441 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 $GIT_COMMITTER_DATE 446 data <input <<-INPUT_END && 461 commit refs/heads/invalid-committer 462 committer Name email> $GIT_COMMITTER_DATE 463 data <input <<-INPUT_END && 474 commit refs/heads/invalid-committer 475 committer Name $GIT_COMMITTER_DATE 476 data <input <<-INPUT_END && 487 commit refs/heads/invalid-committer 488 committer Name > $GIT_COMMITTER_DATE 489 data <input <<-INPUT_END && 500 commit refs/heads/invalid-committer 501 committer Name input <<-INPUT_END && 513 commit refs/heads/invalid-committer 514 committer Name $GIT_COMMITTER_DATE 515 data <input <<-INPUT_END && 526 blob 527 mark :1 528 data < $GIT_COMMITTER_DATE 534 data <input <<-INPUT_END && 546 blob 547 mark :1 548 data < $GIT_COMMITTER_DATE 554 data < $GIT_COMMITTER_DATE 561 data <input <<-INPUT_END && 573 blob 574 mark :1 575 data < $GIT_COMMITTER_DATE 581 data <input <<-INPUT_END && 593 blob 594 mark :1 595 data < $GIT_COMMITTER_DATE 601 data <input <<-INPUT_END && 613 blob 614 mark :1 615 data < $GIT_COMMITTER_DATE 621 data <input <<-INPUT_END && 641 commit refs/heads/branch 642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 643 data <expect <<-EOF && 669 parent $(git rev-parse --verify main^0) 670 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 672 673 second 674 EOF 675 676 git cat-file commit branch | sed 1d >actual && 677 test_cmp expect actual 678 ' 679 680 test_expect_success 'C: validate rename result' ' 681 zero=$ZERO_OID && 682 cat >expect <<-EOF && 683 :000000 100755 $zero $newf A file2/newf 684 :100644 100644 $oldf $oldf R100 file2 file2/oldf 685 :100644 000000 $thrf $zero D file3 686 EOF 687 git diff-tree -M -r main branch >actual && 688 compare_diff_raw expect actual 689 ' 690 691 ### 692 ### series D 693 ### 694 695 test_expect_success 'D: inline data in commit' ' 696 test_tick && 697 cat >input <<-INPUT_END && 698 commit refs/heads/branch 699 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 700 data <expect <<-EOF && 729 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh 730 :000000 100644 $ZERO_OID $f5id A newdir/interesting 731 EOF 732 git diff-tree -M -r branch^ branch >actual && 733 compare_diff_raw expect actual 734 ' 735 736 test_expect_success 'D: verify file5' ' 737 echo "$file5_data" >expect && 738 git cat-file blob branch:newdir/interesting >actual && 739 test_cmp expect actual 740 ' 741 742 test_expect_success 'D: verify file6' ' 743 echo "$file6_data" >expect && 744 git cat-file blob branch:newdir/exec.sh >actual && 745 test_cmp expect actual 746 ' 747 748 ### 749 ### series E 750 ### 751 752 test_expect_success 'E: rfc2822 date, --date-format=raw' ' 753 cat >input <<-INPUT_END && 754 commit refs/heads/branch 755 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500 756 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500 757 data <expect <<-EOF && 777 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> `1170778938` -0500 778 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1170783302` -0500 779 780 RFC 2822 type date 781 EOF 782 git cat-file commit branch | sed 1,2d >actual && 783 test_cmp expect actual 784 ' 785 786 ### 787 ### series F 788 ### 789 790 test_expect_success 'F: non-fast-forward update skips' ' 791 old_branch=$(git rev-parse --verify branch^0) && 792 test_tick && 793 cat >input <<-INPUT_END && 794 commit refs/heads/branch 795 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 796 data <expect <<-EOF && 818 tree $(git rev-parse branch~1^{tree}) 819 parent $(git rev-parse branch~1) 820 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 821 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 822 823 losing things already? 824 EOF 825 git cat-file commit other >actual && 826 test_cmp expect actual 827 ' 828 829 ### 830 ### series G 831 ### 832 833 test_expect_success 'G: non-fast-forward update forced' ' 834 old_branch=$(git rev-parse --verify branch^0) && 835 test_tick && 836 cat >input <<-INPUT_END && 837 commit refs/heads/branch 838 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 839 data <input <<-INPUT_END && 865 commit refs/heads/H 866 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 867 data <expect <<-EOF && 895 :100755 000000 $newf $zero D file2/newf 896 :100644 000000 $oldf $zero D file2/oldf 897 :100755 000000 $f4id $zero D file4 898 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo 899 :100755 000000 $f6id $zero D newdir/exec.sh 900 EOF 901 git diff-tree -M -r H^ H >actual && 902 compare_diff_raw expect actual 903 ' 904 905 test_expect_success 'H: verify file' ' 906 echo "$file5_data" >expect && 907 git cat-file blob H:h/e/l/lo >actual && 908 test_cmp expect actual 909 ' 910 911 ### 912 ### series I 913 ### 914 915 test_expect_success 'I: export-pack-edges option forbidden by default' ' 916 echo "option git export-pack-edges=edges.list" >input && 917 test_must_fail git fast-import err && 918 test_grep "option ${SQ}export-pack-edges${SQ} forbidden in input without --allow-unsafe-features" err 919 ' 920 921 test_expect_success 'I: export-pack-edges' ' 922 test_when_finished "rm edges.list" && 923 cat >input <<-INPUT_END && 924 commit refs/heads/export-boundary 925 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 926 data <expect <<-EOF && 935 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary) 936 EOF 937 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual && 938 test_cmp expect actual 939 ' 940 941 test_expect_success 'I: export-pack-edges via stdin' ' 942 test_when_finished "rm edges.list" && 943 cat >input <<-INPUT_END && 944 option git export-pack-edges=edges.list 945 commit refs/heads/export-boundary-2 946 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 947 data <expect <<-EOF && 956 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary-2) 957 EOF 958 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual && 959 test_cmp expect actual 960 ' 961 962 ### 963 ### series J 964 ### 965 966 test_expect_success 'J: reset existing branch creates empty commit' ' 967 cat >input <<-INPUT_END && 968 commit refs/heads/J 969 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 970 data < $GIT_COMMITTER_DATE 980 data <input <<-INPUT_END && 994 reset refs/heads/J2 995 996 tag wrong_tag 997 from refs/heads/J2 998 data <input <<-INPUT_END && 1011 commit refs/heads/K 1012 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1013 data < $GIT_COMMITTER_DATE 1021 data <input <<-INPUT_END && 1041 blob 1042 mark :1 1043 data < $GIT_COMMITTER_DATE 1055 data < $GIT_COMMITTER_DATE 1065 data <expect <<-EXPECT_END && 1075 :100644 100644 M b. 1076 :040000 040000 M b 1077 :100644 100644 M ba 1078 EXPECT_END 1079 1080 git -c core.protectNTFS=false fast-import output && 1082 cut -d" " -f1,2,5 output >actual && 1083 test_cmp expect actual 1084 ' 1085 1086 test_expect_success 'L: nested tree copy does not corrupt deltas' ' 1087 cat >input <<-INPUT_END && 1088 blob 1089 mark :1 1090 data < `1112912473` -0700 1096 data < `1112912473` -0700 1105 data <expect <<-\EOF && 1114 g/b/f 1115 g/b/h 1116 EOF 1117 1118 test_when_finished "git update-ref -d refs/heads/L2" && 1119 git fast-import tmp && 1121 cut -f 2 actual && 1122 test_cmp expect actual && 1123 git fsck $(git rev-parse L2) 1124 ' 1125 1126 ### 1127 ### series M 1128 ### 1129 1130 test_expect_success 'M: rename file in same subdirectory' ' 1131 test_tick && 1132 cat >input <<-INPUT_END && 1133 commit refs/heads/M1 1134 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1135 data <expect <<-EOF && 1145 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f 1146 EOF 1147 git fast-import actual && 1149 compare_diff_raw expect actual 1150 ' 1151 1152 test_expect_success 'M: rename file to new subdirectory' ' 1153 cat >input <<-INPUT_END && 1154 commit refs/heads/M2 1155 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1156 data <expect <<-EOF && 1166 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you 1167 EOF 1168 git fast-import actual && 1170 compare_diff_raw expect actual 1171 ' 1172 1173 test_expect_success 'M: rename subdirectory to new subdirectory' ' 1174 cat >input <<-INPUT_END && 1175 commit refs/heads/M3 1176 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1177 data <expect <<-EOF && 1187 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you 1188 EOF 1189 git fast-import actual && 1191 compare_diff_raw expect actual 1192 ' 1193 1194 for root in '""' '' 1195 do 1196 test_expect_success "M: rename root ($root) to subdirectory" ' 1197 cat >input <<-INPUT_END && 1198 commit refs/heads/M4 1199 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1200 data <expect <<-EOF && 1210 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf 1211 :100755 100755 $f4id $f4id R100 file4 sub/file4 1212 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you 1213 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh 1214 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting 1215 EOF 1216 git fast-import actual && 1218 compare_diff_raw expect actual 1219 ' 1220 done 1221 1222 ### 1223 ### series N 1224 ### 1225 1226 test_expect_success 'N: copy file in same subdirectory' ' 1227 test_tick && 1228 cat >input <<-INPUT_END && 1229 commit refs/heads/N1 1230 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1231 data <expect <<-EOF && 1241 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f 1242 EOF 1243 git fast-import actual && 1245 compare_diff_raw expect actual 1246 ' 1247 1248 test_expect_success 'N: copy then modify subdirectory' ' 1249 cat >input <<-INPUT_END && 1250 commit refs/heads/N2 1251 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1252 data < $GIT_COMMITTER_DATE 1261 data <expect <<-EOF && 1273 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 1274 :100755 100755 $newf $newf C100 file2/newf file3/newf 1275 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1276 EOF 1277 git fast-import actual && 1279 compare_diff_raw expect actual 1280 ' 1281 1282 test_expect_success 'N: copy dirty subdirectory' ' 1283 cat >input <<-INPUT_END && 1284 commit refs/heads/N3 1285 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1286 data <expect <<-EOF && 1307 :100755 100755 $newf $newf C100 file2/newf file3/newf 1308 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1309 EOF 1310 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1311 cat >input <<-INPUT_END && 1312 commit refs/heads/N4 1313 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1314 data <actual && 1323 compare_diff_raw expect actual 1324 ' 1325 1326 test_expect_success PIPE 'N: read and copy directory' ' 1327 cat >expect <<-EOF && 1328 :100755 100755 $newf $newf C100 file2/newf file3/newf 1329 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1330 EOF 1331 git update-ref -d refs/heads/N4 && 1332 rm -f backflow && 1333 mkfifo backflow && 1334 ( 1335 exec $GIT_COMMITTER_DATE 1339 data <backflow && 1350 git diff-tree -C --find-copies-harder -r N4^ N4 >actual && 1351 compare_diff_raw expect actual 1352 ' 1353 1354 test_expect_success PIPE 'N: empty directory reads as missing' ' 1355 cat <<-\EOF >expect && 1356 OBJNAME 1357 :000000 100644 OBJNAME OBJNAME A unrelated 1358 EOF 1359 echo "missing src" >expect.response && 1360 git update-ref -d refs/heads/read-empty && 1361 rm -f backflow && 1362 mkfifo backflow && 1363 ( 1364 exec $GIT_COMMITTER_DATE 1368 data <response && 1384 cat <<-\EOF 1385 D dst1 1386 D dst2 1387 EOF 1388 ) | 1389 git fast-import --cat-blob-fd=3 3>backflow && 1390 test_cmp expect.response response && 1391 git rev-list read-empty | 1392 git diff-tree -r --root --stdin | 1393 sed "s/$OID_REGEX/OBJNAME/g" >actual && 1394 test_cmp expect actual 1395 ' 1396 1397 for root in '""' '' 1398 do 1399 test_expect_success "N: copy root ($root) by tree hash" ' 1400 cat >expect <<-EOF && 1401 :100755 000000 $newf $zero D file3/newf 1402 :100644 000000 $oldf $zero D file3/oldf 1403 EOF 1404 root_tree=$(git rev-parse refs/heads/branch^0^{tree}) && 1405 cat >input <<-INPUT_END && 1406 commit refs/heads/N6 1407 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1408 data <actual && 1417 compare_diff_raw expect actual 1418 ' 1419 1420 test_expect_success "N: copy root ($root) by path" ' 1421 cat >expect <<-EOF && 1422 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf 1423 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf 1424 :100755 100755 $f4id $f4id C100 file4 oldroot/file4 1425 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh 1426 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting 1427 EOF 1428 cat >input <<-INPUT_END && 1429 commit refs/heads/N-copy-root-path 1430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1431 data <actual && 1440 compare_diff_raw expect actual 1441 ' 1442 done 1443 1444 test_expect_success 'N: delete directory by copying' ' 1445 cat >expect <<-\EOF && 1446 OBJID 1447 :100644 000000 OBJID OBJID D foo/bar/qux 1448 OBJID 1449 :000000 100644 OBJID OBJID A foo/bar/baz 1450 :000000 100644 OBJID OBJID A foo/bar/qux 1451 EOF 1452 empty_tree=$(git mktree input <<-INPUT_END && 1454 commit refs/heads/N-delete 1455 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1456 data < $GIT_COMMITTER_DATE 1473 data <actual && 1483 test_cmp expect actual 1484 ' 1485 1486 test_expect_success 'N: modify copied tree' ' 1487 cat >expect <<-EOF && 1488 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 1489 :100755 100755 $newf $newf C100 file2/newf file3/newf 1490 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1491 EOF 1492 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1493 cat >input <<-INPUT_END && 1494 commit refs/heads/N5 1495 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1496 data < $GIT_COMMITTER_DATE 1505 data <actual && 1516 compare_diff_raw expect actual 1517 ' 1518 1519 test_expect_success 'N: reject foo/ syntax' ' 1520 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1521 test_must_fail git fast-import <<-INPUT_END 1522 commit refs/heads/N5B 1523 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1524 data < $GIT_COMMITTER_DATE 1537 data < $GIT_COMMITTER_DATE 1550 data < $GIT_COMMITTER_DATE 1563 data <expect.foo && 1576 echo hello >expect.bar && 1577 git fast-import <<-SETUP_END && 1578 commit refs/heads/N7 1579 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1580 data < $GIT_COMMITTER_DATE 1595 data <actual.foo && 1606 git show N8:foo/bar >actual.bar && 1607 test_cmp expect.foo actual.foo && 1608 test_cmp expect.bar actual.bar 1609 ' 1610 1611 test_expect_success "N: extract subtree to the root ($root)" ' 1612 branch=$(git rev-parse --verify refs/heads/branch^{tree}) && 1613 cat >input <<-INPUT_END && 1614 commit refs/heads/N9 1615 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1616 data <expect.baz && 1629 echo hello, world >expect.qux && 1630 git fast-import <<-SETUP_END && 1631 commit refs/heads/N10 1632 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1633 data < $GIT_COMMITTER_DATE 1648 data <actual.baz && 1661 git show N11:bar/qux >actual.qux && 1662 git show N11:bar/quux >actual.quux && 1663 test_cmp expect.baz actual.baz && 1664 test_cmp expect.qux actual.qux && 1665 test_cmp expect.qux actual.quux 1666 ' 1667 done 1668 1669 ### 1670 ### series O 1671 ### 1672 1673 test_expect_success 'O: comments are all skipped' ' 1674 cat >input <<-INPUT_END && 1675 #we will 1676 commit refs/heads/O1 1677 # -- ignore all of this text 1678 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1679 data <input <<-INPUT_END && 1710 commit refs/heads/O2 1711 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1712 data <input <<-INPUT_END && 1735 commit refs/heads/O3 1736 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1737 data < $GIT_COMMITTER_DATE 1742 data < $GIT_COMMITTER_DATE 1749 data < $GIT_COMMITTER_DATE 1755 data <expect <<-INPUT_END && 1765 string 1766 of 1767 empty 1768 commits 1769 INPUT_END 1770 1771 git fast-import packlist && 1773 ls -la .git/objects/pack/pack-*.pack >idxlist && 1774 test_line_count = 4 idxlist && 1775 test_line_count = 4 packlist && 1776 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) && 1777 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual && 1778 test_cmp expect actual 1779 ' 1780 1781 test_expect_success 'O: progress outputs as requested by input' ' 1782 cat >input <<-INPUT_END && 1783 commit refs/heads/O4 1784 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1785 data < $GIT_COMMITTER_DATE 1790 data < $GIT_COMMITTER_DATE 1796 data < $GIT_COMMITTER_DATE 1802 data <actual && 1808 grep "progress " expect && 1809 test_cmp expect actual 1810 ' 1811 1812 ### 1813 ### series P (gitlinks) 1814 ### 1815 1816 test_expect_success 'P: superproject & submodule mix' ' 1817 cat >input <<-INPUT_END && 1818 blob 1819 mark :1 1820 data 10 1821 test file 1822 1823 reset refs/heads/sub 1824 commit refs/heads/sub 1825 mark :2 1826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1827 data 12 1828 sub_initial 1829 M 100644 :1 file 1830 1831 blob 1832 mark :3 1833 data < $GIT_COMMITTER_DATE 1842 data 8 1843 initial 1844 from refs/heads/main 1845 M 100644 :3 .gitmodules 1846 M 160000 :2 sub 1847 1848 blob 1849 mark :5 1850 data 20 1851 test file 1852 more data 1853 1854 commit refs/heads/sub 1855 mark :6 1856 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1857 data 11 1858 sub_second 1859 from :2 1860 M 100644 :5 file 1861 1862 commit refs/heads/subuse1 1863 mark :7 1864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1865 data 7 1866 second 1867 from :4 1868 M 160000 :6 sub 1869 1870 INPUT_END 1871 1872 git fast-import input <<-INPUT_END && 1891 blob 1892 mark :1 1893 data < $GIT_COMMITTER_DATE 1902 data 8 1903 initial 1904 from refs/heads/main 1905 M 100644 :1 .gitmodules 1906 M 160000 $SUBPREV sub 1907 1908 commit refs/heads/subuse2 1909 mark :3 1910 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1911 data 7 1912 second 1913 from :2 1914 M 160000 $SUBLAST sub 1915 1916 INPUT_END 1917 1918 git branch -D sub && 1919 git gc --prune=now && 1920 git fast-import input <<-INPUT_END && 1927 commit refs/heads/subuse3 1928 mark :1 1929 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1930 data <input <<-INPUT_END && 1948 blob 1949 mark :1 1950 data < $GIT_COMMITTER_DATE 1957 data <input <<-INPUT_END && 1983 blob 1984 mark :2 1985 data < $GIT_COMMITTER_DATE 1992 data < $GIT_COMMITTER_DATE 2005 data < $GIT_COMMITTER_DATE 2014 data < $GIT_COMMITTER_DATE 2043 data < $GIT_COMMITTER_DATE 2057 data < $GIT_COMMITTER_DATE 2069 data < $GIT_COMMITTER_DATE 2081 data <expect <<-EOF && 2107 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2109 2110 first (:3) 2111 EOF 2112 git cat-file commit notes-test~2 | sed 1d >actual && 2113 test_cmp expect actual 2114 ' 2115 2116 test_expect_success 'Q: verify second commit' ' 2117 cat >expect <<-EOF && 2118 parent $commit1 2119 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2120 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2121 2122 second (:5) 2123 EOF 2124 git cat-file commit notes-test^ | sed 1d >actual && 2125 test_cmp expect actual 2126 ' 2127 2128 test_expect_success 'Q: verify third commit' ' 2129 cat >expect <<-EOF && 2130 parent $commit2 2131 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2132 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2133 2134 third (:6) 2135 EOF 2136 git cat-file commit notes-test | sed 1d >actual && 2137 test_cmp expect actual 2138 ' 2139 2140 test_expect_success 'Q: verify first notes commit' ' 2141 cat >expect <<-EOF && 2142 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2143 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2144 2145 notes (:9) 2146 EOF 2147 git cat-file commit refs/notes/foobar~2 | sed 1d >actual && 2148 test_cmp expect actual 2149 ' 2150 2151 test_expect_success 'Q: verify first notes tree' ' 2152 sort >expect <<-EOF && 2153 100644 blob $commit1 2154 100644 blob $commit2 2155 100644 blob $commit3 2156 EOF 2157 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2158 test_cmp expect actual 2159 ' 2160 2161 test_expect_success 'Q: verify first note for first commit' ' 2162 echo "$note1_data" >expect && 2163 git cat-file blob refs/notes/foobar~2:$commit1 >actual && 2164 test_cmp expect actual 2165 ' 2166 2167 test_expect_success 'Q: verify first note for second commit' ' 2168 echo "$note2_data" >expect && 2169 git cat-file blob refs/notes/foobar~2:$commit2 >actual && 2170 test_cmp expect actual 2171 ' 2172 2173 test_expect_success 'Q: verify first note for third commit' ' 2174 echo "$note3_data" >expect && 2175 git cat-file blob refs/notes/foobar~2:$commit3 >actual && 2176 test_cmp expect actual 2177 ' 2178 2179 test_expect_success 'Q: verify second notes commit' ' 2180 cat >expect <<-EOF && 2181 parent $(git rev-parse --verify refs/notes/foobar~2) 2182 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2183 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2184 2185 notes (:10) 2186 EOF 2187 git cat-file commit refs/notes/foobar^ | sed 1d >actual && 2188 test_cmp expect actual 2189 ' 2190 2191 test_expect_success 'Q: verify second notes tree' ' 2192 sort >expect <<-EOF && 2193 100644 blob $commit1 2194 100644 blob $commit2 2195 100644 blob $commit3 2196 EOF 2197 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2198 test_cmp expect actual 2199 ' 2200 2201 test_expect_success 'Q: verify second note for first commit' ' 2202 echo "$note1b_data" >expect && 2203 git cat-file blob refs/notes/foobar^:$commit1 >actual && 2204 test_cmp expect actual 2205 ' 2206 2207 test_expect_success 'Q: verify first note for second commit' ' 2208 echo "$note2_data" >expect && 2209 git cat-file blob refs/notes/foobar^:$commit2 >actual && 2210 test_cmp expect actual 2211 ' 2212 2213 test_expect_success 'Q: verify first note for third commit' ' 2214 echo "$note3_data" >expect && 2215 git cat-file blob refs/notes/foobar^:$commit3 >actual && 2216 test_cmp expect actual 2217 ' 2218 2219 test_expect_success 'Q: verify third notes commit' ' 2220 cat >expect <<-EOF && 2221 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2222 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2223 2224 notes (:11) 2225 EOF 2226 git cat-file commit refs/notes/foobar2 | sed 1d >actual && 2227 test_cmp expect actual 2228 ' 2229 2230 test_expect_success 'Q: verify third notes tree' ' 2231 sort >expect <<-EOF && 2232 100644 blob $commit1 2233 EOF 2234 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2235 test_cmp expect actual 2236 ' 2237 2238 test_expect_success 'Q: verify third note for first commit' ' 2239 echo "$note1c_data" >expect && 2240 git cat-file blob refs/notes/foobar2:$commit1 >actual && 2241 test_cmp expect actual 2242 ' 2243 2244 test_expect_success 'Q: verify fourth notes commit' ' 2245 cat >expect <<-EOF && 2246 parent $(git rev-parse --verify refs/notes/foobar^) 2247 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2248 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2249 2250 notes (:12) 2251 EOF 2252 git cat-file commit refs/notes/foobar | sed 1d >actual && 2253 test_cmp expect actual 2254 ' 2255 2256 test_expect_success 'Q: verify fourth notes tree' ' 2257 sort >expect <<-EOF && 2258 100644 blob $commit2 2259 EOF 2260 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2261 test_cmp expect actual 2262 ' 2263 2264 test_expect_success 'Q: verify second note for second commit' ' 2265 echo "$note2b_data" >expect && 2266 git cat-file blob refs/notes/foobar:$commit2 >actual && 2267 test_cmp expect actual 2268 ' 2269 2270 test_expect_success 'Q: deny note on empty branch' ' 2271 cat >input <<-EOF && 2272 reset refs/heads/Q0 2273 2274 commit refs/heads/note-Q0 2275 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2276 data <input <<-EOF && 2294 feature no-such-feature-exists 2295 EOF 2296 2297 test_must_fail git fast-import input <<-EOF && 2302 feature date-format=now 2303 EOF 2304 2305 git fast-import input <<-EOF && 2310 blob 2311 data 3 2312 hi 2313 feature date-format=now 2314 EOF 2315 2316 test_must_fail git fast-import git.marks && 2321 echo "feature import-marks=git.marks" >input && 2322 test_must_fail git fast-import input && 2324 test_must_fail git fast-import git.marks && 2329 >git2.marks && 2330 cat >input <<-EOF && 2331 feature import-marks=git.marks 2332 feature import-marks=git2.marks 2333 EOF 2334 2335 test_must_fail git fast-import --allow-unsafe-features input && 2340 test_must_fail git fast-import input <<-EOF && 2345 feature export-marks=git.marks 2346 blob 2347 mark :1 2348 data 3 2349 hi 2350 2351 EOF 2352 2353 git fast-import --allow-unsafe-features input <<-\EOF && 2359 feature export-marks=feature-sub/git.marks 2360 blob 2361 mark :1 2362 data 3 2363 hi 2364 2365 EOF 2366 git fast-import --allow-unsafe-features \ 2367 --export-marks=cmdline-sub/other.marks expect <<-EOF && 2382 :1 $blob 2383 :2 $blob 2384 EOF 2385 git fast-import --export-marks=io.marks <<-\EOF && 2386 blob 2387 mark :1 2388 data 3 2389 hi 2390 2391 EOF 2392 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && 2393 blob 2394 mark :2 2395 data 3 2396 hi 2397 2398 EOF 2399 test_cmp expect io.marks 2400 ' 2401 2402 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' ' 2403 rm -f io.marks && 2404 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF 2405 blob 2406 mark :1 2407 data 3 2408 hi 2409 2410 EOF 2411 ' 2412 2413 test_expect_success 'R: --import-marks-if-exists' ' 2414 rm -f io.marks && 2415 blob=$(echo hi | git hash-object --stdin) && 2416 echo ":1 $blob" >expect && 2417 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && 2418 blob 2419 mark :1 2420 data 3 2421 hi 2422 2423 EOF 2424 test_cmp expect io.marks 2425 ' 2426 2427 test_expect_success 'R: feature import-marks-if-exists' ' 2428 rm -f io.marks && 2429 2430 git fast-import --export-marks=io.marks \ 2431 --allow-unsafe-features <<-\EOF && 2432 feature import-marks-if-exists=not_io.marks 2433 EOF 2434 test_must_be_empty io.marks && 2435 2436 blob=$(echo hi | git hash-object --stdin) && 2437 2438 echo ":1 $blob" >io.marks && 2439 echo ":1 $blob" >expect && 2440 echo ":2 $blob" >>expect && 2441 2442 git fast-import --export-marks=io.marks \ 2443 --allow-unsafe-features <<-\EOF && 2444 feature import-marks-if-exists=io.marks 2445 blob 2446 mark :2 2447 data 3 2448 hi 2449 2450 EOF 2451 test_cmp expect io.marks && 2452 2453 echo ":3 $blob" >>expect && 2454 2455 git fast-import --import-marks=io.marks \ 2456 --export-marks=io.marks \ 2457 --allow-unsafe-features <<-\EOF && 2458 feature import-marks-if-exists=not_io.marks 2459 blob 2460 mark :3 2461 data 3 2462 hi 2463 2464 EOF 2465 test_cmp expect io.marks && 2466 2467 git fast-import --import-marks-if-exists=not_io.marks \ 2468 --export-marks=io.marks \ 2469 --allow-unsafe-features <<-\EOF && 2470 feature import-marks-if-exists=io.marks 2471 EOF 2472 test_must_be_empty io.marks 2473 ' 2474 2475 test_expect_success 'R: import to output marks works without any content' ' 2476 cat >input <<-EOF && 2477 feature import-marks=marks.out 2478 feature export-marks=marks.new 2479 EOF 2480 2481 git fast-import --allow-unsafe-features input <<-EOF && 2487 feature import-marks=nonexistent.marks 2488 feature export-marks=marks.new 2489 EOF 2490 2491 git fast-import --import-marks=marks.out --allow-unsafe-features input <<-EOF && 2498 feature import-marks=nonexistent.marks 2499 feature export-marks=combined.marks 2500 EOF 2501 2502 head -n2 marks.out > one.marks && 2503 tail -n +3 marks.out > two.marks && 2504 git fast-import --import-marks=one.marks --import-marks=two.marks \ 2505 --allow-unsafe-features input <<-EOF && 2511 feature relative-marks 2512 feature import-marks=relative.in 2513 feature export-marks=relative.out 2514 EOF 2515 2516 mkdir -p .git/info/fast-import/ && 2517 cp marks.new .git/info/fast-import/relative.in && 2518 git fast-import --allow-unsafe-features input <<-EOF && 2524 feature relative-marks 2525 feature import-marks=relative.in 2526 feature no-relative-marks 2527 feature export-marks=non-relative.out 2528 EOF 2529 2530 git fast-import --allow-unsafe-features expect <<-EOF && 2551 ${blob} blob 11 2552 yes it can 2553 2554 EOF 2555 echo "cat-blob $blob" | 2556 git fast-import --cat-blob-fd=6 6>actual && 2557 test_cmp expect actual 2558 ' 2559 2560 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' ' 2561 echo hello >greeting && 2562 blob=$(git hash-object -w greeting) && 2563 cat >expect <<-EOF && 2564 ${blob} blob 6 2565 hello 2566 2567 EOF 2568 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && 2569 cat-blob $blob 2570 EOF 2571 test_cmp expect actual.3 && 2572 test_must_be_empty actual.1 && 2573 git fast-import 3>actual.3 >actual.1 <<-EOF && 2574 option cat-blob-fd=3 2575 cat-blob $blob 2576 EOF 2577 test_must_be_empty actual.3 && 2578 test_cmp expect actual.1 2579 ' 2580 2581 test_expect_success !MINGW 'R: print mark for new blob' ' 2582 echo "effluentish" | git hash-object --stdin >expect && 2583 git fast-import --cat-blob-fd=6 6>actual <<-\EOF && 2584 blob 2585 mark :1 2586 data <expect <<-EOF && 2597 ${blob} blob 12 2598 yep yep yep 2599 2600 EOF 2601 git fast-import --cat-blob-fd=6 6>actual <<-\EOF && 2602 blob 2603 mark :1 2604 data <expect <<-EOF && 2615 ${blob} blob 25 2616 a new blob named by sha1 2617 2618 EOF 2619 git fast-import --cat-blob-fd=6 6>actual <<-EOF && 2620 blob 2621 data <big && 2632 for i in 1 2 3 2633 do 2634 cat big big big big >bigger && 2635 cat bigger bigger bigger bigger >big || 2636 exit 2637 done 2638 ) 2639 ' 2640 2641 test_expect_success 'R: print two blobs to stdout' ' 2642 blob1=$(git hash-object big) && 2643 blob1_len=$(wc -c expect && 2655 { 2656 cat <<-\END_PART1 && 2657 blob 2658 mark :1 2659 data <actual && 2674 test_cmp expect actual 2675 ' 2676 2677 test_expect_success PIPE 'R: copy using cat-file' ' 2678 expect_id=$(git hash-object big) && 2679 expect_len=$(wc -c expect.response && 2681 2682 rm -f blobs && 2683 2684 mkfifo blobs && 2685 ( 2686 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && 2687 cat <<-\EOF && 2688 feature cat-blob 2689 blob 2690 mark :1 2691 data <response && 2701 test_copy_bytes $size >blob <&3 && 2702 read newline <&3 && 2703 2704 cat <<-EOF && 2705 commit refs/heads/copied 2706 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2707 data <blobs && 2717 git show copied:file3 >actual && 2718 test_cmp expect.response response && 2719 test_cmp big actual 2720 ' 2721 2722 test_expect_success PIPE 'R: print blob mid-commit' ' 2723 rm -f blobs && 2724 echo "A blob from _before_ the commit." >expect && 2725 mkfifo blobs && 2726 ( 2727 exec 3 $GIT_COMMITTER_DATE 2737 data <actual <&3 && 2745 read newline <&3 && 2746 2747 echo 2748 ) | 2749 git fast-import --cat-blob-fd=3 3>blobs && 2750 test_cmp expect actual 2751 ' 2752 2753 test_expect_success PIPE 'R: print staged blob within commit' ' 2754 rm -f blobs && 2755 echo "A blob from _within_ the commit." >expect && 2756 mkfifo blobs && 2757 ( 2758 exec 3 $GIT_COMMITTER_DATE 2763 data <actual <&3 && 2780 read newline <&3 && 2781 2782 echo deleteall 2783 ) | 2784 git fast-import --cat-blob-fd=3 3>blobs && 2785 test_cmp expect actual 2786 ' 2787 2788 test_expect_success 'R: quiet option results in no stats being output' ' 2789 cat >input <<-EOF && 2790 option git quiet 2791 blob 2792 data 3 2793 hi 2794 2795 EOF 2796 2797 git fast-import 2>output expect <<-\EOF && 2820 OBJID 2821 :000000 100644 OBJID OBJID A hello.c 2822 :000000 100644 OBJID OBJID A hello2.c 2823 EOF 2824 git fast-import <<-EOF && 2825 commit refs/heads/done-ends 2826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2827 data <actual && 2840 test_cmp expect actual 2841 ' 2842 2843 test_expect_success 'R: die on unknown option' ' 2844 cat >input <<-EOF && 2845 option git non-existing-option 2846 EOF 2847 2848 test_must_fail git fast-import input <<-EOF && 2872 option non-existing-vcs non-existing-option 2873 EOF 2874 2875 git fast-import expect <<-EOF && 2882 :3 $ZERO_OID 2883 :1 $blob 2884 :2 $blob 2885 EOF 2886 cp expect io.marks && 2887 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && 2888 2889 EOF 2890 test_cmp expect io.marks 2891 ' 2892 2893 ## 2894 ## R: very large blobs 2895 ## 2896 test_expect_success 'R: blob bigger than threshold' ' 2897 blobsize=$((2*1024*1024 + 53)) && 2898 test-tool genrandom bar $blobsize >expect && 2899 cat >input <<-INPUT_END && 2900 commit refs/heads/big-file 2901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2902 data <>input && 2910 cat >>input <<-INPUT_END && 2911 M 644 inline big2 2912 data $blobsize 2913 INPUT_END 2914 cat expect >>input && 2915 echo >>input && 2916 2917 test_create_repo R && 2918 git --git-dir=R/.git config fastimport.unpackLimit 0 && 2919 git --git-dir=R/.git fast-import --big-file-threshold=1 ../verify 2926 ) 2927 ' 2928 2929 test_expect_success 'R: verify written objects' ' 2930 git --git-dir=R/.git cat-file blob big-file:big1 >actual && 2931 test_cmp_bin expect actual && 2932 a=$(git --git-dir=R/.git rev-parse big-file:big1) && 2933 b=$(git --git-dir=R/.git rev-parse big-file:big2) && 2934 test $a = $b 2935 ' 2936 2937 test_expect_success 'R: blob appears only once' ' 2938 n=$(grep $a verify | wc -l) && 2939 test 1 = $n 2940 ' 2941 2942 ### 2943 ### series S (mark and path parsing) 2944 ### 2945 # 2946 # Make sure missing spaces and EOLs after mark references 2947 # cause errors. 2948 # 2949 # Setup: 2950 # 2951 # 1--2--4 2952 # \ / 2953 # -3- 2954 # 2955 # commit marks: 301, 302, 303, 304 2956 # blob marks: 403, 404, resp. 2957 # note mark: 202 2958 # 2959 # The error message when a space is missing not at the 2960 # end of the line is: 2961 # 2962 # missing space after .. 2963 # 2964 # or when extra characters come after the mark at the end 2965 # of the line: 2966 # 2967 # garbage after .. 2968 # 2969 # or when the dataref is neither "inline " or a known SHA1, 2970 # 2971 # invalid dataref .. 2972 # 2973 test_expect_success 'S: initialize for S tests' ' 2974 test_tick && 2975 2976 cat >input <<-INPUT_END && 2977 commit refs/heads/S 2978 mark :301 2979 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2980 data < $GIT_COMMITTER_DATE 2991 data <err && 3021 commit refs/heads/S 3022 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3023 data <err && 3034 commit refs/heads/S 3035 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3036 data <err && 3050 commit refs/heads/S 3051 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3052 data <err && 3065 commit refs/heads/S 3066 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3067 data <err && 3077 commit refs/heads/S 3078 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3079 data <err && 3093 commit refs/heads/S 3094 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3095 data <err && 3108 commit refs/heads/Snotes 3109 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3110 data <err && 3124 commit refs/heads/S2 3125 mark :303 3126 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3127 data < $GIT_COMMITTER_DATE 3140 data <err && 3157 commit refs/heads/S 3158 mark :304 3159 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3160 data <err && 3175 tag refs/tags/Stag 3176 from :302x 3177 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3178 data <err && 3190 cat-blob :403x 3191 EOF 3192 test_grep "after mark" err 3193 ' 3194 3195 # 3196 # ls markref 3197 # 3198 test_expect_success 'S: ls with garbage after mark must fail' ' 3199 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3200 ls :302x hello.c 3201 EOF 3202 test_grep "space after mark" err 3203 ' 3204 3205 test_expect_success 'S: ls with garbage after sha1 must fail' ' 3206 sha1=$(grep :302 marks | cut -d\ -f2) && 3207 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3208 ls ${sha1}x hello.c 3209 EOF 3210 test_grep "space after tree-ish" err 3211 ' 3212 3213 # 3214 # Path parsing 3215 # 3216 # There are two sorts of ways a path can be parsed, depending on whether it is 3217 # the last field on the line. Additionally, ls without a has a special 3218 # case. Test every occurrence of in the grammar against every error case. 3219 # Paths for the root (empty strings) are tested elsewhere. 3220 # 3221 3222 # 3223 # Valid paths at the end of a line: filemodify, filedelete, filecopy (dest), 3224 # filerename (dest), and ls. 3225 # 3226 # commit :301 from root -- modify hello.c (for setup) 3227 # commit :302 from :301 -- modify $path 3228 # commit :303 from :302 -- delete $path 3229 # commit :304 from :301 -- copy hello.c $path 3230 # commit :305 from :301 -- rename hello.c $path 3231 # ls :305 $path 3232 # 3233 test_path_eol_success () { 3234 local test="$1" path="$2" unquoted_path="$3" 3235 test_expect_success "S: paths at EOL with $test must work" ' 3236 test_when_finished "git branch -D S-path-eol" && 3237 3238 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF >out 2>err && 3239 blob 3240 mark :401 3241 data < $GIT_COMMITTER_DATE 3254 data < $GIT_COMMITTER_DATE 3262 data < $GIT_COMMITTER_DATE 3271 data < $GIT_COMMITTER_DATE 3280 data < $GIT_COMMITTER_DATE 3289 data <tree_m.exp && 3309 git ls-tree $commit_m | sort >tree_m.out && 3310 test_cmp tree_m.exp tree_m.out && 3311 3312 printf "100644 blob $blob1\thello.c\n" >tree_d.exp && 3313 git ls-tree $commit_d >tree_d.out && 3314 test_cmp tree_d.exp tree_d.out && 3315 3316 ( 3317 printf "100644 blob $blob1\t$unquoted_path\n" && 3318 printf "100644 blob $blob1\thello.c\n" 3319 ) | sort >tree_c.exp && 3320 git ls-tree $commit_c | sort >tree_c.out && 3321 test_cmp tree_c.exp tree_c.out && 3322 3323 printf "100644 blob $blob1\t$unquoted_path\n" >tree_r.exp && 3324 git ls-tree $commit_r >tree_r.out && 3325 test_cmp tree_r.exp tree_r.out && 3326 3327 test_cmp out tree_r.exp 3328 ' 3329 } 3330 3331 test_path_eol_success 'quoted spaces' '" hello world.c "' ' hello world.c ' 3332 test_path_eol_success 'unquoted spaces' ' hello world.c ' ' hello world.c ' 3333 test_path_eol_success 'octal escapes' '"\150\151\056\143"' 'hi.c' 3334 3335 # 3336 # Valid paths before a space: filecopy (source) and filerename (source). 3337 # 3338 # commit :301 from root -- modify $path (for setup) 3339 # commit :302 from :301 -- copy $path hello2.c 3340 # commit :303 from :301 -- rename $path hello2.c 3341 # 3342 test_path_space_success () { 3343 local test="$1" path="$2" unquoted_path="$3" 3344 test_expect_success "S: paths before space with $test must work" ' 3345 test_when_finished "git branch -D S-path-space" && 3346 3347 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF 2>err && 3348 blob 3349 mark :401 3350 data < $GIT_COMMITTER_DATE 3357 data < $GIT_COMMITTER_DATE 3365 data < $GIT_COMMITTER_DATE 3374 data <tree_c.exp && 3390 git ls-tree $commit_c | sort >tree_c.out && 3391 test_cmp tree_c.exp tree_c.out && 3392 3393 printf "100644 blob $blob\thello2.c\n" >tree_r.exp && 3394 git ls-tree $commit_r >tree_r.out && 3395 test_cmp tree_r.exp tree_r.out 3396 ' 3397 } 3398 3399 test_path_space_success 'quoted spaces' '" hello world.c "' ' hello world.c ' 3400 test_path_space_success 'no unquoted spaces' 'hello_world.c' 'hello_world.c' 3401 test_path_space_success 'octal escapes' '"\150\151\056\143"' 'hi.c' 3402 3403 # 3404 # Test a single commit change with an invalid path. Run it with all occurrences 3405 # of in the grammar against all error kinds. 3406 # 3407 test_path_fail () { 3408 local change="$1" what="$2" prefix="$3" path="$4" suffix="$5" err_grep="$6" 3409 test_expect_success "S: $change with $what must fail" ' 3410 test_must_fail git fast-import <<-EOF 2>err && 3411 blob 3412 mark :1 3413 data < $GIT_COMMITTER_DATE 3420 data < $GIT_COMMITTER_DATE 3427 data <, the must be quoted. 3470 test_path_eol_quoted_fail 'ls (without dataref in commit)' 'ls ' path 3471 3472 ### 3473 ### series T (ls) 3474 ### 3475 # Setup is carried over from series S. 3476 3477 for root in '""' '' 3478 do 3479 test_expect_success "T: ls root ($root) tree" ' 3480 sed -e "s/Z\$//" >expect <<-EOF && 3481 040000 tree $(git rev-parse S^{tree}) Z 3482 EOF 3483 sha1=$(git rev-parse --verify S) && 3484 git fast-import --import-marks=marks <<-EOF >actual && 3485 ls $sha1 $root 3486 EOF 3487 test_cmp expect actual 3488 ' 3489 done 3490 3491 test_expect_success 'T: delete branch' ' 3492 git branch to-delete && 3493 git fast-import <<-EOF && 3494 reset refs/heads/to-delete 3495 from $ZERO_OID 3496 EOF 3497 test_must_fail git rev-parse --verify refs/heads/to-delete 3498 ' 3499 3500 test_expect_success 'T: empty reset doesnt delete branch' ' 3501 git branch not-to-delete && 3502 git fast-import <<-EOF && 3503 reset refs/heads/not-to-delete 3504 EOF 3505 git show-ref && 3506 git rev-parse --verify refs/heads/not-to-delete 3507 ' 3508 3509 ### 3510 ### series U (filedelete) 3511 ### 3512 3513 test_expect_success 'U: initialize for U tests' ' 3514 cat >input <<-INPUT_END && 3515 commit refs/heads/U 3516 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3517 data <input <<-INPUT_END && 3543 commit refs/heads/U 3544 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3545 data <expect <<-EOF && 3558 :100644 000000 $f8id $ZERO_OID D good/night.txt 3559 EOF 3560 3561 git diff-tree -M -r U^1 U >actual && 3562 3563 compare_diff_raw expect actual 3564 ' 3565 3566 test_expect_success 'U: filedelete directory succeeds' ' 3567 cat >input <<-INPUT_END && 3568 commit refs/heads/U 3569 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3570 data <expect <<-EOF && 3583 :100644 000000 $f9id $ZERO_OID D good/bye.txt 3584 EOF 3585 3586 git diff-tree -M -r U^1 U >actual && 3587 3588 compare_diff_raw expect actual 3589 ' 3590 3591 for root in '""' '' 3592 do 3593 test_expect_success "U: filedelete root ($root) succeeds" ' 3594 cat >input <<-INPUT_END && 3595 commit refs/heads/U-delete-root 3596 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3597 data <expect <<-EOF && 3610 :100644 000000 $f7id $ZERO_OID D hello.c 3611 EOF 3612 3613 git diff-tree -M -r U U-delete-root >actual && 3614 3615 compare_diff_raw expect actual 3616 ' 3617 done 3618 3619 ### 3620 ### series V (checkpoint) 3621 ### 3622 3623 # The commands in input_file should not produce any output on the file 3624 # descriptor set with --cat-blob-fd (or stdout if unspecified). 3625 # 3626 # To make sure you're observing the side effects of checkpoint *before* 3627 # fast-import terminates (and thus writes out its state), check that the 3628 # fast-import process is still running using background_import_still_running 3629 # *after* evaluating the test conditions. 3630 background_import_then_checkpoint () { 3631 options=$1 3632 input_file=$2 3633 3634 mkfifo V.input 3635 exec 8<>V.input 3636 rm V.input 3637 3638 mkfifo V.output 3639 exec 9<>V.output 3640 rm V.output 3641 3642 ( 3643 git fast-import $options <&8 >&9 & 3644 echo $! >&9 3645 wait $! 3646 echo >&2 "background fast-import terminated too early with exit code $?" 3647 # Un-block the read loop in the main shell process. 3648 echo >&9 UNEXPECTED 3649 ) & 3650 sh_pid=$! 3651 read fi_pid <&9 3652 # We don't mind if fast-import has already died by the time the test 3653 # ends. 3654 test_when_finished " 3655 exec 8>&-; exec 9>&-; 3656 kill $sh_pid && wait $sh_pid 3657 kill $fi_pid && wait $fi_pid 3658 true" 3659 3660 # Start in the background to ensure we adhere strictly to (blocking) 3661 # pipes writing sequence. We want to assume that the write below could 3662 # block, e.g. if fast-import blocks writing its own output to &9 3663 # because there is no reader on &9 yet. 3664 ( 3665 cat "$input_file" 3666 echo "checkpoint" 3667 echo "progress checkpoint" 3668 ) >&8 & 3669 3670 last=$( 3671 while read output <&9 3672 do 3673 if test "$output" = "progress checkpoint" || test "$output" = "UNEXPECTED" 3674 then 3675 echo "$output" 3676 break 3677 else 3678 # otherwise ignore cruft 3679 echo >&2 "cruft: $output" 3680 fi 3681 done 3682 ) 3683 3684 test "$last" = "progress checkpoint" 3685 } 3686 3687 background_import_still_running () { 3688 if ! kill -0 "$fi_pid" 3689 then 3690 echo >&2 "background fast-import terminated too early" 3691 false 3692 fi 3693 } 3694 3695 test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' ' 3696 cat >input <<-INPUT_END && 3697 progress foo 3698 progress bar 3699 3700 INPUT_END 3701 3702 background_import_then_checkpoint "" input && 3703 background_import_still_running 3704 ' 3705 3706 test_expect_success PIPE 'V: checkpoint updates refs after reset' ' 3707 cat >input <<-\INPUT_END && 3708 reset refs/heads/V 3709 from refs/heads/U 3710 3711 INPUT_END 3712 3713 background_import_then_checkpoint "" input && 3714 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" && 3715 background_import_still_running 3716 ' 3717 3718 test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' ' 3719 cat >input <<-INPUT_END && 3720 commit refs/heads/V 3721 mark :1 3722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3723 data 0 3724 from refs/heads/U 3725 3726 INPUT_END 3727 3728 background_import_then_checkpoint "--export-marks=marks.actual" input && 3729 3730 echo ":1 $(git rev-parse --verify V)" >marks.expected && 3731 3732 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" && 3733 test_cmp marks.expected marks.actual && 3734 background_import_still_running 3735 ' 3736 3737 # Re-create the exact same commit, but on a different branch: no new object is 3738 # created in the database, but the refs and marks still need to be updated. 3739 test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' ' 3740 cat >input <<-INPUT_END && 3741 commit refs/heads/V2 3742 mark :2 3743 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3744 data 0 3745 from refs/heads/U 3746 3747 INPUT_END 3748 3749 background_import_then_checkpoint "--export-marks=marks.actual" input && 3750 3751 echo ":2 $(git rev-parse --verify V2)" >marks.expected && 3752 3753 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" && 3754 test_cmp marks.expected marks.actual && 3755 background_import_still_running 3756 ' 3757 3758 test_expect_success PIPE 'V: checkpoint updates tags after tag' ' 3759 cat >input <<-INPUT_END && 3760 tag Vtag 3761 from refs/heads/V 3762 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3763 data 0 3764 3765 INPUT_END 3766 3767 background_import_then_checkpoint "" input && 3768 git show-ref -d Vtag && 3769 background_import_still_running 3770 ' 3771 3772 ### 3773 ### series W (get-mark and empty orphan commits) 3774 ### 3775 3776 cat >>W-input <<-W_INPUT_END 3777 commit refs/heads/W-branch 3778 mark :1 3779 author Full Name `1000000000` +0100 3780 committer Full Name `1000000000` +0100 3781 data 27 3782 Intentionally empty commit 3783 LFsget-mark :1 3784 W_INPUT_END 3785 3786 test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' ' 3787 sed -e s/LFs// W-input | tr L "\n" | git fast-import 3788 ' 3789 3790 test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' ' 3791 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import 3792 ' 3793 3794 test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' ' 3795 # Technically, this should fail as it has too many linefeeds 3796 # according to the grammar in fast-import.txt. But, for whatever 3797 # reason, it works. Since using the correct number of newlines 3798 # does not work with older (pre-2.22) versions of git, allow apps 3799 # that used this second-newline workaround to keep working by 3800 # checking it with this test... 3801 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import 3802 ' 3803 3804 test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' ' 3805 # ...but do NOT allow more empty lines than that (see previous test). 3806 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import 3807 ' 3808 3809 ### 3810 ### series X (other new features) 3811 ### 3812 3813 test_expect_success ICONV 'X: handling encoding' ' 3814 test_tick && 3815 cat >input <<-INPUT_END && 3816 commit refs/heads/encoding 3817 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3818 encoding iso-8859-7 3819 data <>input && 3823 3824 git fast-import >othername && 3844 git add othername && 3845 git commit -qm more && 3846 3847 git fast-export --all >tmp && 3848 sed -e s/othername/somename/ tmp >tmp2 && 3849 git fast-import --force msgs && 3850 3851 test_grep "dropping.*since it would point to itself" msgs && 3852 git show-ref >refs && 3853 test_grep ! refs/replace refs 3854 ) 3855 ' 3856 3857 ### 3858 ### series Y (submodules and hash algorithms) 3859 ### 3860 3861 cat >Y-sub-input <<\Y_INPUT_END 3862 blob 3863 mark :1 3864 data 4 3865 foo 3866 3867 reset refs/heads/main 3868 commit refs/heads/main 3869 mark :2 3870 author Full Name `1000000000` +0100 3871 committer Full Name `1000000000` +0100 3872 data 24 3873 Test submodule commit 1 3874 M 100644 :1 file 3875 3876 blob 3877 mark :3 3878 data 8 3879 foo 3880 bar 3881 3882 commit refs/heads/main 3883 mark :4 3884 author Full Name `1000000001` +0100 3885 committer Full Name `1000000001` +0100 3886 data 24 3887 Test submodule commit 2 3888 from :2 3889 M 100644 :3 file 3890 Y_INPUT_END 3891 3892 # Note that the submodule object IDs are intentionally not translated. 3893 cat >Y-main-input <<\Y_INPUT_END 3894 blob 3895 mark :1 3896 data 4 3897 foo 3898 3899 reset refs/heads/main 3900 commit refs/heads/main 3901 mark :2 3902 author Full Name `2000000000` +0100 3903 committer Full Name `2000000000` +0100 3904 data 14 3905 Test commit 1 3906 M 100644 :1 file 3907 3908 blob 3909 mark :3 3910 data 73 3911 [submodule "sub1"] 3912 path = sub1 3913 url = https://void.example.com/main.git 3914 3915 commit refs/heads/main 3916 mark :4 3917 author Full Name `2000000001` +0100 3918 committer Full Name `2000000001` +0100 3919 data 14 3920 Test commit 2 3921 from :2 3922 M 100644 :3 .gitmodules 3923 M 160000 `0712c5be7cf681388e355ef47525aaf23aee1a6d` sub1 3924 3925 blob 3926 mark :5 3927 data 8 3928 foo 3929 bar 3930 3931 commit refs/heads/main 3932 mark :6 3933 author Full Name `2000000002` +0100 3934 committer Full Name `2000000002` +0100 3935 data 14 3936 Test commit 3 3937 from :4 3938 M 100644 :5 file 3939 M 160000 `ff729f5e62f72c0c3978207d9a80e5f3a65f14d7` sub1 3940 Y_INPUT_END 3941 3942 cat >Y-marks <<\Y_INPUT_END 3943 :2 `0712c5be7cf681388e355ef47525aaf23aee1a6d` 3944 :4 `ff729f5e62f72c0c3978207d9a80e5f3a65f14d7` 3945 Y_INPUT_END 3946 3947 test_expect_success 'Y: setup' ' 3948 test_oid_cache <<-EOF 3949 Ymain sha1:`9afed2f9161ddf416c0a1863b8b0725b00070504` 3950 Ymain sha256:`c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3` 3951 EOF 3952 ' 3953 3954 test_expect_success 'Y: rewrite-submodules-to feature forbidden by default' ' 3955 echo "feature rewrite-submodules-to=sub:sub2-marks" >input && 3956 test_must_fail git fast-import err && 3957 test_grep "feature ${SQ}rewrite-submodules-to${SQ} forbidden in input without --allow-unsafe-features" err 3958 ' 3959 3960 test_expect_success 'Y: rewrite-submodules-from feature forbidden by default' ' 3961 echo "feature rewrite-submodules-from=sub:../Y-marks" >input && 3962 test_must_fail git fast-import err && 3963 test_grep "feature ${SQ}rewrite-submodules-from${SQ} forbidden in input without --allow-unsafe-features" err 3964 ' 3965 3966 test_expect_success 'Y: rewrite submodules' ' 3967 test_when_finished "rm -rf main1" && 3968 git init main1 && 3969 ( 3970 cd main1 && 3971 git init sub2 && 3972 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input && 3973 git fast-import --rewrite-submodules-from=sub:../Y-marks \ 3974 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input && 3975 test "$(git rev-parse main)" = "$(test_oid Ymain)" 3976 ) 3977 ' 3978 3979 test_expect_success 'Y: reference pending tag or commit' ' 3980 test_oid_cache <<-EOF && 3981 pending_commit sha1:`85b46dd918355ff17b4109ec738723d42f235a04` 3982 pending_commit sha256:`17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d` 3983 pending_tag sha1:`ec6c4db71feb5f66615214dad2324ce030e777a7` 3984 pending_tag sha256:`85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46` 3985 EOF 3986 3987 git init reference-pending && 3988 ( 3989 cd reference-pending && 3990 git fast-import <<-EOF 3991 commit refs/heads/main 3992 committer A U Thor `1712563200` +0000 3993 data 14 3994 commit message 3995 M 644 inline test file 3996 data 14 3997 dummy content 3998 3999 tag newtag 4000 from $(test_oid pending_commit) 4001 tagger A U Thor `1712563300` +0000 4002 data 11 4003 tag message 4004 # no emty line after tag data! 4005 reset refs/heads/other 4006 from $(test_oid pending_tag) 4007 4008 commit refs/heads/further 4009 committer A U Thor `1712563400` +0000 4010 data 21 4011 what about 2nd commit 4012 from $(test_oid pending_commit) 4013 M 644 inline other test file 4014 data 19 4015 more dummy content 4016 4017 done 4018 EOF 4019 ) 4020 ' 4021 4022 test_expect_success 'Y: rewrite submodules via stdin' ' 4023 test_when_finished "rm -rf main1" && 4024 git init main1 && 4025 ( 4026 cd main1 && 4027 git init sub2 && 4028 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input && 4029 { 4030 echo "feature rewrite-submodules-to=sub:sub2-marks" && 4031 echo "feature rewrite-submodules-from=sub:../Y-marks" && 4032 cat ../Y-main-input 4033 } | git fast-import --allow-unsafe-features && 4034 test "$(git rev-parse main)" = "$(test_oid Ymain)" 4035 ) 4036 ' 4037 4038 test_done