t / t9300-fast-import.shon commit Teach fast-import to import subtrees named by tree id (334fba6)
   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
  10file2_data='file2
  11second line of EOF'
  12
  13file3_data='EOF
  14in 3rd file
  15 END'
  16
  17file4_data=abcd
  18file4_len=4
  19
  20file5_data='an inline file.
  21  we should see it later.'
  22
  23file6_data='#!/bin/sh
  24echo "$@"'
  25
  26###
  27### series A
  28###
  29
  30test_tick
  31cat >input <<INPUT_END
  32blob
  33mark :2
  34data <<EOF
  35$file2_data
  36EOF
  37
  38blob
  39mark :3
  40data <<END
  41$file3_data
  42END
  43
  44blob
  45mark :4
  46data $file4_len
  47$file4_data
  48commit refs/heads/master
  49mark :5
  50committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  51data <<COMMIT
  52initial
  53COMMIT
  54
  55M 644 :2 file2
  56M 644 :3 file3
  57M 755 :4 file4
  58
  59tag series-A
  60from :5
  61data <<EOF
  62An annotated tag without a tagger
  63EOF
  64
  65INPUT_END
  66test_expect_success \
  67    'A: create pack from stdin' \
  68    'git fast-import --export-marks=marks.out <input &&
  69         git whatchanged master'
  70test_expect_success \
  71        'A: verify pack' \
  72        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
  73
  74cat >expect <<EOF
  75author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  76committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  77
  78initial
  79EOF
  80test_expect_success \
  81        'A: verify commit' \
  82        'git cat-file commit master | sed 1d >actual &&
  83        test_cmp expect actual'
  84
  85cat >expect <<EOF
  86100644 blob file2
  87100644 blob file3
  88100755 blob file4
  89EOF
  90test_expect_success \
  91        'A: verify tree' \
  92        'git cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
  93         test_cmp expect actual'
  94
  95echo "$file2_data" >expect
  96test_expect_success \
  97        'A: verify file2' \
  98        'git cat-file blob master:file2 >actual && test_cmp expect actual'
  99
 100echo "$file3_data" >expect
 101test_expect_success \
 102        'A: verify file3' \
 103        'git cat-file blob master:file3 >actual && test_cmp expect actual'
 104
 105printf "$file4_data" >expect
 106test_expect_success \
 107        'A: verify file4' \
 108        'git cat-file blob master:file4 >actual && test_cmp expect actual'
 109
 110cat >expect <<EOF
 111object $(git rev-parse refs/heads/master)
 112type commit
 113tag series-A
 114
 115An annotated tag without a tagger
 116EOF
 117test_expect_success 'A: verify tag/series-A' '
 118        git cat-file tag tags/series-A >actual &&
 119        test_cmp expect actual
 120'
 121
 122cat >expect <<EOF
 123:2 `git rev-parse --verify master:file2`
 124:3 `git rev-parse --verify master:file3`
 125:4 `git rev-parse --verify master:file4`
 126:5 `git rev-parse --verify master^0`
 127EOF
 128test_expect_success \
 129        'A: verify marks output' \
 130        'test_cmp expect marks.out'
 131
 132test_expect_success \
 133        'A: verify marks import' \
 134        'git fast-import \
 135                --import-marks=marks.out \
 136                --export-marks=marks.new \
 137                </dev/null &&
 138        test_cmp expect marks.new'
 139
 140test_tick
 141cat >input <<INPUT_END
 142commit refs/heads/verify--import-marks
 143committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 144data <<COMMIT
 145recreate from :5
 146COMMIT
 147
 148from :5
 149M 755 :2 copy-of-file2
 150
 151INPUT_END
 152test_expect_success \
 153        'A: verify marks import does not crash' \
 154        'git fast-import --import-marks=marks.out <input &&
 155         git whatchanged verify--import-marks'
 156test_expect_success \
 157        'A: verify pack' \
 158        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 159cat >expect <<EOF
 160:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
 161EOF
 162git diff-tree -M -r master verify--import-marks >actual
 163test_expect_success \
 164        'A: verify diff' \
 165        'compare_diff_raw expect actual &&
 166         test `git rev-parse --verify master:file2` \
 167            = `git rev-parse --verify verify--import-marks:copy-of-file2`'
 168
 169###
 170### series B
 171###
 172
 173test_tick
 174cat >input <<INPUT_END
 175commit refs/heads/branch
 176mark :1
 177committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 178data <<COMMIT
 179corrupt
 180COMMIT
 181
 182from refs/heads/master
 183M 755 0000000000000000000000000000000000000001 zero1
 184
 185INPUT_END
 186test_expect_success 'B: fail on invalid blob sha1' '
 187    test_must_fail git fast-import <input
 188'
 189rm -f .git/objects/pack_* .git/objects/index_*
 190
 191cat >input <<INPUT_END
 192commit .badbranchname
 193committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 194data <<COMMIT
 195corrupt
 196COMMIT
 197
 198from refs/heads/master
 199
 200INPUT_END
 201test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
 202    test_must_fail git fast-import <input
 203'
 204rm -f .git/objects/pack_* .git/objects/index_*
 205
 206cat >input <<INPUT_END
 207commit bad[branch]name
 208committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 209data <<COMMIT
 210corrupt
 211COMMIT
 212
 213from refs/heads/master
 214
 215INPUT_END
 216test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
 217    test_must_fail git fast-import <input
 218'
 219rm -f .git/objects/pack_* .git/objects/index_*
 220
 221cat >input <<INPUT_END
 222commit TEMP_TAG
 223committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 224data <<COMMIT
 225tag base
 226COMMIT
 227
 228from refs/heads/master
 229
 230INPUT_END
 231test_expect_success \
 232    'B: accept branch name "TEMP_TAG"' \
 233    'git fast-import <input &&
 234         test -f .git/TEMP_TAG &&
 235         test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
 236rm -f .git/TEMP_TAG
 237
 238###
 239### series C
 240###
 241
 242newf=`echo hi newf | git hash-object -w --stdin`
 243oldf=`git rev-parse --verify master:file2`
 244test_tick
 245cat >input <<INPUT_END
 246commit refs/heads/branch
 247committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 248data <<COMMIT
 249second
 250COMMIT
 251
 252from refs/heads/master
 253M 644 $oldf file2/oldf
 254M 755 $newf file2/newf
 255D file3
 256
 257INPUT_END
 258test_expect_success \
 259    'C: incremental import create pack from stdin' \
 260    'git fast-import <input &&
 261         git whatchanged branch'
 262test_expect_success \
 263        'C: verify pack' \
 264        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 265test_expect_success \
 266        'C: validate reuse existing blob' \
 267        'test $newf = `git rev-parse --verify branch:file2/newf`
 268         test $oldf = `git rev-parse --verify branch:file2/oldf`'
 269
 270cat >expect <<EOF
 271parent `git rev-parse --verify master^0`
 272author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 273committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 274
 275second
 276EOF
 277test_expect_success \
 278        'C: verify commit' \
 279        'git cat-file commit branch | sed 1d >actual &&
 280         test_cmp expect actual'
 281
 282cat >expect <<EOF
 283:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 284:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 285:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 286EOF
 287git diff-tree -M -r master branch >actual
 288test_expect_success \
 289        'C: validate rename result' \
 290        'compare_diff_raw expect actual'
 291
 292###
 293### series D
 294###
 295
 296test_tick
 297cat >input <<INPUT_END
 298commit refs/heads/branch
 299committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 300data <<COMMIT
 301third
 302COMMIT
 303
 304from refs/heads/branch^0
 305M 644 inline newdir/interesting
 306data <<EOF
 307$file5_data
 308EOF
 309
 310M 755 inline newdir/exec.sh
 311data <<EOF
 312$file6_data
 313EOF
 314
 315INPUT_END
 316test_expect_success \
 317    'D: inline data in commit' \
 318    'git fast-import <input &&
 319         git whatchanged branch'
 320test_expect_success \
 321        'D: verify pack' \
 322        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 323
 324cat >expect <<EOF
 325:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
 326:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
 327EOF
 328git diff-tree -M -r branch^ branch >actual
 329test_expect_success \
 330        'D: validate new files added' \
 331        'compare_diff_raw expect actual'
 332
 333echo "$file5_data" >expect
 334test_expect_success \
 335        'D: verify file5' \
 336        'git cat-file blob branch:newdir/interesting >actual &&
 337         test_cmp expect actual'
 338
 339echo "$file6_data" >expect
 340test_expect_success \
 341        'D: verify file6' \
 342        'git cat-file blob branch:newdir/exec.sh >actual &&
 343         test_cmp expect actual'
 344
 345###
 346### series E
 347###
 348
 349cat >input <<INPUT_END
 350commit refs/heads/branch
 351author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 352committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 353data <<COMMIT
 354RFC 2822 type date
 355COMMIT
 356
 357from refs/heads/branch^0
 358
 359INPUT_END
 360test_expect_success 'E: rfc2822 date, --date-format=raw' '
 361    test_must_fail git fast-import --date-format=raw <input
 362'
 363test_expect_success \
 364    'E: rfc2822 date, --date-format=rfc2822' \
 365    'git fast-import --date-format=rfc2822 <input'
 366test_expect_success \
 367        'E: verify pack' \
 368        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 369
 370cat >expect <<EOF
 371author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
 372committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
 373
 374RFC 2822 type date
 375EOF
 376test_expect_success \
 377        'E: verify commit' \
 378        'git cat-file commit branch | sed 1,2d >actual &&
 379        test_cmp expect actual'
 380
 381###
 382### series F
 383###
 384
 385old_branch=`git rev-parse --verify branch^0`
 386test_tick
 387cat >input <<INPUT_END
 388commit refs/heads/branch
 389committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 390data <<COMMIT
 391losing things already?
 392COMMIT
 393
 394from refs/heads/branch~1
 395
 396reset refs/heads/other
 397from refs/heads/branch
 398
 399INPUT_END
 400test_expect_success \
 401    'F: non-fast-forward update skips' \
 402    'if git fast-import <input
 403         then
 404                echo BAD gfi did not fail
 405                return 1
 406         else
 407                if test $old_branch = `git rev-parse --verify branch^0`
 408                then
 409                        : branch unaffected and failure returned
 410                        return 0
 411                else
 412                        echo BAD gfi changed branch $old_branch
 413                        return 1
 414                fi
 415         fi
 416        '
 417test_expect_success \
 418        'F: verify pack' \
 419        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 420
 421cat >expect <<EOF
 422tree `git rev-parse branch~1^{tree}`
 423parent `git rev-parse branch~1`
 424author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 425committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 426
 427losing things already?
 428EOF
 429test_expect_success \
 430        'F: verify other commit' \
 431        'git cat-file commit other >actual &&
 432        test_cmp expect actual'
 433
 434###
 435### series G
 436###
 437
 438old_branch=`git rev-parse --verify branch^0`
 439test_tick
 440cat >input <<INPUT_END
 441commit refs/heads/branch
 442committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 443data <<COMMIT
 444losing things already?
 445COMMIT
 446
 447from refs/heads/branch~1
 448
 449INPUT_END
 450test_expect_success \
 451    'G: non-fast-forward update forced' \
 452    'git fast-import --force <input'
 453test_expect_success \
 454        'G: verify pack' \
 455        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 456test_expect_success \
 457        'G: branch changed, but logged' \
 458        'test $old_branch != `git rev-parse --verify branch^0` &&
 459         test $old_branch = `git rev-parse --verify branch@{1}`'
 460
 461###
 462### series H
 463###
 464
 465test_tick
 466cat >input <<INPUT_END
 467commit refs/heads/H
 468committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 469data <<COMMIT
 470third
 471COMMIT
 472
 473from refs/heads/branch^0
 474M 644 inline i-will-die
 475data <<EOF
 476this file will never exist.
 477EOF
 478
 479deleteall
 480M 644 inline h/e/l/lo
 481data <<EOF
 482$file5_data
 483EOF
 484
 485INPUT_END
 486test_expect_success \
 487    'H: deletall, add 1' \
 488    'git fast-import <input &&
 489         git whatchanged H'
 490test_expect_success \
 491        'H: verify pack' \
 492        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 493
 494cat >expect <<EOF
 495:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
 496:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
 497:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
 498:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
 499:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
 500EOF
 501git diff-tree -M -r H^ H >actual
 502test_expect_success \
 503        'H: validate old files removed, new files added' \
 504        'compare_diff_raw expect actual'
 505
 506echo "$file5_data" >expect
 507test_expect_success \
 508        'H: verify file' \
 509        'git cat-file blob H:h/e/l/lo >actual &&
 510         test_cmp expect actual'
 511
 512###
 513### series I
 514###
 515
 516cat >input <<INPUT_END
 517commit refs/heads/export-boundary
 518committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 519data <<COMMIT
 520we have a border.  its only 40 characters wide.
 521COMMIT
 522
 523from refs/heads/branch
 524
 525INPUT_END
 526test_expect_success \
 527    'I: export-pack-edges' \
 528    'git fast-import --export-pack-edges=edges.list <input'
 529
 530cat >expect <<EOF
 531.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
 532EOF
 533test_expect_success \
 534        'I: verify edge list' \
 535        'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
 536         test_cmp expect actual'
 537
 538###
 539### series J
 540###
 541
 542cat >input <<INPUT_END
 543commit refs/heads/J
 544committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 545data <<COMMIT
 546create J
 547COMMIT
 548
 549from refs/heads/branch
 550
 551reset refs/heads/J
 552
 553commit refs/heads/J
 554committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 555data <<COMMIT
 556initialize J
 557COMMIT
 558
 559INPUT_END
 560test_expect_success \
 561    'J: reset existing branch creates empty commit' \
 562    'git fast-import <input'
 563test_expect_success \
 564        'J: branch has 1 commit, empty tree' \
 565        'test 1 = `git rev-list J | wc -l` &&
 566         test 0 = `git ls-tree J | wc -l`'
 567
 568###
 569### series K
 570###
 571
 572cat >input <<INPUT_END
 573commit refs/heads/K
 574committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 575data <<COMMIT
 576create K
 577COMMIT
 578
 579from refs/heads/branch
 580
 581commit refs/heads/K
 582committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 583data <<COMMIT
 584redo K
 585COMMIT
 586
 587from refs/heads/branch^1
 588
 589INPUT_END
 590test_expect_success \
 591    'K: reinit branch with from' \
 592    'git fast-import <input'
 593test_expect_success \
 594    'K: verify K^1 = branch^1' \
 595    'test `git rev-parse --verify branch^1` \
 596                = `git rev-parse --verify K^1`'
 597
 598###
 599### series L
 600###
 601
 602cat >input <<INPUT_END
 603blob
 604mark :1
 605data <<EOF
 606some data
 607EOF
 608
 609blob
 610mark :2
 611data <<EOF
 612other data
 613EOF
 614
 615commit refs/heads/L
 616committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 617data <<COMMIT
 618create L
 619COMMIT
 620
 621M 644 :1 b.
 622M 644 :1 b/other
 623M 644 :1 ba
 624
 625commit refs/heads/L
 626committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 627data <<COMMIT
 628update L
 629COMMIT
 630
 631M 644 :2 b.
 632M 644 :2 b/other
 633M 644 :2 ba
 634INPUT_END
 635
 636cat >expect <<EXPECT_END
 637:100644 100644 4268632... 55d3a52... M  b.
 638:040000 040000 0ae5cac... 443c768... M  b
 639:100644 100644 4268632... 55d3a52... M  ba
 640EXPECT_END
 641
 642test_expect_success \
 643    'L: verify internal tree sorting' \
 644        'git fast-import <input &&
 645         git diff-tree --abbrev --raw L^ L >output &&
 646         test_cmp expect output'
 647
 648###
 649### series M
 650###
 651
 652test_tick
 653cat >input <<INPUT_END
 654commit refs/heads/M1
 655committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 656data <<COMMIT
 657file rename
 658COMMIT
 659
 660from refs/heads/branch^0
 661R file2/newf file2/n.e.w.f
 662
 663INPUT_END
 664
 665cat >expect <<EOF
 666:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
 667EOF
 668test_expect_success \
 669        'M: rename file in same subdirectory' \
 670        'git fast-import <input &&
 671         git diff-tree -M -r M1^ M1 >actual &&
 672         compare_diff_raw expect actual'
 673
 674cat >input <<INPUT_END
 675commit refs/heads/M2
 676committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 677data <<COMMIT
 678file rename
 679COMMIT
 680
 681from refs/heads/branch^0
 682R file2/newf i/am/new/to/you
 683
 684INPUT_END
 685
 686cat >expect <<EOF
 687:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
 688EOF
 689test_expect_success \
 690        'M: rename file to new subdirectory' \
 691        'git fast-import <input &&
 692         git diff-tree -M -r M2^ M2 >actual &&
 693         compare_diff_raw expect actual'
 694
 695cat >input <<INPUT_END
 696commit refs/heads/M3
 697committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 698data <<COMMIT
 699file rename
 700COMMIT
 701
 702from refs/heads/M2^0
 703R i other/sub
 704
 705INPUT_END
 706
 707cat >expect <<EOF
 708:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
 709EOF
 710test_expect_success \
 711        'M: rename subdirectory to new subdirectory' \
 712        'git fast-import <input &&
 713         git diff-tree -M -r M3^ M3 >actual &&
 714         compare_diff_raw expect actual'
 715
 716###
 717### series N
 718###
 719
 720test_tick
 721cat >input <<INPUT_END
 722commit refs/heads/N1
 723committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 724data <<COMMIT
 725file copy
 726COMMIT
 727
 728from refs/heads/branch^0
 729C file2/newf file2/n.e.w.f
 730
 731INPUT_END
 732
 733cat >expect <<EOF
 734:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
 735EOF
 736test_expect_success \
 737        'N: copy file in same subdirectory' \
 738        'git fast-import <input &&
 739         git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
 740         compare_diff_raw expect actual'
 741
 742cat >input <<INPUT_END
 743commit refs/heads/N2
 744committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 745data <<COMMIT
 746clean directory copy
 747COMMIT
 748
 749from refs/heads/branch^0
 750C file2 file3
 751
 752commit refs/heads/N2
 753committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 754data <<COMMIT
 755modify directory copy
 756COMMIT
 757
 758M 644 inline file3/file5
 759data <<EOF
 760$file5_data
 761EOF
 762
 763INPUT_END
 764
 765cat >expect <<EOF
 766:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
 767:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
 768:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
 769EOF
 770test_expect_success \
 771        'N: copy then modify subdirectory' \
 772        'git fast-import <input &&
 773         git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
 774         compare_diff_raw expect actual'
 775
 776cat >input <<INPUT_END
 777commit refs/heads/N3
 778committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 779data <<COMMIT
 780dirty directory copy
 781COMMIT
 782
 783from refs/heads/branch^0
 784M 644 inline file2/file5
 785data <<EOF
 786$file5_data
 787EOF
 788
 789C file2 file3
 790D file2/file5
 791
 792INPUT_END
 793
 794test_expect_success \
 795        'N: copy dirty subdirectory' \
 796        'git fast-import <input &&
 797         test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
 798
 799test_expect_success \
 800        'N: copy directory by id' \
 801        'cat >expect <<-\EOF &&
 802        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
 803        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
 804        EOF
 805         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 806         cat >input <<-INPUT_END &&
 807        commit refs/heads/N4
 808        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 809        data <<COMMIT
 810        copy by tree hash
 811        COMMIT
 812
 813        from refs/heads/branch^0
 814        M 040000 $subdir file3
 815        INPUT_END
 816         git fast-import <input &&
 817         git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
 818         compare_diff_raw expect actual'
 819
 820test_expect_success \
 821        'N: modify copied tree' \
 822        'cat >expect <<-\EOF &&
 823        :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
 824        :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
 825        :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
 826        EOF
 827         subdir=$(git rev-parse refs/heads/branch^0:file2) &&
 828         cat >input <<-INPUT_END &&
 829        commit refs/heads/N5
 830        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 831        data <<COMMIT
 832        copy by tree hash
 833        COMMIT
 834
 835        from refs/heads/branch^0
 836        M 040000 $subdir file3
 837
 838        commit refs/heads/N5
 839        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 840        data <<COMMIT
 841        modify directory copy
 842        COMMIT
 843
 844        M 644 inline file3/file5
 845        data <<EOF
 846        $file5_data
 847        EOF
 848        INPUT_END
 849         git fast-import <input &&
 850         git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
 851         compare_diff_raw expect actual'
 852
 853###
 854### series O
 855###
 856
 857cat >input <<INPUT_END
 858#we will
 859commit refs/heads/O1
 860# -- ignore all of this text
 861committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 862# $GIT_COMMITTER_NAME has inserted here for his benefit.
 863data <<COMMIT
 864dirty directory copy
 865COMMIT
 866
 867# don't forget the import blank line!
 868#
 869# yes, we started from our usual base of branch^0.
 870# i like branch^0.
 871from refs/heads/branch^0
 872# and we need to reuse file2/file5 from N3 above.
 873M 644 inline file2/file5
 874# otherwise the tree will be different
 875data <<EOF
 876$file5_data
 877EOF
 878
 879# don't forget to copy file2 to file3
 880C file2 file3
 881#
 882# or to delete file5 from file2.
 883D file2/file5
 884# are we done yet?
 885
 886INPUT_END
 887
 888test_expect_success \
 889        'O: comments are all skipped' \
 890        'git fast-import <input &&
 891         test `git rev-parse N3` = `git rev-parse O1`'
 892
 893cat >input <<INPUT_END
 894commit refs/heads/O2
 895committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 896data <<COMMIT
 897dirty directory copy
 898COMMIT
 899from refs/heads/branch^0
 900M 644 inline file2/file5
 901data <<EOF
 902$file5_data
 903EOF
 904C file2 file3
 905D file2/file5
 906
 907INPUT_END
 908
 909test_expect_success \
 910        'O: blank lines not necessary after data commands' \
 911        'git fast-import <input &&
 912         test `git rev-parse N3` = `git rev-parse O2`'
 913
 914test_expect_success \
 915        'O: repack before next test' \
 916        'git repack -a -d'
 917
 918cat >input <<INPUT_END
 919commit refs/heads/O3
 920committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 921data <<COMMIT
 922zstring
 923COMMIT
 924commit refs/heads/O3
 925committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 926data <<COMMIT
 927zof
 928COMMIT
 929checkpoint
 930commit refs/heads/O3
 931mark :5
 932committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 933data <<COMMIT
 934zempty
 935COMMIT
 936checkpoint
 937commit refs/heads/O3
 938committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 939data <<COMMIT
 940zcommits
 941COMMIT
 942reset refs/tags/O3-2nd
 943from :5
 944reset refs/tags/O3-3rd
 945from :5
 946INPUT_END
 947
 948cat >expect <<INPUT_END
 949string
 950of
 951empty
 952commits
 953INPUT_END
 954test_expect_success \
 955        'O: blank lines not necessary after other commands' \
 956        'git fast-import <input &&
 957         test 8 = `find .git/objects/pack -type f | wc -l` &&
 958         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
 959         git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
 960         test_cmp expect actual'
 961
 962cat >input <<INPUT_END
 963commit refs/heads/O4
 964committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 965data <<COMMIT
 966zstring
 967COMMIT
 968commit refs/heads/O4
 969committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 970data <<COMMIT
 971zof
 972COMMIT
 973progress Two commits down, 2 to go!
 974commit refs/heads/O4
 975committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 976data <<COMMIT
 977zempty
 978COMMIT
 979progress Three commits down, 1 to go!
 980commit refs/heads/O4
 981committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 982data <<COMMIT
 983zcommits
 984COMMIT
 985progress I'm done!
 986INPUT_END
 987test_expect_success \
 988        'O: progress outputs as requested by input' \
 989        'git fast-import <input >actual &&
 990         grep "progress " <input >expect &&
 991         test_cmp expect actual'
 992
 993###
 994### series P (gitlinks)
 995###
 996
 997cat >input <<INPUT_END
 998blob
 999mark :1
