t / t9300-fast-import.shon commit Merge branch 'bc/maint-keep-pack' (c9d8563)
   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
  59INPUT_END
  60test_expect_success \
  61    'A: create pack from stdin' \
  62    'git fast-import --export-marks=marks.out <input &&
  63         git whatchanged master'
  64test_expect_success \
  65        'A: verify pack' \
  66        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
  67
  68cat >expect <<EOF
  69author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  70committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  71
  72initial
  73EOF
  74test_expect_success \
  75        'A: verify commit' \
  76        'git cat-file commit master | sed 1d >actual &&
  77        test_cmp expect actual'
  78
  79cat >expect <<EOF
  80100644 blob file2
  81100644 blob file3
  82100755 blob file4
  83EOF
  84test_expect_success \
  85        'A: verify tree' \
  86        'git cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
  87         test_cmp expect actual'
  88
  89echo "$file2_data" >expect
  90test_expect_success \
  91        'A: verify file2' \
  92        'git cat-file blob master:file2 >actual && test_cmp expect actual'
  93
  94echo "$file3_data" >expect
  95test_expect_success \
  96        'A: verify file3' \
  97        'git cat-file blob master:file3 >actual && test_cmp expect actual'
  98
  99printf "$file4_data" >expect
 100test_expect_success \
 101        'A: verify file4' \
 102        'git cat-file blob master:file4 >actual && test_cmp expect actual'
 103
 104cat >expect <<EOF
 105:2 `git rev-parse --verify master:file2`
 106:3 `git rev-parse --verify master:file3`
 107:4 `git rev-parse --verify master:file4`
 108:5 `git rev-parse --verify master^0`
 109EOF
 110test_expect_success \
 111        'A: verify marks output' \
 112        'test_cmp expect marks.out'
 113
 114test_expect_success \
 115        'A: verify marks import' \
 116        'git fast-import \
 117                --import-marks=marks.out \
 118                --export-marks=marks.new \
 119                </dev/null &&
 120        test_cmp expect marks.new'
 121
 122test_tick
 123cat >input <<INPUT_END
 124commit refs/heads/verify--import-marks
 125committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 126data <<COMMIT
 127recreate from :5
 128COMMIT
 129
 130from :5
 131M 755 :2 copy-of-file2
 132
 133INPUT_END
 134test_expect_success \
 135        'A: verify marks import does not crash' \
 136        'git fast-import --import-marks=marks.out <input &&
 137         git whatchanged verify--import-marks'
 138test_expect_success \
 139        'A: verify pack' \
 140        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 141cat >expect <<EOF
 142:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
 143EOF
 144git diff-tree -M -r master verify--import-marks >actual
 145test_expect_success \
 146        'A: verify diff' \
 147        'compare_diff_raw expect actual &&
 148         test `git rev-parse --verify master:file2` \
 149            = `git rev-parse --verify verify--import-marks:copy-of-file2`'
 150
 151###
 152### series B
 153###
 154
 155test_tick
 156cat >input <<INPUT_END
 157commit refs/heads/branch
 158mark :1
 159committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 160data <<COMMIT
 161corrupt
 162COMMIT
 163
 164from refs/heads/master
 165M 755 0000000000000000000000000000000000000001 zero1
 166
 167INPUT_END
 168test_expect_success 'B: fail on invalid blob sha1' '
 169    test_must_fail git fast-import <input
 170'
 171rm -f .git/objects/pack_* .git/objects/index_*
 172
 173cat >input <<INPUT_END
 174commit .badbranchname
 175committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 176data <<COMMIT
 177corrupt
 178COMMIT
 179
 180from refs/heads/master
 181
 182INPUT_END
 183test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
 184    test_must_fail git fast-import <input
 185'
 186rm -f .git/objects/pack_* .git/objects/index_*
 187
 188cat >input <<INPUT_END
 189commit bad[branch]name
 190committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 191data <<COMMIT
 192corrupt
 193COMMIT
 194
 195from refs/heads/master
 196
 197INPUT_END
 198test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
 199    test_must_fail git fast-import <input
 200'
 201rm -f .git/objects/pack_* .git/objects/index_*
 202
 203cat >input <<INPUT_END
 204commit TEMP_TAG
 205committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 206data <<COMMIT
 207tag base
 208COMMIT
 209
 210from refs/heads/master
 211
 212INPUT_END
 213test_expect_success \
 214    'B: accept branch name "TEMP_TAG"' \
 215    'git fast-import <input &&
 216         test -f .git/TEMP_TAG &&
 217         test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
 218rm -f .git/TEMP_TAG
 219
 220###
 221### series C
 222###
 223
 224newf=`echo hi newf | git hash-object -w --stdin`
 225oldf=`git rev-parse --verify master:file2`
 226test_tick
 227cat >input <<INPUT_END
 228commit refs/heads/branch
 229committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 230data <<COMMIT
 231second
 232COMMIT
 233
 234from refs/heads/master
 235M 644 $oldf file2/oldf
 236M 755 $newf file2/newf
 237D file3
 238
 239INPUT_END
 240test_expect_success \
 241    'C: incremental import create pack from stdin' \
 242    'git fast-import <input &&
 243         git whatchanged branch'
 244test_expect_success \
 245        'C: verify pack' \
 246        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 247test_expect_success \
 248        'C: validate reuse existing blob' \
 249        'test $newf = `git rev-parse --verify branch:file2/newf`
 250         test $oldf = `git rev-parse --verify branch:file2/oldf`'
 251
 252cat >expect <<EOF
 253parent `git rev-parse --verify master^0`
 254author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 255committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 256
 257second
 258EOF
 259test_expect_success \
 260        'C: verify commit' \
 261        'git cat-file commit branch | sed 1d >actual &&
 262         test_cmp expect actual'
 263
 264cat >expect <<EOF
 265:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 266:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 267:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 268EOF
 269git diff-tree -M -r master branch >actual
 270test_expect_success \
 271        'C: validate rename result' \
 272        'compare_diff_raw expect actual'
 273
 274###
 275### series D
 276###
 277
 278test_tick
 279cat >input <<INPUT_END
 280commit refs/heads/branch
 281committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 282data <<COMMIT
 283third
 284COMMIT
 285
 286from refs/heads/branch^0
 287M 644 inline newdir/interesting
 288data <<EOF
 289$file5_data
 290EOF
 291
 292M 755 inline newdir/exec.sh
 293data <<EOF
 294$file6_data
 295EOF
 296
 297INPUT_END
 298test_expect_success \
 299    'D: inline data in commit' \
 300    'git fast-import <input &&
 301         git whatchanged branch'
 302test_expect_success \
 303        'D: verify pack' \
 304        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 305
 306cat >expect <<EOF
 307:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
 308:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
 309EOF
 310git diff-tree -M -r branch^ branch >actual
 311test_expect_success \
 312        'D: validate new files added' \
 313        'compare_diff_raw expect actual'
 314
 315echo "$file5_data" >expect
 316test_expect_success \
 317        'D: verify file5' \
 318        'git cat-file blob branch:newdir/interesting >actual &&
 319         test_cmp expect actual'
 320
 321echo "$file6_data" >expect
 322test_expect_success \
 323        'D: verify file6' \
 324        'git cat-file blob branch:newdir/exec.sh >actual &&
 325         test_cmp expect actual'
 326
 327###
 328### series E
 329###
 330
 331cat >input <<INPUT_END
 332commit refs/heads/branch
 333author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 334committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 335data <<COMMIT
 336RFC 2822 type date
 337COMMIT
 338
 339from refs/heads/branch^0
 340
 341INPUT_END
 342test_expect_success 'E: rfc2822 date, --date-format=raw' '
 343    test_must_fail git fast-import --date-format=raw <input
 344'
 345test_expect_success \
 346    'E: rfc2822 date, --date-format=rfc2822' \
 347    'git fast-import --date-format=rfc2822 <input'
 348test_expect_success \
 349        'E: verify pack' \
 350        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 351
 352cat >expect <<EOF
 353author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
 354committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
 355
 356RFC 2822 type date
 357EOF
 358test_expect_success \
 359        'E: verify commit' \
 360        'git cat-file commit branch | sed 1,2d >actual &&
 361        test_cmp expect actual'
 362
 363###
 364### series F
 365###
 366
 367old_branch=`git rev-parse --verify branch^0`
 368test_tick
 369cat >input <<INPUT_END
 370commit refs/heads/branch
 371committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 372data <<COMMIT
 373losing things already?
 374COMMIT
 375
 376from refs/heads/branch~1
 377
 378reset refs/heads/other
 379from refs/heads/branch
 380
 381INPUT_END
 382test_expect_success \
 383    'F: non-fast-forward update skips' \
 384    'if git fast-import <input
 385         then
 386                echo BAD gfi did not fail
 387                return 1
 388         else
 389                if test $old_branch = `git rev-parse --verify branch^0`
 390                then
 391                        : branch unaffected and failure returned
 392                        return 0
 393                else
 394                        echo BAD gfi changed branch $old_branch
 395                        return 1
 396                fi
 397         fi
 398        '
 399test_expect_success \
 400        'F: verify pack' \
 401        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 402
 403cat >expect <<EOF
 404tree `git rev-parse branch~1^{tree}`
 405parent `git rev-parse branch~1`
 406author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 407committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 408
 409losing things already?
 410EOF
 411test_expect_success \
 412        'F: verify other commit' \
 413        'git cat-file commit other >actual &&
 414        test_cmp expect actual'
 415
 416###
 417### series G
 418###
 419
 420old_branch=`git rev-parse --verify branch^0`
 421test_tick
 422cat >input <<INPUT_END
 423commit refs/heads/branch
 424committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 425data <<COMMIT
 426losing things already?
 427COMMIT
 428
 429from refs/heads/branch~1
 430
 431INPUT_END
 432test_expect_success \
 433    'G: non-fast-forward update forced' \
 434    'git fast-import --force <input'
 435test_expect_success \
 436        'G: verify pack' \
 437        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 438test_expect_success \
 439        'G: branch changed, but logged' \
 440        'test $old_branch != `git rev-parse --verify branch^0` &&
 441         test $old_branch = `git rev-parse --verify branch@{1}`'
 442
 443###
 444### series H
 445###
 446
 447test_tick
 448cat >input <<INPUT_END
 449commit refs/heads/H
 450committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 451data <<COMMIT
 452third
 453COMMIT
 454
 455from refs/heads/branch^0
 456M 644 inline i-will-die
 457data <<EOF
 458this file will never exist.
 459EOF
 460
 461deleteall
 462M 644 inline h/e/l/lo
 463data <<EOF
 464$file5_data
 465EOF
 466
 467INPUT_END
 468test_expect_success \
 469    'H: deletall, add 1' \
 470    'git fast-import <input &&
 471         git whatchanged H'
 472test_expect_success \
 473        'H: verify pack' \
 474        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
 475
 476cat >expect <<EOF
 477:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
 478:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
 479:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
 480:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
 481:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
 482EOF
 483git diff-tree -M -r H^ H >actual
 484test_expect_success \
 485        'H: validate old files removed, new files added' \
 486        'compare_diff_raw expect actual'
 487
 488echo "$file5_data" >expect
 489test_expect_success \
 490        'H: verify file' \
 491        'git cat-file blob H:h/e/l/lo >actual &&
 492         test_cmp expect actual'
 493
 494###
 495### series I
 496###
 497
 498cat >input <<INPUT_END
 499commit refs/heads/export-boundary
 500committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 501data <<COMMIT
 502we have a border.  its only 40 characters wide.
 503COMMIT
 504
 505from refs/heads/branch
 506
 507INPUT_END
 508test_expect_success \
 509    'I: export-pack-edges' \
 510    'git fast-import --export-pack-edges=edges.list <input'
 511
 512cat >expect <<EOF
 513.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
 514EOF
 515test_expect_success \
 516        'I: verify edge list' \
 517        'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
 518         test_cmp expect actual'
 519
 520###
 521### series J
 522###
 523
 524cat >input <<INPUT_END
 525commit refs/heads/J
 526committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 527data <<COMMIT
 528create J
 529COMMIT
 530
 531from refs/heads/branch
 532
 533reset refs/heads/J
 534
 535commit refs/heads/J
 536committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 537data <<COMMIT
 538initialize J
 539COMMIT
 540
 541INPUT_END
 542test_expect_success \
 543    'J: reset existing branch creates empty commit' \
 544    'git fast-import <input'
 545test_expect_success \
 546        'J: branch has 1 commit, empty tree' \
 547        'test 1 = `git rev-list J | wc -l` &&
 548         test 0 = `git ls-tree J | wc -l`'
 549
 550###
 551### series K
 552###
 553
 554cat >input <<INPUT_END
 555commit refs/heads/K
 556committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 557data <<COMMIT
 558create K
 559COMMIT
 560
 561from refs/heads/branch
 562
 563commit refs/heads/K
 564committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 565data <<COMMIT
 566redo K
 567COMMIT
 568
 569from refs/heads/branch^1
 570
 571INPUT_END
 572test_expect_success \
 573    'K: reinit branch with from' \
 574    'git fast-import <input'
 575test_expect_success \
 576    'K: verify K^1 = branch^1' \
 577    'test `git rev-parse --verify branch^1` \
 578                = `git rev-parse --verify K^1`'
 579
 580###
 581### series L
 582###
 583
 584cat >input <<INPUT_END
 585blob
 586mark :1
 587data <<EOF
 588some data
 589EOF
 590
 591blob
 592mark :2
 593data <<EOF
 594other data
 595EOF
 596
 597commit refs/heads/L
 598committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 599data <<COMMIT
 600create L
 601COMMIT
 602
 603M 644 :1 b.
 604M 644 :1 b/other
 605M 644 :1 ba
 606
 607commit refs/heads/L
 608committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 609data <<COMMIT
 610update L
 611COMMIT
 612
 613M 644 :2 b.
 614M 644 :2 b/other
 615M 644 :2 ba
 616INPUT_END
 617
 618cat >expect <<EXPECT_END
 619:100644 100644 4268632... 55d3a52... M  b.
 620:040000 040000 0ae5cac... 443c768... M  b
 621:100644 100644 4268632... 55d3a52... M  ba
 622EXPECT_END
 623
 624test_expect_success \
 625    'L: verify internal tree sorting' \
 626        'git fast-import <input &&
 627         git diff-tree --abbrev --raw L^ L >output &&
 628         test_cmp expect output'
 629
 630###
 631### series M
 632###
 633
 634test_tick
 635cat >input <<INPUT_END
 636commit refs/heads/M1
 637committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 638data <<COMMIT
 639file rename
 640COMMIT
 641
 642from refs/heads/branch^0
 643R file2/newf file2/n.e.w.f
 644
 645INPUT_END
 646
 647cat >expect <<EOF
 648:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      file2/n.e.w.f
 649EOF
 650test_expect_success \
 651        'M: rename file in same subdirectory' \
 652        'git fast-import <input &&
 653         git diff-tree -M -r M1^ M1 >actual &&
 654         compare_diff_raw expect actual'
 655
 656cat >input <<INPUT_END
 657commit refs/heads/M2
 658committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 659data <<COMMIT
 660file rename
 661COMMIT
 662
 663from refs/heads/branch^0
 664R file2/newf i/am/new/to/you
 665
 666INPUT_END
 667
 668cat >expect <<EOF
 669:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   file2/newf      i/am/new/to/you
 670EOF
 671test_expect_success \
 672        'M: rename file to new subdirectory' \
 673        'git fast-import <input &&
 674         git diff-tree -M -r M2^ M2 >actual &&
 675         compare_diff_raw expect actual'
 676
 677cat >input <<INPUT_END
 678commit refs/heads/M3
 679committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 680data <<COMMIT
 681file rename
 682COMMIT
 683
 684from refs/heads/M2^0
 685R i other/sub
 686
 687INPUT_END
 688
 689cat >expect <<EOF
 690:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100   i/am/new/to/you other/sub/am/new/to/you
 691EOF
 692test_expect_success \
 693        'M: rename subdirectory to new subdirectory' \
 694        'git fast-import <input &&
 695         git diff-tree -M -r M3^ M3 >actual &&
 696         compare_diff_raw expect actual'
 697
 698###
 699### series N
 700###
 701
 702test_tick
 703cat >input <<INPUT_END
 704commit refs/heads/N1
 705committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 706data <<COMMIT
 707file copy
 708COMMIT
 709
 710from refs/heads/branch^0
 711C file2/newf file2/n.e.w.f
 712
 713INPUT_END
 714
 715cat >expect <<EOF
 716:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file2/n.e.w.f
 717EOF
 718test_expect_success \
 719        'N: copy file in same subdirectory' \
 720        'git fast-import <input &&
 721         git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
 722         compare_diff_raw expect actual'
 723
 724cat >input <<INPUT_END
 725commit refs/heads/N2
 726committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 727data <<COMMIT
 728clean directory copy
 729COMMIT
 730
 731from refs/heads/branch^0
 732C file2 file3
 733
 734commit refs/heads/N2
 735committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 736data <<COMMIT
 737modify directory copy
 738COMMIT
 739
 740M 644 inline file3/file5
 741data <<EOF
 742$file5_data
 743EOF
 744
 745INPUT_END
 746
 747cat >expect <<EOF
 748:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100   newdir/interesting      file3/file5
 749:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100   file2/newf      file3/newf
 750:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100   file2/oldf      file3/oldf
 751EOF
 752test_expect_success \
 753        'N: copy then modify subdirectory' \
 754        'git fast-import <input &&
 755         git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
 756         compare_diff_raw expect actual'
 757
 758cat >input <<INPUT_END
 759commit refs/heads/N3
 760committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 761data <<COMMIT
 762dirty directory copy
 763COMMIT
 764
 765from refs/heads/branch^0
 766M 644 inline file2/file5
 767data <<EOF
 768$file5_data
 769EOF
 770
 771C file2 file3
 772D file2/file5
 773
 774INPUT_END
 775
 776test_expect_success \
 777        'N: copy dirty subdirectory' \
 778        'git fast-import <input &&
 779         test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
 780
 781###
 782### series O
 783###
 784
 785cat >input <<INPUT_END
 786#we will
 787commit refs/heads/O1
 788# -- ignore all of this text
 789committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 790# $GIT_COMMITTER_NAME has inserted here for his benefit.
 791data <<COMMIT
 792dirty directory copy
 793COMMIT
 794
 795# don't forget the import blank line!
 796#
 797# yes, we started from our usual base of branch^0.
 798# i like branch^0.
 799from refs/heads/branch^0
 800# and we need to reuse file2/file5 from N3 above.
 801M 644 inline file2/file5
 802# otherwise the tree will be different
 803data <<EOF
 804$file5_data
 805EOF
 806
 807# don't forget to copy file2 to file3
 808C file2 file3
 809#
 810# or to delete file5 from file2.
 811D file2/file5
 812# are we done yet?
 813
 814INPUT_END
 815
 816test_expect_success \
 817        'O: comments are all skipped' \
 818        'git fast-import <input &&
 819         test `git rev-parse N3` = `git rev-parse O1`'
 820
 821cat >input <<INPUT_END
 822commit refs/heads/O2
 823committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 824data <<COMMIT
 825dirty directory copy
 826COMMIT
 827from refs/heads/branch^0
 828M 644 inline file2/file5
 829data <<EOF
 830$file5_data
 831EOF
 832C file2 file3
 833D file2/file5
 834
 835INPUT_END
 836
 837test_expect_success \
 838        'O: blank lines not necessary after data commands' \
 839        'git fast-import <input &&
 840         test `git rev-parse N3` = `git rev-parse O2`'
 841
 842test_expect_success \
 843        'O: repack before next test' \
 844        'git repack -a -d'
 845
 846cat >input <<INPUT_END
 847commit refs/heads/O3
 848committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 849data <<COMMIT
 850zstring
 851COMMIT
 852commit refs/heads/O3
 853committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 854data <<COMMIT
 855zof
 856COMMIT
 857checkpoint
 858commit refs/heads/O3
 859mark :5
 860committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 861data <<COMMIT
 862zempty
 863COMMIT
 864checkpoint
 865commit refs/heads/O3
 866committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 867data <<COMMIT
 868zcommits
 869COMMIT
 870reset refs/tags/O3-2nd
 871from :5
 872reset refs/tags/O3-3rd
 873from :5
 874INPUT_END
 875
 876cat >expect <<INPUT_END
 877string
 878of
 879empty
 880commits
 881INPUT_END
 882test_expect_success \
 883        'O: blank lines not necessary after other commands' \
 884        'git fast-import <input &&
 885         test 8 = `find .git/objects/pack -type f | wc -l` &&
 886         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
 887         git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
 888         test_cmp expect actual'
 889
 890cat >input <<INPUT_END
 891commit refs/heads/O4
 892committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 893data <<COMMIT
 894zstring
 895COMMIT
 896commit refs/heads/O4
 897committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 898data <<COMMIT
 899zof
 900COMMIT
 901progress Two commits down, 2 to go!
 902commit refs/heads/O4
 903committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 904data <<COMMIT
 905zempty
 906COMMIT
 907progress Three commits down, 1 to go!
 908commit refs/heads/O4
 909committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 910data <<COMMIT
 911zcommits
 912COMMIT
 913progress I'm done!
 914INPUT_END
 915test_expect_success \
 916        'O: progress outputs as requested by input' \
 917        'git fast-import <input >actual &&
 918         grep "progress " <input >expect &&
 919         test_cmp expect actual'
 920
 921###
 922### series P (gitlinks)
 923###
 924
 925cat >input <<INPUT_END
 926blob
 927mark :1
 928data 10
 929test file
 930
 931reset refs/heads/sub
 932commit refs/heads/sub
 933mark :2
 934committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 935data 12
 936sub_initial
 937M 100644 :1 file
 938
 939blob
 940mark :3
 941data <<DATAEND
 942[submodule "sub"]
 943        path = sub
 944        url = "`pwd`/sub"
 945DATAEND
 946
 947commit refs/heads/subuse1
 948mark :4
 949committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 950data 8
 951initial
 952from refs/heads/master
 953M 100644 :3 .gitmodules
 954M 160000 :2 sub
 955
 956blob
 957mark :5
 958data 20
 959test file
 960more data
 961
 962commit refs/heads/sub
 963mark :6
 964committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 965data 11
 966sub_second
 967from :2
 968M 100644 :5 file
 969
 970commit refs/heads/subuse1
 971mark :7
 972committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 973data 7
 974second
 975from :4
 976M 160000 :6 sub
 977
 978INPUT_END
 979
 980test_expect_success \
 981        'P: supermodule & submodule mix' \
 982        'git fast-import <input &&
 983         git checkout subuse1 &&
 984         rm -rf sub && mkdir sub && cd sub &&
 985         git init &&
 986         git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
 987         git checkout master &&
 988         cd .. &&
 989         git submodule init &&
 990         git submodule update'
 991
 992SUBLAST=$(git rev-parse --verify sub)
 993SUBPREV=$(git rev-parse --verify sub^)
 994
 995cat >input <<INPUT_END
 996blob
 997mark :1
 998data <<DATAEND
 999[submodule "sub"]
