t / t9300-fast-import.shon commit cvsserver: Add some useful commandline options (693b632)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Shawn Pearce
   4#
   5
   6test_description='test git-fast-import utility'
   7. ./test-lib.sh
   8. ../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        git diff 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         git diff expect actual'
  88
  89echo "$file2_data" >expect
  90test_expect_success \
  91        'A: verify file2' \
  92        'git-cat-file blob master:file2 >actual && git diff expect actual'
  93
  94echo "$file3_data" >expect
  95test_expect_success \
  96        'A: verify file3' \
  97        'git-cat-file blob master:file3 >actual && git diff expect actual'
  98
  99printf "$file4_data" >expect
 100test_expect_success \
 101        'A: verify file4' \
 102        'git-cat-file blob master:file4 >actual && git diff 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        'git diff 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        git diff -u 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_failure \
 169    'B: fail on invalid blob sha1' \
 170    'git-fast-import <input'
 171rm -f .git/objects/pack_* .git/objects/index_*
 172
 173###
 174### series C
 175###
 176
 177newf=`echo hi newf | git-hash-object -w --stdin`
 178oldf=`git-rev-parse --verify master:file2`
 179test_tick
 180cat >input <<INPUT_END
 181commit refs/heads/branch
 182committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 183data <<COMMIT
 184second
 185COMMIT
 186
 187from refs/heads/master
 188M 644 $oldf file2/oldf
 189M 755 $newf file2/newf
 190D file3
 191
 192INPUT_END
 193test_expect_success \
 194    'C: incremental import create pack from stdin' \
 195    'git-fast-import <input &&
 196         git-whatchanged branch'
 197test_expect_success \
 198        'C: verify pack' \
 199        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 200test_expect_success \
 201        'C: validate reuse existing blob' \
 202        'test $newf = `git-rev-parse --verify branch:file2/newf`
 203         test $oldf = `git-rev-parse --verify branch:file2/oldf`'
 204
 205cat >expect <<EOF
 206parent `git-rev-parse --verify master^0`
 207author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 208committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 209
 210second
 211EOF
 212test_expect_success \
 213        'C: verify commit' \
 214        'git-cat-file commit branch | sed 1d >actual &&
 215         git diff expect actual'
 216
 217cat >expect <<EOF
 218:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 219:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 220:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 221EOF
 222git-diff-tree -M -r master branch >actual
 223test_expect_success \
 224        'C: validate rename result' \
 225        'compare_diff_raw expect actual'
 226
 227###
 228### series D
 229###
 230
 231test_tick
 232cat >input <<INPUT_END
 233commit refs/heads/branch
 234committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 235data <<COMMIT
 236third
 237COMMIT
 238
 239from refs/heads/branch^0
 240M 644 inline newdir/interesting
 241data <<EOF
 242$file5_data
 243EOF
 244
 245M 755 inline newdir/exec.sh
 246data <<EOF
 247$file6_data
 248EOF
 249
 250INPUT_END
 251test_expect_success \
 252    'D: inline data in commit' \
 253    'git-fast-import <input &&
 254         git-whatchanged branch'
 255test_expect_success \
 256        'D: verify pack' \
 257        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 258
 259cat >expect <<EOF
 260:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
 261:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
 262EOF
 263git-diff-tree -M -r branch^ branch >actual
 264test_expect_success \
 265        'D: validate new files added' \
 266        'compare_diff_raw expect actual'
 267
 268echo "$file5_data" >expect
 269test_expect_success \
 270        'D: verify file5' \
 271        'git-cat-file blob branch:newdir/interesting >actual &&
 272         git diff expect actual'
 273
 274echo "$file6_data" >expect
 275test_expect_success \
 276        'D: verify file6' \
 277        'git-cat-file blob branch:newdir/exec.sh >actual &&
 278         git diff expect actual'
 279
 280###
 281### series E
 282###
 283
 284cat >input <<INPUT_END
 285commit refs/heads/branch
 286author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 287committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 288data <<COMMIT
 289RFC 2822 type date
 290COMMIT
 291
 292from refs/heads/branch^0
 293
 294INPUT_END
 295test_expect_failure \
 296    'E: rfc2822 date, --date-format=raw' \
 297    'git-fast-import --date-format=raw <input'
 298test_expect_success \
 299    'E: rfc2822 date, --date-format=rfc2822' \
 300    'git-fast-import --date-format=rfc2822 <input'
 301test_expect_success \
 302        'E: verify pack' \
 303        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 304
 305cat >expect <<EOF
 306author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
 307committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
 308
 309RFC 2822 type date
 310EOF
 311test_expect_success \
 312        'E: verify commit' \
 313        'git-cat-file commit branch | sed 1,2d >actual &&
 314        git diff expect actual'
 315
 316###
 317### series F
 318###
 319
 320old_branch=`git-rev-parse --verify branch^0`
 321test_tick
 322cat >input <<INPUT_END
 323commit refs/heads/branch
 324committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 325data <<COMMIT
 326losing things already?
 327COMMIT
 328
 329from refs/heads/branch~1
 330
 331reset refs/heads/other
 332from refs/heads/branch
 333
 334INPUT_END
 335test_expect_success \
 336    'F: non-fast-forward update skips' \
 337    'if git-fast-import <input
 338         then
 339                echo BAD gfi did not fail
 340                return 1
 341         else
 342                if test $old_branch = `git-rev-parse --verify branch^0`
 343                then
 344                        : branch unaffected and failure returned
 345                        return 0
 346                else
 347                        echo BAD gfi changed branch $old_branch
 348                        return 1
 349                fi
 350         fi
 351        '
 352test_expect_success \
 353        'F: verify pack' \
 354        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 355
 356cat >expect <<EOF
 357tree `git-rev-parse branch~1^{tree}`
 358parent `git-rev-parse branch~1`
 359author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 360committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 361
 362losing things already?
 363EOF
 364test_expect_success \
 365        'F: verify other commit' \
 366        'git-cat-file commit other >actual &&
 367        git diff expect actual'
 368
 369###
 370### series G
 371###
 372
 373old_branch=`git-rev-parse --verify branch^0`
 374test_tick
 375cat >input <<INPUT_END
 376commit refs/heads/branch
 377committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 378data <<COMMIT
 379losing things already?
 380COMMIT
 381
 382from refs/heads/branch~1
 383
 384INPUT_END
 385test_expect_success \
 386    'G: non-fast-forward update forced' \
 387    'git-fast-import --force <input'
 388test_expect_success \
 389        'G: verify pack' \
 390        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 391test_expect_success \
 392        'G: branch changed, but logged' \
 393        'test $old_branch != `git-rev-parse --verify branch^0` &&
 394         test $old_branch = `git-rev-parse --verify branch@{1}`'
 395
 396###
 397### series H
 398###
 399
 400test_tick
 401cat >input <<INPUT_END
 402commit refs/heads/H
 403committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 404data <<COMMIT
 405third
 406COMMIT
 407
 408from refs/heads/branch^0
 409M 644 inline i-will-die
 410data <<EOF
 411this file will never exist.
 412EOF
 413
 414deleteall
 415M 644 inline h/e/l/lo
 416data <<EOF
 417$file5_data
 418EOF
 419
 420INPUT_END
 421test_expect_success \
 422    'H: deletall, add 1' \
 423    'git-fast-import <input &&
 424         git-whatchanged H'
 425test_expect_success \
 426        'H: verify pack' \
 427        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 428
 429cat >expect <<EOF
 430:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
 431:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
 432:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
 433:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
 434:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
 435EOF
 436git-diff-tree -M -r H^ H >actual
 437test_expect_success \
 438        'H: validate old files removed, new files added' \
 439        'compare_diff_raw expect actual'
 440
 441echo "$file5_data" >expect
 442test_expect_success \
 443        'H: verify file' \
 444        'git-cat-file blob H:h/e/l/lo >actual &&
 445         git diff expect actual'
 446
 447###
 448### series I
 449###
 450
 451cat >input <<INPUT_END
 452commit refs/heads/export-boundary
 453committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 454data <<COMMIT
 455we have a border.  its only 40 characters wide.
 456COMMIT
 457
 458from refs/heads/branch
 459
 460INPUT_END
 461test_expect_success \
 462    'I: export-pack-edges' \
 463    'git-fast-import --export-pack-edges=edges.list <input'
 464
 465cat >expect <<EOF
 466.git/objects/pack/pack-.pack: `git-rev-parse --verify export-boundary`
 467EOF
 468test_expect_success \
 469        'I: verify edge list' \
 470        'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
 471         git diff expect actual'
 472
 473###
 474### series J
 475###
 476
 477cat >input <<INPUT_END
 478commit refs/heads/J
 479committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 480data <<COMMIT
 481create J
 482COMMIT
 483
 484from refs/heads/branch
 485
 486reset refs/heads/J
 487
 488commit refs/heads/J
 489committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 490data <<COMMIT
 491initialize J
 492COMMIT
 493
 494INPUT_END
 495test_expect_success \
 496    'J: reset existing branch creates empty commit' \
 497    'git-fast-import <input'
 498test_expect_success \
 499        'J: branch has 1 commit, empty tree' \
 500        'test 1 = `git-rev-list J | wc -l` &&
 501         test 0 = `git ls-tree J | wc -l`'
 502
 503###
 504### series K
 505###
 506
 507cat >input <<INPUT_END
 508commit refs/heads/K
 509committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 510data <<COMMIT
 511create K
 512COMMIT
 513
 514from refs/heads/branch
 515
 516commit refs/heads/K
 517committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 518data <<COMMIT
 519redo K
 520COMMIT
 521
 522from refs/heads/branch^1
 523
 524INPUT_END
 525test_expect_success \
 526    'K: reinit branch with from' \
 527    'git-fast-import <input'
 528test_expect_success \
 529    'K: verify K^1 = branch^1' \
 530    'test `git-rev-parse --verify branch^1` \
 531                = `git-rev-parse --verify K^1`'
 532
 533###
 534### series L
 535###
 536
 537cat >input <<INPUT_END
 538blob
 539mark :1
 540data <<EOF
 541some data
 542EOF
 543
 544blob
 545mark :2
 546data <<EOF
 547other data
 548EOF
 549
 550commit refs/heads/L
 551committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 552data <<COMMIT
 553create L
 554COMMIT
 555
 556M 644 :1 b.
 557M 644 :1 b/other
 558M 644 :1 ba
 559
 560commit refs/heads/L
 561committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 562data <<COMMIT
 563update L
 564COMMIT
 565
 566M 644 :2 b.
 567M 644 :2 b/other
 568M 644 :2 ba
 569INPUT_END
 570
 571cat >expect <<EXPECT_END
 572:100644 100644 4268632... 55d3a52... M  b.
 573:040000 040000 0ae5cac... 443c768... M  b
 574:100644 100644 4268632... 55d3a52... M  ba
 575EXPECT_END
 576
 577test_expect_success \
 578    'L: verify internal tree sorting' \
 579        'git-fast-import <input &&
 580         git-diff --raw L^ L >output &&
 581         git diff expect output'
 582
 583test_done