t / t9300-fast-import.shon commit parseopt: add OPT_NOOP_NOARG (6acec03)
   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
 823###
 824### series K
 825###
 826
 827cat >input <<INPUT_END
 828commit refs/heads/K
 829committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 830data <<COMMIT
 831create K
 832COMMIT
 833
 834from refs/heads/branch
 835
 836commit refs/heads/K
 837committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 838data <<COMMIT
 839redo K
 840COMMIT
 841
 842from refs/heads/branch^1
 843
 844INPUT_END
 845test_expect_success \
 846    'K: reinit branch with from' \
 847    'git fast-import <input'
 848test_expect_success \
 849    'K: verify K^1 = branch^1' \
 850    'test `git rev-parse --verify branch^1` \
 851                = `git rev-parse --verify K^1`'
 852
 853###
 854### series L
 855###
 856
 857cat >input <<INPUT_END
 858blob
 859mark :1
 860data <<EOF
 861some data
 862EOF
 863
 864blob
 865mark :2
 866data <<EOF
 867other data
 868EOF
 869
 870commit refs/heads/L
 871committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 872data <<COMMIT
 873create L
 874COMMIT
 875
 876M 644 :1 b.
 877M 644 :1 b/other
 878M 644 :1 ba
 879
 880commit refs/heads/L
 881committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 882data <<COMMIT
 883update L
 884COMMIT
 885
 886M 644 :2 b.
 887M 644 :2 b/other
 888M 644 :2 ba
 889INPUT_END
 890
 891cat >expect <<EXPECT_END
 892:100644 100644 4268632... 55d3a52... M  b.
 893:040000 040000 0ae5cac... 443c768... M  b
 894:100644 100644 4268632... 55d3a52... M  ba
 895EXPECT_END
 896
 897test_expect_success \
 898    'L: verify internal tree sorting' \
 899        'git fast-import <input &&
 900         git diff-tree --abbrev --raw L^ L >output &&
 901         test_cmp expect output'
 902
 903cat >input <<INPUT_END
 904blob
 905mark :1
 906data <<EOF
 907the data
 908EOF
 909
 910commit refs/heads/L2
 911committer C O Mitter <committer@example.com> 1112912473 -0700
 912data <<COMMIT
 913init L2
 914COMMIT
 915M 644 :1 a/b/c
 916M 644 :1 a/b/d
 917M 644 :1 a/e/f
 918
 919commit refs/heads/L2
 920committer C O Mitter <committer@example.com> 1112912473 -0700
 921data <<COMMIT
 922update L2
 923COMMIT
 924C a g
 925C a/e g/b
 926M 644 :1 g/b/h
 927INPUT_END
 928
 929cat <<EOF >expect
 930g/b/f
 931g/b/h
 932EOF
 933
 934test_expect_success \
 935    'L: nested tree copy does not corrupt deltas' \
 936        'git fast-import <input &&
 937        git ls-tree L2 g/b/ >tmp &&
 938        cat tmp | cut -f 2 >actual &&
 939        test_cmp expect actual &&
 940        git fsck `git rev-parse L2`'
 941
 942git update-ref -d refs/heads/L2
 943
 944###
 945### series M
 946###
 947
 948test_tick
 949cat >input <<INPUT_END
 950commit refs/heads/M1
 951committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 952data <<COMMIT
 953file rename
 954COMMIT
 955
 956from refs/heads/branch^0
 957R file2/newf file2/n.e.w.f
 958
 959INPUT_END
 960
 961cat >expect <<EOF
 962:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
 963EOF
 964test_expect_success \
 965        'M: rename file in same subdirectory' \
 966        'git fast-import <input &&
 967         git diff-tree -M -r M1^ M1 >actual &&
 968         compare_diff_raw expect actual'
 969
 970cat >input <<INPUT_END
 971commit refs/heads/M2
 972committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 973data <<COMMIT
 974file rename
 975COMMIT
 976
 977from refs/heads/branch^0
 978R file2/newf i/am/new/to/you
 979
 980INPUT_END
 981
 982cat >expect <<EOF
 983:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
 984EOF
 985test_expect_success \
 986        'M: rename file to new subdirectory' \
 987        'git fast-import <input &&
 988         git diff-tree -M -r M2^ M2 >actual &&
 989         compare_diff_raw expect actual'
 990
 991cat >input <<INPUT_END
 992commit refs/heads/M3
 993committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 994data <<COMMIT
 995file rename
 996COMMIT
 997
 998from refs/heads/M2^0
 999R i other/sub
