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