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