t / t9300-fast-import.shon commit add simple tests of consistency across rebase types (2aad7ca)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Shawn Pearce
   4#
   5
   6test_description='test git fast-import utility'
   7. ./test-lib.sh
   8. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
   9
  10# Print $1 bytes from stdin to stdout.
  11#
  12# This could be written as "head -c $1", but IRIX "head" does not
  13# support the -c option.
  14head_c () {
  15        "$PERL_PATH" -e '
  16                my $len = $ARGV[1];
  17                while ($len > 0) {
  18                        my $s;
  19                        my $nread = sysread(STDIN, $s, $len);
  20                        die "cannot read: $!" unless defined($nread);
  21                        print $s;
  22                        $len -= $nread;
  23                }
  24        ' - "$1"
  25}
  26
  27verify_packs () {
  28        for p in .git/objects/pack/*.pack
  29        do
  30                git verify-pack "$@" "$p" || return
  31        done
  32}
  33
  34file2_data='file2
  35second line of EOF'
  36
  37file3_data='EOF
  38in 3rd file
  39 END'
  40
  41file4_data=abcd
  42file4_len=4
  43
  44file5_data='an inline file.
  45  we should see it later.'
  46
  47file6_data='#!/bin/sh
  48echo "$@"'
  49
  50>empty
  51
  52###
  53### series A
  54###
  55
  56test_tick
  57
  58test_expect_success 'empty stream succeeds' '
  59        git fast-import </dev/null
  60'
  61
  62cat >input <<INPUT_END
  63blob
  64mark :2
  65data <<EOF
  66$file2_data
  67EOF
  68
  69blob
  70mark :3
  71data <<END
  72$file3_data
  73END
  74
  75blob
  76mark :4
  77data $file4_len
  78$file4_data
  79commit refs/heads/master
  80mark :5
  81committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  82data <<COMMIT
  83initial
  84COMMIT
  85
  86M 644 :2 file2
  87M 644 :3 file3
  88M 755 :4 file4
  89
  90tag series-A
  91from :5
  92data <<EOF
  93An annotated tag without a tagger
  94EOF
  95
  96tag series-A-blob
  97from :3
  98data <<EOF
  99An annotated tag that annotates a blob.
 100EOF
 101
 102INPUT_END
 103test_expect_success \
 104    'A: create pack from stdin' \
 105    'git fast-import --export-marks=marks.out <input &&
 106         git whatchanged master'
 107
 108test_expect_success 'A: verify pack' '
 109        verify_packs
 110'
 111
 112cat >expect <<EOF
 113author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 114committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 115
 116initial
 117EOF
 118test_expect_success \
 119        'A: verify commit' \
 120        'git cat-file commit master | sed 1d >actual &&
 121        test_cmp expect actual'
 122
 123cat >expect <<EOF
 124100644 blob file2
 125100644 blob file3
 126100755 blob file4
 127EOF
 128test_expect_success \
 129        'A: verify tree' \
 130        'git cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
 131         test_cmp expect actual'
 132
 133echo "$file2_data" >expect
 134test_expect_success \
 135        'A: verify file2' \
 136        'git cat-file blob master:file2 >actual && test_cmp expect actual'
 137
 138echo "$file3_data" >expect
 139test_expect_success \
 140        'A: verify file3' \
 141        'git cat-file blob master:file3 >actual && test_cmp expect actual'
 142
 143printf "$file4_data" >expect
 144test_expect_success \
 145        'A: verify file4' \
 146        'git cat-file blob master:file4 >actual && test_cmp expect actual'
 147
 148cat >expect <<EOF
 149object $(git rev-parse refs/heads/master)
 150type commit
 151tag series-A
 152
 153An annotated tag without a tagger
 154EOF
 155test_expect_success 'A: verify tag/series-A' '
 156        git cat-file tag tags/series-A >actual &&
 157        test_cmp expect actual
 158'
 159
 160cat >expect <<EOF
 161object $(git rev-parse refs/heads/master:file3)
 162type blob
 163tag series-A-blob
 164
 165An annotated tag that annotates a blob.
 166EOF
 167test_expect_success 'A: verify tag/series-A-blob' '
 168        git cat-file tag tags/series-A-blob >actual &&
 169        test_cmp expect actual
 170'
 171
 172cat >expect <<EOF
 173:2 `git rev-parse --verify master:file2`
 174:3 `git rev-parse --verify master:file3`
 175:4 `git rev-parse --verify master:file4`
 176:5 `git rev-parse --verify master^0`
 177EOF
 178test_expect_success \
 179        'A: verify marks output' \
 180        'test_cmp expect marks.out'
 181
 182test_expect_success \
 183        'A: verify marks import' \
 184        'git fast-import \
 185                --import-marks=marks.out \
 186                --export-marks=marks.new \
 187                </dev/null &&
 188        test_cmp expect marks.new'
 189
 190test_tick
 191new_blob=$(echo testing | git hash-object --stdin)
 192cat >input <<INPUT_END
 193tag series-A-blob-2
 194from $(git rev-parse refs/heads/master:file3)
 195data <<EOF
 196Tag blob by sha1.
 197EOF
 198
 199blob
 200mark :6
 201data <<EOF
 202testing
 203EOF
 204
 205commit refs/heads/new_blob
 206committer  <> 0 +0000
 207data 0
 208M 644 :6 new_blob
 209#pretend we got sha1 from fast-import
 210ls "new_blob"
 211
 212tag series-A-blob-3
 213from $new_blob
 214data <<EOF
 215Tag new_blob.
 216EOF
 217INPUT_END
 218
 219cat >expect <<EOF
 220object $(git rev-parse refs/heads/master:file3)
 221type blob
 222tag series-A-blob-2
 223
 224Tag blob by sha1.
 225object $new_blob
 226type blob
 227tag series-A-blob-3
 228
 229Tag new_blob.
 230EOF
 231
 232test_expect_success \
 233        'A: tag blob by sha1' \
 234        'git fast-import <input &&
 235        git cat-file tag tags/series-A-blob-2 >actual &&
 236        git cat-file tag tags/series-A-blob-3 >>actual &&
 237        test_cmp expect actual'
 238
 239test_tick
 240cat >input <<INPUT_END
 241commit refs/heads/verify--import-marks
 242committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 243data <<COMMIT
 244recreate from :5
 245COMMIT
 246
 247from :5
 248M 755 :2 copy-of-file2
 249
 250INPUT_END
 251test_expect_success \
 252        'A: verify marks import does not crash' \
 253        'git fast-import --import-marks=marks.out <input &&
 254         git whatchanged verify--import-marks'
 255
 256test_expect_success 'A: verify pack' '
 257        verify_packs
 258'
 259
 260cat >expect <<EOF
 261:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
 262EOF
 263git diff-tree -M -r master verify--import-marks >actual
 264test_expect_success \
 265        'A: verify diff' \
 266        'compare_diff_raw expect actual &&
 267         test `git rev-parse --verify master:file2` \
 268            = `git rev-parse --verify verify--import-marks:copy-of-file2`'
 269
 270test_tick
 271mt=$(git hash-object --stdin < /dev/null)
 272: >input.blob
 273: >marks.exp
 274: >tree.exp
 275
 276cat >input.commit <<EOF
 277commit refs/heads/verify--dump-marks
 278committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 279data <<COMMIT
 280test the sparse array dumping routines with exponentially growing marks
 281COMMIT
 282EOF
 283
 284i=0
 285l=4
 286m=6
 287n=7
 288while test "$i" -lt 27; do
 289    cat >>input.blob <<EOF
 290blob
 291mark :$l
 292data 0
 293blob
 294mark :$m
 295data 0
 296blob
 297mark :$n
 298data 0
 299EOF
 300    echo "M 100644 :$l l$i" >>input.commit
 301    echo "M 100644 :$m m$i" >>input.commit
 302    echo "M 100644 :$n n$i" >>input.commit
 303
 304    echo ":$l $mt" >>marks.exp
 305    echo ":$m $mt" >>marks.exp
 306    echo ":$n $mt" >>marks.exp
 307
 308    printf "100644 blob $mt\tl$i\n" >>tree.exp
 309    printf "100644 blob $mt\tm$i\n" >>tree.exp
 310    printf "100644 blob $mt\tn$i\n" >>tree.exp
 311
 312    l=$(($l + $l))
 313    m=$(($m + $m))
 314    n=$(($l + $n))
 315
 316    i=$((1 + $i))
 317done
 318
 319sort tree.exp > tree.exp_s
 320
 321test_expect_success 'A: export marks with large values' '
 322        cat input.blob input.commit | git fast-import --export-marks=marks.large &&
 323        git ls-tree refs/heads/verify--dump-marks >tree.out &&
 324        test_cmp tree.exp_s tree.out &&
 325        test_cmp marks.exp marks.large'
 326
 327###
 328### series B
 329###
 330
 331test_tick
 332cat >input <<INPUT_END
 333commit refs/heads/branch
 334mark :1
 335committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 336data <<COMMIT
 337corrupt
 338COMMIT
 339
 340from refs/heads/master
 341M 755 0000000000000000000000000000000000000001 zero1
 342
 343INPUT_END
 344test_expect_success 'B: fail on invalid blob sha1' '
 345    test_must_fail git fast-import <input
 346'
 347rm -f .git/objects/pack_* .git/objects/index_*
 348
 349cat >input <<INPUT_END
 350commit .badbranchname
 351committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 352data <<COMMIT
 353corrupt
 354COMMIT
 355
 356from refs/heads/master
 357
 358INPUT_END
 359test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
 360    test_must_fail git fast-import <input
 361'
 362rm -f .git/objects/pack_* .git/objects/index_*
 363
 364cat >input <<INPUT_END
 365commit bad[branch]name
 366committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 367data <<COMMIT
 368corrupt
 369COMMIT
 370
 371from refs/heads/master
 372
 373INPUT_END
 374test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
 375    test_must_fail git fast-import <input
 376'
 377rm -f .git/objects/pack_* .git/objects/index_*
 378
 379cat >input <<INPUT_END
 380commit TEMP_TAG
 381committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 382data <<COMMIT
 383tag base
 384COMMIT
 385
 386from refs/heads/master
 387
 388INPUT_END
 389test_expect_success \
 390    'B: accept branch name "TEMP_TAG"' \
 391    'git fast-import <input &&
 392         test -f .git/TEMP_TAG &&
 393         test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
 394rm -f .git/TEMP_TAG
 395
 396git gc 2>/dev/null >/dev/null
 397git prune 2>/dev/null >/dev/null
 398
 399cat >input <<INPUT_END
 400commit refs/heads/empty-committer-1
 401committer  <> $GIT_COMMITTER_DATE
 402data <<COMMIT
 403empty commit
 404COMMIT
 405INPUT_END
 406test_expect_success 'B: accept empty committer' '
 407        git fast-import <input &&
 408        out=$(git fsck) &&
 409        echo "$out" &&
 410        test -z "$out"
 411'
 412git update-ref -d refs/heads/empty-committer-1 || true
 413
 414git gc 2>/dev/null >/dev/null
 415git prune 2>/dev/null >/dev/null
 416
 417cat >input <<INPUT_END
 418commit refs/heads/empty-committer-2
 419committer <a@b.com> $GIT_COMMITTER_DATE
 420data <<COMMIT
 421empty commit
 422COMMIT
 423INPUT_END
 424test_expect_success 'B: accept and fixup committer with no name' '
 425        git fast-import <input &&
 426        out=$(git fsck) &&
 427        echo "$out" &&
 428        test -z "$out"
 429'
 430git update-ref -d refs/heads/empty-committer-2 || true
 431
 432git gc 2>/dev/null >/dev/null
 433git prune 2>/dev/null >/dev/null
 434
 435cat >input <<INPUT_END
 436commit refs/heads/invalid-committer
 437committer Name email> $GIT_COMMITTER_DATE
 438data <<COMMIT
 439empty commit
 440COMMIT
 441INPUT_END
 442test_expect_success 'B: fail on invalid committer (1)' '
 443        test_must_fail git fast-import <input
 444'
 445git update-ref -d refs/heads/invalid-committer || true
 446
 447cat >input <<INPUT_END
 448commit refs/heads/invalid-committer
 449committer Name <e<mail> $GIT_COMMITTER_DATE
 450data <<COMMIT
 451empty commit
 452COMMIT
 453INPUT_END
 454test_expect_success 'B: fail on invalid committer (2)' '
 455        test_must_fail git fast-import <input
 456'
 457git update-ref -d refs/heads/invalid-committer || true
 458
 459cat >input <<INPUT_END
 460commit refs/heads/invalid-committer
 461committer Name <email>> $GIT_COMMITTER_DATE
 462data <<COMMIT
 463empty commit
 464COMMIT
 465INPUT_END
 466test_expect_success 'B: fail on invalid committer (3)' '
 467        test_must_fail git fast-import <input
 468'
 469git update-ref -d refs/heads/invalid-committer || true
 470
 471cat >input <<INPUT_END
 472commit refs/heads/invalid-committer
 473committer Name <email $GIT_COMMITTER_DATE
 474data <<COMMIT
 475empty commit
 476COMMIT
 477INPUT_END
 478test_expect_success 'B: fail on invalid committer (4)' '
 479        test_must_fail git fast-import <input
 480'
 481git update-ref -d refs/heads/invalid-committer || true
 482
 483cat >input <<INPUT_END
 484commit refs/heads/invalid-committer
 485committer Name<email> $GIT_COMMITTER_DATE
 486data <<COMMIT
 487empty commit
 488COMMIT
 489INPUT_END
 490test_expect_success 'B: fail on invalid committer (5)' '
 491        test_must_fail git fast-import <input
 492'
 493git update-ref -d refs/heads/invalid-committer || true
 494
 495###
 496### series C
 497###
 498
 499newf=`echo hi newf | git hash-object -w --stdin`
 500oldf=`git rev-parse --verify master:file2`
 501test_tick
 502cat >input <<INPUT_END
 503commit refs/heads/branch
 504committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 505data <<COMMIT
 506second
 507COMMIT
 508
 509from refs/heads/master
 510M 644 $oldf file2/oldf
 511M 755 $newf file2/newf
 512D file3
 513
 514INPUT_END
 515test_expect_success \
 516    'C: incremental import create pack from stdin' \
 517    'git fast-import <input &&
 518         git whatchanged branch'
 519
 520test_expect_success 'C: verify pack' '
 521        verify_packs
 522'
 523
 524test_expect_success \
 525        'C: validate reuse existing blob' \
 526        'test $newf = `git rev-parse --verify branch:file2/newf` &&
 527         test $oldf = `git rev-parse --verify branch:file2/oldf`'
 528
 529cat >expect <<EOF
 530parent `git rev-parse --verify master^0`
 531author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 532committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 533
 534second
 535EOF
 536test_expect_success \
 537        'C: verify commit' \
 538        'git cat-file commit branch | sed 1d >actual &&
 539         test_cmp expect actual'
 540
 541cat >expect <<EOF
 542:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 543:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 544:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 545EOF
 546git diff-tree -M -r master branch >actual
 547test_expect_success \
 548        'C: validate rename result' \
 549        'compare_diff_raw expect actual'
 550
 551###
 552### series D
 553###
 554
 555test_tick
 556cat >input <<INPUT_END
 557commit refs/heads/branch
 558committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 559data <<COMMIT
 560third
 561COMMIT
 562
 563from refs/heads/branch^0
 564M 644 inline newdir/interesting
 565data <<EOF
 566$file5_data
 567EOF
 568
 569M 755 inline newdir/exec.sh
 570data <<EOF
 571$file6_data
 572EOF
 573
 574INPUT_END
 575test_expect_success \
 576    'D: inline data in commit' \
 577    'git fast-import <input &&
 578         git whatchanged branch'
 579
 580test_expect_success 'D: verify pack' '
 581        verify_packs
 582'
 583
 584cat >expect <<EOF
 585:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
 586:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
 587EOF
 588git diff-tree -M -r branch^ branch >actual
 589test_expect_success \
 590        'D: validate new files added' \
 591        'compare_diff_raw expect actual'
 592
 593echo "$file5_data" >expect
 594test_expect_success \
 595        'D: verify file5' \
 596        'git cat-file blob branch:newdir/interesting >actual &&
 597         test_cmp expect actual'
 598
 599echo "$file6_data" >expect
 600test_expect_success \
 601        'D: verify file6' \
 602        'git cat-file blob branch:newdir/exec.sh >actual &&
 603         test_cmp expect actual'
 604
 605###
 606### series E
 607###
 608
 609cat >input <<INPUT_END
 610commit refs/heads/branch
 611author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 612committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 613data <<COMMIT
 614RFC 2822 type date
 615COMMIT
 616
 617from refs/heads/branch^0
 618
 619INPUT_END
 620test_expect_success 'E: rfc2822 date, --date-format=raw' '
 621    test_must_fail git fast-import --date-format=raw <input
 622'
 623test_expect_success \
 624    'E: rfc2822 date, --date-format=rfc2822' \
 625    'git fast-import --date-format=rfc2822 <input'
 626
 627test_expect_success 'E: verify pack' '
 628        verify_packs
 629'
 630
 631cat >expect <<EOF
 632author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
 633committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
 634
 635RFC 2822 type date
 636EOF
 637test_expect_success \
 638        'E: verify commit' \
 639        'git cat-file commit branch | sed 1,2d >actual &&
 640        test_cmp expect actual'
 641
 642###
 643### series F
 644###
 645
 646old_branch=`git rev-parse --verify branch^0`
 647test_tick
 648cat >input <<INPUT_END
 649commit refs/heads/branch
 650committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 651data <<COMMIT
 652losing things already?
 653COMMIT
 654
 655from refs/heads/branch~1
 656
 657reset refs/heads/other
 658from refs/heads/branch
 659
 660INPUT_END
 661test_expect_success \
 662    'F: non-fast-forward update skips' \
 663    'if git fast-import <input
 664         then
 665                echo BAD gfi did not fail
 666                return 1
 667         else
 668                if test $old_branch = `git rev-parse --verify branch^0`
 669                then
 670                        : branch unaffected and failure returned
 671                        return 0
 672                else
 673                        echo BAD gfi changed branch $old_branch
 674                        return 1
 675                fi
 676         fi
 677        '
 678
 679test_expect_success 'F: verify pack' '
 680        verify_packs
 681'
 682
 683cat >expect <<EOF
 684tree `git rev-parse branch~1^{tree}`
 685parent `git rev-parse branch~1`
 686author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 687committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 688
 689losing things already?
 690EOF
 691test_expect_success \
 692        'F: verify other commit' \
 693        'git cat-file commit other >actual &&
 694        test_cmp expect actual'
 695
 696###
 697### series G
 698###
 699
 700old_branch=`git rev-parse --verify branch^0`
 701test_tick
 702cat >input <<INPUT_END
 703commit refs/heads/branch
 704committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 705data <<COMMIT
 706losing things already?
 707COMMIT
 708
 709from refs/heads/branch~1
 710
 711INPUT_END
 712test_expect_success \
 713    'G: non-fast-forward update forced' \
 714    'git fast-import --force <input'
 715
 716test_expect_success 'G: verify pack' '
 717        verify_packs
 718'
 719
 720test_expect_success \
 721        'G: branch changed, but logged' \
 722        'test $old_branch != `git rev-parse --verify branch^0` &&
 723         test $old_branch = `git rev-parse --verify branch@{1}`'
 724
 725###
 726### series H
 727###
 728
 729test_tick
 730cat >input <<INPUT_END
 731commit refs/heads/H
 732committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 733data <<COMMIT
 734third
 735COMMIT
 736
 737from refs/heads/branch^0
 738M 644 inline i-will-die
 739data <<EOF
 740this file will never exist.
 741EOF
 742
 743deleteall
 744M 644 inline h/e/l/lo
 745data <<EOF
 746$file5_data
 747EOF
 748
 749INPUT_END
 750test_expect_success \
 751    'H: deletall, add 1' \
 752    'git fast-import <input &&
 753         git whatchanged H'
 754
 755test_expect_success 'H: verify pack' '
 756        verify_packs
 757'
 758
 759cat >expect <<EOF
 760:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
 761:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
 762:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
 763:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
 764:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
 765EOF
 766git diff-tree -M -r H^ H >actual
 767test_expect_success \
 768        'H: validate old files removed, new files added' \
 769        'compare_diff_raw expect actual'
 770
 771echo "$file5_data" >expect
 772test_expect_success \
 773        'H: verify file' \
 774        'git cat-file blob H:h/e/l/lo >actual &&
 775         test_cmp expect actual'
 776
 777###
 778### series I
 779###
 780
 781cat >input <<INPUT_END
 782commit refs/heads/export-boundary
 783committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 784data <<COMMIT
 785we have a border.  its only 40 characters wide.
 786COMMIT
 787
 788from refs/heads/branch
 789
 790INPUT_END
 791test_expect_success \
 792    'I: export-pack-edges' \
 793    'git fast-import --export-pack-edges=edges.list <input'
 794
 795cat >expect <<EOF
 796.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
 797EOF
 798test_expect_success \
 799        'I: verify edge list' \
 800        'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
 801         test_cmp expect actual'
 802
 803###
 804### series J
 805###
 806
 807cat >input <<INPUT_END
 808commit refs/heads/J
 809committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 810data <<COMMIT
 811create J
 812COMMIT
 813
 814from refs/heads/branch
 815
 816reset refs/heads/J
 817
 818commit refs/heads/J
 819committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 820data <<COMMIT
 821initialize J
 822COMMIT
 823
 824INPUT_END
 825test_expect_success \
 826    'J: reset existing branch creates empty commit' \
 827    'git fast-import <input'
 828test_expect_success \
 829        'J: branch has 1 commit, empty tree' \
 830        'test 1 = `git rev-list J | wc -l` &&
 831         test 0 = `git ls-tree J | wc -l`'
 832
 833cat >input <<INPUT_END
 834reset refs/heads/J2
 835
 836tag wrong_tag
 837from refs/heads/J2
 838data <<EOF
 839Tag branch that was reset.
 840EOF
 841INPUT_END
 842test_expect_success \
 843        'J: tag must fail on empty branch' \
 844        'test_must_fail git fast-import <input'
 845###
 846### series K
 847###
 848
 849cat >input <<INPUT_END
 850commit refs/heads/K
 851committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 852data <<COMMIT
 853create K
 854COMMIT
 855
 856from refs/heads/branch
 857
 858commit refs/heads/K
 859committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 860data <<COMMIT
 861redo K
 862COMMIT
 863
 864from refs/heads/branch^1
 865
 866INPUT_END
 867test_expect_success \
 868    'K: reinit branch with from' \
 869    'git fast-import <input'
 870test_expect_success \
 871    'K: verify K^1 = branch^1' \
 872    'test `git rev-parse --verify branch^1` \
 873                = `git rev-parse --verify K^1`'
 874
 875###
 876### series L
 877###
 878
 879cat >input <<INPUT_END
 880blob
 881mark :1
 882data <<EOF
 883some data
 884EOF
 885
 886blob
 887mark :2
 888data <<EOF
 889other data
 890EOF
 891
 892commit refs/heads/L
 893committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 894data <<COMMIT
 895create L
 896COMMIT
 897
 898M 644 :1 b.
 899M 644 :1 b/other
 900M 644 :1 ba
 901
 902commit refs/heads/L
 903committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 904data <<COMMIT
 905update L
 906COMMIT
 907
 908M 644 :2 b.
 909M 644 :2 b/other
 910M 644 :2 ba
 911INPUT_END
 912
 913cat >expect <<EXPECT_END
 914:100644 100644 4268632... 55d3a52... M  b.
 915:040000 040000 0ae5cac... 443c768... M  b
 916:100644 100644 4268632... 55d3a52... M  ba
 917EXPECT_END
 918
 919test_expect_success \
 920    'L: verify internal tree sorting' \
 921        'git fast-import <input &&
 922         git diff-tree --abbrev --raw L^ L >output &&
 923         test_cmp expect output'
 924
 925cat >input <<INPUT_END
 926blob
 927mark :1
 928data <<EOF
 929the data
 930EOF
 931
 932commit refs/heads/L2
 933committer C O Mitter <committer@example.com> 1112912473 -0700
 934data <<COMMIT
 935init L2
 936COMMIT
 937M 644 :1 a/b/c
 938M 644 :1 a/b/d
 939M 644 :1 a/e/f
 940
 941commit refs/heads/L2
 942committer C O Mitter <committer@example.com> 1112912473 -0700
 943data <<COMMIT
 944update L2
 945COMMIT
 946C a g
 947C a/e g/b
 948M 644 :1 g/b/h
 949INPUT_END
 950
 951cat <<EOF >expect
 952g/b/f
 953g/b/h
 954EOF
 955
 956test_expect_success \
 957    'L: nested tree copy does not corrupt deltas' \
 958        'git fast-import <input &&
 959        git ls-tree L2 g/b/ >tmp &&
 960        cat tmp | cut -f 2 >actual &&
 961        test_cmp expect actual &&
 962        git fsck `git rev-parse L2`'
 963
 964git update-ref -d refs/heads/L2
 965
 966###
 967### series M
 968###
 969
 970test_tick
 971cat >input <<INPUT_END
 972commit refs/heads/M1
 973committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 974data <<COMMIT
 975file rename
 976COMMIT
 977
 978from refs/heads/branch^0
 979R file2/newf file2/n.e.w.f
 980
 981INPUT_END
 982
 983cat >expect <<EOF
 984:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
 985EOF
 986test_expect_success \
 987        'M: rename file in same subdirectory' \
 988        'git fast-import <input &&
 989         git diff-tree -M -r M1^ M1 >actual &&
 990         compare_diff_raw expect actual'
 991
 992cat >input <<INPUT_END
 993commit refs/heads/M2
 994committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 995data <<COMMIT
 996file rename
 997COMMIT
 998
 999from refs/heads/branch^0
1000R file2/newf i/am/new/to/you
1001
1002INPUT_END
1003
1004cat >expect <<EOF
1005:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
1006EOF
1007test_expect_success \
1008        'M: rename file to new subdirectory' \
1009        'git fast-import <input &&
1010         git diff-tree -M -r M2^ M2 >actual &&
1011         compare_diff_raw expect actual'
1012
1013cat >input <<INPUT_END
1014commit refs/heads/M3
1015committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1016data <<COMMIT
1017file rename
1018COMMIT
1019
1020from refs/heads/M2^0
1021R i other/sub
1022
1023INPUT_END
1024
1025cat >expect <<EOF
1026:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
1027EOF
1028test_expect_success \
1029        'M: rename subdirectory to new subdirectory' \
1030        'git fast-import <input &&
1031         git diff-tree -M -r M3^ M3 >actual &&
1032         compare_diff_raw expect actual'
1033
1034###
1035### series N
1036###
1037
1038test_tick
1039cat >input <<INPUT_END
1040commit refs/heads/N1
1041committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1042data <<COMMIT
1043file copy
1044COMMIT
1045
1046from refs/heads/branch^0
1047C file2/newf file2/n.e.w.f
1048
1049INPUT_END
1050
1051cat >expect <<EOF
1052:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
1053EOF
1054test_expect_success \
1055        'N: copy file in same subdirectory' \
1056        'git fast-import <input &&
1057         git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1058         compare_diff_raw expect actual'
1059
1060cat >input <<INPUT_END
1061commit refs/heads/N2
1062committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1063data <<COMMIT
1064clean directory copy
1065COMMIT
1066
1067from refs/heads/branch^0
1068C file2 file3
1069
1070commit refs/heads/N2
1071committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1072data <<COMMIT
1073modify directory copy
1074COMMIT
1075
1076M 644 inline file3/file5
1077data <<EOF
1078$file5_data
1079EOF
1080
1081INPUT_END
1082
1083cat >expect <<EOF
1084:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1085:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1086:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1087EOF
1088test_expect_success \
1089        'N: copy then modify subdirectory' \
1090        'git fast-import <input &&
1091         git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1092         compare_diff_raw expect actual'
1093
1094cat >input <<INPUT_END
1095commit refs/heads/N3
1096committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1097data <<COMMIT
1098dirty directory copy
1099COMMIT
1100
1101from refs/heads/branch^0
1102M 644 inline file2/file5
1103data <<EOF
1104$file5_data
1105EOF
1106
1107C file2 file3
1108D file2/file5
1109
1110INPUT_END
1111
1112test_expect_success \
1113        'N: copy dirty subdirectory' \
1114        'git fast-import <input &&
1115         test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1116
1117test_expect_success \
1118        'N: copy directory by id' \
1119        'cat >expect <<-\EOF &&
1120        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1121        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1122        EOF
1123         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1124         cat >input <<-INPUT_END &&
1125        commit refs/heads/N4
1126        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1127        data <<COMMIT
1128        copy by tree hash
1129        COMMIT
1130
1131        from refs/heads/branch^0
1132        M 040000 $subdir file3
1133        INPUT_END
1134         git fast-import <input &&
1135         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1136         compare_diff_raw expect actual'
1137
1138test_expect_success PIPE 'N: read and copy directory' '
1139        cat >expect <<-\EOF
1140        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1141        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1142        EOF
1143        git update-ref -d refs/heads/N4 &&
1144        rm -f backflow &&
1145        mkfifo backflow &&
1146        (
1147                exec <backflow &&
1148                cat <<-EOF &&
1149                commit refs/heads/N4
1150                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1151                data <<COMMIT
1152                copy by tree hash, part 2
1153                COMMIT
1154
1155                from refs/heads/branch^0
1156                ls "file2"
1157                EOF
1158                read mode type tree filename &&
1159                echo "M 040000 $tree file3"
1160        ) |
1161        git fast-import --cat-blob-fd=3 3>backflow &&
1162        git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1163        compare_diff_raw expect actual
1164'
1165
1166test_expect_success PIPE 'N: empty directory reads as missing' '
1167        cat <<-\EOF >expect &&
1168        OBJNAME
1169        :000000 100644 OBJNAME OBJNAME A        unrelated
1170        EOF
1171        echo "missing src" >expect.response &&
1172        git update-ref -d refs/heads/read-empty &&
1173        rm -f backflow &&
1174        mkfifo backflow &&
1175        (
1176                exec <backflow &&
1177                cat <<-EOF &&
1178                commit refs/heads/read-empty
1179                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1180                data <<COMMIT
1181                read "empty" (missing) directory
1182                COMMIT
1183
1184                M 100644 inline src/greeting
1185                data <<BLOB
1186                hello
1187                BLOB
1188                C src/greeting dst1/non-greeting
1189                C src/greeting unrelated
1190                # leave behind "empty" src directory
1191                D src/greeting
1192                ls "src"
1193                EOF
1194                read -r line &&
1195                printf "%s\n" "$line" >response &&
1196                cat <<-\EOF
1197                D dst1
1198                D dst2
1199                EOF
1200        ) |
1201        git fast-import --cat-blob-fd=3 3>backflow &&
1202        test_cmp expect.response response &&
1203        git rev-list read-empty |
1204        git diff-tree -r --root --stdin |
1205        sed "s/$_x40/OBJNAME/g" >actual &&
1206        test_cmp expect actual
1207'
1208
1209test_expect_success \
1210        'N: copy root directory by tree hash' \
1211        'cat >expect <<-\EOF &&
1212        :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1213        :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1214        EOF
1215         root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1216         cat >input <<-INPUT_END &&
1217        commit refs/heads/N6
1218        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1219        data <<COMMIT
1220        copy root directory by tree hash
1221        COMMIT
1222
1223        from refs/heads/branch^0
1224        M 040000 $root ""
1225        INPUT_END
1226         git fast-import <input &&
1227         git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1228         compare_diff_raw expect actual'
1229
1230test_expect_success \
1231        'N: delete directory by copying' \
1232        'cat >expect <<-\EOF &&
1233        OBJID
1234        :100644 000000 OBJID OBJID D    foo/bar/qux
1235        OBJID
1236        :000000 100644 OBJID OBJID A    foo/bar/baz
1237        :000000 100644 OBJID OBJID A    foo/bar/qux
1238        EOF
1239         empty_tree=$(git mktree </dev/null) &&
1240         cat >input <<-INPUT_END &&
1241        commit refs/heads/N-delete
1242        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1243        data <<COMMIT
1244        collect data to be deleted
1245        COMMIT
1246
1247        deleteall
1248        M 100644 inline foo/bar/baz
1249        data <<DATA_END
1250        hello
1251        DATA_END
1252        C "foo/bar/baz" "foo/bar/qux"
1253        C "foo/bar/baz" "foo/bar/quux/1"
1254        C "foo/bar/baz" "foo/bar/quuux"
1255        M 040000 $empty_tree foo/bar/quux
1256        M 040000 $empty_tree foo/bar/quuux
1257
1258        commit refs/heads/N-delete
1259        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1260        data <<COMMIT
1261        delete subdirectory
1262        COMMIT
1263
1264        M 040000 $empty_tree foo/bar/qux
1265        INPUT_END
1266         git fast-import <input &&
1267         git rev-list N-delete |
1268                git diff-tree -r --stdin --root --always |
1269                sed -e "s/$_x40/OBJID/g" >actual &&
1270         test_cmp expect actual'
1271
1272test_expect_success \
1273        'N: modify copied tree' \
1274        'cat >expect <<-\EOF &&
1275        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1276        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1277        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1278        EOF
1279         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1280         cat >input <<-INPUT_END &&
1281        commit refs/heads/N5
1282        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1283        data <<COMMIT
1284        copy by tree hash
1285        COMMIT
1286
1287        from refs/heads/branch^0
1288        M 040000 $subdir file3
1289
1290        commit refs/heads/N5
1291        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1292        data <<COMMIT
1293        modify directory copy
1294        COMMIT
1295
1296        M 644 inline file3/file5
1297        data <<EOF
1298        $file5_data
1299        EOF
1300        INPUT_END
1301         git fast-import <input &&
1302         git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1303         compare_diff_raw expect actual'
1304
1305test_expect_success \
1306        'N: reject foo/ syntax' \
1307        'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1308         test_must_fail git fast-import <<-INPUT_END
1309        commit refs/heads/N5B
1310        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1311        data <<COMMIT
1312        copy with invalid syntax
1313        COMMIT
1314
1315        from refs/heads/branch^0
1316        M 040000 $subdir file3/
1317        INPUT_END'
1318
1319test_expect_success \
1320        'N: reject foo/ syntax in copy source' \
1321        'test_must_fail git fast-import <<-INPUT_END
1322        commit refs/heads/N5C
1323        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1324        data <<COMMIT
1325        copy with invalid syntax
1326        COMMIT
1327
1328        from refs/heads/branch^0
1329        C file2/ file3
1330        INPUT_END'
1331
1332test_expect_success \
1333        'N: reject foo/ syntax in rename source' \
1334        'test_must_fail git fast-import <<-INPUT_END
1335        commit refs/heads/N5D
1336        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1337        data <<COMMIT
1338        rename with invalid syntax
1339        COMMIT
1340
1341        from refs/heads/branch^0
1342        R file2/ file3
1343        INPUT_END'
1344
1345test_expect_success \
1346        'N: reject foo/ syntax in ls argument' \
1347        'test_must_fail git fast-import <<-INPUT_END
1348        commit refs/heads/N5E
1349        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1350        data <<COMMIT
1351        copy with invalid syntax
1352        COMMIT
1353
1354        from refs/heads/branch^0
1355        ls "file2/"
1356        INPUT_END'
1357
1358test_expect_success \
1359        'N: copy to root by id and modify' \
1360        'echo "hello, world" >expect.foo &&
1361         echo hello >expect.bar &&
1362         git fast-import <<-SETUP_END &&
1363        commit refs/heads/N7
1364        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1365        data <<COMMIT
1366        hello, tree
1367        COMMIT
1368
1369        deleteall
1370        M 644 inline foo/bar
1371        data <<EOF
1372        hello
1373        EOF
1374        SETUP_END
1375
1376         tree=$(git rev-parse --verify N7:) &&
1377         git fast-import <<-INPUT_END &&
1378        commit refs/heads/N8
1379        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1380        data <<COMMIT
1381        copy to root by id and modify
1382        COMMIT
1383
1384        M 040000 $tree ""
1385        M 644 inline foo/foo
1386        data <<EOF
1387        hello, world
1388        EOF
1389        INPUT_END
1390         git show N8:foo/foo >actual.foo &&
1391         git show N8:foo/bar >actual.bar &&
1392         test_cmp expect.foo actual.foo &&
1393         test_cmp expect.bar actual.bar'
1394
1395test_expect_success \
1396        'N: extract subtree' \
1397        'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1398         cat >input <<-INPUT_END &&
1399        commit refs/heads/N9
1400        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1401        data <<COMMIT
1402        extract subtree branch:newdir
1403        COMMIT
1404
1405        M 040000 $branch ""
1406        C "newdir" ""
1407        INPUT_END
1408         git fast-import <input &&
1409         git diff --exit-code branch:newdir N9'
1410
1411test_expect_success \
1412        'N: modify subtree, extract it, and modify again' \
1413        'echo hello >expect.baz &&
1414         echo hello, world >expect.qux &&
1415         git fast-import <<-SETUP_END &&
1416        commit refs/heads/N10
1417        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418        data <<COMMIT
1419        hello, tree
1420        COMMIT
1421
1422        deleteall
1423        M 644 inline foo/bar/baz
1424        data <<EOF
1425        hello
1426        EOF
1427        SETUP_END
1428
1429         tree=$(git rev-parse --verify N10:) &&
1430         git fast-import <<-INPUT_END &&
1431        commit refs/heads/N11
1432        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1433        data <<COMMIT
1434        copy to root by id and modify
1435        COMMIT
1436
1437        M 040000 $tree ""
1438        M 100644 inline foo/bar/qux
1439        data <<EOF
1440        hello, world
1441        EOF
1442        R "foo" ""
1443        C "bar/qux" "bar/quux"
1444        INPUT_END
1445         git show N11:bar/baz >actual.baz &&
1446         git show N11:bar/qux >actual.qux &&
1447         git show N11:bar/quux >actual.quux &&
1448         test_cmp expect.baz actual.baz &&
1449         test_cmp expect.qux actual.qux &&
1450         test_cmp expect.qux actual.quux'
1451
1452###
1453### series O
1454###
1455
1456cat >input <<INPUT_END
1457#we will
1458commit refs/heads/O1
1459# -- ignore all of this text
1460committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1461# $GIT_COMMITTER_NAME has inserted here for his benefit.
1462data <<COMMIT
1463dirty directory copy
1464COMMIT
1465
1466# don't forget the import blank line!
1467#
1468# yes, we started from our usual base of branch^0.
1469# i like branch^0.
1470from refs/heads/branch^0
1471# and we need to reuse file2/file5 from N3 above.
1472M 644 inline file2/file5
1473# otherwise the tree will be different
1474data <<EOF
1475$file5_data
1476EOF
1477
1478# don't forget to copy file2 to file3
1479C file2 file3
1480#
1481# or to delete file5 from file2.
1482D file2/file5
1483# are we done yet?
1484
1485INPUT_END
1486
1487test_expect_success \
1488        'O: comments are all skipped' \
1489        'git fast-import <input &&
1490         test `git rev-parse N3` = `git rev-parse O1`'
1491
1492cat >input <<INPUT_END
1493commit refs/heads/O2
1494committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1495data <<COMMIT
1496dirty directory copy
1497COMMIT
1498from refs/heads/branch^0
1499M 644 inline file2/file5
1500data <<EOF
1501$file5_data
1502EOF
1503C file2 file3
1504D file2/file5
1505
1506INPUT_END
1507
1508test_expect_success \
1509        'O: blank lines not necessary after data commands' \
1510        'git fast-import <input &&
1511         test `git rev-parse N3` = `git rev-parse O2`'
1512
1513test_expect_success \
1514        'O: repack before next test' \
1515        'git repack -a -d'
1516
1517cat >input <<INPUT_END
1518commit refs/heads/O3
1519committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520data <<COMMIT
1521zstring
1522COMMIT
1523commit refs/heads/O3
1524committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1525data <<COMMIT
1526zof
1527COMMIT
1528checkpoint
1529commit refs/heads/O3
1530mark :5
1531committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1532data <<COMMIT
1533zempty
1534COMMIT
1535checkpoint
1536commit refs/heads/O3
1537committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538data <<COMMIT
1539zcommits
1540COMMIT
1541reset refs/tags/O3-2nd
1542from :5
1543reset refs/tags/O3-3rd
1544from :5
1545INPUT_END
1546
1547cat >expect <<INPUT_END
1548string
1549of
1550empty
1551commits
1552INPUT_END
1553test_expect_success \
1554        'O: blank lines not necessary after other commands' \
1555        'git fast-import <input &&
1556         test 8 = `find .git/objects/pack -type f | wc -l` &&
1557         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1558         git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1559         test_cmp expect actual'
1560
1561cat >input <<INPUT_END
1562commit refs/heads/O4
1563committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1564data <<COMMIT
1565zstring
1566COMMIT
1567commit refs/heads/O4
1568committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1569data <<COMMIT
1570zof
1571COMMIT
1572progress Two commits down, 2 to go!
1573commit refs/heads/O4
1574committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575data <<COMMIT
1576zempty
1577COMMIT
1578progress Three commits down, 1 to go!
1579commit refs/heads/O4
1580committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1581data <<COMMIT
1582zcommits
1583COMMIT
1584progress I'm done!
1585INPUT_END
1586test_expect_success \
1587        'O: progress outputs as requested by input' \
1588        'git fast-import <input >actual &&
1589         grep "progress " <input >expect &&
1590         test_cmp expect actual'
1591
1592###
1593### series P (gitlinks)
1594###
1595
1596cat >input <<INPUT_END
1597blob
1598mark :1
1599data 10
1600test file
1601
1602reset refs/heads/sub
1603commit refs/heads/sub
1604mark :2
1605committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1606data 12
1607sub_initial
1608M 100644 :1 file
1609
1610blob
1611mark :3
1612data <<DATAEND
1613[submodule "sub"]
1614        path = sub
1615        url = "`pwd`/sub"
1616DATAEND
1617
1618commit refs/heads/subuse1
1619mark :4
1620committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1621data 8
1622initial
1623from refs/heads/master
1624M 100644 :3 .gitmodules
1625M 160000 :2 sub
1626
1627blob
1628mark :5
1629data 20
1630test file
1631more data
1632
1633commit refs/heads/sub
1634mark :6
1635committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1636data 11
1637sub_second
1638from :2
1639M 100644 :5 file
1640
1641commit refs/heads/subuse1
1642mark :7
1643committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644data 7
1645second
1646from :4
1647M 160000 :6 sub
1648
1649INPUT_END
1650
1651test_expect_success \
1652        'P: superproject & submodule mix' \
1653        'git fast-import <input &&
1654         git checkout subuse1 &&
1655         rm -rf sub && mkdir sub && (cd sub &&
1656         git init &&
1657         git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1658         git checkout master) &&
1659         git submodule init &&
1660         git submodule update'
1661
1662SUBLAST=$(git rev-parse --verify sub)
1663SUBPREV=$(git rev-parse --verify sub^)
1664
1665cat >input <<INPUT_END
1666blob
1667mark :1
1668data <<DATAEND
1669[submodule "sub"]
1670        path = sub
1671        url = "`pwd`/sub"
1672DATAEND
1673
1674commit refs/heads/subuse2
1675mark :2
1676committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1677data 8
1678initial
1679from refs/heads/master
1680M 100644 :1 .gitmodules
1681M 160000 $SUBPREV sub
1682
1683commit refs/heads/subuse2
1684mark :3
1685committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1686data 7
1687second
1688from :2
1689M 160000 $SUBLAST sub
1690
1691INPUT_END
1692
1693test_expect_success \
1694        'P: verbatim SHA gitlinks' \
1695        'git branch -D sub &&
1696         git gc && git prune &&
1697         git fast-import <input &&
1698         test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1699
1700test_tick
1701cat >input <<INPUT_END
1702commit refs/heads/subuse3
1703mark :1
1704committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1705data <<COMMIT
1706corrupt
1707COMMIT
1708
1709from refs/heads/subuse2
1710M 160000 inline sub
1711data <<DATA
1712$SUBPREV
1713DATA
1714
1715INPUT_END
1716
1717test_expect_success 'P: fail on inline gitlink' '
1718    test_must_fail git fast-import <input'
1719
1720test_tick
1721cat >input <<INPUT_END
1722blob
1723mark :1
1724data <<DATA
1725$SUBPREV
1726DATA
1727
1728commit refs/heads/subuse3
1729mark :2
1730committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1731data <<COMMIT
1732corrupt
1733COMMIT
1734
1735from refs/heads/subuse2
1736M 160000 :1 sub
1737
1738INPUT_END
1739
1740test_expect_success 'P: fail on blob mark in gitlink' '
1741    test_must_fail git fast-import <input'
1742
1743###
1744### series Q (notes)
1745###
1746
1747note1_data="The first note for the first commit"
1748note2_data="The first note for the second commit"
1749note3_data="The first note for the third commit"
1750note1b_data="The second note for the first commit"
1751note1c_data="The third note for the first commit"
1752note2b_data="The second note for the second commit"
1753
1754test_tick
1755cat >input <<INPUT_END
1756blob
1757mark :2
1758data <<EOF
1759$file2_data
1760EOF
1761
1762commit refs/heads/notes-test
1763mark :3
1764committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1765data <<COMMIT
1766first (:3)
1767COMMIT
1768
1769M 644 :2 file2
1770
1771blob
1772mark :4
1773data $file4_len
1774$file4_data
1775commit refs/heads/notes-test
1776mark :5
1777committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1778data <<COMMIT
1779second (:5)
1780COMMIT
1781
1782M 644 :4 file4
1783
1784commit refs/heads/notes-test
1785mark :6
1786committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1787data <<COMMIT
1788third (:6)
1789COMMIT
1790
1791M 644 inline file5
1792data <<EOF
1793$file5_data
1794EOF
1795
1796M 755 inline file6
1797data <<EOF
1798$file6_data
1799EOF
1800
1801blob
1802mark :7
1803data <<EOF
1804$note1_data
1805EOF
1806
1807blob
1808mark :8
1809data <<EOF
1810$note2_data
1811EOF
1812
1813commit refs/notes/foobar
1814mark :9
1815committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1816data <<COMMIT
1817notes (:9)
1818COMMIT
1819
1820N :7 :3
1821N :8 :5
1822N inline :6
1823data <<EOF
1824$note3_data
1825EOF
1826
1827commit refs/notes/foobar
1828mark :10
1829committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1830data <<COMMIT
1831notes (:10)
1832COMMIT
1833
1834N inline :3
1835data <<EOF
1836$note1b_data
1837EOF
1838
1839commit refs/notes/foobar2
1840mark :11
1841committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842data <<COMMIT
1843notes (:11)
1844COMMIT
1845
1846N inline :3
1847data <<EOF
1848$note1c_data
1849EOF
1850
1851commit refs/notes/foobar
1852mark :12
1853committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1854data <<COMMIT
1855notes (:12)
1856COMMIT
1857
1858deleteall
1859N inline :5
1860data <<EOF
1861$note2b_data
1862EOF
1863
1864INPUT_END
1865
1866test_expect_success \
1867        'Q: commit notes' \
1868        'git fast-import <input &&
1869         git whatchanged notes-test'
1870
1871test_expect_success 'Q: verify pack' '
1872        verify_packs
1873'
1874
1875commit1=$(git rev-parse notes-test~2)
1876commit2=$(git rev-parse notes-test^)
1877commit3=$(git rev-parse notes-test)
1878
1879cat >expect <<EOF
1880author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1881committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1882
1883first (:3)
1884EOF
1885test_expect_success \
1886        'Q: verify first commit' \
1887        'git cat-file commit notes-test~2 | sed 1d >actual &&
1888        test_cmp expect actual'
1889
1890cat >expect <<EOF
1891parent $commit1
1892author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1893committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1894
1895second (:5)
1896EOF
1897test_expect_success \
1898        'Q: verify second commit' \
1899        'git cat-file commit notes-test^ | sed 1d >actual &&
1900        test_cmp expect actual'
1901
1902cat >expect <<EOF
1903parent $commit2
1904author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1905committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1906
1907third (:6)
1908EOF
1909test_expect_success \
1910        'Q: verify third commit' \
1911        'git cat-file commit notes-test | sed 1d >actual &&
1912        test_cmp expect actual'
1913
1914cat >expect <<EOF
1915author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1916committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1917
1918notes (:9)
1919EOF
1920test_expect_success \
1921        'Q: verify first notes commit' \
1922        'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1923        test_cmp expect actual'
1924
1925cat >expect.unsorted <<EOF
1926100644 blob $commit1
1927100644 blob $commit2
1928100644 blob $commit3
1929EOF
1930cat expect.unsorted | sort >expect
1931test_expect_success \
1932        'Q: verify first notes tree' \
1933        'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1934         test_cmp expect actual'
1935
1936echo "$note1_data" >expect
1937test_expect_success \
1938        'Q: verify first note for first commit' \
1939        'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1940
1941echo "$note2_data" >expect
1942test_expect_success \
1943        'Q: verify first note for second commit' \
1944        'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1945
1946echo "$note3_data" >expect
1947test_expect_success \
1948        'Q: verify first note for third commit' \
1949        'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1950
1951cat >expect <<EOF
1952parent `git rev-parse --verify refs/notes/foobar~2`
1953author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1954committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1955
1956notes (:10)
1957EOF
1958test_expect_success \
1959        'Q: verify second notes commit' \
1960        'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1961        test_cmp expect actual'
1962
1963cat >expect.unsorted <<EOF
1964100644 blob $commit1
1965100644 blob $commit2
1966100644 blob $commit3
1967EOF
1968cat expect.unsorted | sort >expect
1969test_expect_success \
1970        'Q: verify second notes tree' \
1971        'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1972         test_cmp expect actual'
1973
1974echo "$note1b_data" >expect
1975test_expect_success \
1976        'Q: verify second note for first commit' \
1977        'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1978
1979echo "$note2_data" >expect
1980test_expect_success \
1981        'Q: verify first note for second commit' \
1982        'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1983
1984echo "$note3_data" >expect
1985test_expect_success \
1986        'Q: verify first note for third commit' \
1987        'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1988
1989cat >expect <<EOF
1990author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1991committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1992
1993notes (:11)
1994EOF
1995test_expect_success \
1996        'Q: verify third notes commit' \
1997        'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1998        test_cmp expect actual'
1999
2000cat >expect.unsorted <<EOF
2001100644 blob $commit1
2002EOF
2003cat expect.unsorted | sort >expect
2004test_expect_success \
2005        'Q: verify third notes tree' \
2006        'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
2007         test_cmp expect actual'
2008
2009echo "$note1c_data" >expect
2010test_expect_success \
2011        'Q: verify third note for first commit' \
2012        'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2013
2014cat >expect <<EOF
2015parent `git rev-parse --verify refs/notes/foobar^`
2016author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2017committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2018
2019notes (:12)
2020EOF
2021test_expect_success \
2022        'Q: verify fourth notes commit' \
2023        'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2024        test_cmp expect actual'
2025
2026cat >expect.unsorted <<EOF
2027100644 blob $commit2
2028EOF
2029cat expect.unsorted | sort >expect
2030test_expect_success \
2031        'Q: verify fourth notes tree' \
2032        'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
2033         test_cmp expect actual'
2034
2035echo "$note2b_data" >expect
2036test_expect_success \
2037        'Q: verify second note for second commit' \
2038        'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2039
2040cat >input <<EOF
2041reset refs/heads/Q0
2042
2043commit refs/heads/note-Q0
2044committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2045data <<COMMIT
2046Note for an empty branch.
2047COMMIT
2048
2049N inline refs/heads/Q0
2050data <<NOTE
2051some note
2052NOTE
2053EOF
2054test_expect_success \
2055        'Q: deny note on empty branch' \
2056        'test_must_fail git fast-import <input'
2057###
2058### series R (feature and option)
2059###
2060
2061cat >input <<EOF
2062feature no-such-feature-exists
2063EOF
2064
2065test_expect_success 'R: abort on unsupported feature' '
2066        test_must_fail git fast-import <input
2067'
2068
2069cat >input <<EOF
2070feature date-format=now
2071EOF
2072
2073test_expect_success 'R: supported feature is accepted' '
2074        git fast-import <input
2075'
2076
2077cat >input << EOF
2078blob
2079data 3
2080hi
2081feature date-format=now
2082EOF
2083
2084test_expect_success 'R: abort on receiving feature after data command' '
2085        test_must_fail git fast-import <input
2086'
2087
2088cat >input << EOF
2089feature import-marks=git.marks
2090feature import-marks=git2.marks
2091EOF
2092
2093test_expect_success 'R: only one import-marks feature allowed per stream' '
2094        test_must_fail git fast-import <input
2095'
2096
2097cat >input << EOF
2098feature export-marks=git.marks
2099blob
2100mark :1
2101data 3
2102hi
2103
2104EOF
2105
2106test_expect_success \
2107    'R: export-marks feature results in a marks file being created' \
2108    'cat input | git fast-import &&
2109    grep :1 git.marks'
2110
2111test_expect_success \
2112    'R: export-marks options can be overridden by commandline options' \
2113    'cat input | git fast-import --export-marks=other.marks &&
2114    grep :1 other.marks'
2115
2116test_expect_success 'R: catch typo in marks file name' '
2117        test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2118        echo "feature import-marks=nonexistent.marks" |
2119        test_must_fail git fast-import
2120'
2121
2122test_expect_success 'R: import and output marks can be the same file' '
2123        rm -f io.marks &&
2124        blob=$(echo hi | git hash-object --stdin) &&
2125        cat >expect <<-EOF &&
2126        :1 $blob
2127        :2 $blob
2128        EOF
2129        git fast-import --export-marks=io.marks <<-\EOF &&
2130        blob
2131        mark :1
2132        data 3
2133        hi
2134
2135        EOF
2136        git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2137        blob
2138        mark :2
2139        data 3
2140        hi
2141
2142        EOF
2143        test_cmp expect io.marks
2144'
2145
2146test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2147        rm -f io.marks &&
2148        test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2149        blob
2150        mark :1
2151        data 3
2152        hi
2153
2154        EOF
2155'
2156
2157test_expect_success 'R: --import-marks-if-exists' '
2158        rm -f io.marks &&
2159        blob=$(echo hi | git hash-object --stdin) &&
2160        echo ":1 $blob" >expect &&
2161        git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2162        blob
2163        mark :1
2164        data 3
2165        hi
2166
2167        EOF
2168        test_cmp expect io.marks
2169'
2170
2171test_expect_success 'R: feature import-marks-if-exists' '
2172        rm -f io.marks &&
2173        >expect &&
2174
2175        git fast-import --export-marks=io.marks <<-\EOF &&
2176        feature import-marks-if-exists=not_io.marks
2177        EOF
2178        test_cmp expect io.marks &&
2179
2180        blob=$(echo hi | git hash-object --stdin) &&
2181
2182        echo ":1 $blob" >io.marks &&
2183        echo ":1 $blob" >expect &&
2184        echo ":2 $blob" >>expect &&
2185
2186        git fast-import --export-marks=io.marks <<-\EOF &&
2187        feature import-marks-if-exists=io.marks
2188        blob
2189        mark :2
2190        data 3
2191        hi
2192
2193        EOF
2194        test_cmp expect io.marks &&
2195
2196        echo ":3 $blob" >>expect &&
2197
2198        git fast-import --import-marks=io.marks \
2199                        --export-marks=io.marks <<-\EOF &&
2200        feature import-marks-if-exists=not_io.marks
2201        blob
2202        mark :3
2203        data 3
2204        hi
2205
2206        EOF
2207        test_cmp expect io.marks &&
2208
2209        >expect &&
2210
2211        git fast-import --import-marks-if-exists=not_io.marks \
2212                        --export-marks=io.marks <<-\EOF
2213        feature import-marks-if-exists=io.marks
2214        EOF
2215        test_cmp expect io.marks
2216'
2217
2218cat >input << EOF
2219feature import-marks=marks.out
2220feature export-marks=marks.new
2221EOF
2222
2223test_expect_success \
2224    'R: import to output marks works without any content' \
2225    'cat input | git fast-import &&
2226    test_cmp marks.out marks.new'
2227
2228cat >input <<EOF
2229feature import-marks=nonexistent.marks
2230feature export-marks=marks.new
2231EOF
2232
2233test_expect_success \
2234    'R: import marks prefers commandline marks file over the stream' \
2235    'cat input | git fast-import --import-marks=marks.out &&
2236    test_cmp marks.out marks.new'
2237
2238
2239cat >input <<EOF
2240feature import-marks=nonexistent.marks
2241feature export-marks=combined.marks
2242EOF
2243
2244test_expect_success 'R: multiple --import-marks= should be honoured' '
2245    head -n2 marks.out > one.marks &&
2246    tail -n +3 marks.out > two.marks &&
2247    git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2248    test_cmp marks.out combined.marks
2249'
2250
2251cat >input <<EOF
2252feature relative-marks
2253feature import-marks=relative.in
2254feature export-marks=relative.out
2255EOF
2256
2257test_expect_success 'R: feature relative-marks should be honoured' '
2258    mkdir -p .git/info/fast-import/ &&
2259    cp marks.new .git/info/fast-import/relative.in &&
2260    git fast-import <input &&
2261    test_cmp marks.new .git/info/fast-import/relative.out
2262'
2263
2264cat >input <<EOF
2265feature relative-marks
2266feature import-marks=relative.in
2267feature no-relative-marks
2268feature export-marks=non-relative.out
2269EOF
2270
2271test_expect_success 'R: feature no-relative-marks should be honoured' '
2272    git fast-import <input &&
2273    test_cmp marks.new non-relative.out
2274'
2275
2276test_expect_success 'R: feature ls supported' '
2277        echo "feature ls" |
2278        git fast-import
2279'
2280
2281test_expect_success 'R: feature cat-blob supported' '
2282        echo "feature cat-blob" |
2283        git fast-import
2284'
2285
2286test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2287        test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2288'
2289
2290test_expect_success NOT_MINGW 'R: print old blob' '
2291        blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2292        cat >expect <<-EOF &&
2293        ${blob} blob 11
2294        yes it can
2295
2296        EOF
2297        echo "cat-blob $blob" |
2298        git fast-import --cat-blob-fd=6 6>actual &&
2299        test_cmp expect actual
2300'
2301
2302test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' '
2303        echo hello >greeting &&
2304        blob=$(git hash-object -w greeting) &&
2305        cat >expect <<-EOF &&
2306        ${blob} blob 6
2307        hello
2308
2309        EOF
2310        git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2311        cat-blob $blob
2312        EOF
2313        test_cmp expect actual.3 &&
2314        test_cmp empty actual.1 &&
2315        git fast-import 3>actual.3 >actual.1 <<-EOF &&
2316        option cat-blob-fd=3
2317        cat-blob $blob
2318        EOF
2319        test_cmp empty actual.3 &&
2320        test_cmp expect actual.1
2321'
2322
2323test_expect_success NOT_MINGW 'R: print new blob' '
2324        blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2325        cat >expect <<-EOF &&
2326        ${blob} blob 12
2327        yep yep yep
2328
2329        EOF
2330        git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2331        blob
2332        mark :1
2333        data <<BLOB_END
2334        yep yep yep
2335        BLOB_END
2336        cat-blob :1
2337        EOF
2338        test_cmp expect actual
2339'
2340
2341test_expect_success NOT_MINGW 'R: print new blob by sha1' '
2342        blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2343        cat >expect <<-EOF &&
2344        ${blob} blob 25
2345        a new blob named by sha1
2346
2347        EOF
2348        git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2349        blob
2350        data <<BLOB_END
2351        a new blob named by sha1
2352        BLOB_END
2353        cat-blob $blob
2354        EOF
2355        test_cmp expect actual
2356'
2357
2358test_expect_success 'setup: big file' '
2359        (
2360                echo "the quick brown fox jumps over the lazy dog" >big &&
2361                for i in 1 2 3
2362                do
2363                        cat big big big big >bigger &&
2364                        cat bigger bigger bigger bigger >big ||
2365                        exit
2366                done
2367        )
2368'
2369
2370test_expect_success 'R: print two blobs to stdout' '
2371        blob1=$(git hash-object big) &&
2372        blob1_len=$(wc -c <big) &&
2373        blob2=$(echo hello | git hash-object --stdin) &&
2374        {
2375                echo ${blob1} blob $blob1_len &&
2376                cat big &&
2377                cat <<-EOF
2378
2379                ${blob2} blob 6
2380                hello
2381
2382                EOF
2383        } >expect &&
2384        {
2385                cat <<-\END_PART1 &&
2386                        blob
2387                        mark :1
2388                        data <<data_end
2389                END_PART1
2390                cat big &&
2391                cat <<-\EOF
2392                        data_end
2393                        blob
2394                        mark :2
2395                        data <<data_end
2396                        hello
2397                        data_end
2398                        cat-blob :1
2399                        cat-blob :2
2400                EOF
2401        } |
2402        git fast-import >actual &&
2403        test_cmp expect actual
2404'
2405
2406test_expect_success PIPE 'R: copy using cat-file' '
2407        expect_id=$(git hash-object big) &&
2408        expect_len=$(wc -c <big) &&
2409        echo $expect_id blob $expect_len >expect.response &&
2410
2411        rm -f blobs &&
2412        cat >frontend <<-\FRONTEND_END &&
2413        #!/bin/sh
2414        FRONTEND_END
2415
2416        mkfifo blobs &&
2417        (
2418                export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2419                cat <<-\EOF &&
2420                feature cat-blob
2421                blob
2422                mark :1
2423                data <<BLOB
2424                EOF
2425                cat big &&
2426                cat <<-\EOF &&
2427                BLOB
2428                cat-blob :1
2429                EOF
2430
2431                read blob_id type size <&3 &&
2432                echo "$blob_id $type $size" >response &&
2433                head_c $size >blob <&3 &&
2434                read newline <&3 &&
2435
2436                cat <<-EOF &&
2437                commit refs/heads/copied
2438                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2439                data <<COMMIT
2440                copy big file as file3
2441                COMMIT
2442                M 644 inline file3
2443                data <<BLOB
2444                EOF
2445                cat blob &&
2446                echo BLOB
2447        ) 3<blobs |
2448        git fast-import --cat-blob-fd=3 3>blobs &&
2449        git show copied:file3 >actual &&
2450        test_cmp expect.response response &&
2451        test_cmp big actual
2452'
2453
2454test_expect_success PIPE 'R: print blob mid-commit' '
2455        rm -f blobs &&
2456        echo "A blob from _before_ the commit." >expect &&
2457        mkfifo blobs &&
2458        (
2459                exec 3<blobs &&
2460                cat <<-EOF &&
2461                feature cat-blob
2462                blob
2463                mark :1
2464                data <<BLOB
2465                A blob from _before_ the commit.
2466                BLOB
2467                commit refs/heads/temporary
2468                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2469                data <<COMMIT
2470                Empty commit
2471                COMMIT
2472                cat-blob :1
2473                EOF
2474
2475                read blob_id type size <&3 &&
2476                head_c $size >actual <&3 &&
2477                read newline <&3 &&
2478
2479                echo
2480        ) |
2481        git fast-import --cat-blob-fd=3 3>blobs &&
2482        test_cmp expect actual
2483'
2484
2485test_expect_success PIPE 'R: print staged blob within commit' '
2486        rm -f blobs &&
2487        echo "A blob from _within_ the commit." >expect &&
2488        mkfifo blobs &&
2489        (
2490                exec 3<blobs &&
2491                cat <<-EOF &&
2492                feature cat-blob
2493                commit refs/heads/within
2494                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2495                data <<COMMIT
2496                Empty commit
2497                COMMIT
2498                M 644 inline within
2499                data <<BLOB
2500                A blob from _within_ the commit.
2501                BLOB
2502                EOF
2503
2504                to_get=$(
2505                        echo "A blob from _within_ the commit." |
2506                        git hash-object --stdin
2507                ) &&
2508                echo "cat-blob $to_get" &&
2509
2510                read blob_id type size <&3 &&
2511                head_c $size >actual <&3 &&
2512                read newline <&3 &&
2513
2514                echo deleteall
2515        ) |
2516        git fast-import --cat-blob-fd=3 3>blobs &&
2517        test_cmp expect actual
2518'
2519
2520cat >input << EOF
2521option git quiet
2522blob
2523data 3
2524hi
2525
2526EOF
2527
2528test_expect_success 'R: quiet option results in no stats being output' '
2529    cat input | git fast-import 2> output &&
2530    test_cmp empty output
2531'
2532
2533test_expect_success 'R: feature done means terminating "done" is mandatory' '
2534        echo feature done | test_must_fail git fast-import &&
2535        test_must_fail git fast-import --done </dev/null
2536'
2537
2538test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2539        git fast-import <<-\EOF &&
2540        feature done
2541        done
2542        trailing gibberish
2543        EOF
2544        git fast-import <<-\EOF
2545        done
2546        more trailing gibberish
2547        EOF
2548'
2549
2550test_expect_success 'R: terminating "done" within commit' '
2551        cat >expect <<-\EOF &&
2552        OBJID
2553        :000000 100644 OBJID OBJID A    hello.c
2554        :000000 100644 OBJID OBJID A    hello2.c
2555        EOF
2556        git fast-import <<-EOF &&
2557        commit refs/heads/done-ends
2558        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2559        data <<EOT
2560        Commit terminated by "done" command
2561        EOT
2562        M 100644 inline hello.c
2563        data <<EOT
2564        Hello, world.
2565        EOT
2566        C hello.c hello2.c
2567        done
2568        EOF
2569        git rev-list done-ends |
2570        git diff-tree -r --stdin --root --always |
2571        sed -e "s/$_x40/OBJID/g" >actual &&
2572        test_cmp expect actual
2573'
2574
2575cat >input <<EOF
2576option git non-existing-option
2577EOF
2578
2579test_expect_success 'R: die on unknown option' '
2580    test_must_fail git fast-import <input
2581'
2582
2583test_expect_success 'R: unknown commandline options are rejected' '\
2584    test_must_fail git fast-import --non-existing-option < /dev/null
2585'
2586
2587test_expect_success 'R: die on invalid option argument' '
2588        echo "option git active-branches=-5" |
2589        test_must_fail git fast-import &&
2590        echo "option git depth=" |
2591        test_must_fail git fast-import &&
2592        test_must_fail git fast-import --depth="5 elephants" </dev/null
2593'
2594
2595cat >input <<EOF
2596option non-existing-vcs non-existing-option
2597EOF
2598
2599test_expect_success 'R: ignore non-git options' '
2600    git fast-import <input
2601'
2602
2603##
2604## R: very large blobs
2605##
2606blobsize=$((2*1024*1024 + 53))
2607test-genrandom bar $blobsize >expect
2608cat >input <<INPUT_END
2609commit refs/heads/big-file
2610committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2611data <<COMMIT
2612R - big file
2613COMMIT
2614
2615M 644 inline big1
2616data $blobsize
2617INPUT_END
2618cat expect >>input
2619cat >>input <<INPUT_END
2620M 644 inline big2
2621data $blobsize
2622INPUT_END
2623cat expect >>input
2624echo >>input
2625
2626test_expect_success \
2627        'R: blob bigger than threshold' \
2628        'test_create_repo R &&
2629         git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2630
2631test_expect_success 'R: verify created pack' '
2632        (
2633                cd R &&
2634                verify_packs -v > ../verify
2635        )
2636'
2637
2638test_expect_success \
2639        'R: verify written objects' \
2640        'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2641         test_cmp expect actual &&
2642         a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2643         b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2644         test $a = $b'
2645test_expect_success \
2646        'R: blob appears only once' \
2647        'n=$(grep $a verify | wc -l) &&
2648         test 1 = $n'
2649
2650###
2651### series S
2652###
2653#
2654# Make sure missing spaces and EOLs after mark references
2655# cause errors.
2656#
2657# Setup:
2658#
2659#   1--2--4
2660#    \   /
2661#     -3-
2662#
2663#   commit marks:  301, 302, 303, 304
2664#   blob marks:              403, 404, resp.
2665#   note mark:          202
2666#
2667# The error message when a space is missing not at the
2668# end of the line is:
2669#
2670#   Missing space after ..
2671#
2672# or when extra characters come after the mark at the end
2673# of the line:
2674#
2675#   Garbage after ..
2676#
2677# or when the dataref is neither "inline " or a known SHA1,
2678#
2679#   Invalid dataref ..
2680#
2681test_tick
2682
2683cat >input <<INPUT_END
2684commit refs/heads/S
2685mark :301
2686committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2687data <<COMMIT
2688commit 1
2689COMMIT
2690M 100644 inline hello.c
2691data <<BLOB
2692blob 1
2693BLOB
2694
2695commit refs/heads/S
2696mark :302
2697committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2698data <<COMMIT
2699commit 2
2700COMMIT
2701from :301
2702M 100644 inline hello.c
2703data <<BLOB
2704blob 2
2705BLOB
2706
2707blob
2708mark :403
2709data <<BLOB
2710blob 3
2711BLOB
2712
2713blob
2714mark :202
2715data <<BLOB
2716note 2
2717BLOB
2718INPUT_END
2719
2720test_expect_success 'S: initialize for S tests' '
2721        git fast-import --export-marks=marks <input
2722'
2723
2724#
2725# filemodify, three datarefs
2726#
2727test_expect_success 'S: filemodify with garbage after mark must fail' '
2728        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2729        commit refs/heads/S
2730        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2731        data <<COMMIT
2732        commit N
2733        COMMIT
2734        M 100644 :403x hello.c
2735        EOF
2736        cat err &&
2737        test_i18ngrep "space after mark" err
2738'
2739
2740# inline is misspelled; fast-import thinks it is some unknown dataref
2741test_expect_success 'S: filemodify with garbage after inline must fail' '
2742        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2743        commit refs/heads/S
2744        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2745        data <<COMMIT
2746        commit N
2747        COMMIT
2748        M 100644 inlineX hello.c
2749        data <<BLOB
2750        inline
2751        BLOB
2752        EOF
2753        cat err &&
2754        test_i18ngrep "nvalid dataref" err
2755'
2756
2757test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2758        sha1=$(grep :403 marks | cut -d\  -f2) &&
2759        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2760        commit refs/heads/S
2761        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2762        data <<COMMIT
2763        commit N
2764        COMMIT
2765        M 100644 ${sha1}x hello.c
2766        EOF
2767        cat err &&
2768        test_i18ngrep "space after SHA1" err
2769'
2770
2771#
2772# notemodify, three ways to say dataref
2773#
2774test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2775        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2776        commit refs/heads/S
2777        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2778        data <<COMMIT
2779        commit S note dataref markref
2780        COMMIT
2781        N :202x :302
2782        EOF
2783        cat err &&
2784        test_i18ngrep "space after mark" err
2785'
2786
2787test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2788        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2789        commit refs/heads/S
2790        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2791        data <<COMMIT
2792        commit S note dataref inline
2793        COMMIT
2794        N inlineX :302
2795        data <<BLOB
2796        note blob
2797        BLOB
2798        EOF
2799        cat err &&
2800        test_i18ngrep "nvalid dataref" err
2801'
2802
2803test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2804        sha1=$(grep :202 marks | cut -d\  -f2) &&
2805        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2806        commit refs/heads/S
2807        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2808        data <<COMMIT
2809        commit S note dataref sha1
2810        COMMIT
2811        N ${sha1}x :302
2812        EOF
2813        cat err &&
2814        test_i18ngrep "space after SHA1" err
2815'
2816
2817#
2818# notemodify, mark in committish
2819#
2820test_expect_success 'S: notemodify with garbarge after mark committish must fail' '
2821        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2822        commit refs/heads/Snotes
2823        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2824        data <<COMMIT
2825        commit S note committish
2826        COMMIT
2827        N :202 :302x
2828        EOF
2829        cat err &&
2830        test_i18ngrep "after mark" err
2831'
2832
2833#
2834# from
2835#
2836test_expect_success 'S: from with garbage after mark must fail' '
2837        # no &&
2838        git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err
2839        commit refs/heads/S2
2840        mark :303
2841        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842        data <<COMMIT
2843        commit 3
2844        COMMIT
2845        from :301x
2846        M 100644 :403 hello.c
2847        EOF
2848
2849        ret=$? &&
2850        echo returned $ret &&
2851        test $ret -ne 0 && # failed, but it created the commit
2852
2853        # go create the commit, need it for merge test
2854        git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2855        commit refs/heads/S2
2856        mark :303
2857        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2858        data <<COMMIT
2859        commit 3
2860        COMMIT
2861        from :301
2862        M 100644 :403 hello.c
2863        EOF
2864
2865        # now evaluate the error
2866        cat err &&
2867        test_i18ngrep "after mark" err
2868'
2869
2870
2871#
2872# merge
2873#
2874test_expect_success 'S: merge with garbage after mark must fail' '
2875        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2876        commit refs/heads/S
2877        mark :304
2878        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2879        data <<COMMIT
2880        merge 4
2881        COMMIT
2882        from :302
2883        merge :303x
2884        M 100644 :403 hello.c
2885        EOF
2886        cat err &&
2887        test_i18ngrep "after mark" err
2888'
2889
2890#
2891# tag, from markref
2892#
2893test_expect_success 'S: tag with garbage after mark must fail' '
2894        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2895        tag refs/tags/Stag
2896        from :302x
2897        tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2898        data <<TAG
2899        tag S
2900        TAG
2901        EOF
2902        cat err &&
2903        test_i18ngrep "after mark" err
2904'
2905
2906#
2907# cat-blob markref
2908#
2909test_expect_success 'S: cat-blob with garbage after mark must fail' '
2910        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2911        cat-blob :403x
2912        EOF
2913        cat err &&
2914        test_i18ngrep "after mark" err
2915'
2916
2917#
2918# ls markref
2919#
2920test_expect_success 'S: ls with garbage after mark must fail' '
2921        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2922        ls :302x hello.c
2923        EOF
2924        cat err &&
2925        test_i18ngrep "space after mark" err
2926'
2927
2928test_expect_success 'S: ls with garbage after sha1 must fail' '
2929        sha1=$(grep :302 marks | cut -d\  -f2) &&
2930        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2931        ls ${sha1}x hello.c
2932        EOF
2933        cat err &&
2934        test_i18ngrep "space after tree-ish" err
2935'
2936
2937test_done