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