1000data 10
1001test file
1002
1003reset refs/heads/sub
1004commit refs/heads/sub
1005mark :2
1006committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007data 12
1008sub_initial
1009M 100644 :1 file
1010
1011blob
1012mark :3
1013data <<DATAEND
1014[submodule "sub"]
1015        path = sub
1016        url = "`pwd`/sub"
1017DATAEND
1018
1019commit refs/heads/subuse1
1020mark :4
1021committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1022data 8
1023initial
1024from refs/heads/master
1025M 100644 :3 .gitmodules
1026M 160000 :2 sub
1027
1028blob
1029mark :5
1030data 20
1031test file
1032more data
1033
1034commit refs/heads/sub
1035mark :6
1036committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1037data 11
1038sub_second
1039from :2
1040M 100644 :5 file
1041
1042commit refs/heads/subuse1
1043mark :7
1044committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1045data 7
1046second
1047from :4
1048M 160000 :6 sub
1049
1050INPUT_END
1051
1052test_expect_success \
1053        'P: supermodule & submodule mix' \
1054        'git fast-import <input &&
1055         git checkout subuse1 &&
1056         rm -rf sub && mkdir sub && cd sub &&
1057         git init &&
1058         git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1059         git checkout master &&
1060         cd .. &&
1061         git submodule init &&
1062         git submodule update'
1063
1064SUBLAST=$(git rev-parse --verify sub)
1065SUBPREV=$(git rev-parse --verify sub^)
1066
1067cat >input <<INPUT_END
1068blob
1069mark :1
1070data <<DATAEND
1071[submodule "sub"]
1072        path = sub
1073        url = "`pwd`/sub"
1074DATAEND
1075
1076commit refs/heads/subuse2
1077mark :2
1078committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1079data 8
1080initial
1081from refs/heads/master
1082M 100644 :1 .gitmodules
1083M 160000 $SUBPREV sub
1084
1085commit refs/heads/subuse2
1086mark :3
1087committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1088data 7
1089second
1090from :2
1091M 160000 $SUBLAST sub
1092
1093INPUT_END
1094
1095test_expect_success \
1096        'P: verbatim SHA gitlinks' \
1097        'git branch -D sub &&
1098         git gc && git prune &&
1099         git fast-import <input &&
1100         test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1101
1102test_tick
1103cat >input <<INPUT_END
1104commit refs/heads/subuse3
1105mark :1
1106committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1107data <<COMMIT
1108corrupt
1109COMMIT
1110
1111from refs/heads/subuse2
1112M 160000 inline sub
1113data <<DATA
1114$SUBPREV
1115DATA
1116
1117INPUT_END
1118
1119test_expect_success 'P: fail on inline gitlink' '
1120    test_must_fail git fast-import <input'
1121
1122test_tick
1123cat >input <<INPUT_END
1124blob
1125mark :1
1126data <<DATA
1127$SUBPREV
1128DATA
1129
1130commit refs/heads/subuse3
1131mark :2
1132committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1133data <<COMMIT
1134corrupt
1135COMMIT
1136
1137from refs/heads/subuse2
1138M 160000 :1 sub
1139
1140INPUT_END
1141
1142test_expect_success 'P: fail on blob mark in gitlink' '
1143    test_must_fail git fast-import <input'
1144
1145###
1146### series Q (notes)
1147###
1148
1149note1_data="The first note for the first commit"
1150note2_data="The first note for the second commit"
1151note3_data="The first note for the third commit"
1152note1b_data="The second note for the first commit"
1153note1c_data="The third note for the first commit"
1154note2b_data="The second note for the second commit"
1155
1156test_tick
1157cat >input <<INPUT_END
1158blob
1159mark :2
1160data <<EOF
1161$file2_data
1162EOF
1163
1164commit refs/heads/notes-test
1165mark :3
1166committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1167data <<COMMIT
1168first (:3)
1169COMMIT
1170
1171M 644 :2 file2
1172
1173blob
1174mark :4
1175data $file4_len
1176$file4_data
1177commit refs/heads/notes-test
1178mark :5
1179committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1180data <<COMMIT
1181second (:5)
1182COMMIT
1183
1184M 644 :4 file4
1185
1186commit refs/heads/notes-test
1187mark :6
1188committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1189data <<COMMIT
1190third (:6)
1191COMMIT
1192
1193M 644 inline file5
1194data <<EOF
1195$file5_data
1196EOF
1197
1198M 755 inline file6
1199data <<EOF
1200$file6_data
1201EOF
1202
1203blob
1204mark :7
1205data <<EOF
1206$note1_data
1207EOF
1208
1209blob
1210mark :8
1211data <<EOF
1212$note2_data
1213EOF
1214
1215commit refs/notes/foobar
1216mark :9
1217committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1218data <<COMMIT
1219notes (:9)
1220COMMIT
1221
1222N :7 :3
1223N :8 :5
1224N inline :6
1225data <<EOF
1226$note3_data
1227EOF
1228
1229commit refs/notes/foobar
1230mark :10
1231committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1232data <<COMMIT
1233notes (:10)
1234COMMIT
1235
1236N inline :3
1237data <<EOF
1238$note1b_data
1239EOF
1240
1241commit refs/notes/foobar2
1242mark :11
1243committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1244data <<COMMIT
1245notes (:11)
1246COMMIT
1247
1248N inline :3
1249data <<EOF
1250$note1c_data
1251EOF
1252
1253commit refs/notes/foobar
1254mark :12
1255committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1256data <<COMMIT
1257notes (:12)
1258COMMIT
1259
1260deleteall
1261N inline :5
1262data <<EOF
1263$note2b_data
1264EOF
1265
1266INPUT_END
1267
1268test_expect_success \
1269        'Q: commit notes' \
1270        'git fast-import <input &&
1271         git whatchanged notes-test'
1272test_expect_success \
1273        'Q: verify pack' \
1274        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1275
1276commit1=$(git rev-parse notes-test~2)
1277commit2=$(git rev-parse notes-test^)
1278commit3=$(git rev-parse notes-test)
1279
1280cat >expect <<EOF
1281author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1282committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1283
1284first (:3)
1285EOF
1286test_expect_success \
1287        'Q: verify first commit' \
1288        'git cat-file commit notes-test~2 | sed 1d >actual &&
1289        test_cmp expect actual'
1290
1291cat >expect <<EOF
1292parent $commit1
1293author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1294committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1295
1296second (:5)
1297EOF
1298test_expect_success \
1299        'Q: verify second commit' \
1300        'git cat-file commit notes-test^ | sed 1d >actual &&
1301        test_cmp expect actual'
1302
1303cat >expect <<EOF
1304parent $commit2
1305author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1306committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1307
1308third (:6)
1309EOF
1310test_expect_success \
1311        'Q: verify third commit' \
1312        'git cat-file commit notes-test | sed 1d >actual &&
1313        test_cmp expect actual'
1314
1315cat >expect <<EOF
1316author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1317committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1318
1319notes (:9)
1320EOF
1321test_expect_success \
1322        'Q: verify first notes commit' \
1323        'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1324        test_cmp expect actual'
1325
1326cat >expect.unsorted <<EOF
1327100644 blob $commit1
1328100644 blob $commit2
1329100644 blob $commit3
1330EOF
1331cat expect.unsorted | sort >expect
1332test_expect_success \
1333        'Q: verify first notes tree' \
1334        'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1335         test_cmp expect actual'
1336
1337echo "$note1_data" >expect
1338test_expect_success \
1339        'Q: verify first note for first commit' \
1340        'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1341
1342echo "$note2_data" >expect
1343test_expect_success \
1344        'Q: verify first note for second commit' \
1345        'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1346
1347echo "$note3_data" >expect
1348test_expect_success \
1349        'Q: verify first note for third commit' \
1350        'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1351
1352cat >expect <<EOF
1353parent `git rev-parse --verify refs/notes/foobar~2`
1354author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1355committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1356
1357notes (:10)
1358EOF
1359test_expect_success \
1360        'Q: verify second notes commit' \
1361        'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1362        test_cmp expect actual'
1363
1364cat >expect.unsorted <<EOF
1365100644 blob $commit1
1366100644 blob $commit2
1367100644 blob $commit3
1368EOF
1369cat expect.unsorted | sort >expect
1370test_expect_success \
1371        'Q: verify second notes tree' \
1372        'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1373         test_cmp expect actual'
1374
1375echo "$note1b_data" >expect
1376test_expect_success \
1377        'Q: verify second note for first commit' \
1378        'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1379
1380echo "$note2_data" >expect
1381test_expect_success \
1382        'Q: verify first note for second commit' \
1383        'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1384
1385echo "$note3_data" >expect
1386test_expect_success \
1387        'Q: verify first note for third commit' \
1388        'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1389
1390cat >expect <<EOF
1391author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1392committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1393
1394notes (:11)
1395EOF
1396test_expect_success \
1397        'Q: verify third notes commit' \
1398        'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1399        test_cmp expect actual'
1400
1401cat >expect.unsorted <<EOF
1402100644 blob $commit1
1403EOF
1404cat expect.unsorted | sort >expect
1405test_expect_success \
1406        'Q: verify third notes tree' \
1407        'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]*  / /" >actual &&
1408         test_cmp expect actual'
1409
1410echo "$note1c_data" >expect
1411test_expect_success \
1412        'Q: verify third note for first commit' \
1413        'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1414
1415cat >expect <<EOF
1416parent `git rev-parse --verify refs/notes/foobar^`
1417author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1418committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1419
1420notes (:12)
1421EOF
1422test_expect_success \
1423        'Q: verify fourth notes commit' \
1424        'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1425        test_cmp expect actual'
1426
1427cat >expect.unsorted <<EOF
1428100644 blob $commit2
1429EOF
1430cat expect.unsorted | sort >expect
1431test_expect_success \
1432        'Q: verify fourth notes tree' \
1433        'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]*   / /" >actual &&
1434         test_cmp expect actual'
1435
1436echo "$note2b_data" >expect
1437test_expect_success \
1438        'Q: verify second note for second commit' \
1439        'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1440
1441###
1442### series R (feature and option)
1443###
1444
1445cat >input <<EOF
1446feature no-such-feature-exists
1447EOF
1448
1449test_expect_success 'R: abort on unsupported feature' '
1450        test_must_fail git fast-import <input
1451'
1452
1453cat >input <<EOF
1454feature date-format=now
1455EOF
1456
1457test_expect_success 'R: supported feature is accepted' '
1458        git fast-import <input
1459'
1460
1461cat >input << EOF
1462blob
1463data 3
1464hi
1465feature date-format=now
1466EOF
1467
1468test_expect_success 'R: abort on receiving feature after data command' '
1469        test_must_fail git fast-import <input
1470'
1471
1472cat >input << EOF
1473feature import-marks=git.marks
1474feature import-marks=git2.marks
1475EOF
1476
1477test_expect_success 'R: only one import-marks feature allowed per stream' '
1478        test_must_fail git fast-import <input
1479'
1480
1481cat >input << EOF
1482feature export-marks=git.marks
1483blob
1484mark :1
1485data 3
1486hi
1487
1488EOF
1489
1490test_expect_success \
1491    'R: export-marks feature results in a marks file being created' \
1492    'cat input | git fast-import &&
1493    grep :1 git.marks'
1494
1495test_expect_success \
1496    'R: export-marks options can be overriden by commandline options' \
1497    'cat input | git fast-import --export-marks=other.marks &&
1498    grep :1 other.marks'
1499
1500cat >input << EOF
1501feature import-marks=marks.out
1502feature export-marks=marks.new
1503EOF
1504
1505test_expect_success \
1506    'R: import to output marks works without any content' \
1507    'cat input | git fast-import &&
1508    test_cmp marks.out marks.new'
1509
1510cat >input <<EOF
1511feature import-marks=nonexistant.marks
1512feature export-marks=marks.new
1513EOF
1514
1515test_expect_success \
1516    'R: import marks prefers commandline marks file over the stream' \
1517    'cat input | git fast-import --import-marks=marks.out &&
1518    test_cmp marks.out marks.new'
1519
1520
1521cat >input <<EOF
1522feature import-marks=nonexistant.marks
1523feature export-marks=combined.marks
1524EOF
1525
1526test_expect_success 'R: multiple --import-marks= should be honoured' '
1527    head -n2 marks.out > one.marks &&
1528    tail -n +3 marks.out > two.marks &&
1529    git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
1530    test_cmp marks.out combined.marks
1531'
1532
1533cat >input <<EOF
1534feature relative-marks
1535feature import-marks=relative.in
1536feature export-marks=relative.out
1537EOF
1538
1539test_expect_success 'R: feature relative-marks should be honoured' '
1540    mkdir -p .git/info/fast-import/ &&
1541    cp marks.new .git/info/fast-import/relative.in &&
1542    git fast-import <input &&
1543    test_cmp marks.new .git/info/fast-import/relative.out
1544'
1545
1546cat >input <<EOF
1547feature relative-marks
1548feature import-marks=relative.in
1549feature no-relative-marks
1550feature export-marks=non-relative.out
1551EOF
1552
1553test_expect_success 'R: feature no-relative-marks should be honoured' '
1554    git fast-import <input &&
1555    test_cmp marks.new non-relative.out
1556'
1557
1558cat >input << EOF
1559option git quiet
1560blob
1561data 3
1562hi
1563
1564EOF
1565
1566touch empty
1567
1568test_expect_success 'R: quiet option results in no stats being output' '
1569    cat input | git fast-import 2> output &&
1570    test_cmp empty output
1571'
1572
1573cat >input <<EOF
1574option git non-existing-option
1575EOF
1576
1577test_expect_success 'R: die on unknown option' '
1578    test_must_fail git fast-import <input
1579'
1580
1581test_expect_success 'R: unknown commandline options are rejected' '\
1582    test_must_fail git fast-import --non-existing-option < /dev/null
1583'
1584
1585cat >input <<EOF
1586option non-existing-vcs non-existing-option
1587EOF
1588
1589test_expect_success 'R: ignore non-git options' '
1590    git fast-import <input
1591'
1592
1593##
1594## R: very large blobs
1595##
1596blobsize=$((2*1024*1024 + 53))
1597test-genrandom bar $blobsize >expect
1598cat >input <<INPUT_END
1599commit refs/heads/big-file
1600committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1601data <<COMMIT
1602R - big file
1603COMMIT
1604
1605M 644 inline big1
1606data $blobsize
1607INPUT_END
1608cat expect >>input
1609cat >>input <<INPUT_END
1610M 644 inline big2
1611data $blobsize
1612INPUT_END
1613cat expect >>input
1614echo >>input
1615
1616test_expect_success \
1617        'R: blob bigger than threshold' \
1618        'test_create_repo R &&
1619         git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
1620test_expect_success \
1621        'R: verify created pack' \
1622        ': >verify &&
1623         for p in R/.git/objects/pack/*.pack;
1624         do
1625           git verify-pack -v $p >>verify || exit;
1626         done'
1627test_expect_success \
1628        'R: verify written objects' \
1629        'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
1630         test_cmp expect actual &&
1631         a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
1632         b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
1633         test $a = $b'
1634test_expect_success \
1635        'R: blob appears only once' \
1636        'n=$(grep $a verify | wc -l) &&
1637         test 1 = $n'
1638
1639test_done