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