t / t9300-fast-import.shon commit Merge branch 'tm/completion-push-set-upstream' (33ce7c1)
   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: copy to root by id and modify' \
1311        'echo "hello, world" >expect.foo &&
1312         echo hello >expect.bar &&
1313         git fast-import <<-SETUP_END &&
1314        commit refs/heads/N7
1315        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1316        data <<COMMIT
1317        hello, tree
1318        COMMIT
1319
1320        deleteall
1321        M 644 inline foo/bar
1322        data <<EOF
1323        hello
1324        EOF
1325        SETUP_END
1326
1327         tree=$(git rev-parse --verify N7:) &&
1328         git fast-import <<-INPUT_END &&
1329        commit refs/heads/N8
1330        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1331        data <<COMMIT
1332        copy to root by id and modify
1333        COMMIT
1334
1335        M 040000 $tree ""
1336        M 644 inline foo/foo
1337        data <<EOF
1338        hello, world
1339        EOF
1340        INPUT_END
1341         git show N8:foo/foo >actual.foo &&
1342         git show N8:foo/bar >actual.bar &&
1343         test_cmp expect.foo actual.foo &&
1344         test_cmp expect.bar actual.bar'
1345
1346test_expect_success \
1347        'N: extract subtree' \
1348        'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1349         cat >input <<-INPUT_END &&
1350        commit refs/heads/N9
1351        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1352        data <<COMMIT
1353        extract subtree branch:newdir
1354        COMMIT
1355
1356        M 040000 $branch ""
1357        C "newdir" ""
1358        INPUT_END
1359         git fast-import <input &&
1360         git diff --exit-code branch:newdir N9'
1361
1362test_expect_success \
1363        'N: modify subtree, extract it, and modify again' \
1364        'echo hello >expect.baz &&
1365         echo hello, world >expect.qux &&
1366         git fast-import <<-SETUP_END &&
1367        commit refs/heads/N10
1368        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1369        data <<COMMIT
1370        hello, tree
1371        COMMIT
1372
1373        deleteall
1374        M 644 inline foo/bar/baz
1375        data <<EOF
1376        hello
1377        EOF
1378        SETUP_END
1379
1380         tree=$(git rev-parse --verify N10:) &&
1381         git fast-import <<-INPUT_END &&
1382        commit refs/heads/N11
1383        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1384        data <<COMMIT
1385        copy to root by id and modify
1386        COMMIT
1387
1388        M 040000 $tree ""
1389        M 100644 inline foo/bar/qux
1390        data <<EOF
1391        hello, world
1392        EOF
1393        R "foo" ""
1394        C "bar/qux" "bar/quux"
1395        INPUT_END
1396         git show N11:bar/baz >actual.baz &&
1397         git show N11:bar/qux >actual.qux &&
1398         git show N11:bar/quux >actual.quux &&
1399         test_cmp expect.baz actual.baz &&
1400         test_cmp expect.qux actual.qux &&
1401         test_cmp expect.qux actual.quux'
1402
1403###
1404### series O
1405###
1406
1407cat >input <<INPUT_END
1408#we will
1409commit refs/heads/O1
1410# -- ignore all of this text
1411committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1412# $GIT_COMMITTER_NAME has inserted here for his benefit.
1413data <<COMMIT
1414dirty directory copy
1415COMMIT
1416
1417# don't forget the import blank line!
1418#
1419# yes, we started from our usual base of branch^0.
1420# i like branch^0.
1421from refs/heads/branch^0
1422# and we need to reuse file2/file5 from N3 above.
1423M 644 inline file2/file5
1424# otherwise the tree will be different
1425data <<EOF
1426$file5_data
1427EOF
1428
1429# don't forget to copy file2 to file3
1430C file2 file3
1431#
1432# or to delete file5 from file2.
1433D file2/file5
1434# are we done yet?
1435
1436INPUT_END
1437
1438test_expect_success \
1439        'O: comments are all skipped' \
1440        'git fast-import <input &&
1441         test `git rev-parse N3` = `git rev-parse O1`'
1442
1443cat >input <<INPUT_END
1444commit refs/heads/O2
1445committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1446data <<COMMIT
1447dirty directory copy
1448COMMIT
1449from refs/heads/branch^0
1450M 644 inline file2/file5
1451data <<EOF
1452$file5_data
1453EOF
1454C file2 file3
1455D file2/file5
1456
1457INPUT_END
1458
1459test_expect_success \
1460        'O: blank lines not necessary after data commands' \
1461        'git fast-import <input &&
1462         test `git rev-parse N3` = `git rev-parse O2`'
1463
1464test_expect_success \
1465        'O: repack before next test' \
1466        'git repack -a -d'
1467
1468cat >input <<INPUT_END
1469commit refs/heads/O3
1470committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1471data <<COMMIT
1472zstring
1473COMMIT
1474commit refs/heads/O3
1475committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1476data <<COMMIT
1477zof
1478COMMIT
1479checkpoint
1480commit refs/heads/O3
1481mark :5
1482committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1483data <<COMMIT
1484zempty
1485COMMIT
1486checkpoint
1487commit refs/heads/O3
1488committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1489data <<COMMIT
1490zcommits
1491COMMIT
1492reset refs/tags/O3-2nd
1493from :5
1494reset refs/tags/O3-3rd
1495from :5
1496INPUT_END
1497
1498cat >expect <<INPUT_END
1499string
1500of
1501empty
1502commits
1503INPUT_END
1504test_expect_success \
1505        'O: blank lines not necessary after other commands' \
1506        'git fast-import <input &&
1507         test 8 = `find .git/objects/pack -type f | wc -l` &&
1508         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1509         git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1510         test_cmp expect actual'
1511
1512cat >input <<INPUT_END
1513commit refs/heads/O4
1514committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1515data <<COMMIT
1516zstring
1517COMMIT
1518commit refs/heads/O4
1519committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520data <<COMMIT
1521zof
1522COMMIT
1523progress Two commits down, 2 to go!
1524commit refs/heads/O4
1525committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1526data <<COMMIT
1527zempty
1528COMMIT
1529progress Three commits down, 1 to go!
1530commit refs/heads/O4
1531committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1532data <<COMMIT
1533zcommits
1534COMMIT
1535progress I'm done!
1536INPUT_END
1537test_expect_success \
1538        'O: progress outputs as requested by input' \
1539        'git fast-import <input >actual &&
1540         grep "progress " <input >expect &&
1541         test_cmp expect actual'
1542
1543###
1544### series P (gitlinks)
1545###
1546
1547cat >input <<INPUT_END
1548blob
1549mark :1
1550data 10
1551test file
1552
1553reset refs/heads/sub
1554commit refs/heads/sub
1555mark :2
1556committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1557data 12
1558sub_initial
1559M 100644 :1 file
1560
1561blob
1562mark :3
1563data <<DATAEND
1564[submodule "sub"]
1565        path = sub
1566        url = "`pwd`/sub"
1567DATAEND
1568
1569commit refs/heads/subuse1
1570mark :4
1571committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1572data 8
1573initial
1574from refs/heads/master
1575M 100644 :3 .gitmodules
1576M 160000 :2 sub
1577
1578blob
1579mark :5
1580data 20
1581test file
1582more data
1583
1584commit refs/heads/sub
1585mark :6
1586committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1587data 11
1588sub_second
1589from :2
1590M 100644 :5 file
1591
1592commit refs/heads/subuse1
1593mark :7
1594committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1595data 7
1596second
1597from :4
1598M 160000 :6 sub
1599
1600INPUT_END
1601
1602test_expect_success \
1603        'P: supermodule & submodule mix' \
1604        'git fast-import <input &&
1605         git checkout subuse1 &&
1606         rm -rf sub && mkdir sub && (cd sub &&
1607         git init &&
1608         git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1609         git checkout master) &&
1610         git submodule init &&
1611         git submodule update'
1612
1613SUBLAST=$(git rev-parse --verify sub)
1614SUBPREV=$(git rev-parse --verify sub^)
1615
1616cat >input <<INPUT_END
1617blob
1618mark :1
1619data <<DATAEND
1620[submodule "sub"]
1621        path = sub
1622        url = "`pwd`/sub"
1623DATAEND
1624
1625commit refs/heads/subuse2
1626mark :2
1627committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1628data 8
1629initial
1630from refs/heads/master
1631M 100644 :1 .gitmodules
1632M 160000 $SUBPREV sub
1633
1634commit refs/heads/subuse2
1635mark :3
1636committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1637data 7
1638second
1639from :2
1640M 160000 $SUBLAST sub
1641
1642INPUT_END
1643
1644test_expect_success \
1645        'P: verbatim SHA gitlinks' \
1646        'git branch -D sub &&
1647         git gc && git prune &&
1648         git fast-import <input &&
1649         test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1650
1651test_tick
1652cat >input <<INPUT_END
1653commit refs/heads/subuse3
1654mark :1
1655committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1656data <<COMMIT
1657corrupt
1658COMMIT
1659
1660from refs/heads/subuse2
1661M 160000 inline sub
1662data <<DATA
1663$SUBPREV
1664DATA
1665
1666INPUT_END
1667
1668test_expect_success 'P: fail on inline gitlink' '
1669    test_must_fail git fast-import <input'
1670
1671test_tick
1672cat >input <<INPUT_END
1673blob
1674mark :1
1675data <<DATA
1676$SUBPREV
1677DATA
1678
1679commit refs/heads/subuse3
1680mark :2
1681committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1682data <<COMMIT
1683corrupt
1684COMMIT
1685
1686from refs/heads/subuse2
1687M 160000 :1 sub
1688
1689INPUT_END
1690
1691test_expect_success 'P: fail on blob mark in gitlink' '
1692    test_must_fail git fast-import <input'
1693
1694###
1695### series Q (notes)
1696###
1697
1698note1_data="The first note for the first commit"
1699note2_data="The first note for the second commit"
1700note3_data="The first note for the third commit"
1701note1b_data="The second note for the first commit"
1702note1c_data="The third note for the first commit"
1703note2b_data="The second note for the second commit"
1704
1705test_tick
1706cat >input <<INPUT_END
1707blob
1708mark :2
1709data <<EOF
1710$file2_data
1711EOF
1712
1713commit refs/heads/notes-test
1714mark :3
1715committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1716data <<COMMIT
1717first (:3)
1718COMMIT
1719
1720M 644 :2 file2
1721
1722blob
1723mark :4
1724data $file4_len
1725$file4_data
1726commit refs/heads/notes-test
1727mark :5
1728committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1729data <<COMMIT
1730second (:5)
1731COMMIT
1732
1733M 644 :4 file4
1734
1735commit refs/heads/notes-test
1736mark :6
1737committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1738data <<COMMIT
1739third (:6)
1740COMMIT
1741
1742M 644 inline file5
1743data <<EOF
1744$file5_data
1745EOF
1746
1747M 755 inline file6
1748data <<EOF
1749$file6_data
1750EOF
1751
1752blob
1753mark :7
1754data <<EOF
1755$note1_data
1756EOF
1757
1758blob
1759mark :8
1760data <<EOF
1761$note2_data
1762EOF
1763
1764commit refs/notes/foobar
1765mark :9
1766committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1767data <<COMMIT
1768notes (:9)
1769COMMIT
1770
1771N :7 :3
1772N :8 :5
1773N inline :6
1774data <<EOF
1775$note3_data
1776EOF
1777
1778commit refs/notes/foobar
1779mark :10
1780committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1781data <<COMMIT
1782notes (:10)
1783COMMIT
1784
1785N inline :3
1786data <<EOF
1787$note1b_data
1788EOF
1789
1790commit refs/notes/foobar2
1791mark :11
1792committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1793data <<COMMIT
1794notes (:11)
1795COMMIT
1796
1797N inline :3
1798data <<EOF
1799$note1c_data
1800EOF
1801
1802commit refs/notes/foobar
1803mark :12
1804committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1805data <<COMMIT
1806notes (:12)
1807COMMIT
1808
1809deleteall
1810N inline :5
1811data <<EOF
1812$note2b_data
1813EOF
1814
1815INPUT_END
1816
1817test_expect_success \
1818        'Q: commit notes' \
1819        'git fast-import <input &&
1820         git whatchanged notes-test'
1821test_expect_success \
1822        'Q: verify pack' \
1823        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1824
1825commit1=$(git rev-parse notes-test~2)
1826commit2=$(git rev-parse notes-test^)
1827commit3=$(git rev-parse notes-test)
1828
1829cat >expect <<EOF
1830author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1831committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1832
1833first (:3)
1834EOF
1835test_expect_success \
1836        'Q: verify first commit' \
1837        'git cat-file commit notes-test~2 | sed 1d >actual &&
1838        test_cmp expect actual'
1839
1840cat >expect <<EOF
1841parent $commit1
1842author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1843committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1844
1845second (:5)
1846EOF
1847test_expect_success \
1848        'Q: verify second commit' \
1849        'git cat-file commit notes-test^ | sed 1d >actual &&
1850        test_cmp expect actual'
1851
1852cat >expect <<EOF
1853parent $commit2
1854author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1855committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1856
1857third (:6)
1858EOF
1859test_expect_success \
1860        'Q: verify third commit' \
1861        'git cat-file commit notes-test | sed 1d >actual &&
1862        test_cmp expect actual'
1863
1864cat >expect <<EOF
1865author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1866committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1867
1868notes (:9)
1869EOF
1870test_expect_success \
1871        'Q: verify first notes commit' \
1872        'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1873        test_cmp expect actual'
1874
1875cat >expect.unsorted <<EOF
1876100644 blob $commit1
1877100644 blob $commit2
1878100644 blob $commit3
1879EOF
1880cat expect.unsorted | sort >expect
1881test_expect_success \
1882        'Q: verify first notes tree' \
1883        'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1884         test_cmp expect actual'
1885
1886echo "$note1_data" >expect
1887test_expect_success \
1888        'Q: verify first note for first commit' \
1889        'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1890
1891echo "$note2_data" >expect
1892test_expect_success \
1893        'Q: verify first note for second commit' \
1894        'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1895
1896echo "$note3_data" >expect
1897test_expect_success \
1898        'Q: verify first note for third commit' \
1899        'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1900
1901cat >expect <<EOF
1902parent `git rev-parse --verify refs/notes/foobar~2`
1903author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1904committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1905
1906notes (:10)
1907EOF
1908test_expect_success \
1909        'Q: verify second notes commit' \
1910        'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1911        test_cmp expect actual'
1912
1913cat >expect.unsorted <<EOF
1914100644 blob $commit1
1915100644 blob $commit2
1916100644 blob $commit3
1917EOF
1918cat expect.unsorted | sort >expect
1919test_expect_success \
1920        'Q: verify second notes tree' \
1921        'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1922         test_cmp expect actual'
1923
1924echo "$note1b_data" >expect
1925test_expect_success \
1926        'Q: verify second note for first commit' \
1927        'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1928
1929echo "$note2_data" >expect
1930test_expect_success \
1931        'Q: verify first note for second commit' \
1932        'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1933
1934echo "$note3_data" >expect
1935test_expect_success \
1936        'Q: verify first note for third commit' \
1937        'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1938
1939cat >expect <<EOF
1940author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1941committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1942
1943notes (:11)
1944EOF
1945test_expect_success \
1946        'Q: verify third notes commit' \
1947        'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1948        test_cmp expect actual'
1949
1950cat >expect.unsorted <<EOF
1951100644 blob $commit1
1952EOF
1953cat expect.unsorted | sort >expect
1954test_expect_success \
1955        'Q: verify third notes tree' \
1956        'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1957         test_cmp expect actual'
1958
1959echo "$note1c_data" >expect
1960test_expect_success \
1961        'Q: verify third note for first commit' \
1962        'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1963
1964cat >expect <<EOF
1965parent `git rev-parse --verify refs/notes/foobar^`
1966author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1967committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1968
1969notes (:12)
1970EOF
1971test_expect_success \
1972        'Q: verify fourth notes commit' \
1973        'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1974        test_cmp expect actual'
1975
1976cat >expect.unsorted <<EOF
1977100644 blob $commit2
1978EOF
1979cat expect.unsorted | sort >expect
1980test_expect_success \
1981        'Q: verify fourth notes tree' \
1982        'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1983         test_cmp expect actual'
1984
1985echo "$note2b_data" >expect
1986test_expect_success \
1987        'Q: verify second note for second commit' \
1988        'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1989
1990cat >input <<EOF
1991reset refs/heads/Q0
1992
1993commit refs/heads/note-Q0
1994committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1995data <<COMMIT
1996Note for an empty branch.
1997COMMIT
1998
1999N inline refs/heads/Q0
2000data <<NOTE
2001some note
2002NOTE
2003EOF
2004test_expect_success \
2005        'Q: deny note on empty branch' \
2006        'test_must_fail git fast-import <input'
2007###
2008### series R (feature and option)
2009###
2010
2011cat >input <<EOF
2012feature no-such-feature-exists
2013EOF
2014
2015test_expect_success 'R: abort on unsupported feature' '
2016        test_must_fail git fast-import <input
2017'
2018
2019cat >input <<EOF
2020feature date-format=now
2021EOF
2022
2023test_expect_success 'R: supported feature is accepted' '
2024        git fast-import <input
2025'
2026
2027cat >input << EOF
2028blob
2029data 3
2030hi
2031feature date-format=now
2032EOF
2033
2034test_expect_success 'R: abort on receiving feature after data command' '
2035        test_must_fail git fast-import <input
2036'
2037
2038cat >input << EOF
2039feature import-marks=git.marks
2040feature import-marks=git2.marks
2041EOF
2042
2043test_expect_success 'R: only one import-marks feature allowed per stream' '
2044        test_must_fail git fast-import <input
2045'
2046
2047cat >input << EOF
2048feature export-marks=git.marks
2049blob
2050mark :1
2051data 3
2052hi
2053
2054EOF
2055
2056test_expect_success \
2057    'R: export-marks feature results in a marks file being created' \
2058    'cat input | git fast-import &&
2059    grep :1 git.marks'
2060
2061test_expect_success \
2062    'R: export-marks options can be overriden by commandline options' \
2063    'cat input | git fast-import --export-marks=other.marks &&
2064    grep :1 other.marks'
2065
2066test_expect_success 'R: catch typo in marks file name' '
2067        test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2068        echo "feature import-marks=nonexistent.marks" |
2069        test_must_fail git fast-import
2070'
2071
2072test_expect_success 'R: import and output marks can be the same file' '
2073        rm -f io.marks &&
2074        blob=$(echo hi | git hash-object --stdin) &&
2075        cat >expect <<-EOF &&
2076        :1 $blob
2077        :2 $blob
2078        EOF
2079        git fast-import --export-marks=io.marks <<-\EOF &&
2080        blob
2081        mark :1
2082        data 3
2083        hi
2084
2085        EOF
2086        git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2087        blob
2088        mark :2
2089        data 3
2090        hi
2091
2092        EOF
2093        test_cmp expect io.marks
2094'
2095
2096test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2097        rm -f io.marks &&
2098        test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2099        blob
2100        mark :1
2101        data 3
2102        hi
2103
2104        EOF
2105'
2106
2107test_expect_success 'R: --import-marks-if-exists' '
2108        rm -f io.marks &&
2109        blob=$(echo hi | git hash-object --stdin) &&
2110        echo ":1 $blob" >expect &&
2111        git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2112        blob
2113        mark :1
2114        data 3
2115        hi
2116
2117        EOF
2118        test_cmp expect io.marks
2119'
2120
2121test_expect_success 'R: feature import-marks-if-exists' '
2122        rm -f io.marks &&
2123        >expect &&
2124
2125        git fast-import --export-marks=io.marks <<-\EOF &&
2126        feature import-marks-if-exists=not_io.marks
2127        EOF
2128        test_cmp expect io.marks &&
2129
2130        blob=$(echo hi | git hash-object --stdin) &&
2131
2132        echo ":1 $blob" >io.marks &&
2133        echo ":1 $blob" >expect &&
2134        echo ":2 $blob" >>expect &&
2135
2136        git fast-import --export-marks=io.marks <<-\EOF &&
2137        feature import-marks-if-exists=io.marks
2138        blob
2139        mark :2
2140        data 3
2141        hi
2142
2143        EOF
2144        test_cmp expect io.marks &&
2145
2146        echo ":3 $blob" >>expect &&
2147
2148        git fast-import --import-marks=io.marks \
2149                        --export-marks=io.marks <<-\EOF &&
2150        feature import-marks-if-exists=not_io.marks
2151        blob
2152        mark :3
2153        data 3
2154        hi
2155
2156        EOF
2157        test_cmp expect io.marks &&
2158
2159        >expect &&
2160
2161        git fast-import --import-marks-if-exists=not_io.marks \
2162                        --export-marks=io.marks <<-\EOF
2163        feature import-marks-if-exists=io.marks
2164        EOF
2165        test_cmp expect io.marks
2166'
2167
2168cat >input << EOF
2169feature import-marks=marks.out
2170feature export-marks=marks.new
2171EOF
2172
2173test_expect_success \
2174    'R: import to output marks works without any content' \
2175    'cat input | git fast-import &&
2176    test_cmp marks.out marks.new'
2177
2178cat >input <<EOF
2179feature import-marks=nonexistent.marks
2180feature export-marks=marks.new
2181EOF
2182
2183test_expect_success \
2184    'R: import marks prefers commandline marks file over the stream' \
2185    'cat input | git fast-import --import-marks=marks.out &&
2186    test_cmp marks.out marks.new'
2187
2188
2189cat >input <<EOF
2190feature import-marks=nonexistent.marks
2191feature export-marks=combined.marks
2192EOF
2193
2194test_expect_success 'R: multiple --import-marks= should be honoured' '
2195    head -n2 marks.out > one.marks &&
2196    tail -n +3 marks.out > two.marks &&
2197    git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2198    test_cmp marks.out combined.marks
2199'
2200
2201cat >input <<EOF
2202feature relative-marks
2203feature import-marks=relative.in
2204feature export-marks=relative.out
2205EOF
2206
2207test_expect_success 'R: feature relative-marks should be honoured' '
2208    mkdir -p .git/info/fast-import/ &&
2209    cp marks.new .git/info/fast-import/relative.in &&
2210    git fast-import <input &&
2211    test_cmp marks.new .git/info/fast-import/relative.out
2212'
2213
2214cat >input <<EOF
2215feature relative-marks
2216feature import-marks=relative.in
2217feature no-relative-marks
2218feature export-marks=non-relative.out
2219EOF
2220
2221test_expect_success 'R: feature no-relative-marks should be honoured' '
2222    git fast-import <input &&
2223    test_cmp marks.new non-relative.out
2224'
2225
2226test_expect_success 'R: feature ls supported' '
2227        echo "feature ls" |
2228        git fast-import
2229'
2230
2231test_expect_success 'R: feature cat-blob supported' '
2232        echo "feature cat-blob" |
2233        git fast-import
2234'
2235
2236test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2237        test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2238'
2239
2240test_expect_success 'R: print old blob' '
2241        blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2242        cat >expect <<-EOF &&
2243        ${blob} blob 11
2244        yes it can
2245
2246        EOF
2247        echo "cat-blob $blob" |
2248        git fast-import --cat-blob-fd=6 6>actual &&
2249        test_cmp expect actual
2250'
2251
2252test_expect_success 'R: in-stream cat-blob-fd not respected' '
2253        echo hello >greeting &&
2254        blob=$(git hash-object -w greeting) &&
2255        cat >expect <<-EOF &&
2256        ${blob} blob 6
2257        hello
2258
2259        EOF
2260        git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2261        cat-blob $blob
2262        EOF
2263        test_cmp expect actual.3 &&
2264        test_cmp empty actual.1 &&
2265        git fast-import 3>actual.3 >actual.1 <<-EOF &&
2266        option cat-blob-fd=3
2267        cat-blob $blob
2268        EOF
2269        test_cmp empty actual.3 &&
2270        test_cmp expect actual.1
2271'
2272
2273test_expect_success 'R: print new blob' '
2274        blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2275        cat >expect <<-EOF &&
2276        ${blob} blob 12
2277        yep yep yep
2278
2279        EOF
2280        git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2281        blob
2282        mark :1
2283        data <<BLOB_END
2284        yep yep yep
2285        BLOB_END
2286        cat-blob :1
2287        EOF
2288        test_cmp expect actual
2289'
2290
2291test_expect_success 'R: print new blob by sha1' '
2292        blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2293        cat >expect <<-EOF &&
2294        ${blob} blob 25
2295        a new blob named by sha1
2296
2297        EOF
2298        git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2299        blob
2300        data <<BLOB_END
2301        a new blob named by sha1
2302        BLOB_END
2303        cat-blob $blob
2304        EOF
2305        test_cmp expect actual
2306'
2307
2308test_expect_success 'setup: big file' '
2309        (
2310                echo "the quick brown fox jumps over the lazy dog" >big &&
2311                for i in 1 2 3
2312                do
2313                        cat big big big big >bigger &&
2314                        cat bigger bigger bigger bigger >big ||
2315                        exit
2316                done
2317        )
2318'
2319
2320test_expect_success 'R: print two blobs to stdout' '
2321        blob1=$(git hash-object big) &&
2322        blob1_len=$(wc -c <big) &&
2323        blob2=$(echo hello | git hash-object --stdin) &&
2324        {
2325                echo ${blob1} blob $blob1_len &&
2326                cat big &&
2327                cat <<-EOF
2328
2329                ${blob2} blob 6
2330                hello
2331
2332                EOF
2333        } >expect &&
2334        {
2335                cat <<-\END_PART1 &&
2336                        blob
2337                        mark :1
2338                        data <<data_end
2339                END_PART1
2340                cat big &&
2341                cat <<-\EOF
2342                        data_end
2343                        blob
2344                        mark :2
2345                        data <<data_end
2346                        hello
2347                        data_end
2348                        cat-blob :1
2349                        cat-blob :2
2350                EOF
2351        } |
2352        git fast-import >actual &&
2353        test_cmp expect actual
2354'
2355
2356test_expect_success PIPE 'R: copy using cat-file' '
2357        expect_id=$(git hash-object big) &&
2358        expect_len=$(wc -c <big) &&
2359        echo $expect_id blob $expect_len >expect.response &&
2360
2361        rm -f blobs &&
2362        cat >frontend <<-\FRONTEND_END &&
2363        #!/bin/sh
2364        FRONTEND_END
2365
2366        mkfifo blobs &&
2367        (
2368                export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2369                cat <<-\EOF &&
2370                feature cat-blob
2371                blob
2372                mark :1
2373                data <<BLOB
2374                EOF
2375                cat big &&
2376                cat <<-\EOF &&
2377                BLOB
2378                cat-blob :1
2379                EOF
2380
2381                read blob_id type size <&3 &&
2382                echo "$blob_id $type $size" >response &&
2383                head_c $size >blob <&3 &&
2384                read newline <&3 &&
2385
2386                cat <<-EOF &&
2387                commit refs/heads/copied
2388                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2389                data <<COMMIT
2390                copy big file as file3
2391                COMMIT
2392                M 644 inline file3
2393                data <<BLOB
2394                EOF
2395                cat blob &&
2396                echo BLOB
2397        ) 3<blobs |
2398        git fast-import --cat-blob-fd=3 3>blobs &&
2399        git show copied:file3 >actual &&
2400        test_cmp expect.response response &&
2401        test_cmp big actual
2402'
2403
2404test_expect_success PIPE 'R: print blob mid-commit' '
2405        rm -f blobs &&
2406        echo "A blob from _before_ the commit." >expect &&
2407        mkfifo blobs &&
2408        (
2409                exec 3<blobs &&
2410                cat <<-EOF &&
2411                feature cat-blob
2412                blob
2413                mark :1
2414                data <<BLOB
2415                A blob from _before_ the commit.
2416                BLOB
2417                commit refs/heads/temporary
2418                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2419                data <<COMMIT
2420                Empty commit
2421                COMMIT
2422                cat-blob :1
2423                EOF
2424
2425                read blob_id type size <&3 &&
2426                head_c $size >actual <&3 &&
2427                read newline <&3 &&
2428
2429                echo
2430        ) |
2431        git fast-import --cat-blob-fd=3 3>blobs &&
2432        test_cmp expect actual
2433'
2434
2435test_expect_success PIPE 'R: print staged blob within commit' '
2436        rm -f blobs &&
2437        echo "A blob from _within_ the commit." >expect &&
2438        mkfifo blobs &&
2439        (
2440                exec 3<blobs &&
2441                cat <<-EOF &&
2442                feature cat-blob
2443                commit refs/heads/within
2444                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2445                data <<COMMIT
2446                Empty commit
2447                COMMIT
2448                M 644 inline within
2449                data <<BLOB
2450                A blob from _within_ the commit.
2451                BLOB
2452                EOF
2453
2454                to_get=$(
2455                        echo "A blob from _within_ the commit." |
2456                        git hash-object --stdin
2457                ) &&
2458                echo "cat-blob $to_get" &&
2459
2460                read blob_id type size <&3 &&
2461                head_c $size >actual <&3 &&
2462                read newline <&3 &&
2463
2464                echo deleteall
2465        ) |
2466        git fast-import --cat-blob-fd=3 3>blobs &&
2467        test_cmp expect actual
2468'
2469
2470cat >input << EOF
2471option git quiet
2472blob
2473data 3
2474hi
2475
2476EOF
2477
2478test_expect_success 'R: quiet option results in no stats being output' '
2479    cat input | git fast-import 2> output &&
2480    test_cmp empty output
2481'
2482
2483test_expect_success 'R: feature done means terminating "done" is mandatory' '
2484        echo feature done | test_must_fail git fast-import &&
2485        test_must_fail git fast-import --done </dev/null
2486'
2487
2488test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2489        git fast-import <<-\EOF &&
2490        feature done
2491        done
2492        trailing gibberish
2493        EOF
2494        git fast-import <<-\EOF
2495        done
2496        more trailing gibberish
2497        EOF
2498'
2499
2500test_expect_success 'R: terminating "done" within commit' '
2501        cat >expect <<-\EOF &&
2502        OBJID
2503        :000000 100644 OBJID OBJID A    hello.c
2504        :000000 100644 OBJID OBJID A    hello2.c
2505        EOF
2506        git fast-import <<-EOF &&
2507        commit refs/heads/done-ends
2508        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2509        data <<EOT
2510        Commit terminated by "done" command
2511        EOT
2512        M 100644 inline hello.c
2513        data <<EOT
2514        Hello, world.
2515        EOT
2516        C hello.c hello2.c
2517        done
2518        EOF
2519        git rev-list done-ends |
2520        git diff-tree -r --stdin --root --always |
2521        sed -e "s/$_x40/OBJID/g" >actual &&
2522        test_cmp expect actual
2523'
2524
2525cat >input <<EOF
2526option git non-existing-option
2527EOF
2528
2529test_expect_success 'R: die on unknown option' '
2530    test_must_fail git fast-import <input
2531'
2532
2533test_expect_success 'R: unknown commandline options are rejected' '\
2534    test_must_fail git fast-import --non-existing-option < /dev/null
2535'
2536
2537test_expect_success 'R: die on invalid option argument' '
2538        echo "option git active-branches=-5" |
2539        test_must_fail git fast-import &&
2540        echo "option git depth=" |
2541        test_must_fail git fast-import &&
2542        test_must_fail git fast-import --depth="5 elephants" </dev/null
2543'
2544
2545cat >input <<EOF
2546option non-existing-vcs non-existing-option
2547EOF
2548
2549test_expect_success 'R: ignore non-git options' '
2550    git fast-import <input
2551'
2552
2553##
2554## R: very large blobs
2555##
2556blobsize=$((2*1024*1024 + 53))
2557test-genrandom bar $blobsize >expect
2558cat >input <<INPUT_END
2559commit refs/heads/big-file
2560committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2561data <<COMMIT
2562R - big file
2563COMMIT
2564
2565M 644 inline big1
2566data $blobsize
2567INPUT_END
2568cat expect >>input
2569cat >>input <<INPUT_END
2570M 644 inline big2
2571data $blobsize
2572INPUT_END
2573cat expect >>input
2574echo >>input
2575
2576test_expect_success \
2577        'R: blob bigger than threshold' \
2578        'test_create_repo R &&
2579         git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2580test_expect_success \
2581        'R: verify created pack' \
2582        ': >verify &&
2583         for p in R/.git/objects/pack/*.pack;
2584         do
2585           git verify-pack -v $p >>verify || exit;
2586         done'
2587test_expect_success \
2588        'R: verify written objects' \
2589        'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2590         test_cmp expect actual &&
2591         a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2592         b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2593         test $a = $b'
2594test_expect_success \
2595        'R: blob appears only once' \
2596        'n=$(grep $a verify | wc -l) &&
2597         test 1 = $n'
2598
2599test_done