756d6a9905e6bb38e7dbf0d5a39a5d63849816e6
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='git fast-export'
   7. ./test-lib.sh
   8
   9test_expect_success 'setup' '
  10
  11        echo break it > file0 &&
  12        git add file0 &&
  13        test_tick &&
  14        echo Wohlauf > file &&
  15        git add file &&
  16        test_tick &&
  17        git commit -m initial &&
  18        echo die Luft > file &&
  19        echo geht frisch > file2 &&
  20        git add file file2 &&
  21        test_tick &&
  22        git commit -m second &&
  23        echo und > file2 &&
  24        test_tick &&
  25        git commit -m third file2 &&
  26        test_tick &&
  27        git tag rein &&
  28        git checkout -b wer HEAD^ &&
  29        echo lange > file2 &&
  30        test_tick &&
  31        git commit -m sitzt file2 &&
  32        test_tick &&
  33        git tag -a -m valentin muss &&
  34        git merge -s ours master
  35
  36'
  37
  38test_expect_success 'fast-export | fast-import' '
  39
  40        MASTER=$(git rev-parse --verify master) &&
  41        REIN=$(git rev-parse --verify rein) &&
  42        WER=$(git rev-parse --verify wer) &&
  43        MUSS=$(git rev-parse --verify muss) &&
  44        mkdir new &&
  45        git --git-dir=new/.git init &&
  46        git fast-export --all >actual &&
  47        (cd new &&
  48         git fast-import &&
  49         test $MASTER = $(git rev-parse --verify refs/heads/master) &&
  50         test $REIN = $(git rev-parse --verify refs/tags/rein) &&
  51         test $WER = $(git rev-parse --verify refs/heads/wer) &&
  52         test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
  53
  54'
  55
  56test_expect_success 'fast-export master~2..master' '
  57
  58        git fast-export master~2..master >actual &&
  59        sed "s/master/partial/" actual |
  60                (cd new &&
  61                 git fast-import &&
  62                 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
  63                 git diff --exit-code master partial &&
  64                 git diff --exit-code master^ partial^ &&
  65                 test_must_fail git rev-parse partial~2)
  66
  67'
  68
  69test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
  70
  71        git fast-export --reference-excluded-parents master~2..master >actual &&
  72        grep commit.refs/heads/master actual >commit-count &&
  73        test_line_count = 2 commit-count &&
  74        sed "s/master/rewrite/" actual |
  75                (cd new &&
  76                 git fast-import &&
  77                 test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
  78'
  79
  80test_expect_success 'fast-export --show-original-ids' '
  81
  82        git fast-export --show-original-ids master >output &&
  83        grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
  84        git rev-list --objects master muss >objects-and-names &&
  85        awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
  86        comm -23 actual commits-trees-blobs >unfound &&
  87        test_must_be_empty unfound
  88'
  89
  90test_expect_success 'fast-export --show-original-ids | git fast-import' '
  91
  92        git fast-export --show-original-ids master muss | git fast-import --quiet &&
  93        test $MASTER = $(git rev-parse --verify refs/heads/master) &&
  94        test $MUSS = $(git rev-parse --verify refs/tags/muss)
  95'
  96
  97test_expect_success 'iso-8859-7' '
  98
  99        test_when_finished "git reset --hard HEAD~1" &&
 100        test_config i18n.commitencoding iso-8859-7 &&
 101        test_tick &&
 102        echo rosten >file &&
 103        git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
 104        git fast-export wer^..wer >iso-8859-7.fi &&
 105        sed "s/wer/i18n/" iso-8859-7.fi |
 106                (cd new &&
 107                 git fast-import &&
 108                 # The commit object, if not re-encoded, would be 240 bytes.
 109                 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
 110                 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
 111                 # to \xCF\x80 (\317\200) in UTF-8 adds a byte.  Check for
 112                 # the expected size.
 113                 test 221 -eq "$(git cat-file -s i18n)" &&
 114                 # ...and for the expected translation of bytes.
 115                 git cat-file commit i18n >actual &&
 116                 grep $(printf "\317\200") actual &&
 117                 # Also make sure the commit does not have the "encoding" header
 118                 ! grep ^encoding actual)
 119'
 120
 121test_expect_success 'import/export-marks' '
 122
 123        git checkout -b marks master &&
 124        git fast-export --export-marks=tmp-marks HEAD &&
 125        test -s tmp-marks &&
 126        test_line_count = 3 tmp-marks &&
 127        git fast-export --import-marks=tmp-marks \
 128                --export-marks=tmp-marks HEAD >actual &&
 129        test $(grep ^commit actual | wc -l) -eq 0 &&
 130        echo change > file &&
 131        git commit -m "last commit" file &&
 132        git fast-export --import-marks=tmp-marks \
 133                --export-marks=tmp-marks HEAD >actual &&
 134        test $(grep ^commit\  actual | wc -l) -eq 1 &&
 135        test_line_count = 4 tmp-marks
 136
 137'
 138
 139cat > signed-tag-import << EOF
 140tag sign-your-name
 141from $(git rev-parse HEAD)
 142tagger C O Mitter <committer@example.com> 1112911993 -0700
 143data 210
 144A message for a sign
 145-----BEGIN PGP SIGNATURE-----
 146Version: GnuPG v1.4.5 (GNU/Linux)
 147
 148fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
 149aturefakedsignaturefake=
 150=/59v
 151-----END PGP SIGNATURE-----
 152EOF
 153
 154test_expect_success 'set up faked signed tag' '
 155
 156        cat signed-tag-import | git fast-import
 157
 158'
 159
 160test_expect_success 'signed-tags=abort' '
 161
 162        test_must_fail git fast-export --signed-tags=abort sign-your-name
 163
 164'
 165
 166test_expect_success 'signed-tags=verbatim' '
 167
 168        git fast-export --signed-tags=verbatim sign-your-name > output &&
 169        grep PGP output
 170
 171'
 172
 173test_expect_success 'signed-tags=strip' '
 174
 175        git fast-export --signed-tags=strip sign-your-name > output &&
 176        ! grep PGP output
 177
 178'
 179
 180test_expect_success 'signed-tags=warn-strip' '
 181        git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
 182        ! grep PGP output &&
 183        test -s err
 184'
 185
 186test_expect_success 'setup submodule' '
 187
 188        git checkout -f master &&
 189        mkdir sub &&
 190        (
 191                cd sub &&
 192                git init  &&
 193                echo test file > file &&
 194                git add file &&
 195                git commit -m sub_initial
 196        ) &&
 197        git submodule add "$(pwd)/sub" sub &&
 198        git commit -m initial &&
 199        test_tick &&
 200        (
 201                cd sub &&
 202                echo more data >> file &&
 203                git add file &&
 204                git commit -m sub_second
 205        ) &&
 206        git add sub &&
 207        git commit -m second
 208
 209'
 210
 211test_expect_success 'submodule fast-export | fast-import' '
 212
 213        SUBENT1=$(git ls-tree master^ sub) &&
 214        SUBENT2=$(git ls-tree master sub) &&
 215        rm -rf new &&
 216        mkdir new &&
 217        git --git-dir=new/.git init &&
 218        git fast-export --signed-tags=strip --all >actual &&
 219        (cd new &&
 220         git fast-import &&
 221         test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
 222         test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
 223         git checkout master &&
 224         git submodule init &&
 225         git submodule update &&
 226         cmp sub/file ../sub/file) <actual
 227
 228'
 229
 230GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
 231GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
 232
 233test_expect_success 'setup copies' '
 234
 235        git checkout -b copy rein &&
 236        git mv file file3 &&
 237        git commit -m move1 &&
 238        test_tick &&
 239        cp file2 file4 &&
 240        git add file4 &&
 241        git mv file2 file5 &&
 242        git commit -m copy1 &&
 243        test_tick &&
 244        cp file3 file6 &&
 245        git add file6 &&
 246        git commit -m copy2 &&
 247        test_tick &&
 248        echo more text >> file6 &&
 249        echo even more text >> file6 &&
 250        git add file6 &&
 251        git commit -m modify &&
 252        test_tick &&
 253        cp file6 file7 &&
 254        echo test >> file7 &&
 255        git add file7 &&
 256        git commit -m copy_modify
 257
 258'
 259
 260test_expect_success 'fast-export -C -C | fast-import' '
 261
 262        ENTRY=$(git rev-parse --verify copy) &&
 263        rm -rf new &&
 264        mkdir new &&
 265        git --git-dir=new/.git init &&
 266        git fast-export -C -C --signed-tags=strip --all > output &&
 267        grep "^C file2 file4\$" output &&
 268        cat output |
 269        (cd new &&
 270         git fast-import &&
 271         test $ENTRY = $(git rev-parse --verify refs/heads/copy))
 272
 273'
 274
 275test_expect_success 'fast-export | fast-import when master is tagged' '
 276
 277        git tag -m msg last &&
 278        git fast-export -C -C --signed-tags=strip --all > output &&
 279        test $(grep -c "^tag " output) = 3
 280
 281'
 282
 283cat > tag-content << EOF
 284object $(git rev-parse HEAD)
 285type commit
 286tag rosten
 287EOF
 288
 289test_expect_success 'cope with tagger-less tags' '
 290
 291        TAG=$(git hash-object -t tag -w tag-content) &&
 292        git update-ref refs/tags/sonnenschein $TAG &&
 293        git fast-export -C -C --signed-tags=strip --all > output &&
 294        test $(grep -c "^tag " output) = 4 &&
 295        ! grep "Unspecified Tagger" output &&
 296        git fast-export -C -C --signed-tags=strip --all \
 297                --fake-missing-tagger > output &&
 298        test $(grep -c "^tag " output) = 4 &&
 299        grep "Unspecified Tagger" output
 300
 301'
 302
 303test_expect_success 'setup for limiting exports by PATH' '
 304        mkdir limit-by-paths &&
 305        (
 306                cd limit-by-paths &&
 307                git init &&
 308                echo hi > there &&
 309                git add there &&
 310                git commit -m "First file" &&
 311                echo foo > bar &&
 312                git add bar &&
 313                git commit -m "Second file" &&
 314                git tag -a -m msg mytag &&
 315                echo morefoo >> bar &&
 316                git add bar &&
 317                git commit -m "Change to second file"
 318        )
 319'
 320
 321cat > limit-by-paths/expected << EOF
 322blob
 323mark :1
 324data 3
 325hi
 326
 327reset refs/tags/mytag
 328commit refs/tags/mytag
 329mark :2
 330author A U Thor <author@example.com> 1112912713 -0700
 331committer C O Mitter <committer@example.com> 1112912713 -0700
 332data 11
 333First file
 334M 100644 :1 there
 335
 336EOF
 337
 338test_expect_success 'dropping tag of filtered out object' '
 339(
 340        cd limit-by-paths &&
 341        git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
 342        test_cmp expected output
 343)
 344'
 345
 346cat >> limit-by-paths/expected << EOF
 347tag mytag
 348from :2
 349tagger C O Mitter <committer@example.com> 1112912713 -0700
 350data 4
 351msg
 352
 353EOF
 354
 355test_expect_success 'rewriting tag of filtered out object' '
 356(
 357        cd limit-by-paths &&
 358        git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
 359        test_cmp expected output
 360)
 361'
 362
 363test_expect_success 'rewrite tag predating pathspecs to nothing' '
 364        test_create_repo rewrite_tag_predating_pathspecs &&
 365        (
 366                cd rewrite_tag_predating_pathspecs &&
 367
 368                test_commit initial &&
 369
 370                git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
 371
 372                test_commit bar &&
 373
 374                git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
 375                grep from.$ZERO_OID output
 376        )
 377'
 378
 379cat > limit-by-paths/expected << EOF
 380blob
 381mark :1
 382data 4
 383foo
 384
 385blob
 386mark :2
 387data 3
 388hi
 389
 390reset refs/heads/master
 391commit refs/heads/master
 392mark :3
 393author A U Thor <author@example.com> 1112912713 -0700
 394committer C O Mitter <committer@example.com> 1112912713 -0700
 395data 12
 396Second file
 397M 100644 :1 bar
 398M 100644 :2 there
 399
 400EOF
 401
 402test_expect_failure 'no exact-ref revisions included' '
 403        (
 404                cd limit-by-paths &&
 405                git fast-export master~2..master~1 > output &&
 406                test_cmp expected output
 407        )
 408'
 409
 410test_expect_success 'path limiting with import-marks does not lose unmodified files'        '
 411        git checkout -b simple marks~2 &&
 412        git fast-export --export-marks=marks simple -- file > /dev/null &&
 413        echo more content >> file &&
 414        test_tick &&
 415        git commit -mnext file &&
 416        git fast-export --import-marks=marks simple -- file file0 >actual &&
 417        grep file0 actual
 418'
 419
 420test_expect_success 'avoid corrupt stream with non-existent mark' '
 421        test_create_repo avoid_non_existent_mark &&
 422        (
 423                cd avoid_non_existent_mark &&
 424
 425                test_commit important-path &&
 426
 427                test_commit ignored &&
 428
 429                git branch A &&
 430                git branch B &&
 431
 432                echo foo >>important-path.t &&
 433                git add important-path.t &&
 434                test_commit more changes &&
 435
 436                git fast-export --all -- important-path.t | git fast-import --force
 437        )
 438'
 439
 440test_expect_success 'full-tree re-shows unmodified files'        '
 441        git checkout -f simple &&
 442        git fast-export --full-tree simple >actual &&
 443        test $(grep -c file0 actual) -eq 3
 444'
 445
 446test_expect_success 'set-up a few more tags for tag export tests' '
 447        git checkout -f master &&
 448        HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
 449        git tag    tree_tag        -m "tagging a tree" $HEAD_TREE &&
 450        git tag -a tree_tag-obj    -m "tagging a tree" $HEAD_TREE &&
 451        git tag    tag-obj_tag     -m "tagging a tag" tree_tag-obj &&
 452        git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
 453'
 454
 455test_expect_success 'tree_tag'        '
 456        mkdir result &&
 457        (cd result && git init) &&
 458        git fast-export tree_tag > fe-stream &&
 459        (cd result && git fast-import < ../fe-stream)
 460'
 461
 462# NEEDSWORK: not just check return status, but validate the output
 463test_expect_success 'tree_tag-obj'    'git fast-export tree_tag-obj'
 464test_expect_success 'tag-obj_tag'     'git fast-export tag-obj_tag'
 465test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
 466
 467test_expect_success 'directory becomes symlink'        '
 468        git init dirtosymlink &&
 469        git init result &&
 470        (
 471                cd dirtosymlink &&
 472                mkdir foo &&
 473                mkdir bar &&
 474                echo hello > foo/world &&
 475                echo hello > bar/world &&
 476                git add foo/world bar/world &&
 477                git commit -q -mone &&
 478                git rm -r foo &&
 479                test_ln_s_add bar foo &&
 480                git commit -q -mtwo
 481        ) &&
 482        (
 483                cd dirtosymlink &&
 484                git fast-export master -- foo |
 485                (cd ../result && git fast-import --quiet)
 486        ) &&
 487        (cd result && git show master:foo)
 488'
 489
 490test_expect_success 'fast-export quotes pathnames' '
 491        git init crazy-paths &&
 492        (cd crazy-paths &&
 493         blob=$(echo foo | git hash-object -w --stdin) &&
 494         git update-index --add \
 495                --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
 496                --cacheinfo 100644 $blob "path with \"quote\"" \
 497                --cacheinfo 100644 $blob "path with \\backslash" \
 498                --cacheinfo 100644 $blob "path with space" &&
 499         git commit -m addition &&
 500         git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
 501         git read-tree --empty &&
 502         git update-index -z --index-info <index &&
 503         git commit -m rename &&
 504         git read-tree --empty &&
 505         git commit -m deletion &&
 506         git fast-export -M HEAD >export.out &&
 507         git rev-list HEAD >expect &&
 508         git init result &&
 509         cd result &&
 510         git fast-import <../export.out &&
 511         git rev-list HEAD >actual &&
 512         test_cmp ../expect actual
 513        )
 514'
 515
 516test_expect_success 'test bidirectionality' '
 517        >marks-cur &&
 518        >marks-new &&
 519        git init marks-test &&
 520        git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
 521        git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
 522        (cd marks-test &&
 523        git reset --hard &&
 524        echo Wohlauf > file &&
 525        git commit -a -m "back in time") &&
 526        git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
 527        git fast-import --export-marks=marks-cur --import-marks=marks-cur
 528'
 529
 530cat > expected << EOF
 531blob
 532mark :13
 533data 5
 534bump
 535
 536commit refs/heads/master
 537mark :14
 538author A U Thor <author@example.com> 1112912773 -0700
 539committer C O Mitter <committer@example.com> 1112912773 -0700
 540data 5
 541bump
 542from :12
 543M 100644 :13 file
 544
 545EOF
 546
 547test_expect_success 'avoid uninteresting refs' '
 548        > tmp-marks &&
 549        git fast-export --import-marks=tmp-marks \
 550                --export-marks=tmp-marks master > /dev/null &&
 551        git tag v1.0 &&
 552        git branch uninteresting &&
 553        echo bump > file &&
 554        git commit -a -m bump &&
 555        git fast-export --import-marks=tmp-marks \
 556                --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
 557        test_cmp expected actual
 558'
 559
 560cat > expected << EOF
 561reset refs/heads/master
 562from :14
 563
 564EOF
 565
 566test_expect_success 'refs are updated even if no commits need to be exported' '
 567        > tmp-marks &&
 568        git fast-export --import-marks=tmp-marks \
 569                --export-marks=tmp-marks master > /dev/null &&
 570        git fast-export --import-marks=tmp-marks \
 571                --export-marks=tmp-marks master > actual &&
 572        test_cmp expected actual
 573'
 574
 575test_expect_success 'use refspec' '
 576        git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
 577        grep "^commit " actual2 | sort | uniq >actual &&
 578        echo "commit refs/heads/foobar" > expected &&
 579        test_cmp expected actual
 580'
 581
 582test_expect_success 'delete ref because entire history excluded' '
 583        git branch to-delete &&
 584        git fast-export to-delete ^to-delete >actual &&
 585        cat >expected <<-EOF &&
 586        reset refs/heads/to-delete
 587        from 0000000000000000000000000000000000000000
 588
 589        EOF
 590        test_cmp expected actual
 591'
 592
 593test_expect_success 'delete refspec' '
 594        git fast-export --refspec :refs/heads/to-delete >actual &&
 595        cat >expected <<-EOF &&
 596        reset refs/heads/to-delete
 597        from 0000000000000000000000000000000000000000
 598
 599        EOF
 600        test_cmp expected actual
 601'
 602
 603test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
 604        test_create_repo src &&
 605        echo a_line >src/file.txt &&
 606        git -C src add file.txt &&
 607        git -C src commit -m 1st_commit &&
 608
 609        cp src/file.txt src/file2.txt &&
 610        echo another_line >>src/file.txt &&
 611        git -C src add file.txt file2.txt &&
 612        git -C src commit -m 2nd_commit &&
 613
 614        test_create_repo dst &&
 615        git -C src fast-export --all -C >actual &&
 616        git -C dst fast-import <actual &&
 617        git -C src show >expected &&
 618        git -C dst show >actual &&
 619        test_cmp expected actual
 620'
 621
 622test_expect_success 'merge commit gets exported with --import-marks' '
 623        test_create_repo merging &&
 624        (
 625                cd merging &&
 626                test_commit initial &&
 627                git checkout -b topic &&
 628                test_commit on-topic &&
 629                git checkout master &&
 630                test_commit on-master &&
 631                test_tick &&
 632                git merge --no-ff -m Yeah topic &&
 633
 634                echo ":1 $(git rev-parse HEAD^^)" >marks &&
 635                git fast-export --import-marks=marks master >out &&
 636                grep Yeah out
 637        )
 638'
 639
 640test_done