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