t / t9300-fast-import.shon commit convert.c: ident + core.autocrlf didn't work (caa47ad)
   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
  27verify_packs () {
  28        for p in .git/objects/pack/*.pack
  29        do
  30                git verify-pack "$@" "$p" || return
  31        done
  32}
  33
  34file2_data='file2
  35second line of EOF'
  36
  37file3_data='EOF
  38in 3rd file
  39 END'
  40
  41file4_data=abcd
  42file4_len=4
  43
  44file5_data='an inline file.
  45  we should see it later.'
  46
  47file6_data='#!/bin/sh
  48echo "$@"'
  49
  50###
  51### series A
  52###
  53
  54test_expect_success 'empty stream succeeds' '
  55        git fast-import </dev/null
  56'
  57
  58test_expect_success 'A: create pack from stdin' '
  59        test_tick &&
  60        cat >input <<-INPUT_END &&
  61        blob
  62        mark :2
  63        data <<EOF
  64        $file2_data
  65        EOF
  66
  67        blob
  68        mark :3
  69        data <<END
  70        $file3_data
  71        END
  72
  73        blob
  74        mark :4
  75        data $file4_len
  76        $file4_data
  77        commit refs/heads/master
  78        mark :5
  79        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  80        data <<COMMIT
  81        initial
  82        COMMIT
  83
  84        M 644 :2 file2
  85        M 644 :3 file3
  86        M 755 :4 file4
  87
  88        tag series-A
  89        from :5
  90        data <<EOF
  91        An annotated tag without a tagger
  92        EOF
  93
  94        tag series-A-blob
  95        from :3
  96        data <<EOF
  97        An annotated tag that annotates a blob.
  98        EOF
  99
 100        INPUT_END
 101        git fast-import --export-marks=marks.out <input &&
 102        git whatchanged master
 103'
 104
 105test_expect_success 'A: verify pack' '
 106        verify_packs
 107'
 108
 109test_expect_success 'A: verify commit' '
 110        cat >expect <<-EOF &&
 111        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 112        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 113
 114        initial
 115        EOF
 116        git cat-file commit master | sed 1d >actual &&
 117        test_cmp expect actual
 118'
 119
 120test_expect_success 'A: verify tree' '
 121        cat >expect <<-EOF &&
 122        100644 blob file2
 123        100644 blob file3
 124        100755 blob file4
 125        EOF
 126        git cat-file -p master^{tree} | sed "s/ [0-9a-f]*       / /" >actual &&
 127        test_cmp expect actual
 128'
 129
 130test_expect_success 'A: verify file2' '
 131        echo "$file2_data" >expect &&
 132        git cat-file blob master:file2 >actual &&
 133        test_cmp expect actual
 134'
 135
 136test_expect_success 'A: verify file3' '
 137        echo "$file3_data" >expect &&
 138        git cat-file blob master:file3 >actual &&
 139        test_cmp expect actual
 140'
 141
 142test_expect_success 'A: verify file4' '
 143        printf "$file4_data" >expect &&
 144        git cat-file blob master:file4 >actual &&
 145        test_cmp expect actual
 146'
 147
 148test_expect_success 'A: verify tag/series-A' '
 149        cat >expect <<-EOF &&
 150        object $(git rev-parse refs/heads/master)
 151        type commit
 152        tag series-A
 153
 154        An annotated tag without a tagger
 155        EOF
 156        git cat-file tag tags/series-A >actual &&
 157        test_cmp expect actual
 158'
 159
 160test_expect_success 'A: verify tag/series-A-blob' '
 161        cat >expect <<-EOF &&
 162        object $(git rev-parse refs/heads/master:file3)
 163        type blob
 164        tag series-A-blob
 165
 166        An annotated tag that annotates a blob.
 167        EOF
 168        git cat-file tag tags/series-A-blob >actual &&
 169        test_cmp expect actual
 170'
 171
 172test_expect_success 'A: verify marks output' '
 173        cat >expect <<-EOF &&
 174        :2 $(git rev-parse --verify master:file2)
 175        :3 $(git rev-parse --verify master:file3)
 176        :4 $(git rev-parse --verify master:file4)
 177        :5 $(git rev-parse --verify master^0)
 178        EOF
 179        test_cmp expect marks.out
 180'
 181
 182test_expect_success 'A: verify marks import' '
 183        git fast-import \
 184                --import-marks=marks.out \
 185                --export-marks=marks.new \
 186                </dev/null &&
 187        test_cmp expect marks.new
 188'
 189
 190test_expect_success 'A: tag blob by sha1' '
 191        test_tick &&
 192        new_blob=$(echo testing | git hash-object --stdin) &&
 193        cat >input <<-INPUT_END &&
 194        tag series-A-blob-2
 195        from $(git rev-parse refs/heads/master:file3)
 196        data <<EOF
 197        Tag blob by sha1.
 198        EOF
 199
 200        blob
 201        mark :6
 202        data <<EOF
 203        testing
 204        EOF
 205
 206        commit refs/heads/new_blob
 207        committer  <> 0 +0000
 208        data 0
 209        M 644 :6 new_blob
 210        #pretend we got sha1 from fast-import
 211        ls "new_blob"
 212
 213        tag series-A-blob-3
 214        from $new_blob
 215        data <<EOF
 216        Tag new_blob.
 217        EOF
 218        INPUT_END
 219
 220        cat >expect <<-EOF &&
 221        object $(git rev-parse refs/heads/master:file3)
 222        type blob
 223        tag series-A-blob-2
 224
 225        Tag blob by sha1.
 226        object $new_blob
 227        type blob
 228        tag series-A-blob-3
 229
 230        Tag new_blob.
 231        EOF
 232
 233        git fast-import <input &&
 234        git cat-file tag tags/series-A-blob-2 >actual &&
 235        git cat-file tag tags/series-A-blob-3 >>actual &&
 236        test_cmp expect actual
 237'
 238
 239test_expect_success 'A: verify marks import does not crash' '
 240        test_tick &&
 241        cat >input <<-INPUT_END &&
 242        commit refs/heads/verify--import-marks
 243        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 244        data <<COMMIT
 245        recreate from :5
 246        COMMIT
 247
 248        from :5
 249        M 755 :2 copy-of-file2
 250
 251        INPUT_END
 252
 253        git fast-import --import-marks=marks.out <input &&
 254        git whatchanged verify--import-marks
 255'
 256
 257test_expect_success 'A: verify pack' '
 258        verify_packs
 259'
 260
 261test_expect_success 'A: verify diff' '
 262        cat >expect <<-EOF &&
 263        :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
 264        EOF
 265        git diff-tree -M -r master verify--import-marks >actual &&
 266        compare_diff_raw expect actual &&
 267        test $(git rev-parse --verify master:file2) \
 268            = $(git rev-parse --verify verify--import-marks:copy-of-file2)
 269'
 270
 271test_expect_success 'A: export marks with large values' '
 272        test_tick &&
 273        mt=$(git hash-object --stdin < /dev/null) &&
 274        >input.blob &&
 275        >marks.exp &&
 276        >tree.exp &&
 277
 278        cat >input.commit <<-EOF &&
 279        commit refs/heads/verify--dump-marks
 280        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 281        data <<COMMIT
 282        test the sparse array dumping routines with exponentially growing marks
 283        COMMIT
 284        EOF
 285
 286        i=0 l=4 m=6 n=7 &&
 287        while test "$i" -lt 27
 288        do
 289                cat >>input.blob <<-EOF &&
 290                blob
 291                mark :$l
 292                data 0
 293                blob
 294                mark :$m
 295                data 0
 296                blob
 297                mark :$n
 298                data 0
 299                EOF
 300                echo "M 100644 :$l l$i" >>input.commit &&
 301                echo "M 100644 :$m m$i" >>input.commit &&
 302                echo "M 100644 :$n n$i" >>input.commit &&
 303
 304                echo ":$l $mt" >>marks.exp &&
 305                echo ":$m $mt" >>marks.exp &&
 306                echo ":$n $mt" >>marks.exp &&
 307
 308                printf "100644 blob $mt\tl$i\n" >>tree.exp &&
 309                printf "100644 blob $mt\tm$i\n" >>tree.exp &&
 310                printf "100644 blob $mt\tn$i\n" >>tree.exp &&
 311
 312                l=$(($l + $l)) &&
 313                m=$(($m + $m)) &&
 314                n=$(($l + $n)) &&
 315
 316                i=$((1 + $i)) || return 1
 317        done &&
 318
 319        sort tree.exp > tree.exp_s &&
 320
 321        cat input.blob input.commit | git fast-import --export-marks=marks.large &&
 322        git ls-tree refs/heads/verify--dump-marks >tree.out &&
 323        test_cmp tree.exp_s tree.out &&
 324        test_cmp marks.exp marks.large
 325'
 326
 327###
 328### series B
 329###
 330
 331test_expect_success 'B: fail on invalid blob sha1' '
 332        test_tick &&
 333        cat >input <<-INPUT_END &&
 334        commit refs/heads/branch
 335        mark :1
 336        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 337        data <<COMMIT
 338        corrupt
 339        COMMIT
 340
 341        from refs/heads/master
 342        M 755 0000000000000000000000000000000000000001 zero1
 343
 344        INPUT_END
 345
 346        test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
 347        test_must_fail git fast-import <input
 348'
 349
 350test_expect_success 'B: accept branch name "TEMP_TAG"' '
 351        cat >input <<-INPUT_END &&
 352        commit TEMP_TAG
 353        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 354        data <<COMMIT
 355        tag base
 356        COMMIT
 357
 358        from refs/heads/master
 359
 360        INPUT_END
 361
 362        test_when_finished "rm -f .git/TEMP_TAG
 363                git gc
 364                git prune" &&
 365        git fast-import <input &&
 366        test -f .git/TEMP_TAG &&
 367        test $(git rev-parse master) = $(git rev-parse TEMP_TAG^)
 368'
 369
 370test_expect_success 'B: accept empty committer' '
 371        cat >input <<-INPUT_END &&
 372        commit refs/heads/empty-committer-1
 373        committer  <> $GIT_COMMITTER_DATE
 374        data <<COMMIT
 375        empty commit
 376        COMMIT
 377        INPUT_END
 378
 379        test_when_finished "git update-ref -d refs/heads/empty-committer-1
 380                git gc
 381                git prune" &&
 382        git fast-import <input &&
 383        out=$(git fsck) &&
 384        echo "$out" &&
 385        test -z "$out"
 386'
 387
 388test_expect_success 'B: accept and fixup committer with no name' '
 389        cat >input <<-INPUT_END &&
 390        commit refs/heads/empty-committer-2
 391        committer <a@b.com> $GIT_COMMITTER_DATE
 392        data <<COMMIT
 393        empty commit
 394        COMMIT
 395        INPUT_END
 396
 397        test_when_finished "git update-ref -d refs/heads/empty-committer-2
 398                git gc
 399                git prune" &&
 400        git fast-import <input &&
 401        out=$(git fsck) &&
 402        echo "$out" &&
 403        test -z "$out"
 404'
 405
 406test_expect_success 'B: fail on invalid committer (1)' '
 407        cat >input <<-INPUT_END &&
 408        commit refs/heads/invalid-committer
 409        committer Name email> $GIT_COMMITTER_DATE
 410        data <<COMMIT
 411        empty commit
 412        COMMIT
 413        INPUT_END
 414
 415        test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
 416        test_must_fail git fast-import <input
 417'
 418
 419test_expect_success 'B: fail on invalid committer (2)' '
 420        cat >input <<-INPUT_END &&
 421        commit refs/heads/invalid-committer
 422        committer Name <e<mail> $GIT_COMMITTER_DATE
 423        data <<COMMIT
 424        empty commit
 425        COMMIT
 426        INPUT_END
 427
 428        test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
 429        test_must_fail git fast-import <input
 430'
 431
 432test_expect_success 'B: fail on invalid committer (3)' '
 433        cat >input <<-INPUT_END &&
 434        commit refs/heads/invalid-committer
 435        committer Name <email>> $GIT_COMMITTER_DATE
 436        data <<COMMIT
 437        empty commit
 438        COMMIT
 439        INPUT_END
 440
 441        test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
 442        test_must_fail git fast-import <input
 443'
 444
 445test_expect_success 'B: fail on invalid committer (4)' '
 446        cat >input <<-INPUT_END &&
 447        commit refs/heads/invalid-committer
 448        committer Name <email $GIT_COMMITTER_DATE
 449        data <<COMMIT
 450        empty commit
 451        COMMIT
 452        INPUT_END
 453
 454        test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
 455        test_must_fail git fast-import <input
 456'
 457
 458test_expect_success 'B: fail on invalid committer (5)' '
 459        cat >input <<-INPUT_END &&
 460        commit refs/heads/invalid-committer
 461        committer Name<email> $GIT_COMMITTER_DATE
 462        data <<COMMIT
 463        empty commit
 464        COMMIT
 465        INPUT_END
 466
 467        test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
 468        test_must_fail git fast-import <input
 469'
 470
 471###
 472### series C
 473###
 474
 475test_expect_success 'C: incremental import create pack from stdin' '
 476        newf=$(echo hi newf | git hash-object -w --stdin) &&
 477        oldf=$(git rev-parse --verify master:file2) &&
 478        test_tick &&
 479        cat >input <<-INPUT_END &&
 480        commit refs/heads/branch
 481        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 482        data <<COMMIT
 483        second
 484        COMMIT
 485
 486        from refs/heads/master
 487        M 644 $oldf file2/oldf
 488        M 755 $newf file2/newf
 489        D file3
 490
 491        INPUT_END
 492
 493        git fast-import <input &&
 494        git whatchanged branch
 495'
 496
 497test_expect_success 'C: verify pack' '
 498        verify_packs
 499'
 500
 501test_expect_success 'C: validate reuse existing blob' '
 502        test $newf = $(git rev-parse --verify branch:file2/newf) &&
 503        test $oldf = $(git rev-parse --verify branch:file2/oldf)
 504'
 505
 506test_expect_success 'C: verify commit' '
 507        cat >expect <<-EOF &&
 508        parent $(git rev-parse --verify master^0)
 509        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 510        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 511
 512        second
 513        EOF
 514
 515        git cat-file commit branch | sed 1d >actual &&
 516        test_cmp expect actual
 517'
 518
 519test_expect_success 'C: validate rename result' '
 520        cat >expect <<-EOF &&
 521        :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 522        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 523        :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 524        EOF
 525        git diff-tree -M -r master branch >actual &&
 526        compare_diff_raw expect actual
 527'
 528
 529###
 530### series D
 531###
 532
 533test_expect_success 'D: inline data in commit' '
 534        test_tick &&
 535        cat >input <<-INPUT_END &&
 536        commit refs/heads/branch
 537        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 538        data <<COMMIT
 539        third
 540        COMMIT
 541
 542        from refs/heads/branch^0
 543        M 644 inline newdir/interesting
 544        data <<EOF
 545        $file5_data
 546        EOF
 547
 548        M 755 inline newdir/exec.sh
 549        data <<EOF
 550        $file6_data
 551        EOF
 552
 553        INPUT_END
 554
 555        git fast-import <input &&
 556        git whatchanged branch
 557'
 558
 559test_expect_success 'D: verify pack' '
 560        verify_packs
 561'
 562
 563test_expect_success 'D: validate new files added' '
 564        cat >expect <<-EOF &&
 565        :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A      newdir/exec.sh
 566        :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A      newdir/interesting
 567        EOF
 568        git diff-tree -M -r branch^ branch >actual &&
 569        compare_diff_raw expect actual
 570'
 571
 572test_expect_success 'D: verify file5' '
 573        echo "$file5_data" >expect &&
 574        git cat-file blob branch:newdir/interesting >actual &&
 575        test_cmp expect actual
 576'
 577
 578test_expect_success 'D: verify file6' '
 579        echo "$file6_data" >expect &&
 580        git cat-file blob branch:newdir/exec.sh >actual &&
 581        test_cmp expect actual
 582'
 583
 584###
 585### series E
 586###
 587
 588test_expect_success 'E: rfc2822 date, --date-format=raw' '
 589        cat >input <<-INPUT_END &&
 590        commit refs/heads/branch
 591        author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 592        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 593        data <<COMMIT
 594        RFC 2822 type date
 595        COMMIT
 596
 597        from refs/heads/branch^0
 598
 599        INPUT_END
 600
 601        test_must_fail git fast-import --date-format=raw <input
 602'
 603test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
 604        git fast-import --date-format=rfc2822 <input
 605'
 606
 607test_expect_success 'E: verify pack' '
 608        verify_packs
 609'
 610
 611test_expect_success 'E: verify commit' '
 612        cat >expect <<-EOF &&
 613        author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
 614        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
 615
 616        RFC 2822 type date
 617        EOF
 618        git cat-file commit branch | sed 1,2d >actual &&
 619        test_cmp expect actual
 620'
 621
 622###
 623### series F
 624###
 625
 626test_expect_success 'F: non-fast-forward update skips' '
 627        old_branch=$(git rev-parse --verify branch^0) &&
 628        test_tick &&
 629        cat >input <<-INPUT_END &&
 630        commit refs/heads/branch
 631        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 632        data <<COMMIT
 633        losing things already?
 634        COMMIT
 635
 636        from refs/heads/branch~1
 637
 638        reset refs/heads/other
 639        from refs/heads/branch
 640
 641        INPUT_END
 642
 643        test_must_fail git fast-import <input &&
 644        # branch must remain unaffected
 645        test $old_branch = $(git rev-parse --verify branch^0)
 646'
 647
 648test_expect_success 'F: verify pack' '
 649        verify_packs
 650'
 651
 652test_expect_success 'F: verify other commit' '
 653        cat >expect <<-EOF &&
 654        tree $(git rev-parse branch~1^{tree})
 655        parent $(git rev-parse branch~1)
 656        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 657        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 658
 659        losing things already?
 660        EOF
 661        git cat-file commit other >actual &&
 662        test_cmp expect actual
 663'
 664
 665###
 666### series G
 667###
 668
 669test_expect_success 'G: non-fast-forward update forced' '
 670        old_branch=$(git rev-parse --verify branch^0) &&
 671        test_tick &&
 672        cat >input <<-INPUT_END &&
 673        commit refs/heads/branch
 674        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 675        data <<COMMIT
 676        losing things already?
 677        COMMIT
 678
 679        from refs/heads/branch~1
 680
 681        INPUT_END
 682        git fast-import --force <input
 683'
 684
 685test_expect_success 'G: verify pack' '
 686        verify_packs
 687'
 688
 689test_expect_success 'G: branch changed, but logged' '
 690        test $old_branch != $(git rev-parse --verify branch^0) &&
 691        test $old_branch = $(git rev-parse --verify branch@{1})
 692'
 693
 694###
 695### series H
 696###
 697
 698test_expect_success 'H: deletall, add 1' '
 699        test_tick &&
 700        cat >input <<-INPUT_END &&
 701        commit refs/heads/H
 702        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 703        data <<COMMIT
 704        third
 705        COMMIT
 706
 707        from refs/heads/branch^0
 708        M 644 inline i-will-die
 709        data <<EOF
 710        this file will never exist.
 711        EOF
 712
 713        deleteall
 714        M 644 inline h/e/l/lo
 715        data <<EOF
 716        $file5_data
 717        EOF
 718
 719        INPUT_END
 720        git fast-import <input &&
 721        git whatchanged H
 722'
 723
 724test_expect_success 'H: verify pack' '
 725        verify_packs
 726'
 727
 728test_expect_success 'H: validate old files removed, new files added' '
 729        cat >expect <<-EOF &&
 730        :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
 731        :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
 732        :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
 733        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
 734        :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
 735        EOF
 736        git diff-tree -M -r H^ H >actual &&
 737        compare_diff_raw expect actual
 738'
 739
 740test_expect_success 'H: verify file' '
 741        echo "$file5_data" >expect &&
 742        git cat-file blob H:h/e/l/lo >actual &&
 743        test_cmp expect actual
 744'
 745
 746###
 747### series I
 748###
 749
 750test_expect_success 'I: export-pack-edges' '
 751        cat >input <<-INPUT_END &&
 752        commit refs/heads/export-boundary
 753        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 754        data <<COMMIT
 755        we have a border.  its only 40 characters wide.
 756        COMMIT
 757
 758        from refs/heads/branch
 759
 760        INPUT_END
 761        git fast-import --export-pack-edges=edges.list <input
 762'
 763
 764test_expect_success 'I: verify edge list' '
 765        cat >expect <<-EOF &&
 766        .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
 767        EOF
 768        sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
 769        test_cmp expect actual
 770'
 771
 772###
 773### series J
 774###
 775
 776test_expect_success 'J: reset existing branch creates empty commit' '
 777        cat >input <<-INPUT_END &&
 778        commit refs/heads/J
 779        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 780        data <<COMMIT
 781        create J
 782        COMMIT
 783
 784        from refs/heads/branch
 785
 786        reset refs/heads/J
 787
 788        commit refs/heads/J
 789        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 790        data <<COMMIT
 791        initialize J
 792        COMMIT
 793
 794        INPUT_END
 795        git fast-import <input
 796'
 797test_expect_success 'J: branch has 1 commit, empty tree' '
 798        test 1 = $(git rev-list J | wc -l) &&
 799        test 0 = $(git ls-tree J | wc -l)
 800'
 801
 802test_expect_success 'J: tag must fail on empty branch' '
 803        cat >input <<-INPUT_END &&
 804        reset refs/heads/J2
 805
 806        tag wrong_tag
 807        from refs/heads/J2
 808        data <<EOF
 809        Tag branch that was reset.
 810        EOF
 811        INPUT_END
 812        test_must_fail git fast-import <input
 813'
 814
 815###
 816### series K
 817###
 818
 819test_expect_success 'K: reinit branch with from' '
 820        cat >input <<-INPUT_END &&
 821        commit refs/heads/K
 822        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 823        data <<COMMIT
 824        create K
 825        COMMIT
 826
 827        from refs/heads/branch
 828
 829        commit refs/heads/K
 830        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 831        data <<COMMIT
 832        redo K
 833        COMMIT
 834
 835        from refs/heads/branch^1
 836
 837        INPUT_END
 838        git fast-import <input
 839'
 840test_expect_success 'K: verify K^1 = branch^1' '
 841        test $(git rev-parse --verify branch^1) \
 842                = $(git rev-parse --verify K^1)
 843'
 844
 845###
 846### series L
 847###
 848
 849test_expect_success 'L: verify internal tree sorting' '
 850        cat >input <<-INPUT_END &&
 851        blob
 852        mark :1
 853        data <<EOF
 854        some data
 855        EOF
 856
 857        blob
 858        mark :2
 859        data <<EOF
 860        other data
 861        EOF
 862
 863        commit refs/heads/L
 864        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 865        data <<COMMIT
 866        create L
 867        COMMIT
 868
 869        M 644 :1 b.
 870        M 644 :1 b/other
 871        M 644 :1 ba
 872
 873        commit refs/heads/L
 874        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 875        data <<COMMIT
 876        update L
 877        COMMIT
 878
 879        M 644 :2 b.
 880        M 644 :2 b/other
 881        M 644 :2 ba
 882        INPUT_END
 883
 884        cat >expect <<-EXPECT_END &&
 885        :100644 100644 4268632... 55d3a52... M  b.
 886        :040000 040000 0ae5cac... 443c768... M  b
 887        :100644 100644 4268632... 55d3a52... M  ba
 888        EXPECT_END
 889
 890        git fast-import <input &&
 891        git diff-tree --abbrev --raw L^ L >output &&
 892        test_cmp expect output
 893'
 894
 895test_expect_success 'L: nested tree copy does not corrupt deltas' '
 896        cat >input <<-INPUT_END &&
 897        blob
 898        mark :1
 899        data <<EOF
 900        the data
 901        EOF
 902
 903        commit refs/heads/L2
 904        committer C O Mitter <committer@example.com> 1112912473 -0700
 905        data <<COMMIT
 906        init L2
 907        COMMIT
 908        M 644 :1 a/b/c
 909        M 644 :1 a/b/d
 910        M 644 :1 a/e/f
 911
 912        commit refs/heads/L2
 913        committer C O Mitter <committer@example.com> 1112912473 -0700
 914        data <<COMMIT
 915        update L2
 916        COMMIT
 917        C a g
 918        C a/e g/b
 919        M 644 :1 g/b/h
 920        INPUT_END
 921
 922        cat >expect <<-\EOF &&
 923        g/b/f
 924        g/b/h
 925        EOF
 926
 927        test_when_finished "git update-ref -d refs/heads/L2" &&
 928        git fast-import <input &&
 929        git ls-tree L2 g/b/ >tmp &&
 930        cat tmp | cut -f 2 >actual &&
 931        test_cmp expect actual &&
 932        git fsck $(git rev-parse L2)
 933'
 934
 935###
 936### series M
 937###
 938
 939test_expect_success 'M: rename file in same subdirectory' '
 940        test_tick &&
 941        cat >input <<-INPUT_END &&
 942        commit refs/heads/M1
 943        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 944        data <<COMMIT
 945        file rename
 946        COMMIT
 947
 948        from refs/heads/branch^0
 949        R file2/newf file2/n.e.w.f
 950
 951        INPUT_END
 952
 953        cat >expect <<-EOF &&
 954        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
 955        EOF
 956        git fast-import <input &&
 957        git diff-tree -M -r M1^ M1 >actual &&
 958        compare_diff_raw expect actual
 959'
 960
 961test_expect_success 'M: rename file to new subdirectory' '
 962        cat >input <<-INPUT_END &&
 963        commit refs/heads/M2
 964        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 965        data <<COMMIT
 966        file rename
 967        COMMIT
 968
 969        from refs/heads/branch^0
 970        R file2/newf i/am/new/to/you
 971
 972        INPUT_END
 973
 974        cat >expect <<-EOF &&
 975        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
 976        EOF
 977        git fast-import <input &&
 978        git diff-tree -M -r M2^ M2 >actual &&
 979        compare_diff_raw expect actual
 980'
 981
 982test_expect_success 'M: rename subdirectory to new subdirectory' '
 983        cat >input <<-INPUT_END &&
 984        commit refs/heads/M3
 985        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 986        data <<COMMIT
 987        file rename
 988        COMMIT
 989
 990        from refs/heads/M2^0
 991        R i other/sub
 992
 993        INPUT_END
 994
 995        cat >expect <<-EOF &&
 996        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
 997        EOF
 998        git fast-import <input &&
 999        git diff-tree -M -r M3^ M3 >actual &&
1000        compare_diff_raw expect actual
1001'
1002
1003test_expect_success 'M: rename root to subdirectory' '
1004        cat >input <<-INPUT_END &&
1005        commit refs/heads/M4
1006        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007        data <<COMMIT
1008        rename root
1009        COMMIT
1010
1011        from refs/heads/M2^0
1012        R "" sub
1013
1014        INPUT_END
1015
1016        cat >expect <<-EOF &&
1017        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2/oldf      sub/file2/oldf
1018        :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100   file4   sub/file4
1019        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you sub/i/am/new/to/you
1020        :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100   newdir/exec.sh  sub/newdir/exec.sh
1021        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      sub/newdir/interesting
1022        EOF
1023        git fast-import <input &&
1024        git diff-tree -M -r M4^ M4 >actual &&
1025        cat actual &&
1026        compare_diff_raw expect actual
1027'
1028
1029###
1030### series N
1031###
1032
1033test_expect_success 'N: copy file in same subdirectory' '
1034        test_tick &&
1035        cat >input <<-INPUT_END &&
1036        commit refs/heads/N1
1037        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1038        data <<COMMIT
1039        file copy
1040        COMMIT
1041
1042        from refs/heads/branch^0
1043        C file2/newf file2/n.e.w.f
1044
1045        INPUT_END
1046
1047        cat >expect <<-EOF &&
1048        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
1049        EOF
1050        git fast-import <input &&
1051        git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1052        compare_diff_raw expect actual
1053'
1054
1055test_expect_success 'N: copy then modify subdirectory' '
1056        cat >input <<-INPUT_END &&
1057        commit refs/heads/N2
1058        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1059        data <<COMMIT
1060        clean directory copy
1061        COMMIT
1062
1063        from refs/heads/branch^0
1064        C file2 file3
1065
1066        commit refs/heads/N2
1067        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068        data <<COMMIT
1069        modify directory copy
1070        COMMIT
1071
1072        M 644 inline file3/file5
1073        data <<EOF
1074        $file5_data
1075        EOF
1076
1077        INPUT_END
1078
1079        cat >expect <<-EOF &&
1080        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1081        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1082        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1083        EOF
1084        git fast-import <input &&
1085        git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1086        compare_diff_raw expect actual
1087'
1088
1089test_expect_success 'N: copy dirty subdirectory' '
1090        cat >input <<-INPUT_END &&
1091        commit refs/heads/N3
1092        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1093        data <<COMMIT
1094        dirty directory copy
1095        COMMIT
1096
1097        from refs/heads/branch^0
1098        M 644 inline file2/file5
1099        data <<EOF
1100        $file5_data
1101        EOF
1102
1103        C file2 file3
1104        D file2/file5
1105
1106        INPUT_END
1107
1108        git fast-import <input &&
1109        test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1110'
1111
1112test_expect_success 'N: copy directory by id' '
1113        cat >expect <<-\EOF &&
1114        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1115        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1116        EOF
1117        subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1118        cat >input <<-INPUT_END &&
1119        commit refs/heads/N4
1120        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1121        data <<COMMIT
1122        copy by tree hash
1123        COMMIT
1124
1125        from refs/heads/branch^0
1126        M 040000 $subdir file3
1127        INPUT_END
1128        git fast-import <input &&
1129        git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1130        compare_diff_raw expect actual
1131'
1132
1133test_expect_success PIPE 'N: read and copy directory' '
1134        cat >expect <<-\EOF &&
1135        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1136        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1137        EOF
1138        git update-ref -d refs/heads/N4 &&
1139        rm -f backflow &&
1140        mkfifo backflow &&
1141        (
1142                exec <backflow &&
1143                cat <<-EOF &&
1144                commit refs/heads/N4
1145                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1146                data <<COMMIT
1147                copy by tree hash, part 2
1148                COMMIT
1149
1150                from refs/heads/branch^0
1151                ls "file2"
1152                EOF
1153                read mode type tree filename &&
1154                echo "M 040000 $tree file3"
1155        ) |
1156        git fast-import --cat-blob-fd=3 3>backflow &&
1157        git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1158        compare_diff_raw expect actual
1159'
1160
1161test_expect_success PIPE 'N: empty directory reads as missing' '
1162        cat <<-\EOF >expect &&
1163        OBJNAME
1164        :000000 100644 OBJNAME OBJNAME A        unrelated
1165        EOF
1166        echo "missing src" >expect.response &&
1167        git update-ref -d refs/heads/read-empty &&
1168        rm -f backflow &&
1169        mkfifo backflow &&
1170        (
1171                exec <backflow &&
1172                cat <<-EOF &&
1173                commit refs/heads/read-empty
1174                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1175                data <<COMMIT
1176                read "empty" (missing) directory
1177                COMMIT
1178
1179                M 100644 inline src/greeting
1180                data <<BLOB
1181                hello
1182                BLOB
1183                C src/greeting dst1/non-greeting
1184                C src/greeting unrelated
1185                # leave behind "empty" src directory
1186                D src/greeting
1187                ls "src"
1188                EOF
1189                read -r line &&
1190                printf "%s\n" "$line" >response &&
1191                cat <<-\EOF
1192                D dst1
1193                D dst2
1194                EOF
1195        ) |
1196        git fast-import --cat-blob-fd=3 3>backflow &&
1197        test_cmp expect.response response &&
1198        git rev-list read-empty |
1199        git diff-tree -r --root --stdin |
1200        sed "s/$_x40/OBJNAME/g" >actual &&
1201        test_cmp expect actual
1202'
1203
1204test_expect_success 'N: copy root directory by tree hash' '
1205        cat >expect <<-\EOF &&
1206        :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file3/newf
1207        :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file3/oldf
1208        EOF
1209        root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1210        cat >input <<-INPUT_END &&
1211        commit refs/heads/N6
1212        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1213        data <<COMMIT
1214        copy root directory by tree hash
1215        COMMIT
1216
1217        from refs/heads/branch^0
1218        M 040000 $root ""
1219        INPUT_END
1220        git fast-import <input &&
1221        git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1222        compare_diff_raw expect actual
1223'
1224
1225test_expect_success 'N: copy root by path' '
1226        cat >expect <<-\EOF &&
1227        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      oldroot/file2/newf
1228        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      oldroot/file2/oldf
1229        :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100   file4   oldroot/file4
1230        :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100   newdir/exec.sh  oldroot/newdir/exec.sh
1231        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      oldroot/newdir/interesting
1232        EOF
1233        cat >input <<-INPUT_END &&
1234        commit refs/heads/N-copy-root-path
1235        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1236        data <<COMMIT
1237        copy root directory by (empty) path
1238        COMMIT
1239
1240        from refs/heads/branch^0
1241        C "" oldroot
1242        INPUT_END
1243        git fast-import <input &&
1244        git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1245        compare_diff_raw expect actual
1246'
1247
1248test_expect_success 'N: delete directory by copying' '
1249        cat >expect <<-\EOF &&
1250        OBJID
1251        :100644 000000 OBJID OBJID D    foo/bar/qux
1252        OBJID
1253        :000000 100644 OBJID OBJID A    foo/bar/baz
1254        :000000 100644 OBJID OBJID A    foo/bar/qux
1255        EOF
1256        empty_tree=$(git mktree </dev/null) &&
1257        cat >input <<-INPUT_END &&
1258        commit refs/heads/N-delete
1259        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1260        data <<COMMIT
1261        collect data to be deleted
1262        COMMIT
1263
1264        deleteall
1265        M 100644 inline foo/bar/baz
1266        data <<DATA_END
1267        hello
1268        DATA_END
1269        C "foo/bar/baz" "foo/bar/qux"
1270        C "foo/bar/baz" "foo/bar/quux/1"
1271        C "foo/bar/baz" "foo/bar/quuux"
1272        M 040000 $empty_tree foo/bar/quux
1273        M 040000 $empty_tree foo/bar/quuux
1274
1275        commit refs/heads/N-delete
1276        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1277        data <<COMMIT
1278        delete subdirectory
1279        COMMIT
1280
1281        M 040000 $empty_tree foo/bar/qux
1282        INPUT_END
1283        git fast-import <input &&
1284        git rev-list N-delete |
1285                git diff-tree -r --stdin --root --always |
1286                sed -e "s/$_x40/OBJID/g" >actual &&
1287        test_cmp expect actual
1288'
1289
1290test_expect_success 'N: modify copied tree' '
1291        cat >expect <<-\EOF &&
1292        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
1293        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
1294        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
1295        EOF
1296        subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1297        cat >input <<-INPUT_END &&
1298        commit refs/heads/N5
1299        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1300        data <<COMMIT
1301        copy by tree hash
1302        COMMIT
1303
1304        from refs/heads/branch^0
1305        M 040000 $subdir file3
1306
1307        commit refs/heads/N5
1308        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1309        data <<COMMIT
1310        modify directory copy
1311        COMMIT
1312
1313        M 644 inline file3/file5
1314        data <<EOF
1315        $file5_data
1316        EOF
1317        INPUT_END
1318        git fast-import <input &&
1319        git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1320        compare_diff_raw expect actual
1321'
1322
1323test_expect_success 'N: reject foo/ syntax' '
1324        subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1325        test_must_fail git fast-import <<-INPUT_END
1326        commit refs/heads/N5B
1327        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1328        data <<COMMIT
1329        copy with invalid syntax
1330        COMMIT
1331
1332        from refs/heads/branch^0
1333        M 040000 $subdir file3/
1334        INPUT_END
1335'
1336
1337test_expect_success 'N: reject foo/ syntax in copy source' '
1338        test_must_fail git fast-import <<-INPUT_END
1339        commit refs/heads/N5C
1340        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1341        data <<COMMIT
1342        copy with invalid syntax
1343        COMMIT
1344
1345        from refs/heads/branch^0
1346        C file2/ file3
1347        INPUT_END
1348'
1349
1350test_expect_success 'N: reject foo/ syntax in rename source' '
1351        test_must_fail git fast-import <<-INPUT_END
1352        commit refs/heads/N5D
1353        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1354        data <<COMMIT
1355        rename with invalid syntax
1356        COMMIT
1357
1358        from refs/heads/branch^0
1359        R file2/ file3
1360        INPUT_END
1361'
1362
1363test_expect_success 'N: reject foo/ syntax in ls argument' '
1364        test_must_fail git fast-import <<-INPUT_END
1365        commit refs/heads/N5E
1366        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1367        data <<COMMIT
1368        copy with invalid syntax
1369        COMMIT
1370
1371        from refs/heads/branch^0
1372        ls "file2/"
1373        INPUT_END
1374'
1375
1376test_expect_success 'N: copy to root by id and modify' '
1377        echo "hello, world" >expect.foo &&
1378        echo hello >expect.bar &&
1379        git fast-import <<-SETUP_END &&
1380        commit refs/heads/N7
1381        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1382        data <<COMMIT
1383        hello, tree
1384        COMMIT
1385
1386        deleteall
1387        M 644 inline foo/bar
1388        data <<EOF
1389        hello
1390        EOF
1391        SETUP_END
1392
1393        tree=$(git rev-parse --verify N7:) &&
1394        git fast-import <<-INPUT_END &&
1395        commit refs/heads/N8
1396        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1397        data <<COMMIT
1398        copy to root by id and modify
1399        COMMIT
1400
1401        M 040000 $tree ""
1402        M 644 inline foo/foo
1403        data <<EOF
1404        hello, world
1405        EOF
1406        INPUT_END
1407        git show N8:foo/foo >actual.foo &&
1408        git show N8:foo/bar >actual.bar &&
1409        test_cmp expect.foo actual.foo &&
1410        test_cmp expect.bar actual.bar
1411'
1412
1413test_expect_success 'N: extract subtree' '
1414        branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1415        cat >input <<-INPUT_END &&
1416        commit refs/heads/N9
1417        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418        data <<COMMIT
1419        extract subtree branch:newdir
1420        COMMIT
1421
1422        M 040000 $branch ""
1423        C "newdir" ""
1424        INPUT_END
1425        git fast-import <input &&
1426        git diff --exit-code branch:newdir N9
1427'
1428
1429test_expect_success 'N: modify subtree, extract it, and modify again' '
1430        echo hello >expect.baz &&
1431        echo hello, world >expect.qux &&
1432        git fast-import <<-SETUP_END &&
1433        commit refs/heads/N10
1434        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1435        data <<COMMIT
1436        hello, tree
1437        COMMIT
1438
1439        deleteall
1440        M 644 inline foo/bar/baz
1441        data <<EOF
1442        hello
1443        EOF
1444        SETUP_END
1445
1446        tree=$(git rev-parse --verify N10:) &&
1447        git fast-import <<-INPUT_END &&
1448        commit refs/heads/N11
1449        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1450        data <<COMMIT
1451        copy to root by id and modify
1452        COMMIT
1453
1454        M 040000 $tree ""
1455        M 100644 inline foo/bar/qux
1456        data <<EOF
1457        hello, world
1458        EOF
1459        R "foo" ""
1460        C "bar/qux" "bar/quux"
1461        INPUT_END
1462        git show N11:bar/baz >actual.baz &&
1463        git show N11:bar/qux >actual.qux &&
1464        git show N11:bar/quux >actual.quux &&
1465        test_cmp expect.baz actual.baz &&
1466        test_cmp expect.qux actual.qux &&
1467        test_cmp expect.qux actual.quux'
1468
1469###
1470### series O
1471###
1472
1473test_expect_success 'O: comments are all skipped' '
1474        cat >input <<-INPUT_END &&
1475        #we will
1476        commit refs/heads/O1
1477        # -- ignore all of this text
1478        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1479        # $GIT_COMMITTER_NAME has inserted here for his benefit.
1480        data <<COMMIT
1481        dirty directory copy
1482        COMMIT
1483
1484        # do not forget the import blank line!
1485        #
1486        # yes, we started from our usual base of branch^0.
1487        # i like branch^0.
1488        from refs/heads/branch^0
1489        # and we need to reuse file2/file5 from N3 above.
1490        M 644 inline file2/file5
1491        # otherwise the tree will be different
1492        data <<EOF
1493        $file5_data
1494        EOF
1495
1496        # do not forget to copy file2 to file3
1497        C file2 file3
1498        #
1499        # or to delete file5 from file2.
1500        D file2/file5
1501        # are we done yet?
1502
1503        INPUT_END
1504
1505        git fast-import <input &&
1506        test $(git rev-parse N3) = $(git rev-parse O1)
1507'
1508
1509test_expect_success 'O: blank lines not necessary after data commands' '
1510        cat >input <<-INPUT_END &&
1511        commit refs/heads/O2
1512        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1513        data <<COMMIT
1514        dirty directory copy
1515        COMMIT
1516        from refs/heads/branch^0
1517        M 644 inline file2/file5
1518        data <<EOF
1519        $file5_data
1520        EOF
1521        C file2 file3
1522        D file2/file5
1523
1524        INPUT_END
1525
1526        git fast-import <input &&
1527        test $(git rev-parse N3) = $(git rev-parse O2)
1528'
1529
1530test_expect_success 'O: repack before next test' '
1531        git repack -a -d
1532'
1533
1534test_expect_success 'O: blank lines not necessary after other commands' '
1535        cat >input <<-INPUT_END &&
1536        commit refs/heads/O3
1537        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538        data <<COMMIT
1539        zstring
1540        COMMIT
1541        commit refs/heads/O3
1542        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1543        data <<COMMIT
1544        zof
1545        COMMIT
1546        checkpoint
1547        commit refs/heads/O3
1548        mark :5
1549        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1550        data <<COMMIT
1551        zempty
1552        COMMIT
1553        checkpoint
1554        commit refs/heads/O3
1555        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1556        data <<COMMIT
1557        zcommits
1558        COMMIT
1559        reset refs/tags/O3-2nd
1560        from :5
1561        reset refs/tags/O3-3rd
1562        from :5
1563        INPUT_END
1564
1565        cat >expect <<-INPUT_END &&
1566        string
1567        of
1568        empty
1569        commits
1570        INPUT_END
1571
1572        git fast-import <input &&
1573        test 8 = $(find .git/objects/pack -type f | wc -l) &&
1574        test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1575        git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1576        test_cmp expect actual
1577'
1578
1579test_expect_success 'O: progress outputs as requested by input' '
1580        cat >input <<-INPUT_END &&
1581        commit refs/heads/O4
1582        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583        data <<COMMIT
1584        zstring
1585        COMMIT
1586        commit refs/heads/O4
1587        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1588        data <<COMMIT
1589        zof
1590        COMMIT
1591        progress Two commits down, 2 to go!
1592        commit refs/heads/O4
1593        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1594        data <<COMMIT
1595        zempty
1596        COMMIT
1597        progress Three commits down, 1 to go!
1598        commit refs/heads/O4
1599        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1600        data <<COMMIT
1601        zcommits
1602        COMMIT
1603        progress done!
1604        INPUT_END
1605        git fast-import <input >actual &&
1606        grep "progress " <input >expect &&
1607        test_cmp expect actual
1608'
1609
1610###
1611### series P (gitlinks)
1612###
1613
1614test_expect_success 'P: superproject & submodule mix' '
1615        cat >input <<-INPUT_END &&
1616        blob
1617        mark :1
1618        data 10
1619        test file
1620
1621        reset refs/heads/sub
1622        commit refs/heads/sub
1623        mark :2
1624        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625        data 12
1626        sub_initial
1627        M 100644 :1 file
1628
1629        blob
1630        mark :3
1631        data <<DATAEND
1632        [submodule "sub"]
1633                path = sub
1634                url = "$(pwd)/sub"
1635        DATAEND
1636
1637        commit refs/heads/subuse1
1638        mark :4
1639        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1640        data 8
1641        initial
1642        from refs/heads/master
1643        M 100644 :3 .gitmodules
1644        M 160000 :2 sub
1645
1646        blob
1647        mark :5
1648        data 20
1649        test file
1650        more data
1651
1652        commit refs/heads/sub
1653        mark :6
1654        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655        data 11
1656        sub_second
1657        from :2
1658        M 100644 :5 file
1659
1660        commit refs/heads/subuse1
1661        mark :7
1662        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1663        data 7
1664        second
1665        from :4
1666        M 160000 :6 sub
1667
1668        INPUT_END
1669
1670        git fast-import <input &&
1671        git checkout subuse1 &&
1672        rm -rf sub &&
1673        mkdir sub &&
1674        (
1675                cd sub &&
1676                git init &&
1677                git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1678                git checkout master
1679        ) &&
1680        git submodule init &&
1681        git submodule update
1682'
1683
1684test_expect_success 'P: verbatim SHA gitlinks' '
1685        SUBLAST=$(git rev-parse --verify sub) &&
1686        SUBPREV=$(git rev-parse --verify sub^) &&
1687
1688        cat >input <<-INPUT_END &&
1689        blob
1690        mark :1
1691        data <<DATAEND
1692        [submodule "sub"]
1693                path = sub
1694                url = "$(pwd)/sub"
1695        DATAEND
1696
1697        commit refs/heads/subuse2
1698        mark :2
1699        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1700        data 8
1701        initial
1702        from refs/heads/master
1703        M 100644 :1 .gitmodules
1704        M 160000 $SUBPREV sub
1705
1706        commit refs/heads/subuse2
1707        mark :3
1708        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1709        data 7
1710        second
1711        from :2
1712        M 160000 $SUBLAST sub
1713
1714        INPUT_END
1715
1716        git branch -D sub &&
1717        git gc &&
1718        git prune &&
1719        git fast-import <input &&
1720        test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1721'
1722
1723test_expect_success 'P: fail on inline gitlink' '
1724        test_tick &&
1725        cat >input <<-INPUT_END &&
1726        commit refs/heads/subuse3
1727        mark :1
1728        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1729        data <<COMMIT
1730        corrupt
1731        COMMIT
1732
1733        from refs/heads/subuse2
1734        M 160000 inline sub
1735        data <<DATA
1736        $SUBPREV
1737        DATA
1738
1739        INPUT_END
1740
1741        test_must_fail git fast-import <input
1742'
1743
1744test_expect_success 'P: fail on blob mark in gitlink' '
1745        test_tick &&
1746        cat >input <<-INPUT_END &&
1747        blob
1748        mark :1
1749        data <<DATA
1750        $SUBPREV
1751        DATA
1752
1753        commit refs/heads/subuse3
1754        mark :2
1755        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1756        data <<COMMIT
1757        corrupt
1758        COMMIT
1759
1760        from refs/heads/subuse2
1761        M 160000 :1 sub
1762
1763        INPUT_END
1764
1765        test_must_fail git fast-import <input
1766'
1767
1768###
1769### series Q (notes)
1770###
1771
1772test_expect_success 'Q: commit notes' '
1773        note1_data="The first note for the first commit" &&
1774        note2_data="The first note for the second commit" &&
1775        note3_data="The first note for the third commit" &&
1776        note1b_data="The second note for the first commit" &&
1777        note1c_data="The third note for the first commit" &&
1778        note2b_data="The second note for the second commit" &&
1779
1780        test_tick &&
1781        cat >input <<-INPUT_END &&
1782        blob
1783        mark :2
1784        data <<EOF
1785        $file2_data
1786        EOF
1787
1788        commit refs/heads/notes-test
1789        mark :3
1790        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1791        data <<COMMIT
1792        first (:3)
1793        COMMIT
1794
1795        M 644 :2 file2
1796
1797        blob
1798        mark :4
1799        data $file4_len
1800        $file4_data
1801        commit refs/heads/notes-test
1802        mark :5
1803        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1804        data <<COMMIT
1805        second (:5)
1806        COMMIT
1807
1808        M 644 :4 file4
1809
1810        commit refs/heads/notes-test
1811        mark :6
1812        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1813        data <<COMMIT
1814        third (:6)
1815        COMMIT
1816
1817        M 644 inline file5
1818        data <<EOF
1819        $file5_data
1820        EOF
1821
1822        M 755 inline file6
1823        data <<EOF
1824        $file6_data
1825        EOF
1826
1827        blob
1828        mark :7
1829        data <<EOF
1830        $note1_data
1831        EOF
1832
1833        blob
1834        mark :8
1835        data <<EOF
1836        $note2_data
1837        EOF
1838
1839        commit refs/notes/foobar
1840        mark :9
1841        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842        data <<COMMIT
1843        notes (:9)
1844        COMMIT
1845
1846        N :7 :3
1847        N :8 :5
1848        N inline :6
1849        data <<EOF
1850        $note3_data
1851        EOF
1852
1853        commit refs/notes/foobar
1854        mark :10
1855        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1856        data <<COMMIT
1857        notes (:10)
1858        COMMIT
1859
1860        N inline :3
1861        data <<EOF
1862        $note1b_data
1863        EOF
1864
1865        commit refs/notes/foobar2
1866        mark :11
1867        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1868        data <<COMMIT
1869        notes (:11)
1870        COMMIT
1871
1872        N inline :3
1873        data <<EOF
1874        $note1c_data
1875        EOF
1876
1877        commit refs/notes/foobar
1878        mark :12
1879        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1880        data <<COMMIT
1881        notes (:12)
1882        COMMIT
1883
1884        deleteall
1885        N inline :5
1886        data <<EOF
1887        $note2b_data
1888        EOF
1889
1890        INPUT_END
1891
1892        git fast-import <input &&
1893        git whatchanged notes-test
1894'
1895
1896test_expect_success 'Q: verify pack' '
1897        verify_packs
1898'
1899
1900test_expect_success 'Q: verify first commit' '
1901        commit1=$(git rev-parse notes-test~2) &&
1902        commit2=$(git rev-parse notes-test^) &&
1903        commit3=$(git rev-parse notes-test) &&
1904
1905        cat >expect <<-EOF &&
1906        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1907        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1908
1909        first (:3)
1910        EOF
1911        git cat-file commit notes-test~2 | sed 1d >actual &&
1912        test_cmp expect actual
1913'
1914
1915test_expect_success 'Q: verify second commit' '
1916        cat >expect <<-EOF &&
1917        parent $commit1
1918        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1919        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1920
1921        second (:5)
1922        EOF
1923        git cat-file commit notes-test^ | sed 1d >actual &&
1924        test_cmp expect actual
1925'
1926
1927test_expect_success 'Q: verify third commit' '
1928        cat >expect <<-EOF &&
1929        parent $commit2
1930        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1931        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1932
1933        third (:6)
1934        EOF
1935        git cat-file commit notes-test | sed 1d >actual &&
1936        test_cmp expect actual
1937'
1938
1939test_expect_success 'Q: verify first notes commit' '
1940        cat >expect <<-EOF &&
1941        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1942        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1943
1944        notes (:9)
1945        EOF
1946        git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1947        test_cmp expect actual
1948'
1949
1950test_expect_success 'Q: verify first notes tree' '
1951        cat >expect.unsorted <<-EOF &&
1952        100644 blob $commit1
1953        100644 blob $commit2
1954        100644 blob $commit3
1955        EOF
1956        cat expect.unsorted | sort >expect &&
1957        git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1958        test_cmp expect actual
1959'
1960
1961test_expect_success 'Q: verify first note for first commit' '
1962        echo "$note1_data" >expect &&
1963        git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
1964        test_cmp expect actual
1965'
1966
1967test_expect_success 'Q: verify first note for second commit' '
1968        echo "$note2_data" >expect &&
1969        git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
1970        test_cmp expect actual
1971'
1972
1973test_expect_success 'Q: verify first note for third commit' '
1974        echo "$note3_data" >expect &&
1975        git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
1976        test_cmp expect actual
1977'
1978
1979test_expect_success 'Q: verify second notes commit' '
1980        cat >expect <<-EOF &&
1981        parent $(git rev-parse --verify refs/notes/foobar~2)
1982        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1983        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1984
1985        notes (:10)
1986        EOF
1987        git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1988        test_cmp expect actual
1989'
1990
1991test_expect_success 'Q: verify second notes tree' '
1992        cat >expect.unsorted <<-EOF &&
1993        100644 blob $commit1
1994        100644 blob $commit2
1995        100644 blob $commit3
1996        EOF
1997        cat expect.unsorted | sort >expect &&
1998        git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1999        test_cmp expect actual
2000'
2001
2002test_expect_success 'Q: verify second note for first commit' '
2003        echo "$note1b_data" >expect &&
2004        git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2005        test_cmp expect actual
2006'
2007
2008test_expect_success 'Q: verify first note for second commit' '
2009        echo "$note2_data" >expect &&
2010        git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2011        test_cmp expect actual
2012'
2013
2014test_expect_success 'Q: verify first note for third commit' '
2015        echo "$note3_data" >expect &&
2016        git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2017        test_cmp expect actual
2018'
2019
2020test_expect_success 'Q: verify third notes commit' '
2021        cat >expect <<-EOF &&
2022        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2023        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2024
2025        notes (:11)
2026        EOF
2027        git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2028        test_cmp expect actual
2029'
2030
2031test_expect_success 'Q: verify third notes tree' '
2032        cat >expect.unsorted <<-EOF &&
2033        100644 blob $commit1
2034        EOF
2035        cat expect.unsorted | sort >expect &&
2036        git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
2037        test_cmp expect actual
2038'
2039
2040test_expect_success 'Q: verify third note for first commit' '
2041        echo "$note1c_data" >expect &&
2042        git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2043        test_cmp expect actual
2044'
2045
2046test_expect_success 'Q: verify fourth notes commit' '
2047        cat >expect <<-EOF &&
2048        parent $(git rev-parse --verify refs/notes/foobar^)
2049        author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2050        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2051
2052        notes (:12)
2053        EOF
2054        git cat-file commit refs/notes/foobar | sed 1d >actual &&
2055        test_cmp expect actual
2056'
2057
2058test_expect_success 'Q: verify fourth notes tree' '
2059        cat >expect.unsorted <<-EOF &&
2060        100644 blob $commit2
2061        EOF
2062        cat expect.unsorted | sort >expect &&
2063        git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*    / /" >actual &&
2064        test_cmp expect actual
2065'
2066
2067test_expect_success 'Q: verify second note for second commit' '
2068        echo "$note2b_data" >expect &&
2069        git cat-file blob refs/notes/foobar:$commit2 >actual &&
2070        test_cmp expect actual
2071'
2072
2073test_expect_success 'Q: deny note on empty branch' '
2074        cat >input <<-EOF &&
2075        reset refs/heads/Q0
2076
2077        commit refs/heads/note-Q0
2078        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2079        data <<COMMIT
2080        Note for an empty branch.
2081        COMMIT
2082
2083        N inline refs/heads/Q0
2084        data <<NOTE
2085        some note
2086        NOTE
2087        EOF
2088        test_must_fail git fast-import <input
2089'
2090###
2091### series R (feature and option)
2092###
2093
2094test_expect_success 'R: abort on unsupported feature' '
2095        cat >input <<-EOF &&
2096        feature no-such-feature-exists
2097        EOF
2098
2099        test_must_fail git fast-import <input
2100'
2101
2102test_expect_success 'R: supported feature is accepted' '
2103        cat >input <<-EOF &&
2104        feature date-format=now
2105        EOF
2106
2107        git fast-import <input
2108'
2109
2110test_expect_success 'R: abort on receiving feature after data command' '
2111        cat >input <<-EOF &&
2112        blob
2113        data 3
2114        hi
2115        feature date-format=now
2116        EOF
2117
2118        test_must_fail git fast-import <input
2119'
2120
2121test_expect_success 'R: only one import-marks feature allowed per stream' '
2122        cat >input <<-EOF &&
2123        feature import-marks=git.marks
2124        feature import-marks=git2.marks
2125        EOF
2126
2127        test_must_fail git fast-import <input
2128'
2129
2130test_expect_success 'R: export-marks feature results in a marks file being created' '
2131        cat >input <<-EOF &&
2132        feature export-marks=git.marks
2133        blob
2134        mark :1
2135        data 3
2136        hi
2137
2138        EOF
2139
2140        cat input | git fast-import &&
2141        grep :1 git.marks
2142'
2143
2144test_expect_success 'R: export-marks options can be overridden by commandline options' '
2145        cat input | git fast-import --export-marks=other.marks &&
2146        grep :1 other.marks
2147'
2148
2149test_expect_success 'R: catch typo in marks file name' '
2150        test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2151        echo "feature import-marks=nonexistent.marks" |
2152        test_must_fail git fast-import
2153'
2154
2155test_expect_success 'R: import and output marks can be the same file' '
2156        rm -f io.marks &&
2157        blob=$(echo hi | git hash-object --stdin) &&
2158        cat >expect <<-EOF &&
2159        :1 $blob
2160        :2 $blob
2161        EOF
2162        git fast-import --export-marks=io.marks <<-\EOF &&
2163        blob
2164        mark :1
2165        data 3
2166        hi
2167
2168        EOF
2169        git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2170        blob
2171        mark :2
2172        data 3
2173        hi
2174
2175        EOF
2176        test_cmp expect io.marks
2177'
2178
2179test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2180        rm -f io.marks &&
2181        test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2182        blob
2183        mark :1
2184        data 3
2185        hi
2186
2187        EOF
2188'
2189
2190test_expect_success 'R: --import-marks-if-exists' '
2191        rm -f io.marks &&
2192        blob=$(echo hi | git hash-object --stdin) &&
2193        echo ":1 $blob" >expect &&
2194        git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2195        blob
2196        mark :1
2197        data 3
2198        hi
2199
2200        EOF
2201        test_cmp expect io.marks
2202'
2203
2204test_expect_success 'R: feature import-marks-if-exists' '
2205        rm -f io.marks &&
2206        >expect &&
2207
2208        git fast-import --export-marks=io.marks <<-\EOF &&
2209        feature import-marks-if-exists=not_io.marks
2210        EOF
2211        test_cmp expect io.marks &&
2212
2213        blob=$(echo hi | git hash-object --stdin) &&
2214
2215        echo ":1 $blob" >io.marks &&
2216        echo ":1 $blob" >expect &&
2217        echo ":2 $blob" >>expect &&
2218
2219        git fast-import --export-marks=io.marks <<-\EOF &&
2220        feature import-marks-if-exists=io.marks
2221        blob
2222        mark :2
2223        data 3
2224        hi
2225
2226        EOF
2227        test_cmp expect io.marks &&
2228
2229        echo ":3 $blob" >>expect &&
2230
2231        git fast-import --import-marks=io.marks \
2232                        --export-marks=io.marks <<-\EOF &&
2233        feature import-marks-if-exists=not_io.marks
2234        blob
2235        mark :3
2236        data 3
2237        hi
2238
2239        EOF
2240        test_cmp expect io.marks &&
2241
2242        >expect &&
2243
2244        git fast-import --import-marks-if-exists=not_io.marks \
2245                        --export-marks=io.marks <<-\EOF &&
2246        feature import-marks-if-exists=io.marks
2247        EOF
2248        test_cmp expect io.marks
2249'
2250
2251test_expect_success 'R: import to output marks works without any content' '
2252        cat >input <<-EOF &&
2253        feature import-marks=marks.out
2254        feature export-marks=marks.new
2255        EOF
2256
2257        cat input | git fast-import &&
2258        test_cmp marks.out marks.new
2259'
2260
2261test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2262        cat >input <<-EOF &&
2263        feature import-marks=nonexistent.marks
2264        feature export-marks=marks.new
2265        EOF
2266
2267        cat input | git fast-import --import-marks=marks.out &&
2268        test_cmp marks.out marks.new
2269'
2270
2271
2272test_expect_success 'R: multiple --import-marks= should be honoured' '
2273        cat >input <<-EOF &&
2274        feature import-marks=nonexistent.marks
2275        feature export-marks=combined.marks
2276        EOF
2277
2278        head -n2 marks.out > one.marks &&
2279        tail -n +3 marks.out > two.marks &&
2280        git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2281        test_cmp marks.out combined.marks
2282'
2283
2284test_expect_success 'R: feature relative-marks should be honoured' '
2285        cat >input <<-EOF &&
2286        feature relative-marks
2287        feature import-marks=relative.in
2288        feature export-marks=relative.out
2289        EOF
2290
2291        mkdir -p .git/info/fast-import/ &&
2292        cp marks.new .git/info/fast-import/relative.in &&
2293        git fast-import <input &&
2294        test_cmp marks.new .git/info/fast-import/relative.out
2295'
2296
2297test_expect_success 'R: feature no-relative-marks should be honoured' '
2298        cat >input <<-EOF &&
2299        feature relative-marks
2300        feature import-marks=relative.in
2301        feature no-relative-marks
2302        feature export-marks=non-relative.out
2303        EOF
2304
2305        git fast-import <input &&
2306        test_cmp marks.new non-relative.out
2307'
2308
2309test_expect_success 'R: feature ls supported' '
2310        echo "feature ls" |
2311        git fast-import
2312'
2313
2314test_expect_success 'R: feature cat-blob supported' '
2315        echo "feature cat-blob" |
2316        git fast-import
2317'
2318
2319test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2320        test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2321'
2322
2323test_expect_success !MINGW 'R: print old blob' '
2324        blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2325        cat >expect <<-EOF &&
2326        ${blob} blob 11
2327        yes it can
2328
2329        EOF
2330        echo "cat-blob $blob" |
2331        git fast-import --cat-blob-fd=6 6>actual &&
2332        test_cmp expect actual
2333'
2334
2335test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2336        echo hello >greeting &&
2337        blob=$(git hash-object -w greeting) &&
2338        cat >expect <<-EOF &&
2339        ${blob} blob 6
2340        hello
2341
2342        EOF
2343        git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2344        cat-blob $blob
2345        EOF
2346        test_cmp expect actual.3 &&
2347        test_must_be_empty actual.1 &&
2348        git fast-import 3>actual.3 >actual.1 <<-EOF &&
2349        option cat-blob-fd=3
2350        cat-blob $blob
2351        EOF
2352        test_must_be_empty actual.3 &&
2353        test_cmp expect actual.1
2354'
2355
2356test_expect_success !MINGW 'R: print mark for new blob' '
2357        echo "effluentish" | git hash-object --stdin >expect &&
2358        git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2359        blob
2360        mark :1
2361        data <<BLOB_END
2362        effluentish
2363        BLOB_END
2364        get-mark :1
2365        EOF
2366        test_cmp expect actual
2367'
2368
2369test_expect_success !MINGW 'R: print new blob' '
2370        blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2371        cat >expect <<-EOF &&
2372        ${blob} blob 12
2373        yep yep yep
2374
2375        EOF
2376        git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2377        blob
2378        mark :1
2379        data <<BLOB_END
2380        yep yep yep
2381        BLOB_END
2382        cat-blob :1
2383        EOF
2384        test_cmp expect actual
2385'
2386
2387test_expect_success !MINGW 'R: print new blob by sha1' '
2388        blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2389        cat >expect <<-EOF &&
2390        ${blob} blob 25
2391        a new blob named by sha1
2392
2393        EOF
2394        git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2395        blob
2396        data <<BLOB_END
2397        a new blob named by sha1
2398        BLOB_END
2399        cat-blob $blob
2400        EOF
2401        test_cmp expect actual
2402'
2403
2404test_expect_success 'setup: big file' '
2405        (
2406                echo "the quick brown fox jumps over the lazy dog" >big &&
2407                for i in 1 2 3
2408                do
2409                        cat big big big big >bigger &&
2410                        cat bigger bigger bigger bigger >big ||
2411                        exit
2412                done
2413        )
2414'
2415
2416test_expect_success 'R: print two blobs to stdout' '
2417        blob1=$(git hash-object big) &&
2418        blob1_len=$(wc -c <big) &&
2419        blob2=$(echo hello | git hash-object --stdin) &&
2420        {
2421                echo ${blob1} blob $blob1_len &&
2422                cat big &&
2423                cat <<-EOF
2424
2425                ${blob2} blob 6
2426                hello
2427
2428                EOF
2429        } >expect &&
2430        {
2431                cat <<-\END_PART1 &&
2432                        blob
2433                        mark :1
2434                        data <<data_end
2435                END_PART1
2436                cat big &&
2437                cat <<-\EOF
2438                        data_end
2439                        blob
2440                        mark :2
2441                        data <<data_end
2442                        hello
2443                        data_end
2444                        cat-blob :1
2445                        cat-blob :2
2446                EOF
2447        } |
2448        git fast-import >actual &&
2449        test_cmp expect actual
2450'
2451
2452test_expect_success PIPE 'R: copy using cat-file' '
2453        expect_id=$(git hash-object big) &&
2454        expect_len=$(wc -c <big) &&
2455        echo $expect_id blob $expect_len >expect.response &&
2456
2457        rm -f blobs &&
2458        cat >frontend <<-\FRONTEND_END &&
2459        #!/bin/sh
2460        FRONTEND_END
2461
2462        mkfifo blobs &&
2463        (
2464                export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2465                cat <<-\EOF &&
2466                feature cat-blob
2467                blob
2468                mark :1
2469                data <<BLOB
2470                EOF
2471                cat big &&
2472                cat <<-\EOF &&
2473                BLOB
2474                cat-blob :1
2475                EOF
2476
2477                read blob_id type size <&3 &&
2478                echo "$blob_id $type $size" >response &&
2479                head_c $size >blob <&3 &&
2480                read newline <&3 &&
2481
2482                cat <<-EOF &&
2483                commit refs/heads/copied
2484                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2485                data <<COMMIT
2486                copy big file as file3
2487                COMMIT
2488                M 644 inline file3
2489                data <<BLOB
2490                EOF
2491                cat blob &&
2492                echo BLOB
2493        ) 3<blobs |
2494        git fast-import --cat-blob-fd=3 3>blobs &&
2495        git show copied:file3 >actual &&
2496        test_cmp expect.response response &&
2497        test_cmp big actual
2498'
2499
2500test_expect_success PIPE 'R: print blob mid-commit' '
2501        rm -f blobs &&
2502        echo "A blob from _before_ the commit." >expect &&
2503        mkfifo blobs &&
2504        (
2505                exec 3<blobs &&
2506                cat <<-EOF &&
2507                feature cat-blob
2508                blob
2509                mark :1
2510                data <<BLOB
2511                A blob from _before_ the commit.
2512                BLOB
2513                commit refs/heads/temporary
2514                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2515                data <<COMMIT
2516                Empty commit
2517                COMMIT
2518                cat-blob :1
2519                EOF
2520
2521                read blob_id type size <&3 &&
2522                head_c $size >actual <&3 &&
2523                read newline <&3 &&
2524
2525                echo
2526        ) |
2527        git fast-import --cat-blob-fd=3 3>blobs &&
2528        test_cmp expect actual
2529'
2530
2531test_expect_success PIPE 'R: print staged blob within commit' '
2532        rm -f blobs &&
2533        echo "A blob from _within_ the commit." >expect &&
2534        mkfifo blobs &&
2535        (
2536                exec 3<blobs &&
2537                cat <<-EOF &&
2538                feature cat-blob
2539                commit refs/heads/within
2540                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2541                data <<COMMIT
2542                Empty commit
2543                COMMIT
2544                M 644 inline within
2545                data <<BLOB
2546                A blob from _within_ the commit.
2547                BLOB
2548                EOF
2549
2550                to_get=$(
2551                        echo "A blob from _within_ the commit." |
2552                        git hash-object --stdin
2553                ) &&
2554                echo "cat-blob $to_get" &&
2555
2556                read blob_id type size <&3 &&
2557                head_c $size >actual <&3 &&
2558                read newline <&3 &&
2559
2560                echo deleteall
2561        ) |
2562        git fast-import --cat-blob-fd=3 3>blobs &&
2563        test_cmp expect actual
2564'
2565
2566test_expect_success 'R: quiet option results in no stats being output' '
2567        cat >input <<-EOF &&
2568        option git quiet
2569        blob
2570        data 3
2571        hi
2572
2573        EOF
2574
2575        cat input | git fast-import 2> output &&
2576        test_must_be_empty output
2577'
2578
2579test_expect_success 'R: feature done means terminating "done" is mandatory' '
2580        echo feature done | test_must_fail git fast-import &&
2581        test_must_fail git fast-import --done </dev/null
2582'
2583
2584test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2585        git fast-import <<-\EOF &&
2586        feature done
2587        done
2588        trailing gibberish
2589        EOF
2590        git fast-import <<-\EOF
2591        done
2592        more trailing gibberish
2593        EOF
2594'
2595
2596test_expect_success 'R: terminating "done" within commit' '
2597        cat >expect <<-\EOF &&
2598        OBJID
2599        :000000 100644 OBJID OBJID A    hello.c
2600        :000000 100644 OBJID OBJID A    hello2.c
2601        EOF
2602        git fast-import <<-EOF &&
2603        commit refs/heads/done-ends
2604        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2605        data <<EOT
2606        Commit terminated by "done" command
2607        EOT
2608        M 100644 inline hello.c
2609        data <<EOT
2610        Hello, world.
2611        EOT
2612        C hello.c hello2.c
2613        done
2614        EOF
2615        git rev-list done-ends |
2616        git diff-tree -r --stdin --root --always |
2617        sed -e "s/$_x40/OBJID/g" >actual &&
2618        test_cmp expect actual
2619'
2620
2621test_expect_success 'R: die on unknown option' '
2622        cat >input <<-EOF &&
2623        option git non-existing-option
2624        EOF
2625
2626        test_must_fail git fast-import <input
2627'
2628
2629test_expect_success 'R: unknown commandline options are rejected' '\
2630        test_must_fail git fast-import --non-existing-option < /dev/null
2631'
2632
2633test_expect_success 'R: die on invalid option argument' '
2634        echo "option git active-branches=-5" |
2635        test_must_fail git fast-import &&
2636        echo "option git depth=" |
2637        test_must_fail git fast-import &&
2638        test_must_fail git fast-import --depth="5 elephants" </dev/null
2639'
2640
2641test_expect_success 'R: ignore non-git options' '
2642        cat >input <<-EOF &&
2643        option non-existing-vcs non-existing-option
2644        EOF
2645
2646        git fast-import <input
2647'
2648
2649##
2650## R: very large blobs
2651##
2652test_expect_success 'R: blob bigger than threshold' '
2653        blobsize=$((2*1024*1024 + 53)) &&
2654        test-genrandom bar $blobsize >expect &&
2655        cat >input <<-INPUT_END &&
2656        commit refs/heads/big-file
2657        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2658        data <<COMMIT
2659        R - big file
2660        COMMIT
2661
2662        M 644 inline big1
2663        data $blobsize
2664        INPUT_END
2665        cat expect >>input &&
2666        cat >>input <<-INPUT_END &&
2667        M 644 inline big2
2668        data $blobsize
2669        INPUT_END
2670        cat expect >>input &&
2671        echo >>input &&
2672
2673        test_create_repo R &&
2674        git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2675'
2676
2677test_expect_success 'R: verify created pack' '
2678        (
2679                cd R &&
2680                verify_packs -v > ../verify
2681        )
2682'
2683
2684test_expect_success 'R: verify written objects' '
2685        git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2686        test_cmp_bin expect actual &&
2687        a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2688        b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2689        test $a = $b
2690'
2691
2692test_expect_success 'R: blob appears only once' '
2693        n=$(grep $a verify | wc -l) &&
2694        test 1 = $n
2695'
2696
2697###
2698### series S
2699###
2700#
2701# Make sure missing spaces and EOLs after mark references
2702# cause errors.
2703#
2704# Setup:
2705#
2706#   1--2--4
2707#    \   /
2708#     -3-
2709#
2710#   commit marks:  301, 302, 303, 304
2711#   blob marks:              403, 404, resp.
2712#   note mark:          202
2713#
2714# The error message when a space is missing not at the
2715# end of the line is:
2716#
2717#   Missing space after ..
2718#
2719# or when extra characters come after the mark at the end
2720# of the line:
2721#
2722#   Garbage after ..
2723#
2724# or when the dataref is neither "inline " or a known SHA1,
2725#
2726#   Invalid dataref ..
2727#
2728test_expect_success 'S: initialize for S tests' '
2729        test_tick &&
2730
2731        cat >input <<-INPUT_END &&
2732        commit refs/heads/S
2733        mark :301
2734        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2735        data <<COMMIT
2736        commit 1
2737        COMMIT
2738        M 100644 inline hello.c
2739        data <<BLOB
2740        blob 1
2741        BLOB
2742
2743        commit refs/heads/S
2744        mark :302
2745        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2746        data <<COMMIT
2747        commit 2
2748        COMMIT
2749        from :301
2750        M 100644 inline hello.c
2751        data <<BLOB
2752        blob 2
2753        BLOB
2754
2755        blob
2756        mark :403
2757        data <<BLOB
2758        blob 3
2759        BLOB
2760
2761        blob
2762        mark :202
2763        data <<BLOB
2764        note 2
2765        BLOB
2766        INPUT_END
2767
2768        git fast-import --export-marks=marks <input
2769'
2770
2771#
2772# filemodify, three datarefs
2773#
2774test_expect_success 'S: filemodify with garbage after mark must fail' '
2775        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2776        commit refs/heads/S
2777        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2778        data <<COMMIT
2779        commit N
2780        COMMIT
2781        M 100644 :403x hello.c
2782        EOF
2783        cat err &&
2784        test_i18ngrep "space after mark" err
2785'
2786
2787# inline is misspelled; fast-import thinks it is some unknown dataref
2788test_expect_success 'S: filemodify with garbage after inline must fail' '
2789        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2790        commit refs/heads/S
2791        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2792        data <<COMMIT
2793        commit N
2794        COMMIT
2795        M 100644 inlineX hello.c
2796        data <<BLOB
2797        inline
2798        BLOB
2799        EOF
2800        cat err &&
2801        test_i18ngrep "nvalid dataref" err
2802'
2803
2804test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2805        sha1=$(grep :403 marks | cut -d\  -f2) &&
2806        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2807        commit refs/heads/S
2808        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2809        data <<COMMIT
2810        commit N
2811        COMMIT
2812        M 100644 ${sha1}x hello.c
2813        EOF
2814        cat err &&
2815        test_i18ngrep "space after SHA1" err
2816'
2817
2818#
2819# notemodify, three ways to say dataref
2820#
2821test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2822        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2823        commit refs/heads/S
2824        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2825        data <<COMMIT
2826        commit S note dataref markref
2827        COMMIT
2828        N :202x :302
2829        EOF
2830        cat err &&
2831        test_i18ngrep "space after mark" err
2832'
2833
2834test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2835        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2836        commit refs/heads/S
2837        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2838        data <<COMMIT
2839        commit S note dataref inline
2840        COMMIT
2841        N inlineX :302
2842        data <<BLOB
2843        note blob
2844        BLOB
2845        EOF
2846        cat err &&
2847        test_i18ngrep "nvalid dataref" err
2848'
2849
2850test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2851        sha1=$(grep :202 marks | cut -d\  -f2) &&
2852        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2853        commit refs/heads/S
2854        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2855        data <<COMMIT
2856        commit S note dataref sha1
2857        COMMIT
2858        N ${sha1}x :302
2859        EOF
2860        cat err &&
2861        test_i18ngrep "space after SHA1" err
2862'
2863
2864#
2865# notemodify, mark in commit-ish
2866#
2867test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2868        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2869        commit refs/heads/Snotes
2870        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2871        data <<COMMIT
2872        commit S note commit-ish
2873        COMMIT
2874        N :202 :302x
2875        EOF
2876        cat err &&
2877        test_i18ngrep "after mark" err
2878'
2879
2880#
2881# from
2882#
2883test_expect_success 'S: from with garbage after mark must fail' '
2884        test_must_fail \
2885        git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2886        commit refs/heads/S2
2887        mark :303
2888        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2889        data <<COMMIT
2890        commit 3
2891        COMMIT
2892        from :301x
2893        M 100644 :403 hello.c
2894        EOF
2895
2896
2897        # go create the commit, need it for merge test
2898        git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2899        commit refs/heads/S2
2900        mark :303
2901        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2902        data <<COMMIT
2903        commit 3
2904        COMMIT
2905        from :301
2906        M 100644 :403 hello.c
2907        EOF
2908
2909        # now evaluate the error
2910        cat err &&
2911        test_i18ngrep "after mark" err
2912'
2913
2914
2915#
2916# merge
2917#
2918test_expect_success 'S: merge with garbage after mark must fail' '
2919        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2920        commit refs/heads/S
2921        mark :304
2922        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2923        data <<COMMIT
2924        merge 4
2925        COMMIT
2926        from :302
2927        merge :303x
2928        M 100644 :403 hello.c
2929        EOF
2930        cat err &&
2931        test_i18ngrep "after mark" err
2932'
2933
2934#
2935# tag, from markref
2936#
2937test_expect_success 'S: tag with garbage after mark must fail' '
2938        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2939        tag refs/tags/Stag
2940        from :302x
2941        tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2942        data <<TAG
2943        tag S
2944        TAG
2945        EOF
2946        cat err &&
2947        test_i18ngrep "after mark" err
2948'
2949
2950#
2951# cat-blob markref
2952#
2953test_expect_success 'S: cat-blob with garbage after mark must fail' '
2954        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2955        cat-blob :403x
2956        EOF
2957        cat err &&
2958        test_i18ngrep "after mark" err
2959'
2960
2961#
2962# ls markref
2963#
2964test_expect_success 'S: ls with garbage after mark must fail' '
2965        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2966        ls :302x hello.c
2967        EOF
2968        cat err &&
2969        test_i18ngrep "space after mark" err
2970'
2971
2972test_expect_success 'S: ls with garbage after sha1 must fail' '
2973        sha1=$(grep :302 marks | cut -d\  -f2) &&
2974        test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2975        ls ${sha1}x hello.c
2976        EOF
2977        cat err &&
2978        test_i18ngrep "space after tree-ish" err
2979'
2980
2981###
2982### series T (ls)
2983###
2984# Setup is carried over from series S.
2985
2986test_expect_success 'T: ls root tree' '
2987        sed -e "s/Z\$//" >expect <<-EOF &&
2988        040000 tree $(git rev-parse S^{tree})   Z
2989        EOF
2990        sha1=$(git rev-parse --verify S) &&
2991        git fast-import --import-marks=marks <<-EOF >actual &&
2992        ls $sha1 ""
2993        EOF
2994        test_cmp expect actual
2995'
2996
2997test_expect_success 'T: delete branch' '
2998        git branch to-delete &&
2999        git fast-import <<-EOF &&
3000        reset refs/heads/to-delete
3001        from 0000000000000000000000000000000000000000
3002        EOF
3003        test_must_fail git rev-parse --verify refs/heads/to-delete
3004'
3005
3006test_expect_success 'T: empty reset doesnt delete branch' '
3007        git branch not-to-delete &&
3008        git fast-import <<-EOF &&
3009        reset refs/heads/not-to-delete
3010        EOF
3011        git show-ref &&
3012        git rev-parse --verify refs/heads/not-to-delete
3013'
3014
3015###
3016### series U (filedelete)
3017###
3018
3019test_expect_success 'U: initialize for U tests' '
3020        cat >input <<-INPUT_END &&
3021        commit refs/heads/U
3022        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3023        data <<COMMIT
3024        test setup
3025        COMMIT
3026        M 100644 inline hello.c
3027        data <<BLOB
3028        blob 1
3029        BLOB
3030        M 100644 inline good/night.txt
3031        data <<BLOB
3032        sleep well
3033        BLOB
3034        M 100644 inline good/bye.txt
3035        data <<BLOB
3036        au revoir
3037        BLOB
3038
3039        INPUT_END
3040
3041        git fast-import <input
3042'
3043
3044test_expect_success 'U: filedelete file succeeds' '
3045        cat >input <<-INPUT_END &&
3046        commit refs/heads/U
3047        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3048        data <<COMMIT
3049        delete good/night.txt
3050        COMMIT
3051        from refs/heads/U^0
3052        D good/night.txt
3053
3054        INPUT_END
3055
3056        git fast-import <input
3057'
3058
3059test_expect_success 'U: validate file delete result' '
3060        cat >expect <<-EOF &&
3061        :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D      good/night.txt
3062        EOF
3063
3064        git diff-tree -M -r U^1 U >actual &&
3065
3066        compare_diff_raw expect actual
3067'
3068
3069test_expect_success 'U: filedelete directory succeeds' '
3070        cat >input <<-INPUT_END &&
3071        commit refs/heads/U
3072        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3073        data <<COMMIT
3074        delete good dir
3075        COMMIT
3076        from refs/heads/U^0
3077        D good
3078
3079        INPUT_END
3080
3081        git fast-import <input
3082'
3083
3084test_expect_success 'U: validate directory delete result' '
3085        cat >expect <<-EOF &&
3086        :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D      good/bye.txt
3087        EOF
3088
3089        git diff-tree -M -r U^1 U >actual &&
3090
3091        compare_diff_raw expect actual
3092'
3093
3094test_expect_success 'U: filedelete root succeeds' '
3095        cat >input <<-INPUT_END &&
3096        commit refs/heads/U
3097        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3098        data <<COMMIT
3099        must succeed
3100        COMMIT
3101        from refs/heads/U^0
3102        D ""
3103
3104        INPUT_END
3105
3106        git fast-import <input
3107'
3108
3109test_expect_success 'U: validate root delete result' '
3110        cat >expect <<-EOF &&
3111        :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D      hello.c
3112        EOF
3113
3114        git diff-tree -M -r U^1 U >actual &&
3115
3116        compare_diff_raw expect actual
3117'
3118
3119test_done