Git fork
at reftables-rust 3938 lines 89 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2007 Shawn Pearce 4# 5 6test_description='test git fast-import utility' 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 9 10. ./test-lib.sh 11. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash 12 13verify_packs () { 14 for p in .git/objects/pack/*.pack 15 do 16 git verify-pack "$@" "$p" || return 17 done 18} 19 20file2_data='file2 21second line of EOF' 22 23file3_data='EOF 24in 3rd file 25 END' 26 27file4_data=abcd 28file4_len=4 29 30file5_data='an inline file. 31 we should see it later.' 32 33file6_data='#!/bin/sh 34echo "$@"' 35 36### 37### series A 38### 39 40test_expect_success 'empty stream succeeds' ' 41 git config fastimport.unpackLimit 0 && 42 git fast-import </dev/null 43' 44 45test_expect_success 'truncated stream complains' ' 46 echo "tag foo" | test_must_fail git fast-import 47' 48 49test_expect_success 'A: create pack from stdin' ' 50 test_tick && 51 cat >input <<-INPUT_END && 52 blob 53 mark :2 54 data <<EOF 55 $file2_data 56 EOF 57 58 blob 59 mark :3 60 data <<END 61 $file3_data 62 END 63 64 blob 65 mark :4 66 data $file4_len 67 $file4_data 68 commit refs/heads/main 69 mark :5 70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 71 data <<COMMIT 72 initial 73 COMMIT 74 75 M 644 :2 file2 76 M 644 :3 file3 77 M 755 :4 file4 78 79 tag series-A 80 from :5 81 data <<EOF 82 An annotated tag without a tagger 83 EOF 84 85 tag series-A-blob 86 from :3 87 data <<EOF 88 An annotated tag that annotates a blob. 89 EOF 90 91 tag to-be-deleted 92 from :3 93 data <<EOF 94 Another annotated tag that annotates a blob. 95 EOF 96 97 reset refs/tags/to-be-deleted 98 from $ZERO_OID 99 100 tag nested 101 mark :6 102 from :4 103 data <<EOF 104 Tag of our lovely commit 105 EOF 106 107 reset refs/tags/nested 108 from $ZERO_OID 109 110 tag nested 111 mark :7 112 from :6 113 data <<EOF 114 Tag of tag of our lovely commit 115 EOF 116 117 alias 118 mark :8 119 to :5 120 121 INPUT_END 122 git fast-import --export-marks=marks.out <input && 123 git log --raw main 124' 125 126test_expect_success 'A: verify pack' ' 127 verify_packs 128' 129 130test_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 134 135 initial 136 EOF 137 git cat-file commit main | sed 1d >actual && 138 test_cmp expect actual 139' 140 141test_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 151test_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 157test_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 163test_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 169test_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 181test_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 193test_expect_success 'A: verify tag deletion is successful' ' 194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted 195' 196 197test_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 210test_expect_success 'A: verify marks import' ' 211 git fast-import \ 212 --import-marks=marks.out \ 213 --export-marks=marks.new \ 214 </dev/null && 215 test_cmp expect marks.new 216' 217 218test_expect_success 'A: tag blob by sha1' ' 219 test_tick && 220 new_blob=$(echo testing | git hash-object --stdin) && 221 cat >input <<-INPUT_END && 222 tag series-A-blob-2 223 from $(git rev-parse refs/heads/main:file3) 224 data <<EOF 225 Tag blob by sha1. 226 EOF 227 228 blob 229 mark :6 230 data <<EOF 231 testing 232 EOF 233 234 commit refs/heads/new_blob 235 committer <> 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 <<EOF 244 Tag new_blob. 245 EOF 246 INPUT_END 247 248 cat >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 <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 265' 266 267test_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 <<COMMIT 273 recreate from :5 274 COMMIT 275 276 from :5 277 M 755 :2 copy-of-file2 278 279 INPUT_END 280 281 git fast-import --import-marks=marks.out <input && 282 git log --raw verify--import-marks 283' 284 285test_expect_success 'A: verify pack' ' 286 verify_packs 287' 288 289test_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 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 300test_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 <<COMMIT 311 test the sparse array dumping routines with exponentially growing marks 312 COMMIT 313 EOF 314 315 i=0 l=4 m=6 n=7 && 316 while test "$i" -lt 27 317 do 318 cat >>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 360test_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 <<COMMIT 367 corrupt 368 COMMIT 369 370 from refs/heads/main 371 M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1 372 373 INPUT_END 374 375 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" && 376 test_must_fail git fast-import <input 377' 378 379test_expect_success 'B: accept branch name "TEMP_TAG"' ' 380 cat >input <<-INPUT_END && 381 commit TEMP_TAG 382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 383 data <<COMMIT 384 tag base 385 COMMIT 386 387 from refs/heads/main 388 389 INPUT_END 390 391 test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" && 392 git fast-import <input && 393 test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" && 394 test $(git rev-parse main) = $(git rev-parse TEMP_TAG^) 395' 396 397test_expect_success 'B: accept empty committer' ' 398 cat >input <<-INPUT_END && 399 commit refs/heads/empty-committer-1 400 committer <> $GIT_COMMITTER_DATE 401 data <<COMMIT 402 empty commit 403 COMMIT 404 INPUT_END 405 406 test_when_finished "git update-ref -d refs/heads/empty-committer-1 407 git gc --prune=now" && 408 git fast-import <input && 409 out=$(git fsck) && 410 echo "$out" && 411 test -z "$out" 412' 413 414test_expect_success 'B: reject invalid timezone' ' 415 cat >input <<-INPUT_END && 416 commit refs/heads/invalid-timezone 417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 418 data <<COMMIT 419 empty commit 420 COMMIT 421 INPUT_END 422 423 test_when_finished "git update-ref -d refs/heads/invalid-timezone" && 424 test_must_fail git fast-import <input 425' 426 427test_expect_success 'B: accept invalid timezone with raw-permissive' ' 428 cat >input <<-INPUT_END && 429 commit refs/heads/invalid-timezone 430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 431 data <<COMMIT 432 empty commit 433 COMMIT 434 INPUT_END 435 436 git init invalid-timezone && 437 git -C invalid-timezone fast-import --date-format=raw-permissive <input && 438 git -C invalid-timezone cat-file -p invalid-timezone >out && 439 grep "1234567890 [+]051800" out 440' 441 442test_expect_success 'B: accept and fixup committer with no name' ' 443 cat >input <<-INPUT_END && 444 commit refs/heads/empty-committer-2 445 committer <a@b.com> $GIT_COMMITTER_DATE 446 data <<COMMIT 447 empty commit 448 COMMIT 449 INPUT_END 450 451 test_when_finished "git update-ref -d refs/heads/empty-committer-2 452 git gc --prune=now" && 453 git fast-import <input && 454 out=$(git fsck) && 455 echo "$out" && 456 test -z "$out" 457' 458 459test_expect_success 'B: fail on invalid committer (1)' ' 460 cat >input <<-INPUT_END && 461 commit refs/heads/invalid-committer 462 committer Name email> $GIT_COMMITTER_DATE 463 data <<COMMIT 464 empty commit 465 COMMIT 466 INPUT_END 467 468 test_when_finished "git update-ref -d refs/heads/invalid-committer" && 469 test_must_fail git fast-import <input 470' 471 472test_expect_success 'B: fail on invalid committer (2)' ' 473 cat >input <<-INPUT_END && 474 commit refs/heads/invalid-committer 475 committer Name <e<mail> $GIT_COMMITTER_DATE 476 data <<COMMIT 477 empty commit 478 COMMIT 479 INPUT_END 480 481 test_when_finished "git update-ref -d refs/heads/invalid-committer" && 482 test_must_fail git fast-import <input 483' 484 485test_expect_success 'B: fail on invalid committer (3)' ' 486 cat >input <<-INPUT_END && 487 commit refs/heads/invalid-committer 488 committer Name <email>> $GIT_COMMITTER_DATE 489 data <<COMMIT 490 empty commit 491 COMMIT 492 INPUT_END 493 494 test_when_finished "git update-ref -d refs/heads/invalid-committer" && 495 test_must_fail git fast-import <input 496' 497 498test_expect_success 'B: fail on invalid committer (4)' ' 499 cat >input <<-INPUT_END && 500 commit refs/heads/invalid-committer 501 committer Name <email $GIT_COMMITTER_DATE 502 data <<COMMIT 503 empty commit 504 COMMIT 505 INPUT_END 506 507 test_when_finished "git update-ref -d refs/heads/invalid-committer" && 508 test_must_fail git fast-import <input 509' 510 511test_expect_success 'B: fail on invalid committer (5)' ' 512 cat >input <<-INPUT_END && 513 commit refs/heads/invalid-committer 514 committer Name<email> $GIT_COMMITTER_DATE 515 data <<COMMIT 516 empty commit 517 COMMIT 518 INPUT_END 519 520 test_when_finished "git update-ref -d refs/heads/invalid-committer" && 521 test_must_fail git fast-import <input 522' 523 524test_expect_success 'B: fail on invalid file path of ..' ' 525 cat >input <<-INPUT_END && 526 blob 527 mark :1 528 data <<EOF 529 File contents 530 EOF 531 532 commit refs/heads/badpath 533 committer Name <email> $GIT_COMMITTER_DATE 534 data <<COMMIT 535 Commit Message 536 COMMIT 537 M 100644 :1 ../invalid-path 538 INPUT_END 539 540 test_when_finished "git update-ref -d refs/heads/badpath" && 541 test_must_fail git fast-import <input 542' 543 544test_expect_success 'B: fail on invalid file path of .' ' 545 cat >input <<-INPUT_END && 546 blob 547 mark :1 548 data <<EOF 549 File contents 550 EOF 551 552 commit refs/heads/badpath 553 committer Name <email> $GIT_COMMITTER_DATE 554 data <<COMMIT 555 Good path 556 COMMIT 557 M 100644 :1 ok-path 558 559 commit refs/heads/badpath 560 committer Name <email> $GIT_COMMITTER_DATE 561 data <<COMMIT 562 Bad path 563 COMMIT 564 R ok-path ./invalid-path 565 INPUT_END 566 567 test_when_finished "git update-ref -d refs/heads/badpath" && 568 test_must_fail git fast-import <input 569' 570 571test_expect_success WINDOWS 'B: fail on invalid file path of C:' ' 572 cat >input <<-INPUT_END && 573 blob 574 mark :1 575 data <<EOF 576 File contents 577 EOF 578 579 commit refs/heads/badpath 580 committer Name <email> $GIT_COMMITTER_DATE 581 data <<COMMIT 582 Commit Message 583 COMMIT 584 M 100644 :1 C:/invalid-path 585 INPUT_END 586 587 test_when_finished "git update-ref -d refs/heads/badpath" && 588 test_must_fail git fast-import <input 589' 590 591test_expect_success 'B: fail on invalid file path of .git' ' 592 cat >input <<-INPUT_END && 593 blob 594 mark :1 595 data <<EOF 596 File contents 597 EOF 598 599 commit refs/heads/badpath 600 committer Name <email> $GIT_COMMITTER_DATE 601 data <<COMMIT 602 Commit Message 603 COMMIT 604 M 100644 :1 .git/invalid-path 605 INPUT_END 606 607 test_when_finished "git update-ref -d refs/heads/badpath" && 608 test_must_fail git fast-import <input 609' 610 611test_expect_success 'B: fail on invalid file path of .gitmodules' ' 612 cat >input <<-INPUT_END && 613 blob 614 mark :1 615 data <<EOF 616 File contents 617 EOF 618 619 commit refs/heads/badpath 620 committer Name <email> $GIT_COMMITTER_DATE 621 data <<COMMIT 622 Commit Message 623 COMMIT 624 M 120000 :1 .gitmodules 625 INPUT_END 626 627 test_when_finished "git update-ref -d refs/heads/badpath" && 628 test_must_fail git fast-import <input 629' 630 631### 632### series C 633### 634 635test_expect_success 'C: incremental import create pack from stdin' ' 636 newf=$(echo hi newf | git hash-object -w --stdin) && 637 oldf=$(git rev-parse --verify main:file2) && 638 thrf=$(git rev-parse --verify main:file3) && 639 test_tick && 640 cat >input <<-INPUT_END && 641 commit refs/heads/branch 642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 643 data <<COMMIT 644 second 645 COMMIT 646 647 from refs/heads/main 648 M 644 $oldf file2/oldf 649 M 755 $newf file2/newf 650 D file3 651 652 INPUT_END 653 654 git fast-import <input && 655 git log --raw branch 656' 657 658test_expect_success 'C: verify pack' ' 659 verify_packs 660' 661 662test_expect_success 'C: validate reuse existing blob' ' 663 test $newf = $(git rev-parse --verify branch:file2/newf) && 664 test $oldf = $(git rev-parse --verify branch:file2/oldf) 665' 666 667test_expect_success 'C: verify commit' ' 668 cat >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 680test_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 695test_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 <<COMMIT 701 third 702 COMMIT 703 704 from refs/heads/branch^0 705 M 644 inline newdir/interesting 706 data <<EOF 707 $file5_data 708 EOF 709 710 M 755 inline newdir/exec.sh 711 data <<EOF 712 $file6_data 713 EOF 714 715 INPUT_END 716 717 git fast-import <input && 718 git log --raw branch 719' 720 721test_expect_success 'D: verify pack' ' 722 verify_packs 723' 724 725test_expect_success 'D: validate new files added' ' 726 f5id=$(echo "$file5_data" | git hash-object --stdin) && 727 f6id=$(echo "$file6_data" | git hash-object --stdin) && 728 cat >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 736test_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 742test_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 752test_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 <<COMMIT 758 RFC 2822 type date 759 COMMIT 760 761 from refs/heads/branch^0 762 763 INPUT_END 764 765 test_must_fail git fast-import --date-format=raw <input 766' 767test_expect_success 'E: rfc2822 date, --date-format=rfc2822' ' 768 git fast-import --date-format=rfc2822 <input 769' 770 771test_expect_success 'E: verify pack' ' 772 verify_packs 773' 774 775test_expect_success 'E: verify commit' ' 776 cat >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 790test_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 <<COMMIT 797 losing things already? 798 COMMIT 799 800 from refs/heads/branch~1 801 802 reset refs/heads/other 803 from refs/heads/branch 804 805 INPUT_END 806 807 test_must_fail git fast-import <input && 808 # branch must remain unaffected 809 test $old_branch = $(git rev-parse --verify branch^0) 810' 811 812test_expect_success 'F: verify pack' ' 813 verify_packs 814' 815 816test_expect_success 'F: verify other commit' ' 817 cat >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 833test_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 <<COMMIT 840 losing things already? 841 COMMIT 842 843 from refs/heads/branch~1 844 845 INPUT_END 846 git fast-import --force <input 847' 848 849test_expect_success 'G: verify pack' ' 850 verify_packs 851' 852 853test_expect_success 'G: branch changed, but logged' ' 854 test $old_branch != $(git rev-parse --verify branch^0) && 855 test $old_branch = $(git rev-parse --verify branch@{1}) 856' 857 858### 859### series H 860### 861 862test_expect_success 'H: deletall, add 1' ' 863 test_tick && 864 cat >input <<-INPUT_END && 865 commit refs/heads/H 866 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 867 data <<COMMIT 868 third 869 COMMIT 870 871 from refs/heads/branch^0 872 M 644 inline i-will-die 873 data <<EOF 874 this file will never exist. 875 EOF 876 877 deleteall 878 M 644 inline h/e/l/lo 879 data <<EOF 880 $file5_data 881 EOF 882 883 INPUT_END 884 git fast-import <input && 885 git log --raw H 886' 887 888test_expect_success 'H: verify pack' ' 889 verify_packs 890' 891 892test_expect_success 'H: validate old files removed, new files added' ' 893 f4id=$(git rev-parse HEAD:file4) && 894 cat >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 905test_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 915test_expect_success 'I: export-pack-edges' ' 916 cat >input <<-INPUT_END && 917 commit refs/heads/export-boundary 918 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 919 data <<COMMIT 920 we have a border. its only 40 characters wide. 921 COMMIT 922 923 from refs/heads/branch 924 925 INPUT_END 926 git fast-import --export-pack-edges=edges.list <input 927' 928 929test_expect_success 'I: verify edge list' ' 930 cat >expect <<-EOF && 931 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary) 932 EOF 933 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual && 934 test_cmp expect actual 935' 936 937### 938### series J 939### 940 941test_expect_success 'J: reset existing branch creates empty commit' ' 942 cat >input <<-INPUT_END && 943 commit refs/heads/J 944 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 945 data <<COMMIT 946 create J 947 COMMIT 948 949 from refs/heads/branch 950 951 reset refs/heads/J 952 953 commit refs/heads/J 954 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 955 data <<COMMIT 956 initialize J 957 COMMIT 958 959 INPUT_END 960 git fast-import <input 961' 962test_expect_success 'J: branch has 1 commit, empty tree' ' 963 test 1 = $(git rev-list J | wc -l) && 964 test 0 = $(git ls-tree J | wc -l) 965' 966 967test_expect_success 'J: tag must fail on empty branch' ' 968 cat >input <<-INPUT_END && 969 reset refs/heads/J2 970 971 tag wrong_tag 972 from refs/heads/J2 973 data <<EOF 974 Tag branch that was reset. 975 EOF 976 INPUT_END 977 test_must_fail git fast-import <input 978' 979 980### 981### series K 982### 983 984test_expect_success 'K: reinit branch with from' ' 985 cat >input <<-INPUT_END && 986 commit refs/heads/K 987 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 988 data <<COMMIT 989 create K 990 COMMIT 991 992 from refs/heads/branch 993 994 commit refs/heads/K 995 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 996 data <<COMMIT 997 redo K 998 COMMIT 999 1000 from refs/heads/branch^1 1001 1002 INPUT_END 1003 git fast-import <input 1004' 1005test_expect_success 'K: verify K^1 = branch^1' ' 1006 test $(git rev-parse --verify branch^1) \ 1007 = $(git rev-parse --verify K^1) 1008' 1009 1010### 1011### series L 1012### 1013 1014test_expect_success 'L: verify internal tree sorting' ' 1015 cat >input <<-INPUT_END && 1016 blob 1017 mark :1 1018 data <<EOF 1019 some data 1020 EOF 1021 1022 blob 1023 mark :2 1024 data <<EOF 1025 other data 1026 EOF 1027 1028 commit refs/heads/L 1029 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1030 data <<COMMIT 1031 create L 1032 COMMIT 1033 1034 M 644 :1 b. 1035 M 644 :1 b/other 1036 M 644 :1 ba 1037 1038 commit refs/heads/L 1039 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1040 data <<COMMIT 1041 update L 1042 COMMIT 1043 1044 M 644 :2 b. 1045 M 644 :2 b/other 1046 M 644 :2 ba 1047 INPUT_END 1048 1049 cat >expect <<-EXPECT_END && 1050 :100644 100644 M b. 1051 :040000 040000 M b 1052 :100644 100644 M ba 1053 EXPECT_END 1054 1055 git -c core.protectNTFS=false fast-import <input && 1056 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output && 1057 cut -d" " -f1,2,5 output >actual && 1058 test_cmp expect actual 1059' 1060 1061test_expect_success 'L: nested tree copy does not corrupt deltas' ' 1062 cat >input <<-INPUT_END && 1063 blob 1064 mark :1 1065 data <<EOF 1066 the data 1067 EOF 1068 1069 commit refs/heads/L2 1070 committer C O Mitter <committer@example.com> 1112912473 -0700 1071 data <<COMMIT 1072 init L2 1073 COMMIT 1074 M 644 :1 a/b/c 1075 M 644 :1 a/b/d 1076 M 644 :1 a/e/f 1077 1078 commit refs/heads/L2 1079 committer C O Mitter <committer@example.com> 1112912473 -0700 1080 data <<COMMIT 1081 update L2 1082 COMMIT 1083 C a g 1084 C a/e g/b 1085 M 644 :1 g/b/h 1086 INPUT_END 1087 1088 cat >expect <<-\EOF && 1089 g/b/f 1090 g/b/h 1091 EOF 1092 1093 test_when_finished "git update-ref -d refs/heads/L2" && 1094 git fast-import <input && 1095 git ls-tree L2 g/b/ >tmp && 1096 cut -f 2 <tmp >actual && 1097 test_cmp expect actual && 1098 git fsck $(git rev-parse L2) 1099' 1100 1101### 1102### series M 1103### 1104 1105test_expect_success 'M: rename file in same subdirectory' ' 1106 test_tick && 1107 cat >input <<-INPUT_END && 1108 commit refs/heads/M1 1109 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1110 data <<COMMIT 1111 file rename 1112 COMMIT 1113 1114 from refs/heads/branch^0 1115 R file2/newf file2/n.e.w.f 1116 1117 INPUT_END 1118 1119 cat >expect <<-EOF && 1120 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f 1121 EOF 1122 git fast-import <input && 1123 git diff-tree -M -r M1^ M1 >actual && 1124 compare_diff_raw expect actual 1125' 1126 1127test_expect_success 'M: rename file to new subdirectory' ' 1128 cat >input <<-INPUT_END && 1129 commit refs/heads/M2 1130 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1131 data <<COMMIT 1132 file rename 1133 COMMIT 1134 1135 from refs/heads/branch^0 1136 R file2/newf i/am/new/to/you 1137 1138 INPUT_END 1139 1140 cat >expect <<-EOF && 1141 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you 1142 EOF 1143 git fast-import <input && 1144 git diff-tree -M -r M2^ M2 >actual && 1145 compare_diff_raw expect actual 1146' 1147 1148test_expect_success 'M: rename subdirectory to new subdirectory' ' 1149 cat >input <<-INPUT_END && 1150 commit refs/heads/M3 1151 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1152 data <<COMMIT 1153 file rename 1154 COMMIT 1155 1156 from refs/heads/M2^0 1157 R i other/sub 1158 1159 INPUT_END 1160 1161 cat >expect <<-EOF && 1162 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you 1163 EOF 1164 git fast-import <input && 1165 git diff-tree -M -r M3^ M3 >actual && 1166 compare_diff_raw expect actual 1167' 1168 1169for root in '""' '' 1170do 1171 test_expect_success "M: rename root ($root) to subdirectory" ' 1172 cat >input <<-INPUT_END && 1173 commit refs/heads/M4 1174 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1175 data <<COMMIT 1176 rename root 1177 COMMIT 1178 1179 from refs/heads/M2^0 1180 R $root sub 1181 1182 INPUT_END 1183 1184 cat >expect <<-EOF && 1185 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf 1186 :100755 100755 $f4id $f4id R100 file4 sub/file4 1187 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you 1188 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh 1189 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting 1190 EOF 1191 git fast-import <input && 1192 git diff-tree -M -r M4^ M4 >actual && 1193 compare_diff_raw expect actual 1194 ' 1195done 1196 1197### 1198### series N 1199### 1200 1201test_expect_success 'N: copy file in same subdirectory' ' 1202 test_tick && 1203 cat >input <<-INPUT_END && 1204 commit refs/heads/N1 1205 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1206 data <<COMMIT 1207 file copy 1208 COMMIT 1209 1210 from refs/heads/branch^0 1211 C file2/newf file2/n.e.w.f 1212 1213 INPUT_END 1214 1215 cat >expect <<-EOF && 1216 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f 1217 EOF 1218 git fast-import <input && 1219 git diff-tree -C --find-copies-harder -r N1^ N1 >actual && 1220 compare_diff_raw expect actual 1221' 1222 1223test_expect_success 'N: copy then modify subdirectory' ' 1224 cat >input <<-INPUT_END && 1225 commit refs/heads/N2 1226 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1227 data <<COMMIT 1228 clean directory copy 1229 COMMIT 1230 1231 from refs/heads/branch^0 1232 C file2 file3 1233 1234 commit refs/heads/N2 1235 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1236 data <<COMMIT 1237 modify directory copy 1238 COMMIT 1239 1240 M 644 inline file3/file5 1241 data <<EOF 1242 $file5_data 1243 EOF 1244 1245 INPUT_END 1246 1247 cat >expect <<-EOF && 1248 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 1249 :100755 100755 $newf $newf C100 file2/newf file3/newf 1250 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1251 EOF 1252 git fast-import <input && 1253 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual && 1254 compare_diff_raw expect actual 1255' 1256 1257test_expect_success 'N: copy dirty subdirectory' ' 1258 cat >input <<-INPUT_END && 1259 commit refs/heads/N3 1260 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1261 data <<COMMIT 1262 dirty directory copy 1263 COMMIT 1264 1265 from refs/heads/branch^0 1266 M 644 inline file2/file5 1267 data <<EOF 1268 $file5_data 1269 EOF 1270 1271 C file2 file3 1272 D file2/file5 1273 1274 INPUT_END 1275 1276 git fast-import <input && 1277 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree}) 1278' 1279 1280test_expect_success 'N: copy directory by id' ' 1281 cat >expect <<-EOF && 1282 :100755 100755 $newf $newf C100 file2/newf file3/newf 1283 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1284 EOF 1285 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1286 cat >input <<-INPUT_END && 1287 commit refs/heads/N4 1288 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1289 data <<COMMIT 1290 copy by tree hash 1291 COMMIT 1292 1293 from refs/heads/branch^0 1294 M 040000 $subdir file3 1295 INPUT_END 1296 git fast-import <input && 1297 git diff-tree -C --find-copies-harder -r N4^ N4 >actual && 1298 compare_diff_raw expect actual 1299' 1300 1301test_expect_success PIPE 'N: read and copy directory' ' 1302 cat >expect <<-EOF && 1303 :100755 100755 $newf $newf C100 file2/newf file3/newf 1304 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1305 EOF 1306 git update-ref -d refs/heads/N4 && 1307 rm -f backflow && 1308 mkfifo backflow && 1309 ( 1310 exec <backflow && 1311 cat <<-EOF && 1312 commit refs/heads/N4 1313 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1314 data <<COMMIT 1315 copy by tree hash, part 2 1316 COMMIT 1317 1318 from refs/heads/branch^0 1319 ls "file2" 1320 EOF 1321 read mode type tree filename && 1322 echo "M 040000 $tree file3" 1323 ) | 1324 git fast-import --cat-blob-fd=3 3>backflow && 1325 git diff-tree -C --find-copies-harder -r N4^ N4 >actual && 1326 compare_diff_raw expect actual 1327' 1328 1329test_expect_success PIPE 'N: empty directory reads as missing' ' 1330 cat <<-\EOF >expect && 1331 OBJNAME 1332 :000000 100644 OBJNAME OBJNAME A unrelated 1333 EOF 1334 echo "missing src" >expect.response && 1335 git update-ref -d refs/heads/read-empty && 1336 rm -f backflow && 1337 mkfifo backflow && 1338 ( 1339 exec <backflow && 1340 cat <<-EOF && 1341 commit refs/heads/read-empty 1342 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1343 data <<COMMIT 1344 read "empty" (missing) directory 1345 COMMIT 1346 1347 M 100644 inline src/greeting 1348 data <<BLOB 1349 hello 1350 BLOB 1351 C src/greeting dst1/non-greeting 1352 C src/greeting unrelated 1353 # leave behind "empty" src directory 1354 D src/greeting 1355 ls "src" 1356 EOF 1357 read -r line && 1358 printf "%s\n" "$line" >response && 1359 cat <<-\EOF 1360 D dst1 1361 D dst2 1362 EOF 1363 ) | 1364 git fast-import --cat-blob-fd=3 3>backflow && 1365 test_cmp expect.response response && 1366 git rev-list read-empty | 1367 git diff-tree -r --root --stdin | 1368 sed "s/$OID_REGEX/OBJNAME/g" >actual && 1369 test_cmp expect actual 1370' 1371 1372for root in '""' '' 1373do 1374 test_expect_success "N: copy root ($root) by tree hash" ' 1375 cat >expect <<-EOF && 1376 :100755 000000 $newf $zero D file3/newf 1377 :100644 000000 $oldf $zero D file3/oldf 1378 EOF 1379 root_tree=$(git rev-parse refs/heads/branch^0^{tree}) && 1380 cat >input <<-INPUT_END && 1381 commit refs/heads/N6 1382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1383 data <<COMMIT 1384 copy root directory by tree hash 1385 COMMIT 1386 1387 from refs/heads/branch^0 1388 M 040000 $root_tree $root 1389 INPUT_END 1390 git fast-import <input && 1391 git diff-tree -C --find-copies-harder -r N4 N6 >actual && 1392 compare_diff_raw expect actual 1393 ' 1394 1395 test_expect_success "N: copy root ($root) by path" ' 1396 cat >expect <<-EOF && 1397 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf 1398 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf 1399 :100755 100755 $f4id $f4id C100 file4 oldroot/file4 1400 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh 1401 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting 1402 EOF 1403 cat >input <<-INPUT_END && 1404 commit refs/heads/N-copy-root-path 1405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1406 data <<COMMIT 1407 copy root directory by (empty) path 1408 COMMIT 1409 1410 from refs/heads/branch^0 1411 C $root oldroot 1412 INPUT_END 1413 git fast-import <input && 1414 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual && 1415 compare_diff_raw expect actual 1416 ' 1417done 1418 1419test_expect_success 'N: delete directory by copying' ' 1420 cat >expect <<-\EOF && 1421 OBJID 1422 :100644 000000 OBJID OBJID D foo/bar/qux 1423 OBJID 1424 :000000 100644 OBJID OBJID A foo/bar/baz 1425 :000000 100644 OBJID OBJID A foo/bar/qux 1426 EOF 1427 empty_tree=$(git mktree </dev/null) && 1428 cat >input <<-INPUT_END && 1429 commit refs/heads/N-delete 1430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1431 data <<COMMIT 1432 collect data to be deleted 1433 COMMIT 1434 1435 deleteall 1436 M 100644 inline foo/bar/baz 1437 data <<DATA_END 1438 hello 1439 DATA_END 1440 C "foo/bar/baz" "foo/bar/qux" 1441 C "foo/bar/baz" "foo/bar/quux/1" 1442 C "foo/bar/baz" "foo/bar/quuux" 1443 M 040000 $empty_tree foo/bar/quux 1444 M 040000 $empty_tree foo/bar/quuux 1445 1446 commit refs/heads/N-delete 1447 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1448 data <<COMMIT 1449 delete subdirectory 1450 COMMIT 1451 1452 M 040000 $empty_tree foo/bar/qux 1453 INPUT_END 1454 git fast-import <input && 1455 git rev-list N-delete | 1456 git diff-tree -r --stdin --root --always | 1457 sed -e "s/$OID_REGEX/OBJID/g" >actual && 1458 test_cmp expect actual 1459' 1460 1461test_expect_success 'N: modify copied tree' ' 1462 cat >expect <<-EOF && 1463 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 1464 :100755 100755 $newf $newf C100 file2/newf file3/newf 1465 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf 1466 EOF 1467 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1468 cat >input <<-INPUT_END && 1469 commit refs/heads/N5 1470 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1471 data <<COMMIT 1472 copy by tree hash 1473 COMMIT 1474 1475 from refs/heads/branch^0 1476 M 040000 $subdir file3 1477 1478 commit refs/heads/N5 1479 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1480 data <<COMMIT 1481 modify directory copy 1482 COMMIT 1483 1484 M 644 inline file3/file5 1485 data <<EOF 1486 $file5_data 1487 EOF 1488 INPUT_END 1489 git fast-import <input && 1490 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual && 1491 compare_diff_raw expect actual 1492' 1493 1494test_expect_success 'N: reject foo/ syntax' ' 1495 subdir=$(git rev-parse refs/heads/branch^0:file2) && 1496 test_must_fail git fast-import <<-INPUT_END 1497 commit refs/heads/N5B 1498 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1499 data <<COMMIT 1500 copy with invalid syntax 1501 COMMIT 1502 1503 from refs/heads/branch^0 1504 M 040000 $subdir file3/ 1505 INPUT_END 1506' 1507 1508test_expect_success 'N: reject foo/ syntax in copy source' ' 1509 test_must_fail git fast-import <<-INPUT_END 1510 commit refs/heads/N5C 1511 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1512 data <<COMMIT 1513 copy with invalid syntax 1514 COMMIT 1515 1516 from refs/heads/branch^0 1517 C file2/ file3 1518 INPUT_END 1519' 1520 1521test_expect_success 'N: reject foo/ syntax in rename source' ' 1522 test_must_fail git fast-import <<-INPUT_END 1523 commit refs/heads/N5D 1524 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1525 data <<COMMIT 1526 rename with invalid syntax 1527 COMMIT 1528 1529 from refs/heads/branch^0 1530 R file2/ file3 1531 INPUT_END 1532' 1533 1534test_expect_success 'N: reject foo/ syntax in ls argument' ' 1535 test_must_fail git fast-import <<-INPUT_END 1536 commit refs/heads/N5E 1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1538 data <<COMMIT 1539 copy with invalid syntax 1540 COMMIT 1541 1542 from refs/heads/branch^0 1543 ls "file2/" 1544 INPUT_END 1545' 1546 1547for root in '""' '' 1548do 1549 test_expect_success "N: copy to root ($root) by id and modify" ' 1550 echo "hello, world" >expect.foo && 1551 echo hello >expect.bar && 1552 git fast-import <<-SETUP_END && 1553 commit refs/heads/N7 1554 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1555 data <<COMMIT 1556 hello, tree 1557 COMMIT 1558 1559 deleteall 1560 M 644 inline foo/bar 1561 data <<EOF 1562 hello 1563 EOF 1564 SETUP_END 1565 1566 tree=$(git rev-parse --verify N7:) && 1567 git fast-import <<-INPUT_END && 1568 commit refs/heads/N8 1569 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1570 data <<COMMIT 1571 copy to root by id and modify 1572 COMMIT 1573 1574 M 040000 $tree $root 1575 M 644 inline foo/foo 1576 data <<EOF 1577 hello, world 1578 EOF 1579 INPUT_END 1580 git show N8:foo/foo >actual.foo && 1581 git show N8:foo/bar >actual.bar && 1582 test_cmp expect.foo actual.foo && 1583 test_cmp expect.bar actual.bar 1584 ' 1585 1586 test_expect_success "N: extract subtree to the root ($root)" ' 1587 branch=$(git rev-parse --verify refs/heads/branch^{tree}) && 1588 cat >input <<-INPUT_END && 1589 commit refs/heads/N9 1590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1591 data <<COMMIT 1592 extract subtree branch:newdir 1593 COMMIT 1594 1595 M 040000 $branch $root 1596 C "newdir" $root 1597 INPUT_END 1598 git fast-import <input && 1599 git diff --exit-code branch:newdir N9 1600 ' 1601 1602 test_expect_success "N: modify subtree, extract it to the root ($root), and modify again" ' 1603 echo hello >expect.baz && 1604 echo hello, world >expect.qux && 1605 git fast-import <<-SETUP_END && 1606 commit refs/heads/N10 1607 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1608 data <<COMMIT 1609 hello, tree 1610 COMMIT 1611 1612 deleteall 1613 M 644 inline foo/bar/baz 1614 data <<EOF 1615 hello 1616 EOF 1617 SETUP_END 1618 1619 tree=$(git rev-parse --verify N10:) && 1620 git fast-import <<-INPUT_END && 1621 commit refs/heads/N11 1622 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1623 data <<COMMIT 1624 copy to root by id and modify 1625 COMMIT 1626 1627 M 040000 $tree $root 1628 M 100644 inline foo/bar/qux 1629 data <<EOF 1630 hello, world 1631 EOF 1632 R "foo" $root 1633 C "bar/qux" "bar/quux" 1634 INPUT_END 1635 git show N11:bar/baz >actual.baz && 1636 git show N11:bar/qux >actual.qux && 1637 git show N11:bar/quux >actual.quux && 1638 test_cmp expect.baz actual.baz && 1639 test_cmp expect.qux actual.qux && 1640 test_cmp expect.qux actual.quux 1641 ' 1642done 1643 1644### 1645### series O 1646### 1647 1648test_expect_success 'O: comments are all skipped' ' 1649 cat >input <<-INPUT_END && 1650 #we will 1651 commit refs/heads/O1 1652 # -- ignore all of this text 1653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1654 data <<COMMIT 1655 dirty directory copy 1656 COMMIT 1657 1658 # do not forget the import blank line! 1659 # 1660 # yes, we started from our usual base of branch^0. 1661 # i like branch^0. 1662 from refs/heads/branch^0 1663 # and we need to reuse file2/file5 from N3 above. 1664 M 644 inline file2/file5 1665 # otherwise the tree will be different 1666 data <<EOF 1667 $file5_data 1668 EOF 1669 1670 # do not forget to copy file2 to file3 1671 C file2 file3 1672 # 1673 # or to delete file5 from file2. 1674 D file2/file5 1675 # are we done yet? 1676 1677 INPUT_END 1678 1679 git fast-import <input && 1680 test $(git rev-parse N3) = $(git rev-parse O1) 1681' 1682 1683test_expect_success 'O: blank lines not necessary after data commands' ' 1684 cat >input <<-INPUT_END && 1685 commit refs/heads/O2 1686 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1687 data <<COMMIT 1688 dirty directory copy 1689 COMMIT 1690 from refs/heads/branch^0 1691 M 644 inline file2/file5 1692 data <<EOF 1693 $file5_data 1694 EOF 1695 C file2 file3 1696 D file2/file5 1697 1698 INPUT_END 1699 1700 git fast-import <input && 1701 test $(git rev-parse N3) = $(git rev-parse O2) 1702' 1703 1704test_expect_success 'O: repack before next test' ' 1705 git repack -a -d 1706' 1707 1708test_expect_success 'O: blank lines not necessary after other commands' ' 1709 cat >input <<-INPUT_END && 1710 commit refs/heads/O3 1711 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1712 data <<COMMIT 1713 zstring 1714 COMMIT 1715 commit refs/heads/O3 1716 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1717 data <<COMMIT 1718 zof 1719 COMMIT 1720 checkpoint 1721 commit refs/heads/O3 1722 mark :5 1723 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1724 data <<COMMIT 1725 zempty 1726 COMMIT 1727 checkpoint 1728 commit refs/heads/O3 1729 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1730 data <<COMMIT 1731 zcommits 1732 COMMIT 1733 reset refs/tags/O3-2nd 1734 from :5 1735 reset refs/tags/O3-3rd 1736 from :5 1737 INPUT_END 1738 1739 cat >expect <<-INPUT_END && 1740 string 1741 of 1742 empty 1743 commits 1744 INPUT_END 1745 1746 git fast-import <input && 1747 ls -la .git/objects/pack/pack-*.pack >packlist && 1748 ls -la .git/objects/pack/pack-*.pack >idxlist && 1749 test_line_count = 4 idxlist && 1750 test_line_count = 4 packlist && 1751 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) && 1752 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual && 1753 test_cmp expect actual 1754' 1755 1756test_expect_success 'O: progress outputs as requested by input' ' 1757 cat >input <<-INPUT_END && 1758 commit refs/heads/O4 1759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1760 data <<COMMIT 1761 zstring 1762 COMMIT 1763 commit refs/heads/O4 1764 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1765 data <<COMMIT 1766 zof 1767 COMMIT 1768 progress Two commits down, 2 to go! 1769 commit refs/heads/O4 1770 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1771 data <<COMMIT 1772 zempty 1773 COMMIT 1774 progress Three commits down, 1 to go! 1775 commit refs/heads/O4 1776 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1777 data <<COMMIT 1778 zcommits 1779 COMMIT 1780 progress done! 1781 INPUT_END 1782 git fast-import <input >actual && 1783 grep "progress " <input >expect && 1784 test_cmp expect actual 1785' 1786 1787### 1788### series P (gitlinks) 1789### 1790 1791test_expect_success 'P: superproject & submodule mix' ' 1792 cat >input <<-INPUT_END && 1793 blob 1794 mark :1 1795 data 10 1796 test file 1797 1798 reset refs/heads/sub 1799 commit refs/heads/sub 1800 mark :2 1801 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1802 data 12 1803 sub_initial 1804 M 100644 :1 file 1805 1806 blob 1807 mark :3 1808 data <<DATAEND 1809 [submodule "sub"] 1810 path = sub 1811 url = "$(pwd)/sub" 1812 DATAEND 1813 1814 commit refs/heads/subuse1 1815 mark :4 1816 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1817 data 8 1818 initial 1819 from refs/heads/main 1820 M 100644 :3 .gitmodules 1821 M 160000 :2 sub 1822 1823 blob 1824 mark :5 1825 data 20 1826 test file 1827 more data 1828 1829 commit refs/heads/sub 1830 mark :6 1831 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1832 data 11 1833 sub_second 1834 from :2 1835 M 100644 :5 file 1836 1837 commit refs/heads/subuse1 1838 mark :7 1839 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1840 data 7 1841 second 1842 from :4 1843 M 160000 :6 sub 1844 1845 INPUT_END 1846 1847 git fast-import <input && 1848 git checkout subuse1 && 1849 rm -rf sub && 1850 mkdir sub && 1851 ( 1852 cd sub && 1853 git init && 1854 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main && 1855 git checkout main 1856 ) && 1857 git submodule init && 1858 git submodule update 1859' 1860 1861test_expect_success 'P: verbatim SHA gitlinks' ' 1862 SUBLAST=$(git rev-parse --verify sub) && 1863 SUBPREV=$(git rev-parse --verify sub^) && 1864 1865 cat >input <<-INPUT_END && 1866 blob 1867 mark :1 1868 data <<DATAEND 1869 [submodule "sub"] 1870 path = sub 1871 url = "$(pwd)/sub" 1872 DATAEND 1873 1874 commit refs/heads/subuse2 1875 mark :2 1876 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1877 data 8 1878 initial 1879 from refs/heads/main 1880 M 100644 :1 .gitmodules 1881 M 160000 $SUBPREV sub 1882 1883 commit refs/heads/subuse2 1884 mark :3 1885 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1886 data 7 1887 second 1888 from :2 1889 M 160000 $SUBLAST sub 1890 1891 INPUT_END 1892 1893 git branch -D sub && 1894 git gc --prune=now && 1895 git fast-import <input && 1896 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1) 1897' 1898 1899test_expect_success 'P: fail on inline gitlink' ' 1900 test_tick && 1901 cat >input <<-INPUT_END && 1902 commit refs/heads/subuse3 1903 mark :1 1904 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1905 data <<COMMIT 1906 corrupt 1907 COMMIT 1908 1909 from refs/heads/subuse2 1910 M 160000 inline sub 1911 data <<DATA 1912 $SUBPREV 1913 DATA 1914 1915 INPUT_END 1916 1917 test_must_fail git fast-import <input 1918' 1919 1920test_expect_success 'P: fail on blob mark in gitlink' ' 1921 test_tick && 1922 cat >input <<-INPUT_END && 1923 blob 1924 mark :1 1925 data <<DATA 1926 $SUBPREV 1927 DATA 1928 1929 commit refs/heads/subuse3 1930 mark :2 1931 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1932 data <<COMMIT 1933 corrupt 1934 COMMIT 1935 1936 from refs/heads/subuse2 1937 M 160000 :1 sub 1938 1939 INPUT_END 1940 1941 test_must_fail git fast-import <input 1942' 1943 1944### 1945### series Q (notes) 1946### 1947 1948test_expect_success 'Q: commit notes' ' 1949 note1_data="The first note for the first commit" && 1950 note2_data="The first note for the second commit" && 1951 note3_data="The first note for the third commit" && 1952 note1b_data="The second note for the first commit" && 1953 note1c_data="The third note for the first commit" && 1954 note2b_data="The second note for the second commit" && 1955 1956 test_tick && 1957 cat >input <<-INPUT_END && 1958 blob 1959 mark :2 1960 data <<EOF 1961 $file2_data 1962 EOF 1963 1964 commit refs/heads/notes-test 1965 mark :3 1966 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1967 data <<COMMIT 1968 first (:3) 1969 COMMIT 1970 1971 M 644 :2 file2 1972 1973 blob 1974 mark :4 1975 data $file4_len 1976 $file4_data 1977 commit refs/heads/notes-test 1978 mark :5 1979 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1980 data <<COMMIT 1981 second (:5) 1982 COMMIT 1983 1984 M 644 :4 file4 1985 1986 commit refs/heads/notes-test 1987 mark :6 1988 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 1989 data <<COMMIT 1990 third (:6) 1991 COMMIT 1992 1993 M 644 inline file5 1994 data <<EOF 1995 $file5_data 1996 EOF 1997 1998 M 755 inline file6 1999 data <<EOF 2000 $file6_data 2001 EOF 2002 2003 blob 2004 mark :7 2005 data <<EOF 2006 $note1_data 2007 EOF 2008 2009 blob 2010 mark :8 2011 data <<EOF 2012 $note2_data 2013 EOF 2014 2015 commit refs/notes/foobar 2016 mark :9 2017 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2018 data <<COMMIT 2019 notes (:9) 2020 COMMIT 2021 2022 N :7 :3 2023 N :8 :5 2024 N inline :6 2025 data <<EOF 2026 $note3_data 2027 EOF 2028 2029 commit refs/notes/foobar 2030 mark :10 2031 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2032 data <<COMMIT 2033 notes (:10) 2034 COMMIT 2035 2036 N inline :3 2037 data <<EOF 2038 $note1b_data 2039 EOF 2040 2041 commit refs/notes/foobar2 2042 mark :11 2043 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2044 data <<COMMIT 2045 notes (:11) 2046 COMMIT 2047 2048 N inline :3 2049 data <<EOF 2050 $note1c_data 2051 EOF 2052 2053 commit refs/notes/foobar 2054 mark :12 2055 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2056 data <<COMMIT 2057 notes (:12) 2058 COMMIT 2059 2060 deleteall 2061 N inline :5 2062 data <<EOF 2063 $note2b_data 2064 EOF 2065 2066 INPUT_END 2067 2068 git fast-import <input && 2069 git log --raw notes-test 2070' 2071 2072test_expect_success 'Q: verify pack' ' 2073 verify_packs 2074' 2075 2076test_expect_success 'Q: verify first commit' ' 2077 commit1=$(git rev-parse notes-test~2) && 2078 commit2=$(git rev-parse notes-test^) && 2079 commit3=$(git rev-parse notes-test) && 2080 2081 cat >expect <<-EOF && 2082 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2083 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2084 2085 first (:3) 2086 EOF 2087 git cat-file commit notes-test~2 | sed 1d >actual && 2088 test_cmp expect actual 2089' 2090 2091test_expect_success 'Q: verify second commit' ' 2092 cat >expect <<-EOF && 2093 parent $commit1 2094 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2095 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2096 2097 second (:5) 2098 EOF 2099 git cat-file commit notes-test^ | sed 1d >actual && 2100 test_cmp expect actual 2101' 2102 2103test_expect_success 'Q: verify third commit' ' 2104 cat >expect <<-EOF && 2105 parent $commit2 2106 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2107 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2108 2109 third (:6) 2110 EOF 2111 git cat-file commit notes-test | sed 1d >actual && 2112 test_cmp expect actual 2113' 2114 2115test_expect_success 'Q: verify first notes commit' ' 2116 cat >expect <<-EOF && 2117 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2118 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2119 2120 notes (:9) 2121 EOF 2122 git cat-file commit refs/notes/foobar~2 | sed 1d >actual && 2123 test_cmp expect actual 2124' 2125 2126test_expect_success 'Q: verify first notes tree' ' 2127 sort >expect <<-EOF && 2128 100644 blob $commit1 2129 100644 blob $commit2 2130 100644 blob $commit3 2131 EOF 2132 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2133 test_cmp expect actual 2134' 2135 2136test_expect_success 'Q: verify first note for first commit' ' 2137 echo "$note1_data" >expect && 2138 git cat-file blob refs/notes/foobar~2:$commit1 >actual && 2139 test_cmp expect actual 2140' 2141 2142test_expect_success 'Q: verify first note for second commit' ' 2143 echo "$note2_data" >expect && 2144 git cat-file blob refs/notes/foobar~2:$commit2 >actual && 2145 test_cmp expect actual 2146' 2147 2148test_expect_success 'Q: verify first note for third commit' ' 2149 echo "$note3_data" >expect && 2150 git cat-file blob refs/notes/foobar~2:$commit3 >actual && 2151 test_cmp expect actual 2152' 2153 2154test_expect_success 'Q: verify second notes commit' ' 2155 cat >expect <<-EOF && 2156 parent $(git rev-parse --verify refs/notes/foobar~2) 2157 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2158 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2159 2160 notes (:10) 2161 EOF 2162 git cat-file commit refs/notes/foobar^ | sed 1d >actual && 2163 test_cmp expect actual 2164' 2165 2166test_expect_success 'Q: verify second notes tree' ' 2167 sort >expect <<-EOF && 2168 100644 blob $commit1 2169 100644 blob $commit2 2170 100644 blob $commit3 2171 EOF 2172 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2173 test_cmp expect actual 2174' 2175 2176test_expect_success 'Q: verify second note for first commit' ' 2177 echo "$note1b_data" >expect && 2178 git cat-file blob refs/notes/foobar^:$commit1 >actual && 2179 test_cmp expect actual 2180' 2181 2182test_expect_success 'Q: verify first note for second commit' ' 2183 echo "$note2_data" >expect && 2184 git cat-file blob refs/notes/foobar^:$commit2 >actual && 2185 test_cmp expect actual 2186' 2187 2188test_expect_success 'Q: verify first note for third commit' ' 2189 echo "$note3_data" >expect && 2190 git cat-file blob refs/notes/foobar^:$commit3 >actual && 2191 test_cmp expect actual 2192' 2193 2194test_expect_success 'Q: verify third notes commit' ' 2195 cat >expect <<-EOF && 2196 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2197 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2198 2199 notes (:11) 2200 EOF 2201 git cat-file commit refs/notes/foobar2 | sed 1d >actual && 2202 test_cmp expect actual 2203' 2204 2205test_expect_success 'Q: verify third notes tree' ' 2206 sort >expect <<-EOF && 2207 100644 blob $commit1 2208 EOF 2209 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2210 test_cmp expect actual 2211' 2212 2213test_expect_success 'Q: verify third note for first commit' ' 2214 echo "$note1c_data" >expect && 2215 git cat-file blob refs/notes/foobar2:$commit1 >actual && 2216 test_cmp expect actual 2217' 2218 2219test_expect_success 'Q: verify fourth notes commit' ' 2220 cat >expect <<-EOF && 2221 parent $(git rev-parse --verify refs/notes/foobar^) 2222 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2223 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2224 2225 notes (:12) 2226 EOF 2227 git cat-file commit refs/notes/foobar | sed 1d >actual && 2228 test_cmp expect actual 2229' 2230 2231test_expect_success 'Q: verify fourth notes tree' ' 2232 sort >expect <<-EOF && 2233 100644 blob $commit2 2234 EOF 2235 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && 2236 test_cmp expect actual 2237' 2238 2239test_expect_success 'Q: verify second note for second commit' ' 2240 echo "$note2b_data" >expect && 2241 git cat-file blob refs/notes/foobar:$commit2 >actual && 2242 test_cmp expect actual 2243' 2244 2245test_expect_success 'Q: deny note on empty branch' ' 2246 cat >input <<-EOF && 2247 reset refs/heads/Q0 2248 2249 commit refs/heads/note-Q0 2250 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2251 data <<COMMIT 2252 Note for an empty branch. 2253 COMMIT 2254 2255 N inline refs/heads/Q0 2256 data <<NOTE 2257 some note 2258 NOTE 2259 EOF 2260 test_must_fail git fast-import <input 2261' 2262 2263### 2264### series R (feature and option) 2265### 2266 2267test_expect_success 'R: abort on unsupported feature' ' 2268 cat >input <<-EOF && 2269 feature no-such-feature-exists 2270 EOF 2271 2272 test_must_fail git fast-import <input 2273' 2274 2275test_expect_success 'R: supported feature is accepted' ' 2276 cat >input <<-EOF && 2277 feature date-format=now 2278 EOF 2279 2280 git fast-import <input 2281' 2282 2283test_expect_success 'R: abort on receiving feature after data command' ' 2284 cat >input <<-EOF && 2285 blob 2286 data 3 2287 hi 2288 feature date-format=now 2289 EOF 2290 2291 test_must_fail git fast-import <input 2292' 2293 2294test_expect_success 'R: import-marks features forbidden by default' ' 2295 >git.marks && 2296 echo "feature import-marks=git.marks" >input && 2297 test_must_fail git fast-import <input && 2298 echo "feature import-marks-if-exists=git.marks" >input && 2299 test_must_fail git fast-import <input 2300' 2301 2302test_expect_success 'R: only one import-marks feature allowed per stream' ' 2303 >git.marks && 2304 >git2.marks && 2305 cat >input <<-EOF && 2306 feature import-marks=git.marks 2307 feature import-marks=git2.marks 2308 EOF 2309 2310 test_must_fail git fast-import --allow-unsafe-features <input 2311' 2312 2313test_expect_success 'R: export-marks feature forbidden by default' ' 2314 echo "feature export-marks=git.marks" >input && 2315 test_must_fail git fast-import <input 2316' 2317 2318test_expect_success 'R: export-marks feature results in a marks file being created' ' 2319 cat >input <<-EOF && 2320 feature export-marks=git.marks 2321 blob 2322 mark :1 2323 data 3 2324 hi 2325 2326 EOF 2327 2328 git fast-import --allow-unsafe-features <input && 2329 grep :1 git.marks 2330' 2331 2332test_expect_success 'R: export-marks options can be overridden by commandline options' ' 2333 cat >input <<-\EOF && 2334 feature export-marks=feature-sub/git.marks 2335 blob 2336 mark :1 2337 data 3 2338 hi 2339 2340 EOF 2341 git fast-import --allow-unsafe-features \ 2342 --export-marks=cmdline-sub/other.marks <input && 2343 grep :1 cmdline-sub/other.marks && 2344 test_path_is_missing feature-sub 2345' 2346 2347test_expect_success 'R: catch typo in marks file name' ' 2348 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null && 2349 echo "feature import-marks=nonexistent.marks" | 2350 test_must_fail git fast-import --allow-unsafe-features 2351' 2352 2353test_expect_success 'R: import and output marks can be the same file' ' 2354 rm -f io.marks && 2355 blob=$(echo hi | git hash-object --stdin) && 2356 cat >expect <<-EOF && 2357 :1 $blob 2358 :2 $blob 2359 EOF 2360 git fast-import --export-marks=io.marks <<-\EOF && 2361 blob 2362 mark :1 2363 data 3 2364 hi 2365 2366 EOF 2367 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && 2368 blob 2369 mark :2 2370 data 3 2371 hi 2372 2373 EOF 2374 test_cmp expect io.marks 2375' 2376 2377test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' ' 2378 rm -f io.marks && 2379 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF 2380 blob 2381 mark :1 2382 data 3 2383 hi 2384 2385 EOF 2386' 2387 2388test_expect_success 'R: --import-marks-if-exists' ' 2389 rm -f io.marks && 2390 blob=$(echo hi | git hash-object --stdin) && 2391 echo ":1 $blob" >expect && 2392 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && 2393 blob 2394 mark :1 2395 data 3 2396 hi 2397 2398 EOF 2399 test_cmp expect io.marks 2400' 2401 2402test_expect_success 'R: feature import-marks-if-exists' ' 2403 rm -f io.marks && 2404 2405 git fast-import --export-marks=io.marks \ 2406 --allow-unsafe-features <<-\EOF && 2407 feature import-marks-if-exists=not_io.marks 2408 EOF 2409 test_must_be_empty io.marks && 2410 2411 blob=$(echo hi | git hash-object --stdin) && 2412 2413 echo ":1 $blob" >io.marks && 2414 echo ":1 $blob" >expect && 2415 echo ":2 $blob" >>expect && 2416 2417 git fast-import --export-marks=io.marks \ 2418 --allow-unsafe-features <<-\EOF && 2419 feature import-marks-if-exists=io.marks 2420 blob 2421 mark :2 2422 data 3 2423 hi 2424 2425 EOF 2426 test_cmp expect io.marks && 2427 2428 echo ":3 $blob" >>expect && 2429 2430 git fast-import --import-marks=io.marks \ 2431 --export-marks=io.marks \ 2432 --allow-unsafe-features <<-\EOF && 2433 feature import-marks-if-exists=not_io.marks 2434 blob 2435 mark :3 2436 data 3 2437 hi 2438 2439 EOF 2440 test_cmp expect io.marks && 2441 2442 git fast-import --import-marks-if-exists=not_io.marks \ 2443 --export-marks=io.marks \ 2444 --allow-unsafe-features <<-\EOF && 2445 feature import-marks-if-exists=io.marks 2446 EOF 2447 test_must_be_empty io.marks 2448' 2449 2450test_expect_success 'R: import to output marks works without any content' ' 2451 cat >input <<-EOF && 2452 feature import-marks=marks.out 2453 feature export-marks=marks.new 2454 EOF 2455 2456 git fast-import --allow-unsafe-features <input && 2457 test_cmp marks.out marks.new 2458' 2459 2460test_expect_success 'R: import marks prefers commandline marks file over the stream' ' 2461 cat >input <<-EOF && 2462 feature import-marks=nonexistent.marks 2463 feature export-marks=marks.new 2464 EOF 2465 2466 git fast-import --import-marks=marks.out --allow-unsafe-features <input && 2467 test_cmp marks.out marks.new 2468' 2469 2470 2471test_expect_success 'R: multiple --import-marks= should be honoured' ' 2472 cat >input <<-EOF && 2473 feature import-marks=nonexistent.marks 2474 feature export-marks=combined.marks 2475 EOF 2476 2477 head -n2 marks.out > one.marks && 2478 tail -n +3 marks.out > two.marks && 2479 git fast-import --import-marks=one.marks --import-marks=two.marks \ 2480 --allow-unsafe-features <input && 2481 test_cmp marks.out combined.marks 2482' 2483 2484test_expect_success 'R: feature relative-marks should be honoured' ' 2485 cat >input <<-EOF && 2486 feature relative-marks 2487 feature import-marks=relative.in 2488 feature export-marks=relative.out 2489 EOF 2490 2491 mkdir -p .git/info/fast-import/ && 2492 cp marks.new .git/info/fast-import/relative.in && 2493 git fast-import --allow-unsafe-features <input && 2494 test_cmp marks.new .git/info/fast-import/relative.out 2495' 2496 2497test_expect_success 'R: feature no-relative-marks should be honoured' ' 2498 cat >input <<-EOF && 2499 feature relative-marks 2500 feature import-marks=relative.in 2501 feature no-relative-marks 2502 feature export-marks=non-relative.out 2503 EOF 2504 2505 git fast-import --allow-unsafe-features <input && 2506 test_cmp marks.new non-relative.out 2507' 2508 2509test_expect_success 'R: feature ls supported' ' 2510 echo "feature ls" | 2511 git fast-import 2512' 2513 2514test_expect_success 'R: feature cat-blob supported' ' 2515 echo "feature cat-blob" | 2516 git fast-import 2517' 2518 2519test_expect_success 'R: cat-blob-fd must be a nonnegative integer' ' 2520 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null 2521' 2522 2523test_expect_success !MINGW 'R: print old blob' ' 2524 blob=$(echo "yes it can" | git hash-object -w --stdin) && 2525 cat >expect <<-EOF && 2526 ${blob} blob 11 2527 yes it can 2528 2529 EOF 2530 echo "cat-blob $blob" | 2531 git fast-import --cat-blob-fd=6 6>actual && 2532 test_cmp expect actual 2533' 2534 2535test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' ' 2536 echo hello >greeting && 2537 blob=$(git hash-object -w greeting) && 2538 cat >expect <<-EOF && 2539 ${blob} blob 6 2540 hello 2541 2542 EOF 2543 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && 2544 cat-blob $blob 2545 EOF 2546 test_cmp expect actual.3 && 2547 test_must_be_empty actual.1 && 2548 git fast-import 3>actual.3 >actual.1 <<-EOF && 2549 option cat-blob-fd=3 2550 cat-blob $blob 2551 EOF 2552 test_must_be_empty actual.3 && 2553 test_cmp expect actual.1 2554' 2555 2556test_expect_success !MINGW 'R: print mark for new blob' ' 2557 echo "effluentish" | git hash-object --stdin >expect && 2558 git fast-import --cat-blob-fd=6 6>actual <<-\EOF && 2559 blob 2560 mark :1 2561 data <<BLOB_END 2562 effluentish 2563 BLOB_END 2564 get-mark :1 2565 EOF 2566 test_cmp expect actual 2567' 2568 2569test_expect_success !MINGW 'R: print new blob' ' 2570 blob=$(echo "yep yep yep" | git hash-object --stdin) && 2571 cat >expect <<-EOF && 2572 ${blob} blob 12 2573 yep yep yep 2574 2575 EOF 2576 git fast-import --cat-blob-fd=6 6>actual <<-\EOF && 2577 blob 2578 mark :1 2579 data <<BLOB_END 2580 yep yep yep 2581 BLOB_END 2582 cat-blob :1 2583 EOF 2584 test_cmp expect actual 2585' 2586 2587test_expect_success !MINGW 'R: print new blob by sha1' ' 2588 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) && 2589 cat >expect <<-EOF && 2590 ${blob} blob 25 2591 a new blob named by sha1 2592 2593 EOF 2594 git fast-import --cat-blob-fd=6 6>actual <<-EOF && 2595 blob 2596 data <<BLOB_END 2597 a new blob named by sha1 2598 BLOB_END 2599 cat-blob $blob 2600 EOF 2601 test_cmp expect actual 2602' 2603 2604test_expect_success 'setup: big file' ' 2605 ( 2606 echo "the quick brown fox jumps over the lazy dog" >big && 2607 for i in 1 2 3 2608 do 2609 cat big big big big >bigger && 2610 cat bigger bigger bigger bigger >big || 2611 exit 2612 done 2613 ) 2614' 2615 2616test_expect_success 'R: print two blobs to stdout' ' 2617 blob1=$(git hash-object big) && 2618 blob1_len=$(wc -c <big) && 2619 blob2=$(echo hello | git hash-object --stdin) && 2620 { 2621 echo ${blob1} blob $blob1_len && 2622 cat big && 2623 cat <<-EOF 2624 2625 ${blob2} blob 6 2626 hello 2627 2628 EOF 2629 } >expect && 2630 { 2631 cat <<-\END_PART1 && 2632 blob 2633 mark :1 2634 data <<data_end 2635 END_PART1 2636 cat big && 2637 cat <<-\EOF 2638 data_end 2639 blob 2640 mark :2 2641 data <<data_end 2642 hello 2643 data_end 2644 cat-blob :1 2645 cat-blob :2 2646 EOF 2647 } | 2648 git fast-import >actual && 2649 test_cmp expect actual 2650' 2651 2652test_expect_success PIPE 'R: copy using cat-file' ' 2653 expect_id=$(git hash-object big) && 2654 expect_len=$(wc -c <big) && 2655 echo $expect_id blob $expect_len >expect.response && 2656 2657 rm -f blobs && 2658 2659 mkfifo blobs && 2660 ( 2661 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && 2662 cat <<-\EOF && 2663 feature cat-blob 2664 blob 2665 mark :1 2666 data <<BLOB 2667 EOF 2668 cat big && 2669 cat <<-\EOF && 2670 BLOB 2671 cat-blob :1 2672 EOF 2673 2674 read blob_id type size <&3 && 2675 echo "$blob_id $type $size" >response && 2676 test_copy_bytes $size >blob <&3 && 2677 read newline <&3 && 2678 2679 cat <<-EOF && 2680 commit refs/heads/copied 2681 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2682 data <<COMMIT 2683 copy big file as file3 2684 COMMIT 2685 M 644 inline file3 2686 data <<BLOB 2687 EOF 2688 cat blob && 2689 echo BLOB 2690 ) 3<blobs | 2691 git fast-import --cat-blob-fd=3 3>blobs && 2692 git show copied:file3 >actual && 2693 test_cmp expect.response response && 2694 test_cmp big actual 2695' 2696 2697test_expect_success PIPE 'R: print blob mid-commit' ' 2698 rm -f blobs && 2699 echo "A blob from _before_ the commit." >expect && 2700 mkfifo blobs && 2701 ( 2702 exec 3<blobs && 2703 cat <<-EOF && 2704 feature cat-blob 2705 blob 2706 mark :1 2707 data <<BLOB 2708 A blob from _before_ the commit. 2709 BLOB 2710 commit refs/heads/temporary 2711 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2712 data <<COMMIT 2713 Empty commit 2714 COMMIT 2715 cat-blob :1 2716 EOF 2717 2718 read blob_id type size <&3 && 2719 test_copy_bytes $size >actual <&3 && 2720 read newline <&3 && 2721 2722 echo 2723 ) | 2724 git fast-import --cat-blob-fd=3 3>blobs && 2725 test_cmp expect actual 2726' 2727 2728test_expect_success PIPE 'R: print staged blob within commit' ' 2729 rm -f blobs && 2730 echo "A blob from _within_ the commit." >expect && 2731 mkfifo blobs && 2732 ( 2733 exec 3<blobs && 2734 cat <<-EOF && 2735 feature cat-blob 2736 commit refs/heads/within 2737 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2738 data <<COMMIT 2739 Empty commit 2740 COMMIT 2741 M 644 inline within 2742 data <<BLOB 2743 A blob from _within_ the commit. 2744 BLOB 2745 EOF 2746 2747 to_get=$( 2748 echo "A blob from _within_ the commit." | 2749 git hash-object --stdin 2750 ) && 2751 echo "cat-blob $to_get" && 2752 2753 read blob_id type size <&3 && 2754 test_copy_bytes $size >actual <&3 && 2755 read newline <&3 && 2756 2757 echo deleteall 2758 ) | 2759 git fast-import --cat-blob-fd=3 3>blobs && 2760 test_cmp expect actual 2761' 2762 2763test_expect_success 'R: quiet option results in no stats being output' ' 2764 cat >input <<-EOF && 2765 option git quiet 2766 blob 2767 data 3 2768 hi 2769 2770 EOF 2771 2772 git fast-import 2>output <input && 2773 test_must_be_empty output 2774' 2775 2776test_expect_success 'R: feature done means terminating "done" is mandatory' ' 2777 echo feature done | test_must_fail git fast-import && 2778 test_must_fail git fast-import --done </dev/null 2779' 2780 2781test_expect_success 'R: terminating "done" with trailing gibberish is ok' ' 2782 git fast-import <<-\EOF && 2783 feature done 2784 done 2785 trailing gibberish 2786 EOF 2787 git fast-import <<-\EOF 2788 done 2789 more trailing gibberish 2790 EOF 2791' 2792 2793test_expect_success 'R: terminating "done" within commit' ' 2794 cat >expect <<-\EOF && 2795 OBJID 2796 :000000 100644 OBJID OBJID A hello.c 2797 :000000 100644 OBJID OBJID A hello2.c 2798 EOF 2799 git fast-import <<-EOF && 2800 commit refs/heads/done-ends 2801 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2802 data <<EOT 2803 Commit terminated by "done" command 2804 EOT 2805 M 100644 inline hello.c 2806 data <<EOT 2807 Hello, world. 2808 EOT 2809 C hello.c hello2.c 2810 done 2811 EOF 2812 git rev-list done-ends | 2813 git diff-tree -r --stdin --root --always | 2814 sed -e "s/$OID_REGEX/OBJID/g" >actual && 2815 test_cmp expect actual 2816' 2817 2818test_expect_success 'R: die on unknown option' ' 2819 cat >input <<-EOF && 2820 option git non-existing-option 2821 EOF 2822 2823 test_must_fail git fast-import <input 2824' 2825 2826test_expect_success 'R: unknown commandline options are rejected' '\ 2827 test_must_fail git fast-import --non-existing-option < /dev/null 2828' 2829 2830test_expect_success 'R: die on invalid option argument' ' 2831 echo "option git active-branches=-5" | 2832 test_must_fail git fast-import && 2833 echo "option git depth=" | 2834 test_must_fail git fast-import && 2835 test_must_fail git fast-import --depth="5 elephants" </dev/null 2836' 2837 2838test_expect_success 'R: ignore non-git options' ' 2839 cat >input <<-EOF && 2840 option non-existing-vcs non-existing-option 2841 EOF 2842 2843 git fast-import <input 2844' 2845 2846test_expect_success 'R: corrupt lines do not mess marks file' ' 2847 rm -f io.marks && 2848 blob=$(echo hi | git hash-object --stdin) && 2849 cat >expect <<-EOF && 2850 :3 $ZERO_OID 2851 :1 $blob 2852 :2 $blob 2853 EOF 2854 cp expect io.marks && 2855 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && 2856 2857 EOF 2858 test_cmp expect io.marks 2859' 2860 2861## 2862## R: very large blobs 2863## 2864test_expect_success 'R: blob bigger than threshold' ' 2865 blobsize=$((2*1024*1024 + 53)) && 2866 test-tool genrandom bar $blobsize >expect && 2867 cat >input <<-INPUT_END && 2868 commit refs/heads/big-file 2869 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2870 data <<COMMIT 2871 R - big file 2872 COMMIT 2873 2874 M 644 inline big1 2875 data $blobsize 2876 INPUT_END 2877 cat expect >>input && 2878 cat >>input <<-INPUT_END && 2879 M 644 inline big2 2880 data $blobsize 2881 INPUT_END 2882 cat expect >>input && 2883 echo >>input && 2884 2885 test_create_repo R && 2886 git --git-dir=R/.git config fastimport.unpackLimit 0 && 2887 git --git-dir=R/.git fast-import --big-file-threshold=1 <input 2888' 2889 2890test_expect_success 'R: verify created pack' ' 2891 ( 2892 cd R && 2893 verify_packs -v > ../verify 2894 ) 2895' 2896 2897test_expect_success 'R: verify written objects' ' 2898 git --git-dir=R/.git cat-file blob big-file:big1 >actual && 2899 test_cmp_bin expect actual && 2900 a=$(git --git-dir=R/.git rev-parse big-file:big1) && 2901 b=$(git --git-dir=R/.git rev-parse big-file:big2) && 2902 test $a = $b 2903' 2904 2905test_expect_success 'R: blob appears only once' ' 2906 n=$(grep $a verify | wc -l) && 2907 test 1 = $n 2908' 2909 2910### 2911### series S (mark and path parsing) 2912### 2913# 2914# Make sure missing spaces and EOLs after mark references 2915# cause errors. 2916# 2917# Setup: 2918# 2919# 1--2--4 2920# \ / 2921# -3- 2922# 2923# commit marks: 301, 302, 303, 304 2924# blob marks: 403, 404, resp. 2925# note mark: 202 2926# 2927# The error message when a space is missing not at the 2928# end of the line is: 2929# 2930# Missing space after .. 2931# 2932# or when extra characters come after the mark at the end 2933# of the line: 2934# 2935# Garbage after .. 2936# 2937# or when the dataref is neither "inline " or a known SHA1, 2938# 2939# Invalid dataref .. 2940# 2941test_expect_success 'S: initialize for S tests' ' 2942 test_tick && 2943 2944 cat >input <<-INPUT_END && 2945 commit refs/heads/S 2946 mark :301 2947 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2948 data <<COMMIT 2949 commit 1 2950 COMMIT 2951 M 100644 inline hello.c 2952 data <<BLOB 2953 blob 1 2954 BLOB 2955 2956 commit refs/heads/S 2957 mark :302 2958 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2959 data <<COMMIT 2960 commit 2 2961 COMMIT 2962 from :301 2963 M 100644 inline hello.c 2964 data <<BLOB 2965 blob 2 2966 BLOB 2967 2968 blob 2969 mark :403 2970 data <<BLOB 2971 blob 3 2972 BLOB 2973 2974 blob 2975 mark :202 2976 data <<BLOB 2977 note 2 2978 BLOB 2979 INPUT_END 2980 2981 git fast-import --export-marks=marks <input 2982' 2983 2984# 2985# filemodify, three datarefs 2986# 2987test_expect_success 'S: filemodify with garbage after mark must fail' ' 2988 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 2989 commit refs/heads/S 2990 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 2991 data <<COMMIT 2992 commit N 2993 COMMIT 2994 M 100644 :403x hello.c 2995 EOF 2996 test_grep "space after mark" err 2997' 2998 2999# inline is misspelled; fast-import thinks it is some unknown dataref 3000test_expect_success 'S: filemodify with garbage after inline must fail' ' 3001 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3002 commit refs/heads/S 3003 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3004 data <<COMMIT 3005 commit N 3006 COMMIT 3007 M 100644 inlineX hello.c 3008 data <<BLOB 3009 inline 3010 BLOB 3011 EOF 3012 test_grep "nvalid dataref" err 3013' 3014 3015test_expect_success 'S: filemodify with garbage after sha1 must fail' ' 3016 sha1=$(grep :403 marks | cut -d\ -f2) && 3017 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3018 commit refs/heads/S 3019 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3020 data <<COMMIT 3021 commit N 3022 COMMIT 3023 M 100644 ${sha1}x hello.c 3024 EOF 3025 test_grep "space after SHA1" err 3026' 3027 3028# 3029# notemodify, three ways to say dataref 3030# 3031test_expect_success 'S: notemodify with garbage after mark dataref must fail' ' 3032 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3033 commit refs/heads/S 3034 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3035 data <<COMMIT 3036 commit S note dataref markref 3037 COMMIT 3038 N :202x :302 3039 EOF 3040 test_grep "space after mark" err 3041' 3042 3043test_expect_success 'S: notemodify with garbage after inline dataref must fail' ' 3044 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3045 commit refs/heads/S 3046 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3047 data <<COMMIT 3048 commit S note dataref inline 3049 COMMIT 3050 N inlineX :302 3051 data <<BLOB 3052 note blob 3053 BLOB 3054 EOF 3055 test_grep "nvalid dataref" err 3056' 3057 3058test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' ' 3059 sha1=$(grep :202 marks | cut -d\ -f2) && 3060 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3061 commit refs/heads/S 3062 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3063 data <<COMMIT 3064 commit S note dataref sha1 3065 COMMIT 3066 N ${sha1}x :302 3067 EOF 3068 test_grep "space after SHA1" err 3069' 3070 3071# 3072# notemodify, mark in commit-ish 3073# 3074test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' ' 3075 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3076 commit refs/heads/Snotes 3077 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3078 data <<COMMIT 3079 commit S note commit-ish 3080 COMMIT 3081 N :202 :302x 3082 EOF 3083 test_grep "after mark" err 3084' 3085 3086# 3087# from 3088# 3089test_expect_success 'S: from with garbage after mark must fail' ' 3090 test_must_fail \ 3091 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err && 3092 commit refs/heads/S2 3093 mark :303 3094 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3095 data <<COMMIT 3096 commit 3 3097 COMMIT 3098 from :301x 3099 M 100644 :403 hello.c 3100 EOF 3101 3102 3103 # go create the commit, need it for merge test 3104 git fast-import --import-marks=marks --export-marks=marks <<-EOF && 3105 commit refs/heads/S2 3106 mark :303 3107 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3108 data <<COMMIT 3109 commit 3 3110 COMMIT 3111 from :301 3112 M 100644 :403 hello.c 3113 EOF 3114 3115 # now evaluate the error 3116 test_grep "after mark" err 3117' 3118 3119 3120# 3121# merge 3122# 3123test_expect_success 'S: merge with garbage after mark must fail' ' 3124 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3125 commit refs/heads/S 3126 mark :304 3127 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3128 data <<COMMIT 3129 merge 4 3130 COMMIT 3131 from :302 3132 merge :303x 3133 M 100644 :403 hello.c 3134 EOF 3135 test_grep "after mark" err 3136' 3137 3138# 3139# tag, from markref 3140# 3141test_expect_success 'S: tag with garbage after mark must fail' ' 3142 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3143 tag refs/tags/Stag 3144 from :302x 3145 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3146 data <<TAG 3147 tag S 3148 TAG 3149 EOF 3150 test_grep "after mark" err 3151' 3152 3153# 3154# cat-blob markref 3155# 3156test_expect_success 'S: cat-blob with garbage after mark must fail' ' 3157 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3158 cat-blob :403x 3159 EOF 3160 test_grep "after mark" err 3161' 3162 3163# 3164# ls markref 3165# 3166test_expect_success 'S: ls with garbage after mark must fail' ' 3167 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3168 ls :302x hello.c 3169 EOF 3170 test_grep "space after mark" err 3171' 3172 3173test_expect_success 'S: ls with garbage after sha1 must fail' ' 3174 sha1=$(grep :302 marks | cut -d\ -f2) && 3175 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && 3176 ls ${sha1}x hello.c 3177 EOF 3178 test_grep "space after tree-ish" err 3179' 3180 3181# 3182# Path parsing 3183# 3184# There are two sorts of ways a path can be parsed, depending on whether it is 3185# the last field on the line. Additionally, ls without a <dataref> has a special 3186# case. Test every occurrence of <path> in the grammar against every error case. 3187# Paths for the root (empty strings) are tested elsewhere. 3188# 3189 3190# 3191# Valid paths at the end of a line: filemodify, filedelete, filecopy (dest), 3192# filerename (dest), and ls. 3193# 3194# commit :301 from root -- modify hello.c (for setup) 3195# commit :302 from :301 -- modify $path 3196# commit :303 from :302 -- delete $path 3197# commit :304 from :301 -- copy hello.c $path 3198# commit :305 from :301 -- rename hello.c $path 3199# ls :305 $path 3200# 3201test_path_eol_success () { 3202 local test="$1" path="$2" unquoted_path="$3" 3203 test_expect_success "S: paths at EOL with $test must work" ' 3204 test_when_finished "git branch -D S-path-eol" && 3205 3206 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF >out 2>err && 3207 blob 3208 mark :401 3209 data <<BLOB 3210 hello world 3211 BLOB 3212 3213 blob 3214 mark :402 3215 data <<BLOB 3216 hallo welt 3217 BLOB 3218 3219 commit refs/heads/S-path-eol 3220 mark :301 3221 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3222 data <<COMMIT 3223 initial commit 3224 COMMIT 3225 M 100644 :401 hello.c 3226 3227 commit refs/heads/S-path-eol 3228 mark :302 3229 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3230 data <<COMMIT 3231 commit filemodify 3232 COMMIT 3233 from :301 3234 M 100644 :402 $path 3235 3236 commit refs/heads/S-path-eol 3237 mark :303 3238 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3239 data <<COMMIT 3240 commit filedelete 3241 COMMIT 3242 from :302 3243 D $path 3244 3245 commit refs/heads/S-path-eol 3246 mark :304 3247 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3248 data <<COMMIT 3249 commit filecopy dest 3250 COMMIT 3251 from :301 3252 C hello.c $path 3253 3254 commit refs/heads/S-path-eol 3255 mark :305 3256 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3257 data <<COMMIT 3258 commit filerename dest 3259 COMMIT 3260 from :301 3261 R hello.c $path 3262 3263 ls :305 $path 3264 EOF 3265 3266 commit_m=$(grep :302 marks.out | cut -d\ -f2) && 3267 commit_d=$(grep :303 marks.out | cut -d\ -f2) && 3268 commit_c=$(grep :304 marks.out | cut -d\ -f2) && 3269 commit_r=$(grep :305 marks.out | cut -d\ -f2) && 3270 blob1=$(grep :401 marks.out | cut -d\ -f2) && 3271 blob2=$(grep :402 marks.out | cut -d\ -f2) && 3272 3273 ( 3274 printf "100644 blob $blob2\t$unquoted_path\n" && 3275 printf "100644 blob $blob1\thello.c\n" 3276 ) | sort >tree_m.exp && 3277 git ls-tree $commit_m | sort >tree_m.out && 3278 test_cmp tree_m.exp tree_m.out && 3279 3280 printf "100644 blob $blob1\thello.c\n" >tree_d.exp && 3281 git ls-tree $commit_d >tree_d.out && 3282 test_cmp tree_d.exp tree_d.out && 3283 3284 ( 3285 printf "100644 blob $blob1\t$unquoted_path\n" && 3286 printf "100644 blob $blob1\thello.c\n" 3287 ) | sort >tree_c.exp && 3288 git ls-tree $commit_c | sort >tree_c.out && 3289 test_cmp tree_c.exp tree_c.out && 3290 3291 printf "100644 blob $blob1\t$unquoted_path\n" >tree_r.exp && 3292 git ls-tree $commit_r >tree_r.out && 3293 test_cmp tree_r.exp tree_r.out && 3294 3295 test_cmp out tree_r.exp 3296 ' 3297} 3298 3299test_path_eol_success 'quoted spaces' '" hello world.c "' ' hello world.c ' 3300test_path_eol_success 'unquoted spaces' ' hello world.c ' ' hello world.c ' 3301test_path_eol_success 'octal escapes' '"\150\151\056\143"' 'hi.c' 3302 3303# 3304# Valid paths before a space: filecopy (source) and filerename (source). 3305# 3306# commit :301 from root -- modify $path (for setup) 3307# commit :302 from :301 -- copy $path hello2.c 3308# commit :303 from :301 -- rename $path hello2.c 3309# 3310test_path_space_success () { 3311 local test="$1" path="$2" unquoted_path="$3" 3312 test_expect_success "S: paths before space with $test must work" ' 3313 test_when_finished "git branch -D S-path-space" && 3314 3315 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF 2>err && 3316 blob 3317 mark :401 3318 data <<BLOB 3319 hello world 3320 BLOB 3321 3322 commit refs/heads/S-path-space 3323 mark :301 3324 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3325 data <<COMMIT 3326 initial commit 3327 COMMIT 3328 M 100644 :401 $path 3329 3330 commit refs/heads/S-path-space 3331 mark :302 3332 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3333 data <<COMMIT 3334 commit filecopy source 3335 COMMIT 3336 from :301 3337 C $path hello2.c 3338 3339 commit refs/heads/S-path-space 3340 mark :303 3341 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3342 data <<COMMIT 3343 commit filerename source 3344 COMMIT 3345 from :301 3346 R $path hello2.c 3347 3348 EOF 3349 3350 commit_c=$(grep :302 marks.out | cut -d\ -f2) && 3351 commit_r=$(grep :303 marks.out | cut -d\ -f2) && 3352 blob=$(grep :401 marks.out | cut -d\ -f2) && 3353 3354 ( 3355 printf "100644 blob $blob\t$unquoted_path\n" && 3356 printf "100644 blob $blob\thello2.c\n" 3357 ) | sort >tree_c.exp && 3358 git ls-tree $commit_c | sort >tree_c.out && 3359 test_cmp tree_c.exp tree_c.out && 3360 3361 printf "100644 blob $blob\thello2.c\n" >tree_r.exp && 3362 git ls-tree $commit_r >tree_r.out && 3363 test_cmp tree_r.exp tree_r.out 3364 ' 3365} 3366 3367test_path_space_success 'quoted spaces' '" hello world.c "' ' hello world.c ' 3368test_path_space_success 'no unquoted spaces' 'hello_world.c' 'hello_world.c' 3369test_path_space_success 'octal escapes' '"\150\151\056\143"' 'hi.c' 3370 3371# 3372# Test a single commit change with an invalid path. Run it with all occurrences 3373# of <path> in the grammar against all error kinds. 3374# 3375test_path_fail () { 3376 local change="$1" what="$2" prefix="$3" path="$4" suffix="$5" err_grep="$6" 3377 test_expect_success "S: $change with $what must fail" ' 3378 test_must_fail git fast-import <<-EOF 2>err && 3379 blob 3380 mark :1 3381 data <<BLOB 3382 hello world 3383 BLOB 3384 3385 commit refs/heads/S-path-fail 3386 mark :2 3387 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3388 data <<COMMIT 3389 commit setup 3390 COMMIT 3391 M 100644 :1 hello.c 3392 3393 commit refs/heads/S-path-fail 3394 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3395 data <<COMMIT 3396 commit with bad path 3397 COMMIT 3398 from :2 3399 $prefix$path$suffix 3400 EOF 3401 3402 test_grep "$err_grep" err 3403 ' 3404} 3405 3406test_path_base_fail () { 3407 local change="$1" prefix="$2" field="$3" suffix="$4" 3408 test_path_fail "$change" 'unclosed " in '"$field" "$prefix" '"hello.c' "$suffix" "Invalid $field" 3409 test_path_fail "$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "Invalid $field" 3410 test_path_fail "$change" "escaped NUL in quoted $field" "$prefix" '"hello\000"' "$suffix" "NUL in $field" 3411} 3412test_path_eol_quoted_fail () { 3413 local change="$1" prefix="$2" field="$3" 3414 test_path_base_fail "$change" "$prefix" "$field" '' 3415 test_path_fail "$change" "garbage after quoted $field" "$prefix" '"hello.c"' 'x' "Garbage after $field" 3416 test_path_fail "$change" "space after quoted $field" "$prefix" '"hello.c"' ' ' "Garbage after $field" 3417} 3418test_path_eol_fail () { 3419 local change="$1" prefix="$2" field="$3" 3420 test_path_eol_quoted_fail "$change" "$prefix" "$field" 3421} 3422test_path_space_fail () { 3423 local change="$1" prefix="$2" field="$3" 3424 test_path_base_fail "$change" "$prefix" "$field" ' world.c' 3425 test_path_fail "$change" "missing space after quoted $field" "$prefix" '"hello.c"' 'x world.c' "Missing space after $field" 3426 test_path_fail "$change" "missing space after unquoted $field" "$prefix" 'hello.c' '' "Missing space after $field" 3427} 3428 3429test_path_eol_fail filemodify 'M 100644 :1 ' path 3430test_path_eol_fail filedelete 'D ' path 3431test_path_space_fail filecopy 'C ' source 3432test_path_eol_fail filecopy 'C hello.c ' dest 3433test_path_space_fail filerename 'R ' source 3434test_path_eol_fail filerename 'R hello.c ' dest 3435test_path_eol_fail 'ls (in commit)' 'ls :2 ' path 3436 3437# When 'ls' has no <dataref>, the <path> must be quoted. 3438test_path_eol_quoted_fail 'ls (without dataref in commit)' 'ls ' path 3439 3440### 3441### series T (ls) 3442### 3443# Setup is carried over from series S. 3444 3445for root in '""' '' 3446do 3447 test_expect_success "T: ls root ($root) tree" ' 3448 sed -e "s/Z\$//" >expect <<-EOF && 3449 040000 tree $(git rev-parse S^{tree}) Z 3450 EOF 3451 sha1=$(git rev-parse --verify S) && 3452 git fast-import --import-marks=marks <<-EOF >actual && 3453 ls $sha1 $root 3454 EOF 3455 test_cmp expect actual 3456 ' 3457done 3458 3459test_expect_success 'T: delete branch' ' 3460 git branch to-delete && 3461 git fast-import <<-EOF && 3462 reset refs/heads/to-delete 3463 from $ZERO_OID 3464 EOF 3465 test_must_fail git rev-parse --verify refs/heads/to-delete 3466' 3467 3468test_expect_success 'T: empty reset doesnt delete branch' ' 3469 git branch not-to-delete && 3470 git fast-import <<-EOF && 3471 reset refs/heads/not-to-delete 3472 EOF 3473 git show-ref && 3474 git rev-parse --verify refs/heads/not-to-delete 3475' 3476 3477### 3478### series U (filedelete) 3479### 3480 3481test_expect_success 'U: initialize for U tests' ' 3482 cat >input <<-INPUT_END && 3483 commit refs/heads/U 3484 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3485 data <<COMMIT 3486 test setup 3487 COMMIT 3488 M 100644 inline hello.c 3489 data <<BLOB 3490 blob 1 3491 BLOB 3492 M 100644 inline good/night.txt 3493 data <<BLOB 3494 sleep well 3495 BLOB 3496 M 100644 inline good/bye.txt 3497 data <<BLOB 3498 au revoir 3499 BLOB 3500 3501 INPUT_END 3502 3503 f7id=$(echo "blob 1" | git hash-object --stdin) && 3504 f8id=$(echo "sleep well" | git hash-object --stdin) && 3505 f9id=$(echo "au revoir" | git hash-object --stdin) && 3506 git fast-import <input 3507' 3508 3509test_expect_success 'U: filedelete file succeeds' ' 3510 cat >input <<-INPUT_END && 3511 commit refs/heads/U 3512 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3513 data <<COMMIT 3514 delete good/night.txt 3515 COMMIT 3516 from refs/heads/U^0 3517 D good/night.txt 3518 3519 INPUT_END 3520 3521 git fast-import <input 3522' 3523 3524test_expect_success 'U: validate file delete result' ' 3525 cat >expect <<-EOF && 3526 :100644 000000 $f8id $ZERO_OID D good/night.txt 3527 EOF 3528 3529 git diff-tree -M -r U^1 U >actual && 3530 3531 compare_diff_raw expect actual 3532' 3533 3534test_expect_success 'U: filedelete directory succeeds' ' 3535 cat >input <<-INPUT_END && 3536 commit refs/heads/U 3537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3538 data <<COMMIT 3539 delete good dir 3540 COMMIT 3541 from refs/heads/U^0 3542 D good 3543 3544 INPUT_END 3545 3546 git fast-import <input 3547' 3548 3549test_expect_success 'U: validate directory delete result' ' 3550 cat >expect <<-EOF && 3551 :100644 000000 $f9id $ZERO_OID D good/bye.txt 3552 EOF 3553 3554 git diff-tree -M -r U^1 U >actual && 3555 3556 compare_diff_raw expect actual 3557' 3558 3559for root in '""' '' 3560do 3561 test_expect_success "U: filedelete root ($root) succeeds" ' 3562 cat >input <<-INPUT_END && 3563 commit refs/heads/U-delete-root 3564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3565 data <<COMMIT 3566 must succeed 3567 COMMIT 3568 from refs/heads/U^0 3569 D $root 3570 3571 INPUT_END 3572 3573 git fast-import <input 3574 ' 3575 3576 test_expect_success "U: validate root ($root) delete result" ' 3577 cat >expect <<-EOF && 3578 :100644 000000 $f7id $ZERO_OID D hello.c 3579 EOF 3580 3581 git diff-tree -M -r U U-delete-root >actual && 3582 3583 compare_diff_raw expect actual 3584 ' 3585done 3586 3587### 3588### series V (checkpoint) 3589### 3590 3591# The commands in input_file should not produce any output on the file 3592# descriptor set with --cat-blob-fd (or stdout if unspecified). 3593# 3594# To make sure you're observing the side effects of checkpoint *before* 3595# fast-import terminates (and thus writes out its state), check that the 3596# fast-import process is still running using background_import_still_running 3597# *after* evaluating the test conditions. 3598background_import_then_checkpoint () { 3599 options=$1 3600 input_file=$2 3601 3602 mkfifo V.input 3603 exec 8<>V.input 3604 rm V.input 3605 3606 mkfifo V.output 3607 exec 9<>V.output 3608 rm V.output 3609 3610 ( 3611 git fast-import $options <&8 >&9 & 3612 echo $! >&9 3613 wait $! 3614 echo >&2 "background fast-import terminated too early with exit code $?" 3615 # Un-block the read loop in the main shell process. 3616 echo >&9 UNEXPECTED 3617 ) & 3618 sh_pid=$! 3619 read fi_pid <&9 3620 # We don't mind if fast-import has already died by the time the test 3621 # ends. 3622 test_when_finished " 3623 exec 8>&-; exec 9>&-; 3624 kill $sh_pid && wait $sh_pid 3625 kill $fi_pid && wait $fi_pid 3626 true" 3627 3628 # Start in the background to ensure we adhere strictly to (blocking) 3629 # pipes writing sequence. We want to assume that the write below could 3630 # block, e.g. if fast-import blocks writing its own output to &9 3631 # because there is no reader on &9 yet. 3632 ( 3633 cat "$input_file" 3634 echo "checkpoint" 3635 echo "progress checkpoint" 3636 ) >&8 & 3637 3638 error=1 ;# assume the worst 3639 while read output <&9 3640 do 3641 if test "$output" = "progress checkpoint" 3642 then 3643 error=0 3644 break 3645 elif test "$output" = "UNEXPECTED" 3646 then 3647 break 3648 fi 3649 # otherwise ignore cruft 3650 echo >&2 "cruft: $output" 3651 done 3652 3653 if test $error -eq 1 3654 then 3655 false 3656 fi 3657} 3658 3659background_import_still_running () { 3660 if ! kill -0 "$fi_pid" 3661 then 3662 echo >&2 "background fast-import terminated too early" 3663 false 3664 fi 3665} 3666 3667test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' ' 3668 cat >input <<-INPUT_END && 3669 progress foo 3670 progress bar 3671 3672 INPUT_END 3673 3674 background_import_then_checkpoint "" input && 3675 background_import_still_running 3676' 3677 3678test_expect_success PIPE 'V: checkpoint updates refs after reset' ' 3679 cat >input <<-\INPUT_END && 3680 reset refs/heads/V 3681 from refs/heads/U 3682 3683 INPUT_END 3684 3685 background_import_then_checkpoint "" input && 3686 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" && 3687 background_import_still_running 3688' 3689 3690test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' ' 3691 cat >input <<-INPUT_END && 3692 commit refs/heads/V 3693 mark :1 3694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3695 data 0 3696 from refs/heads/U 3697 3698 INPUT_END 3699 3700 background_import_then_checkpoint "--export-marks=marks.actual" input && 3701 3702 echo ":1 $(git rev-parse --verify V)" >marks.expected && 3703 3704 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" && 3705 test_cmp marks.expected marks.actual && 3706 background_import_still_running 3707' 3708 3709# Re-create the exact same commit, but on a different branch: no new object is 3710# created in the database, but the refs and marks still need to be updated. 3711test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' ' 3712 cat >input <<-INPUT_END && 3713 commit refs/heads/V2 3714 mark :2 3715 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3716 data 0 3717 from refs/heads/U 3718 3719 INPUT_END 3720 3721 background_import_then_checkpoint "--export-marks=marks.actual" input && 3722 3723 echo ":2 $(git rev-parse --verify V2)" >marks.expected && 3724 3725 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" && 3726 test_cmp marks.expected marks.actual && 3727 background_import_still_running 3728' 3729 3730test_expect_success PIPE 'V: checkpoint updates tags after tag' ' 3731 cat >input <<-INPUT_END && 3732 tag Vtag 3733 from refs/heads/V 3734 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3735 data 0 3736 3737 INPUT_END 3738 3739 background_import_then_checkpoint "" input && 3740 git show-ref -d Vtag && 3741 background_import_still_running 3742' 3743 3744### 3745### series W (get-mark and empty orphan commits) 3746### 3747 3748cat >>W-input <<-W_INPUT_END 3749 commit refs/heads/W-branch 3750 mark :1 3751 author Full Name <user@company.tld> 1000000000 +0100 3752 committer Full Name <user@company.tld> 1000000000 +0100 3753 data 27 3754 Intentionally empty commit 3755 LFsget-mark :1 3756 W_INPUT_END 3757 3758test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' ' 3759 sed -e s/LFs// W-input | tr L "\n" | git fast-import 3760' 3761 3762test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' ' 3763 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import 3764' 3765 3766test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' ' 3767 # Technically, this should fail as it has too many linefeeds 3768 # according to the grammar in fast-import.txt. But, for whatever 3769 # reason, it works. Since using the correct number of newlines 3770 # does not work with older (pre-2.22) versions of git, allow apps 3771 # that used this second-newline workaround to keep working by 3772 # checking it with this test... 3773 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import 3774' 3775 3776test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' ' 3777 # ...but do NOT allow more empty lines than that (see previous test). 3778 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import 3779' 3780 3781### 3782### series X (other new features) 3783### 3784 3785test_expect_success ICONV 'X: handling encoding' ' 3786 test_tick && 3787 cat >input <<-INPUT_END && 3788 commit refs/heads/encoding 3789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE 3790 encoding iso-8859-7 3791 data <<COMMIT 3792 INPUT_END 3793 3794 printf "Pi: \360\nCOMMIT\n" >>input && 3795 3796 git fast-import <input && 3797 git cat-file -p encoding | grep $(printf "\360") && 3798 git log -1 --format=%B encoding | grep $(printf "\317\200") 3799' 3800 3801test_expect_success 'X: replace ref that becomes useless is removed' ' 3802 git init -qb main testrepo && 3803 cd testrepo && 3804 ( 3805 test_commit test && 3806 3807 test_commit msg somename content && 3808 3809 git mv somename othername && 3810 NEW_TREE=$(git write-tree) && 3811 MSG="$(git log -1 --format=%B HEAD)" && 3812 NEW_COMMIT=$(git commit-tree -p HEAD^1 -m "$MSG" $NEW_TREE) && 3813 git replace main $NEW_COMMIT && 3814 3815 echo more >>othername && 3816 git add othername && 3817 git commit -qm more && 3818 3819 git fast-export --all >tmp && 3820 sed -e s/othername/somename/ tmp >tmp2 && 3821 git fast-import --force <tmp2 2>msgs && 3822 3823 grep "Dropping.*since it would point to itself" msgs && 3824 git show-ref >refs && 3825 ! grep refs/replace refs 3826 ) 3827' 3828 3829### 3830### series Y (submodules and hash algorithms) 3831### 3832 3833cat >Y-sub-input <<\Y_INPUT_END 3834blob 3835mark :1 3836data 4 3837foo 3838 3839reset refs/heads/main 3840commit refs/heads/main 3841mark :2 3842author Full Name <user@company.tld> 1000000000 +0100 3843committer Full Name <user@company.tld> 1000000000 +0100 3844data 24 3845Test submodule commit 1 3846M 100644 :1 file 3847 3848blob 3849mark :3 3850data 8 3851foo 3852bar 3853 3854commit refs/heads/main 3855mark :4 3856author Full Name <user@company.tld> 1000000001 +0100 3857committer Full Name <user@company.tld> 1000000001 +0100 3858data 24 3859Test submodule commit 2 3860from :2 3861M 100644 :3 file 3862Y_INPUT_END 3863 3864# Note that the submodule object IDs are intentionally not translated. 3865cat >Y-main-input <<\Y_INPUT_END 3866blob 3867mark :1 3868data 4 3869foo 3870 3871reset refs/heads/main 3872commit refs/heads/main 3873mark :2 3874author Full Name <user@company.tld> 2000000000 +0100 3875committer Full Name <user@company.tld> 2000000000 +0100 3876data 14 3877Test commit 1 3878M 100644 :1 file 3879 3880blob 3881mark :3 3882data 73 3883[submodule "sub1"] 3884 path = sub1 3885 url = https://void.example.com/main.git 3886 3887commit refs/heads/main 3888mark :4 3889author Full Name <user@company.tld> 2000000001 +0100 3890committer Full Name <user@company.tld> 2000000001 +0100 3891data 14 3892Test commit 2 3893from :2 3894M 100644 :3 .gitmodules 3895M 160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1 3896 3897blob 3898mark :5 3899data 8 3900foo 3901bar 3902 3903commit refs/heads/main 3904mark :6 3905author Full Name <user@company.tld> 2000000002 +0100 3906committer Full Name <user@company.tld> 2000000002 +0100 3907data 14 3908Test commit 3 3909from :4 3910M 100644 :5 file 3911M 160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1 3912Y_INPUT_END 3913 3914cat >Y-marks <<\Y_INPUT_END 3915:2 0712c5be7cf681388e355ef47525aaf23aee1a6d 3916:4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 3917Y_INPUT_END 3918 3919test_expect_success 'Y: setup' ' 3920 test_oid_cache <<-EOF 3921 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504 3922 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3 3923 EOF 3924' 3925 3926test_expect_success 'Y: rewrite submodules' ' 3927 git init main1 && 3928 ( 3929 cd main1 && 3930 git init sub2 && 3931 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input && 3932 git fast-import --rewrite-submodules-from=sub:../Y-marks \ 3933 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input && 3934 test "$(git rev-parse main)" = "$(test_oid Ymain)" 3935 ) 3936' 3937 3938test_done