1000        path = sub
1001        url = "`pwd`/sub"
1002DATAEND
1003
1004commit refs/heads/subuse2
1005mark :2
1006committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007data 8
1008initial
1009from refs/heads/master
1010M 100644 :1 .gitmodules
1011M 160000 $SUBPREV sub
1012
1013commit refs/heads/subuse2
1014mark :3
1015committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1016data 7
1017second
1018from :2
1019M 160000 $SUBLAST sub
1020
1021INPUT_END
1022
1023test_expect_success \
1024        'P: verbatim SHA gitlinks' \
1025        'git branch -D sub &&
1026         git gc && git prune &&
1027         git fast-import <input &&
1028         test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1029
1030test_tick
1031cat >input <<INPUT_END
1032commit refs/heads/subuse3
1033mark :1
1034committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1035data <<COMMIT
1036corrupt
1037COMMIT
1038
1039from refs/heads/subuse2
1040M 160000 inline sub
1041data <<DATA
1042$SUBPREV
1043DATA
1044
1045INPUT_END
1046
1047test_expect_success 'P: fail on inline gitlink' '
1048    test_must_fail git fast-import <input'
1049
1050test_tick
1051cat >input <<INPUT_END
1052blob
1053mark :1
1054data <<DATA
1055$SUBPREV
1056DATA
1057
1058commit refs/heads/subuse3
1059mark :2
1060committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1061data <<COMMIT
1062corrupt
1063COMMIT
1064
1065from refs/heads/subuse2
1066M 160000 :1 sub
1067
1068INPUT_END
1069
1070test_expect_success 'P: fail on blob mark in gitlink' '
1071    test_must_fail git fast-import <input'
1072
1073test_done