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