1000
1001INPUT_END
1002
1003cat >expect <<EOF
1004:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
1005EOF
1006test_expect_success \
1007        'M: rename subdirectory to new subdirectory' \
1008        'git fast-import <input &&
1009         git diff-tree -M -r M3^ M3 >actual &&
1010         compare_diff_raw expect actual'
1011
1012###
1013### series N
1014###
1015
1016test_tick
1017cat >input <<INPUT_END
1018commit refs/heads/N1
1019committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1020data <<COMMIT
1021file copy
1022COMMIT
1023
1024from refs/heads/branch^0
1025C file2/newf file2/n.e.w.f
1026
1027INPUT_END
1028
1029cat >expect <<EOF
1030:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
1031EOF
1032test_expect_success \
1033        'N: copy file in same subdirectory' \
1034        'git fast-import <input &&
1035         git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1036         compare_diff_raw expect actual'
1037
1038cat >input <<INPUT_END
1039commit refs/heads/N2
1040committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1041data <<COMMIT
1042clean directory copy
1043COMMIT
1044
1045from refs/heads/branch^0
1046C file2 file3
1047
1048commit refs/heads/N2
1049committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1050data <<COMMIT
1051modify directory copy
1052COMMIT
1053
1054M 644 inline file3/file5
1055data <<EOF
1056$file5_data
1057EOF
1058
1059INPUT_END
1060
1061cat >expect <<EOF
1062:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1063:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1064:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1065EOF
1066test_expect_success \
1067        'N: copy then modify subdirectory' \
1068        'git fast-import <input &&
1069         git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1070         compare_diff_raw expect actual'
1071
1072cat >input <<INPUT_END
1073commit refs/heads/N3
1074committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1075data <<COMMIT
1076dirty directory copy
1077COMMIT
1078
1079from refs/heads/branch^0
1080M 644 inline file2/file5
1081data <<EOF
1082$file5_data
1083EOF
1084
1085C file2 file3
1086D file2/file5
1087
1088INPUT_END
1089
1090test_expect_success \
1091        'N: copy dirty subdirectory' \
1092        'git fast-import <input &&
1093         test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1094
1095test_expect_success \
1096        'N: copy directory by id' \
1097        'cat >expect <<-\EOF &&
1098        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1099        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1100        EOF
1101         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1102         cat >input <<-INPUT_END &&
1103        commit refs/heads/N4
1104        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1105        data <<COMMIT
1106        copy by tree hash
1107        COMMIT
1108
1109        from refs/heads/branch^0
1110        M 040000 $subdir file3
1111        INPUT_END
1112         git fast-import <input &&
1113         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1114         compare_diff_raw expect actual'
1115
1116test_expect_success PIPE 'N: read and copy directory' '
1117        cat >expect <<-\EOF
1118        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1119        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1120        EOF
1121        git update-ref -d refs/heads/N4 &&
1122        rm -f backflow &&
1123        mkfifo backflow &&
1124        (
1125                exec <backflow &&
1126                cat <<-EOF &&
1127                commit refs/heads/N4
1128                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1129                data <<COMMIT
1130                copy by tree hash, part 2
1131                COMMIT
1132
1133                from refs/heads/branch^0
1134                ls "file2"
1135                EOF
1136                read mode type tree filename &&
1137                echo "M 040000 $tree file3"
1138        ) |
1139        git fast-import --cat-blob-fd=3 3>backflow &&
1140        git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1141        compare_diff_raw expect actual
1142'
1143
1144test_expect_success PIPE 'N: empty directory reads as missing' '
1145        cat <<-\EOF >expect &&
1146        OBJNAME
1147        :000000 100644 OBJNAME OBJNAME A        unrelated
1148        EOF
1149        echo "missing src" >expect.response &&
1150        git update-ref -d refs/heads/read-empty &&
1151        rm -f backflow &&
1152        mkfifo backflow &&
1153        (
1154                exec <backflow &&
1155                cat <<-EOF &&
1156                commit refs/heads/read-empty
1157                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1158                data <<COMMIT
1159                read "empty" (missing) directory
1160                COMMIT
1161
1162                M 100644 inline src/greeting
1163                data <<BLOB
1164                hello
1165                BLOB
1166                C src/greeting dst1/non-greeting
1167                C src/greeting unrelated
1168                # leave behind "empty" src directory
1169                D src/greeting
1170                ls "src"
1171                EOF
1172                read -r line &&
1173                printf "%s\n" "$line" >response &&
1174                cat <<-\EOF
1175                D dst1
1176                D dst2
1177                EOF
1178        ) |
1179        git fast-import --cat-blob-fd=3 3>backflow &&
1180        test_cmp expect.response response &&
1181        git rev-list read-empty |
1182        git diff-tree -r --root --stdin |
1183        sed "s/$_x40/OBJNAME/g" >actual &&
1184        test_cmp expect actual
1185'
1186
1187test_expect_success \
1188        'N: copy root directory by tree hash' \
1189        'cat >expect <<-\EOF &&
1190        :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1191        :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1192        EOF
1193         root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1194         cat >input <<-INPUT_END &&
1195        commit refs/heads/N6
1196        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1197        data <<COMMIT
1198        copy root directory by tree hash
1199        COMMIT
1200
1201        from refs/heads/branch^0
1202        M 040000 $root ""
1203        INPUT_END
1204         git fast-import <input &&
1205         git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1206         compare_diff_raw expect actual'
1207
1208test_expect_success \
1209        'N: delete directory by copying' \
1210        'cat >expect <<-\EOF &&
1211        OBJID
1212        :100644 000000 OBJID OBJID D    foo/bar/qux
1213        OBJID
1214        :000000 100644 OBJID OBJID A    foo/bar/baz
1215        :000000 100644 OBJID OBJID A    foo/bar/qux
1216        EOF
1217         empty_tree=$(git mktree </dev/null) &&
1218         cat >input <<-INPUT_END &&
1219        commit refs/heads/N-delete
1220        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1221        data <<COMMIT
1222        collect data to be deleted
1223        COMMIT
1224
1225        deleteall
1226        M 100644 inline foo/bar/baz
1227        data <<DATA_END
1228        hello
1229        DATA_END
1230        C "foo/bar/baz" "foo/bar/qux"
1231        C "foo/bar/baz" "foo/bar/quux/1"
1232        C "foo/bar/baz" "foo/bar/quuux"
1233        M 040000 $empty_tree foo/bar/quux
1234        M 040000 $empty_tree foo/bar/quuux
1235
1236        commit refs/heads/N-delete
1237        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1238        data <<COMMIT
1239        delete subdirectory
1240        COMMIT
1241
1242        M 040000 $empty_tree foo/bar/qux
1243        INPUT_END
1244         git fast-import <input &&
1245         git rev-list N-delete |
1246                git diff-tree -r --stdin --root --always |
1247                sed -e "s/$_x40/OBJID/g" >actual &&
1248         test_cmp expect actual'
1249
1250test_expect_success \
1251        'N: modify copied tree' \
1252        'cat >expect <<-\EOF &&
1253        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1254        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1255        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1256        EOF
1257         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1258         cat >input <<-INPUT_END &&
1259        commit refs/heads/N5
1260        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1261        data <<COMMIT
1262        copy by tree hash
1263        COMMIT
1264
1265        from refs/heads/branch^0
1266        M 040000 $subdir file3
1267
1268        commit refs/heads/N5
1269        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1270        data <<COMMIT
1271        modify directory copy
1272        COMMIT
1273
1274        M 644 inline file3/file5
1275        data <<EOF
1276        $file5_data
1277        EOF
1278        INPUT_END
1279         git fast-import <input &&
1280         git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1281         compare_diff_raw expect actual'
1282
1283test_expect_success \
1284        'N: reject foo/ syntax' \
1285        'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1286         test_must_fail git fast-import <<-INPUT_END
1287        commit refs/heads/N5B
1288        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1289        data <<COMMIT
1290        copy with invalid syntax
1291        COMMIT
1292
1293        from refs/heads/branch^0
1294        M 040000 $subdir file3/
1295        INPUT_END'
1296
1297test_expect_success \
1298        'N: copy to root by id and modify' \
1299        'echo "hello, world" >expect.foo &&
1300         echo hello >expect.bar &&
1301         git fast-import <<-SETUP_END &&
1302        commit refs/heads/N7
1303        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1304        data <<COMMIT
1305        hello, tree
1306        COMMIT
1307
1308        deleteall
1309        M 644 inline foo/bar
1310        data <<EOF
1311        hello
1312        EOF
1313        SETUP_END
1314
1315         tree=$(git rev-parse --verify N7:) &&
1316         git fast-import <<-INPUT_END &&
1317        commit refs/heads/N8
1318        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1319        data <<COMMIT
1320        copy to root by id and modify
1321        COMMIT
1322
1323        M 040000 $tree ""
1324        M 644 inline foo/foo
1325        data <<EOF
1326        hello, world
1327        EOF
1328        INPUT_END
1329         git show N8:foo/foo >actual.foo &&
1330         git show N8:foo/bar >actual.bar &&
1331         test_cmp expect.foo actual.foo &&
1332         test_cmp expect.bar actual.bar'
1333
1334test_expect_success \
1335        'N: extract subtree' \
1336        'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1337         cat >input <<-INPUT_END &&
1338        commit refs/heads/N9
1339        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1340        data <<COMMIT
1341        extract subtree branch:newdir
1342        COMMIT
1343
1344        M 040000 $branch ""
1345        C "newdir" ""
1346        INPUT_END
1347         git fast-import <input &&
1348         git diff --exit-code branch:newdir N9'
1349
1350test_expect_success \
1351        'N: modify subtree, extract it, and modify again' \
1352        'echo hello >expect.baz &&
1353         echo hello, world >expect.qux &&
1354         git fast-import <<-SETUP_END &&
1355        commit refs/heads/N10
1356        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1357        data <<COMMIT
1358        hello, tree
1359        COMMIT
1360
1361        deleteall
1362        M 644 inline foo/bar/baz
1363        data <<EOF
1364        hello
1365        EOF
1366        SETUP_END
1367
1368         tree=$(git rev-parse --verify N10:) &&
1369         git fast-import <<-INPUT_END &&
1370        commit refs/heads/N11
1371        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1372        data <<COMMIT
1373        copy to root by id and modify
1374        COMMIT
1375
1376        M 040000 $tree ""
1377        M 100644 inline foo/bar/qux
1378        data <<EOF
1379        hello, world
1380        EOF
1381        R "foo" ""
1382        C "bar/qux" "bar/quux"
1383        INPUT_END
1384         git show N11:bar/baz >actual.baz &&
1385         git show N11:bar/qux >actual.qux &&
1386         git show N11:bar/quux >actual.quux &&
1387         test_cmp expect.baz actual.baz &&
1388         test_cmp expect.qux actual.qux &&
1389         test_cmp expect.qux actual.quux'
1390
1391###
1392### series O
1393###
1394
1395cat >input <<INPUT_END
1396#we will
1397commit refs/heads/O1
1398# -- ignore all of this text
1399committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1400# $GIT_COMMITTER_NAME has inserted here for his benefit.
1401data <<COMMIT
1402dirty directory copy
1403COMMIT
1404
1405# don't forget the import blank line!
1406#
1407# yes, we started from our usual base of branch^0.
1408# i like branch^0.
1409from refs/heads/branch^0
1410# and we need to reuse file2/file5 from N3 above.
1411M 644 inline file2/file5
1412# otherwise the tree will be different
1413data <<EOF
1414$file5_data
1415EOF
1416
1417# don't forget to copy file2 to file3
1418C file2 file3
1419#
1420# or to delete file5 from file2.
1421D file2/file5
1422# are we done yet?
1423
1424INPUT_END
1425
1426test_expect_success \
1427        'O: comments are all skipped' \
1428        'git fast-import <input &&
1429         test `git rev-parse N3` = `git rev-parse O1`'
1430
1431cat >input <<INPUT_END
1432commit refs/heads/O2
1433committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1434data <<COMMIT
1435dirty directory copy
1436COMMIT
1437from refs/heads/branch^0
1438M 644 inline file2/file5
1439data <<EOF
1440$file5_data
1441EOF
1442C file2 file3
1443D file2/file5
1444
1445INPUT_END
1446
1447test_expect_success \
1448        'O: blank lines not necessary after data commands' \
1449        'git fast-import <input &&
1450         test `git rev-parse N3` = `git rev-parse O2`'
1451
1452test_expect_success \
1453        'O: repack before next test' \
1454        'git repack -a -d'
1455
1456cat >input <<INPUT_END
1457commit refs/heads/O3
1458committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1459data <<COMMIT
1460zstring
1461COMMIT
1462commit refs/heads/O3
1463committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1464data <<COMMIT
1465zof
1466COMMIT
1467checkpoint
1468commit refs/heads/O3
1469mark :5
1470committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1471data <<COMMIT
1472zempty
1473COMMIT
1474checkpoint
1475commit refs/heads/O3
1476committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1477data <<COMMIT
1478zcommits
1479COMMIT
1480reset refs/tags/O3-2nd
1481from :5
1482reset refs/tags/O3-3rd
1483from :5
1484INPUT_END
1485
1486cat >expect <<INPUT_END
1487string
1488of
1489empty
1490commits
1491INPUT_END
1492test_expect_success \
1493        'O: blank lines not necessary after other commands' \
1494        'git fast-import <input &&
1495         test 8 = `find .git/objects/pack -type f | wc -l` &&
1496         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1497         git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1498         test_cmp expect actual'
1499
1500cat >input <<INPUT_END
1501commit refs/heads/O4
1502committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1503data <<COMMIT
1504zstring
1505COMMIT
1506commit refs/heads/O4
1507committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1508data <<COMMIT
1509zof
1510COMMIT
1511progress Two commits down, 2 to go!
1512commit refs/heads/O4
1513committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1514data <<COMMIT
1515zempty
1516COMMIT
1517progress Three commits down, 1 to go!
1518commit refs/heads/O4
1519committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1520data <<COMMIT
1521zcommits
1522COMMIT
1523progress I'm done!
1524INPUT_END
1525test_expect_success \
1526        'O: progress outputs as requested by input' \
1527        'git fast-import <input >actual &&
1528         grep "progress " <input >expect &&
1529         test_cmp expect actual'
1530
1531###
1532### series P (gitlinks)
1533###
1534
1535cat >input <<INPUT_END
1536blob
1537mark :1
1538data 10
1539test file
1540
1541reset refs/heads/sub
1542commit refs/heads/sub
1543mark :2
1544committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1545data 12
1546sub_initial
1547M 100644 :1 file
1548
1549blob
1550mark :3
1551data <<DATAEND
1552[submodule "sub"]
1553        path = sub
1554        url = "`pwd`/sub"
1555DATAEND
1556
1557commit refs/heads/subuse1
1558mark :4
1559committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1560data 8
1561initial
1562from refs/heads/master
1563M 100644 :3 .gitmodules
1564M 160000 :2 sub
1565
1566blob
1567mark :5
1568data 20
1569test file
1570more data
1571
1572commit refs/heads/sub
1573mark :6
1574committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1575data 11
1576sub_second
1577from :2
1578M 100644 :5 file
1579
1580commit refs/heads/subuse1
1581mark :7
1582committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583data 7
1584second
1585from :4
1586M 160000 :6 sub
1587
1588INPUT_END
1589
1590test_expect_success \
1591        'P: supermodule & submodule mix' \
1592        'git fast-import <input &&
1593         git checkout subuse1 &&
1594         rm -rf sub && mkdir sub && (cd sub &&
1595         git init &&
1596         git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1597         git checkout master) &&
1598         git submodule init &&
1599         git submodule update'
1600
1601SUBLAST=$(git rev-parse --verify sub)
1602SUBPREV=$(git rev-parse --verify sub^)
1603
1604cat >input <<INPUT_END
1605blob
1606mark :1
1607data <<DATAEND
1608[submodule "sub"]
1609        path = sub
1610        url = "`pwd`/sub"
1611DATAEND
1612
1613commit refs/heads/subuse2
1614mark :2
1615committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1616data 8
1617initial
1618from refs/heads/master
1619M 100644 :1 .gitmodules
1620M 160000 $SUBPREV sub
1621
1622commit refs/heads/subuse2
1623mark :3
1624committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625data 7
1626second
1627from :2
1628M 160000 $SUBLAST sub
1629
1630INPUT_END
1631
1632test_expect_success \
1633        'P: verbatim SHA gitlinks' \
1634        'git branch -D sub &&
1635         git gc && git prune &&
1636         git fast-import <input &&
1637         test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1638
1639test_tick
1640cat >input <<INPUT_END
1641commit refs/heads/subuse3
1642mark :1
1643committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1644data <<COMMIT
1645corrupt
1646COMMIT
1647
1648from refs/heads/subuse2
1649M 160000 inline sub
1650data <<DATA
1651$SUBPREV
1652DATA
1653
1654INPUT_END
1655
1656test_expect_success 'P: fail on inline gitlink' '
1657    test_must_fail git fast-import <input'
1658
1659test_tick
1660cat >input <<INPUT_END
1661blob
1662mark :1
1663data <<DATA
1664$SUBPREV
1665DATA
1666
1667commit refs/heads/subuse3
1668mark :2
1669committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1670data <<COMMIT
1671corrupt
1672COMMIT
1673
1674from refs/heads/subuse2
1675M 160000 :1 sub
1676
1677INPUT_END
1678
1679test_expect_success 'P: fail on blob mark in gitlink' '
1680    test_must_fail git fast-import <input'
1681
1682###
1683### series Q (notes)
1684###
1685
1686note1_data="The first note for the first commit"
1687note2_data="The first note for the second commit"
1688note3_data="The first note for the third commit"
1689note1b_data="The second note for the first commit"
1690note1c_data="The third note for the first commit"
1691note2b_data="The second note for the second commit"
1692
1693test_tick
1694cat >input <<INPUT_END
1695blob
1696mark :2
1697data <<EOF
1698$file2_data
1699EOF
1700
1701commit refs/heads/notes-test
1702mark :3
1703committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1704data <<COMMIT
1705first (:3)
1706COMMIT
1707
1708M 644 :2 file2
1709
1710blob
1711mark :4
1712data $file4_len
1713$file4_data
1714commit refs/heads/notes-test
1715mark :5
1716committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1717data <<COMMIT
1718second (:5)
1719COMMIT
1720
1721M 644 :4 file4
1722
1723commit refs/heads/notes-test
1724mark :6
1725committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1726data <<COMMIT
1727third (:6)
1728COMMIT
1729
1730M 644 inline file5
1731data <<EOF
1732$file5_data
1733EOF
1734
1735M 755 inline file6
1736data <<EOF
1737$file6_data
1738EOF
1739
1740blob
1741mark :7
1742data <<EOF
1743$note1_data
1744EOF
1745
1746blob
1747mark :8
1748data <<EOF
1749$note2_data
1750EOF
1751
1752commit refs/notes/foobar
1753mark :9
1754committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1755data <<COMMIT
1756notes (:9)
1757COMMIT
1758
1759N :7 :3
1760N :8 :5
1761N inline :6
1762data <<EOF
1763$note3_data
1764EOF
1765
1766commit refs/notes/foobar
1767mark :10
1768committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1769data <<COMMIT
1770notes (:10)
1771COMMIT
1772
1773N inline :3
1774data <<EOF
1775$note1b_data
1776EOF
1777
1778commit refs/notes/foobar2
1779mark :11
1780committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1781data <<COMMIT
1782notes (:11)
1783COMMIT
1784
1785N inline :3
1786data <<EOF
1787$note1c_data
1788EOF
1789
1790commit refs/notes/foobar
1791mark :12
1792committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1793data <<COMMIT
1794notes (:12)
1795COMMIT
1796
1797deleteall
1798N inline :5
1799data <<EOF
1800$note2b_data
1801EOF
1802
1803INPUT_END
1804
1805test_expect_success \
1806        'Q: commit notes' \
1807        'git fast-import <input &&
1808         git whatchanged notes-test'
1809test_expect_success \
1810        'Q: verify pack' \
1811        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1812
1813commit1=$(git rev-parse notes-test~2)
1814commit2=$(git rev-parse notes-test^)
1815commit3=$(git rev-parse notes-test)
1816
1817cat >expect <<EOF
1818author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1819committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1820
1821first (:3)
1822EOF
1823test_expect_success \
1824        'Q: verify first commit' \
1825        'git cat-file commit notes-test~2 | sed 1d >actual &&
1826        test_cmp expect actual'
1827
1828cat >expect <<EOF
1829parent $commit1
1830author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1831committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1832
1833second (:5)
1834EOF
1835test_expect_success \
1836        'Q: verify second commit' \
1837        'git cat-file commit notes-test^ | sed 1d >actual &&
1838        test_cmp expect actual'
1839
1840cat >expect <<EOF
1841parent $commit2
1842author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1843committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1844
1845third (:6)
1846EOF
1847test_expect_success \
1848        'Q: verify third commit' \
1849        'git cat-file commit notes-test | sed 1d >actual &&
1850        test_cmp expect actual'
1851
1852cat >expect <<EOF
1853author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1854committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1855
1856notes (:9)
1857EOF
1858test_expect_success \
1859        'Q: verify first notes commit' \
1860        'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1861        test_cmp expect actual'
1862
1863cat >expect.unsorted <<EOF
1864100644 blob $commit1
1865100644 blob $commit2
1866100644 blob $commit3
1867EOF
1868cat expect.unsorted | sort >expect
1869test_expect_success \
1870        'Q: verify first notes tree' \
1871        'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1872         test_cmp expect actual'
1873
1874echo "$note1_data" >expect
1875test_expect_success \
1876        'Q: verify first note for first commit' \
1877        'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1878
1879echo "$note2_data" >expect
1880test_expect_success \
1881        'Q: verify first note for second commit' \
1882        'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1883
1884echo "$note3_data" >expect
1885test_expect_success \
1886        'Q: verify first note for third commit' \
1887        'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1888
1889cat >expect <<EOF
1890parent `git rev-parse --verify refs/notes/foobar~2`
1891author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1892committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1893
1894notes (:10)
1895EOF
1896test_expect_success \
1897        'Q: verify second notes commit' \
1898        'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1899        test_cmp expect actual'
1900
1901cat >expect.unsorted <<EOF
1902100644 blob $commit1
1903100644 blob $commit2
1904100644 blob $commit3
1905EOF
1906cat expect.unsorted | sort >expect
1907test_expect_success \
1908        'Q: verify second notes tree' \
1909        'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1910         test_cmp expect actual'
1911
1912echo "$note1b_data" >expect
1913test_expect_success \
1914        'Q: verify second note for first commit' \
1915        'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1916
1917echo "$note2_data" >expect
1918test_expect_success \
1919        'Q: verify first note for second commit' \
1920        'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1921
1922echo "$note3_data" >expect
1923test_expect_success \
1924        'Q: verify first note for third commit' \
1925        'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1926
1927cat >expect <<EOF
1928author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1929committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1930
1931notes (:11)
1932EOF
1933test_expect_success \
1934        'Q: verify third notes commit' \
1935        'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1936        test_cmp expect actual'
1937
1938cat >expect.unsorted <<EOF
1939100644 blob $commit1
1940EOF
1941cat expect.unsorted | sort >expect
1942test_expect_success \
1943        'Q: verify third notes tree' \
1944        'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1945         test_cmp expect actual'
1946
1947echo "$note1c_data" >expect
1948test_expect_success \
1949        'Q: verify third note for first commit' \
1950        'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1951
1952cat >expect <<EOF
1953parent `git rev-parse --verify refs/notes/foobar^`
1954author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1955committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1956
1957notes (:12)
1958EOF
1959test_expect_success \
1960        'Q: verify fourth notes commit' \
1961        'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1962        test_cmp expect actual'
1963
1964cat >expect.unsorted <<EOF
1965100644 blob $commit2
1966EOF
1967cat expect.unsorted | sort >expect
1968test_expect_success \
1969        'Q: verify fourth notes tree' \
1970        'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1971         test_cmp expect actual'
1972
1973echo "$note2b_data" >expect
1974test_expect_success \
1975        'Q: verify second note for second commit' \
1976        'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1977
1978###
1979### series R (feature and option)
1980###
1981
1982cat >input <<EOF
1983feature no-such-feature-exists
1984EOF
1985
1986test_expect_success 'R: abort on unsupported feature' '
1987        test_must_fail git fast-import <input
1988'
1989
1990cat >input <<EOF
1991feature date-format=now
1992EOF
1993
1994test_expect_success 'R: supported feature is accepted' '
1995        git fast-import <input
1996'
1997
1998cat >input << EOF
1999blob
2000data 3
2001hi
2002feature date-format=now
2003EOF
2004
2005test_expect_success 'R: abort on receiving feature after data command' '
2006        test_must_fail git fast-import <input
2007'
2008
2009cat >input << EOF
2010feature import-marks=git.marks
2011feature import-marks=git2.marks
2012EOF
2013
2014test_expect_success 'R: only one import-marks feature allowed per stream' '
2015        test_must_fail git fast-import <input
2016'
2017
2018cat >input << EOF
2019feature export-marks=git.marks
2020blob
2021mark :1
2022data 3
2023hi
2024
2025EOF
2026
2027test_expect_success \
2028    'R: export-marks feature results in a marks file being created' \
2029    'cat input | git fast-import &&
2030    grep :1 git.marks'
2031
2032test_expect_success \
2033    'R: export-marks options can be overriden by commandline options' \
2034    'cat input | git fast-import --export-marks=other.marks &&
2035    grep :1 other.marks'
2036
2037test_expect_success 'R: catch typo in marks file name' '
2038        test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2039        echo "feature import-marks=nonexistent.marks" |
2040        test_must_fail git fast-import
2041'
2042
2043test_expect_success 'R: import and output marks can be the same file' '
2044        rm -f io.marks &&
2045        blob=$(echo hi | git hash-object --stdin) &&
2046        cat >expect <<-EOF &&
2047        :1 $blob
2048        :2 $blob
2049        EOF
2050        git fast-import --export-marks=io.marks <<-\EOF &&
2051        blob
2052        mark :1
2053        data 3
2054        hi
2055
2056        EOF
2057        git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2058        blob
2059        mark :2
2060        data 3
2061        hi
2062
2063        EOF
2064        test_cmp expect io.marks
2065'
2066
2067test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2068        rm -f io.marks &&
2069        test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2070        blob
2071        mark :1
2072        data 3
2073        hi
2074
2075        EOF
2076'
2077
2078test_expect_success 'R: --import-marks-if-exists' '
2079        rm -f io.marks &&
2080        blob=$(echo hi | git hash-object --stdin) &&
2081        echo ":1 $blob" >expect &&
2082        git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2083        blob
2084        mark :1
2085        data 3
2086        hi
2087
2088        EOF
2089        test_cmp expect io.marks
2090'
2091
2092test_expect_success 'R: feature import-marks-if-exists' '
2093        rm -f io.marks &&
2094        >expect &&
2095
2096        git fast-import --export-marks=io.marks <<-\EOF &&
2097        feature import-marks-if-exists=not_io.marks
2098        EOF
2099        test_cmp expect io.marks &&
2100
2101        blob=$(echo hi | git hash-object --stdin) &&
2102
2103        echo ":1 $blob" >io.marks &&
2104        echo ":1 $blob" >expect &&
2105        echo ":2 $blob" >>expect &&
2106
2107        git fast-import --export-marks=io.marks <<-\EOF &&
2108        feature import-marks-if-exists=io.marks
2109        blob
2110        mark :2
2111        data 3
2112        hi
2113
2114        EOF
2115        test_cmp expect io.marks &&
2116
2117        echo ":3 $blob" >>expect &&
2118
2119        git fast-import --import-marks=io.marks \
2120                        --export-marks=io.marks <<-\EOF &&
2121        feature import-marks-if-exists=not_io.marks
2122        blob
2123        mark :3
2124        data 3
2125        hi
2126
2127        EOF
2128        test_cmp expect io.marks &&
2129
2130        >expect &&
2131
2132        git fast-import --import-marks-if-exists=not_io.marks \
2133                        --export-marks=io.marks <<-\EOF
2134        feature import-marks-if-exists=io.marks
2135        EOF
2136        test_cmp expect io.marks
2137'
2138
2139cat >input << EOF
2140feature import-marks=marks.out
2141feature export-marks=marks.new
2142EOF
2143
2144test_expect_success \
2145    'R: import to output marks works without any content' \
2146    'cat input | git fast-import &&
2147    test_cmp marks.out marks.new'
2148
2149cat >input <<EOF
2150feature import-marks=nonexistent.marks
2151feature export-marks=marks.new
2152EOF
2153
2154test_expect_success \
2155    'R: import marks prefers commandline marks file over the stream' \
2156    'cat input | git fast-import --import-marks=marks.out &&
2157    test_cmp marks.out marks.new'
2158
2159
2160cat >input <<EOF
2161feature import-marks=nonexistent.marks
2162feature export-marks=combined.marks
2163EOF
2164
2165test_expect_success 'R: multiple --import-marks= should be honoured' '
2166    head -n2 marks.out > one.marks &&
2167    tail -n +3 marks.out > two.marks &&
2168    git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2169    test_cmp marks.out combined.marks
2170'
2171
2172cat >input <<EOF
2173feature relative-marks
2174feature import-marks=relative.in
2175feature export-marks=relative.out
2176EOF
2177
2178test_expect_success 'R: feature relative-marks should be honoured' '
2179    mkdir -p .git/info/fast-import/ &&
2180    cp marks.new .git/info/fast-import/relative.in &&
2181    git fast-import <input &&
2182    test_cmp marks.new .git/info/fast-import/relative.out
2183'
2184
2185cat >input <<EOF
2186feature relative-marks
2187feature import-marks=relative.in
2188feature no-relative-marks
2189feature export-marks=non-relative.out
2190EOF
2191
2192test_expect_success 'R: feature no-relative-marks should be honoured' '
2193    git fast-import <input &&
2194    test_cmp marks.new non-relative.out
2195'
2196
2197test_expect_success 'R: feature ls supported' '
2198        echo "feature ls" |
2199        git fast-import
2200'
2201
2202test_expect_success 'R: feature cat-blob supported' '
2203        echo "feature cat-blob" |
2204        git fast-import
2205'
2206
2207test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2208        test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2209'
2210
2211test_expect_success 'R: print old blob' '
2212        blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2213        cat >expect <<-EOF &&
2214        ${blob} blob 11
2215        yes it can
2216
2217        EOF
2218        echo "cat-blob $blob" |
2219        git fast-import --cat-blob-fd=6 6>actual &&
2220        test_cmp expect actual
2221'
2222
2223test_expect_success 'R: in-stream cat-blob-fd not respected' '
2224        echo hello >greeting &&
2225        blob=$(git hash-object -w greeting) &&
2226        cat >expect <<-EOF &&
2227        ${blob} blob 6
2228        hello
2229
2230        EOF
2231        git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2232        cat-blob $blob
2233        EOF
2234        test_cmp expect actual.3 &&
2235        test_cmp empty actual.1 &&
2236        git fast-import 3>actual.3 >actual.1 <<-EOF &&
2237        option cat-blob-fd=3
2238        cat-blob $blob
2239        EOF
2240        test_cmp empty actual.3 &&
2241        test_cmp expect actual.1
2242'
2243
2244test_expect_success 'R: print new blob' '
2245        blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2246        cat >expect <<-EOF &&
2247        ${blob} blob 12
2248        yep yep yep
2249
2250        EOF
2251        git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2252        blob
2253        mark :1
2254        data <<BLOB_END
2255        yep yep yep
2256        BLOB_END
2257        cat-blob :1
2258        EOF
2259        test_cmp expect actual
2260'
2261
2262test_expect_success 'R: print new blob by sha1' '
2263        blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2264        cat >expect <<-EOF &&
2265        ${blob} blob 25
2266        a new blob named by sha1
2267
2268        EOF
2269        git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2270        blob
2271        data <<BLOB_END
2272        a new blob named by sha1
2273        BLOB_END
2274        cat-blob $blob
2275        EOF
2276        test_cmp expect actual
2277'
2278
2279test_expect_success 'setup: big file' '
2280        (
2281                echo "the quick brown fox jumps over the lazy dog" >big &&
2282                for i in 1 2 3
2283                do
2284                        cat big big big big >bigger &&
2285                        cat bigger bigger bigger bigger >big ||
2286                        exit
2287                done
2288        )
2289'
2290
2291test_expect_success 'R: print two blobs to stdout' '
2292        blob1=$(git hash-object big) &&
2293        blob1_len=$(wc -c <big) &&
2294        blob2=$(echo hello | git hash-object --stdin) &&
2295        {
2296                echo ${blob1} blob $blob1_len &&
2297                cat big &&
2298                cat <<-EOF
2299
2300                ${blob2} blob 6
2301                hello
2302
2303                EOF
2304        } >expect &&
2305        {
2306                cat <<-\END_PART1 &&
2307                        blob
2308                        mark :1
2309                        data <<data_end
2310                END_PART1
2311                cat big &&
2312                cat <<-\EOF
2313                        data_end
2314                        blob
2315                        mark :2
2316                        data <<data_end
2317                        hello
2318                        data_end
2319                        cat-blob :1
2320                        cat-blob :2
2321                EOF
2322        } |
2323        git fast-import >actual &&
2324        test_cmp expect actual
2325'
2326
2327test_expect_success PIPE 'R: copy using cat-file' '
2328        expect_id=$(git hash-object big) &&
2329        expect_len=$(wc -c <big) &&
2330        echo $expect_id blob $expect_len >expect.response &&
2331
2332        rm -f blobs &&
2333        cat >frontend <<-\FRONTEND_END &&
2334        #!/bin/sh
2335        FRONTEND_END
2336
2337        mkfifo blobs &&
2338        (
2339                export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2340                cat <<-\EOF &&
2341                feature cat-blob
2342                blob
2343                mark :1
2344                data <<BLOB
2345                EOF
2346                cat big &&
2347                cat <<-\EOF &&
2348                BLOB
2349                cat-blob :1
2350                EOF
2351
2352                read blob_id type size <&3 &&
2353                echo "$blob_id $type $size" >response &&
2354                head_c $size >blob <&3 &&
2355                read newline <&3 &&
2356
2357                cat <<-EOF &&
2358                commit refs/heads/copied
2359                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2360                data <<COMMIT
2361                copy big file as file3
2362                COMMIT
2363                M 644 inline file3
2364                data <<BLOB
2365                EOF
2366                cat blob &&
2367                echo BLOB
2368        ) 3<blobs |
2369        git fast-import --cat-blob-fd=3 3>blobs &&
2370        git show copied:file3 >actual &&
2371        test_cmp expect.response response &&
2372        test_cmp big actual
2373'
2374
2375test_expect_success PIPE 'R: print blob mid-commit' '
2376        rm -f blobs &&
2377        echo "A blob from _before_ the commit." >expect &&
2378        mkfifo blobs &&
2379        (
2380                exec 3<blobs &&
2381                cat <<-EOF &&
2382                feature cat-blob
2383                blob
2384                mark :1
2385                data <<BLOB
2386                A blob from _before_ the commit.
2387                BLOB
2388                commit refs/heads/temporary
2389                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2390                data <<COMMIT
2391                Empty commit
2392                COMMIT
2393                cat-blob :1
2394                EOF
2395
2396                read blob_id type size <&3 &&
2397                head_c $size >actual <&3 &&
2398                read newline <&3 &&
2399
2400                echo
2401        ) |
2402        git fast-import --cat-blob-fd=3 3>blobs &&
2403        test_cmp expect actual
2404'
2405
2406test_expect_success PIPE 'R: print staged blob within commit' '
2407        rm -f blobs &&
2408        echo "A blob from _within_ the commit." >expect &&
2409        mkfifo blobs &&
2410        (
2411                exec 3<blobs &&
2412                cat <<-EOF &&
2413                feature cat-blob
2414                commit refs/heads/within
2415                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2416                data <<COMMIT
2417                Empty commit
2418                COMMIT
2419                M 644 inline within
2420                data <<BLOB
2421                A blob from _within_ the commit.
2422                BLOB
2423                EOF
2424
2425                to_get=$(
2426                        echo "A blob from _within_ the commit." |
2427                        git hash-object --stdin
2428                ) &&
2429                echo "cat-blob $to_get" &&
2430
2431                read blob_id type size <&3 &&
2432                head_c $size >actual <&3 &&
2433                read newline <&3 &&
2434
2435                echo deleteall
2436        ) |
2437        git fast-import --cat-blob-fd=3 3>blobs &&
2438        test_cmp expect actual
2439'
2440
2441cat >input << EOF
2442option git quiet
2443blob
2444data 3
2445hi
2446
2447EOF
2448
2449test_expect_success 'R: quiet option results in no stats being output' '
2450    cat input | git fast-import 2> output &&
2451    test_cmp empty output
2452'
2453
2454test_expect_success 'R: feature done means terminating "done" is mandatory' '
2455        echo feature done | test_must_fail git fast-import &&
2456        test_must_fail git fast-import --done </dev/null
2457'
2458
2459test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2460        git fast-import <<-\EOF &&
2461        feature done
2462        done
2463        trailing gibberish
2464        EOF
2465        git fast-import <<-\EOF
2466        done
2467        more trailing gibberish
2468        EOF
2469'
2470
2471test_expect_success 'R: terminating "done" within commit' '
2472        cat >expect <<-\EOF &&
2473        OBJID
2474        :000000 100644 OBJID OBJID A    hello.c
2475        :000000 100644 OBJID OBJID A    hello2.c
2476        EOF
2477        git fast-import <<-EOF &&
2478        commit refs/heads/done-ends
2479        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2480        data <<EOT
2481        Commit terminated by "done" command
2482        EOT
2483        M 100644 inline hello.c
2484        data <<EOT
2485        Hello, world.
2486        EOT
2487        C hello.c hello2.c
2488        done
2489        EOF
2490        git rev-list done-ends |
2491        git diff-tree -r --stdin --root --always |
2492        sed -e "s/$_x40/OBJID/g" >actual &&
2493        test_cmp expect actual
2494'
2495
2496cat >input <<EOF
2497option git non-existing-option
2498EOF
2499
2500test_expect_success 'R: die on unknown option' '
2501    test_must_fail git fast-import <input
2502'
2503
2504test_expect_success 'R: unknown commandline options are rejected' '\
2505    test_must_fail git fast-import --non-existing-option < /dev/null
2506'
2507
2508test_expect_success 'R: die on invalid option argument' '
2509        echo "option git active-branches=-5" |
2510        test_must_fail git fast-import &&
2511        echo "option git depth=" |
2512        test_must_fail git fast-import &&
2513        test_must_fail git fast-import --depth="5 elephants" </dev/null
2514'
2515
2516cat >input <<EOF
2517option non-existing-vcs non-existing-option
2518EOF
2519
2520test_expect_success 'R: ignore non-git options' '
2521    git fast-import <input
2522'
2523
2524##
2525## R: very large blobs
2526##
2527blobsize=$((2*1024*1024 + 53))
2528test-genrandom bar $blobsize >expect
2529cat >input <<INPUT_END
2530commit refs/heads/big-file
2531committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2532data <<COMMIT
2533R - big file
2534COMMIT
2535
2536M 644 inline big1
2537data $blobsize
2538INPUT_END
2539cat expect >>input
2540cat >>input <<INPUT_END
2541M 644 inline big2
2542data $blobsize
2543INPUT_END
2544cat expect >>input
2545echo >>input
2546
2547test_expect_success \
2548        'R: blob bigger than threshold' \
2549        'test_create_repo R &&
2550         git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2551test_expect_success \
2552        'R: verify created pack' \
2553        ': >verify &&
2554         for p in R/.git/objects/pack/*.pack;
2555         do
2556           git verify-pack -v $p >>verify || exit;
2557         done'
2558test_expect_success \
2559        'R: verify written objects' \
2560        'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2561         test_cmp expect actual &&
2562         a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2563         b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2564         test $a = $b'
2565test_expect_success \
2566        'R: blob appears only once' \
2567        'n=$(grep $a verify | wc -l) &&
2568         test 1 = $n'
2569
2570test_done