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