cb9a236245695fb723f9466e9c0d5d98709d7027
   1#!/bin/sh
   2
   3test_description='check svn dumpfile importer'
   4
   5. ./lib-git-svn.sh
   6
   7reinit_git () {
   8        rm -fr .git &&
   9        git init
  10}
  11
  12properties () {
  13        while test "$#" -ne 0
  14        do
  15                property="$1" &&
  16                value="$2" &&
  17                printf "%s\n" "K ${#property}" &&
  18                printf "%s\n" "$property" &&
  19                printf "%s\n" "V ${#value}" &&
  20                printf "%s\n" "$value" &&
  21                shift 2 ||
  22                return 1
  23        done
  24}
  25
  26text_no_props () {
  27        text="$1
  28" &&
  29        printf "%s\n" "Prop-content-length: 10" &&
  30        printf "%s\n" "Text-content-length: ${#text}" &&
  31        printf "%s\n" "Content-length: $((${#text} + 10))" &&
  32        printf "%s\n" "" "PROPS-END" &&
  33        printf "%s\n" "$text"
  34}
  35
  36>empty
  37
  38test_expect_success 'empty dump' '
  39        reinit_git &&
  40        echo "SVN-fs-dump-format-version: 2" >input &&
  41        test-svn-fe input >stream &&
  42        git fast-import <stream
  43'
  44
  45test_expect_success 'v4 dumps not supported' '
  46        reinit_git &&
  47        echo "SVN-fs-dump-format-version: 4" >v4.dump &&
  48        test_must_fail test-svn-fe v4.dump >stream &&
  49        test_cmp empty stream
  50'
  51
  52test_expect_failure 'empty revision' '
  53        reinit_git &&
  54        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
  55        cat >emptyrev.dump <<-\EOF &&
  56        SVN-fs-dump-format-version: 3
  57
  58        Revision-number: 1
  59        Prop-content-length: 0
  60        Content-length: 0
  61
  62        Revision-number: 2
  63        Prop-content-length: 0
  64        Content-length: 0
  65
  66        EOF
  67        test-svn-fe emptyrev.dump >stream &&
  68        git fast-import <stream &&
  69        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
  70        test_cmp expect actual
  71'
  72
  73test_expect_success 'empty properties' '
  74        reinit_git &&
  75        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
  76        cat >emptyprop.dump <<-\EOF &&
  77        SVN-fs-dump-format-version: 3
  78
  79        Revision-number: 1
  80        Prop-content-length: 10
  81        Content-length: 10
  82
  83        PROPS-END
  84
  85        Revision-number: 2
  86        Prop-content-length: 10
  87        Content-length: 10
  88
  89        PROPS-END
  90        EOF
  91        test-svn-fe emptyprop.dump >stream &&
  92        git fast-import <stream &&
  93        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
  94        test_cmp expect actual
  95'
  96
  97test_expect_success 'author name and commit message' '
  98        reinit_git &&
  99        echo "<author@example.com, author@example.com@local>" >expect.author &&
 100        cat >message <<-\EOF &&
 101        A concise summary of the change
 102
 103        A detailed description of the change, why it is needed, what
 104        was broken and why applying this is the best course of action.
 105
 106        * file.c
 107            Details pertaining to an individual file.
 108        EOF
 109        {
 110                properties \
 111                        svn:author author@example.com \
 112                        svn:log "$(cat message)" &&
 113                echo PROPS-END
 114        } >props &&
 115        {
 116                echo "SVN-fs-dump-format-version: 3" &&
 117                echo &&
 118                echo "Revision-number: 1" &&
 119                echo Prop-content-length: $(wc -c <props) &&
 120                echo Content-length: $(wc -c <props) &&
 121                echo &&
 122                cat props
 123        } >log.dump &&
 124        test-svn-fe log.dump >stream &&
 125        git fast-import <stream &&
 126        git log -p --format="%B" HEAD >actual.log &&
 127        git log --format="<%an, %ae>" >actual.author &&
 128        test_cmp message actual.log &&
 129        test_cmp expect.author actual.author
 130'
 131
 132test_expect_success 'unsupported properties are ignored' '
 133        reinit_git &&
 134        echo author >expect &&
 135        cat >extraprop.dump <<-\EOF &&
 136        SVN-fs-dump-format-version: 3
 137
 138        Revision-number: 1
 139        Prop-content-length: 56
 140        Content-length: 56
 141
 142        K 8
 143        nonsense
 144        V 1
 145        y
 146        K 10
 147        svn:author
 148        V 6
 149        author
 150        PROPS-END
 151        EOF
 152        test-svn-fe extraprop.dump >stream &&
 153        git fast-import <stream &&
 154        git log -p --format=%an HEAD >actual &&
 155        test_cmp expect actual
 156'
 157
 158test_expect_failure 'timestamp and empty file' '
 159        echo author@example.com >expect.author &&
 160        echo 1999-01-01 >expect.date &&
 161        echo file >expect.files &&
 162        reinit_git &&
 163        {
 164                properties \
 165                        svn:author author@example.com \
 166                        svn:date "1999-01-01T00:01:002.000000Z" \
 167                        svn:log "add empty file" &&
 168                echo PROPS-END
 169        } >props &&
 170        {
 171                cat <<-EOF &&
 172                SVN-fs-dump-format-version: 3
 173
 174                Revision-number: 1
 175                EOF
 176                echo Prop-content-length: $(wc -c <props) &&
 177                echo Content-length: $(wc -c <props) &&
 178                echo &&
 179                cat props &&
 180                cat <<-\EOF
 181
 182                Node-path: empty-file
 183                Node-kind: file
 184                Node-action: add
 185                Content-length: 0
 186
 187                EOF
 188        } >emptyfile.dump &&
 189        test-svn-fe emptyfile.dump >stream &&
 190        git fast-import <stream &&
 191        git log --format=%an HEAD >actual.author &&
 192        git log --date=short --format=%ad HEAD >actual.date &&
 193        git ls-tree -r --name-only HEAD >actual.files &&
 194        test_cmp expect.author actual.author &&
 195        test_cmp expect.date actual.date &&
 196        test_cmp expect.files actual.files &&
 197        git checkout HEAD empty-file &&
 198        test_cmp empty file
 199'
 200
 201test_expect_success 'directory with files' '
 202        reinit_git &&
 203        printf "%s\n" directory/file1 directory/file2 >expect.files &&
 204        echo hi >hi &&
 205        echo hello >hello &&
 206        {
 207                properties \
 208                        svn:author author@example.com \
 209                        svn:date "1999-02-01T00:01:002.000000Z" \
 210                        svn:log "add directory with some files in it" &&
 211                echo PROPS-END
 212        } >props &&
 213        {
 214                cat <<-EOF &&
 215                SVN-fs-dump-format-version: 3
 216
 217                Revision-number: 1
 218                EOF
 219                echo Prop-content-length: $(wc -c <props) &&
 220                echo Content-length: $(wc -c <props) &&
 221                echo &&
 222                cat props &&
 223                cat <<-\EOF &&
 224
 225                Node-path: directory
 226                Node-kind: dir
 227                Node-action: add
 228                Prop-content-length: 10
 229                Content-length: 10
 230
 231                PROPS-END
 232
 233                Node-path: directory/file1
 234                Node-kind: file
 235                Node-action: add
 236                EOF
 237                text_no_props hello &&
 238                cat <<-\EOF &&
 239                Node-path: directory/file2
 240                Node-kind: file
 241                Node-action: add
 242                EOF
 243                text_no_props hi
 244        } >directory.dump &&
 245        test-svn-fe directory.dump >stream &&
 246        git fast-import <stream &&
 247
 248        git ls-tree -r --name-only HEAD >actual.files &&
 249        git checkout HEAD directory &&
 250        test_cmp expect.files actual.files &&
 251        test_cmp hello directory/file1 &&
 252        test_cmp hi directory/file2
 253'
 254
 255test_expect_success 'node without action' '
 256        cat >inaction.dump <<-\EOF &&
 257        SVN-fs-dump-format-version: 3
 258
 259        Revision-number: 1
 260        Prop-content-length: 10
 261        Content-length: 10
 262
 263        PROPS-END
 264
 265        Node-path: directory
 266        Node-kind: dir
 267        Prop-content-length: 10
 268        Content-length: 10
 269
 270        PROPS-END
 271        EOF
 272        test_must_fail test-svn-fe inaction.dump
 273'
 274
 275test_expect_failure 'change file mode but keep old content' '
 276        reinit_git &&
 277        cat >expect <<-\EOF &&
 278        OBJID
 279        :120000 100644 OBJID OBJID T    greeting
 280        OBJID
 281        :100644 120000 OBJID OBJID T    greeting
 282        OBJID
 283        :000000 100644 OBJID OBJID A    greeting
 284        EOF
 285        echo "link hello" >expect.blob &&
 286        echo hello >hello &&
 287        cat >filemode.dump <<-\EOF &&
 288        SVN-fs-dump-format-version: 3
 289
 290        Revision-number: 1
 291        Prop-content-length: 10
 292        Content-length: 10
 293
 294        PROPS-END
 295
 296        Node-path: greeting
 297        Node-kind: file
 298        Node-action: add
 299        Prop-content-length: 10
 300        Text-content-length: 11
 301        Content-length: 21
 302
 303        PROPS-END
 304        link hello
 305
 306        Revision-number: 2
 307        Prop-content-length: 10
 308        Content-length: 10
 309
 310        PROPS-END
 311
 312        Node-path: greeting
 313        Node-kind: file
 314        Node-action: change
 315        Prop-content-length: 33
 316        Content-length: 33
 317
 318        K 11
 319        svn:special
 320        V 1
 321        *
 322        PROPS-END
 323
 324        Revision-number: 3
 325        Prop-content-length: 10
 326        Content-length: 10
 327
 328        PROPS-END
 329
 330        Node-path: greeting
 331        Node-kind: file
 332        Node-action: change
 333        Prop-content-length: 10
 334        Content-length: 10
 335
 336        PROPS-END
 337        EOF
 338        test-svn-fe filemode.dump >stream &&
 339        git fast-import <stream &&
 340        {
 341                git rev-list HEAD |
 342                git diff-tree --root --stdin |
 343                sed "s/$_x40/OBJID/g"
 344        } >actual &&
 345        git show HEAD:greeting >actual.blob &&
 346        git show HEAD^:greeting >actual.target &&
 347        test_cmp expect actual &&
 348        test_cmp expect.blob actual.blob &&
 349        test_cmp hello actual.target
 350'
 351
 352test_expect_success 'change file mode and reiterate content' '
 353        reinit_git &&
 354        cat >expect <<-\EOF &&
 355        OBJID
 356        :120000 100644 OBJID OBJID T    greeting
 357        OBJID
 358        :100644 120000 OBJID OBJID T    greeting
 359        OBJID
 360        :000000 100644 OBJID OBJID A    greeting
 361        EOF
 362        echo "link hello" >expect.blob &&
 363        echo hello >hello &&
 364        cat >filemode.dump <<-\EOF &&
 365        SVN-fs-dump-format-version: 3
 366
 367        Revision-number: 1
 368        Prop-content-length: 10
 369        Content-length: 10
 370
 371        PROPS-END
 372
 373        Node-path: greeting
 374        Node-kind: file
 375        Node-action: add
 376        Prop-content-length: 10
 377        Text-content-length: 11
 378        Content-length: 21
 379
 380        PROPS-END
 381        link hello
 382
 383        Revision-number: 2
 384        Prop-content-length: 10
 385        Content-length: 10
 386
 387        PROPS-END
 388
 389        Node-path: greeting
 390        Node-kind: file
 391        Node-action: change
 392        Prop-content-length: 33
 393        Text-content-length: 11
 394        Content-length: 44
 395
 396        K 11
 397        svn:special
 398        V 1
 399        *
 400        PROPS-END
 401        link hello
 402
 403        Revision-number: 3
 404        Prop-content-length: 10
 405        Content-length: 10
 406
 407        PROPS-END
 408
 409        Node-path: greeting
 410        Node-kind: file
 411        Node-action: change
 412        Prop-content-length: 10
 413        Text-content-length: 11
 414        Content-length: 21
 415
 416        PROPS-END
 417        link hello
 418        EOF
 419        test-svn-fe filemode.dump >stream &&
 420        git fast-import <stream &&
 421        {
 422                git rev-list HEAD |
 423                git diff-tree --root --stdin |
 424                sed "s/$_x40/OBJID/g"
 425        } >actual &&
 426        git show HEAD:greeting >actual.blob &&
 427        git show HEAD^:greeting >actual.target &&
 428        test_cmp expect actual &&
 429        test_cmp expect.blob actual.blob &&
 430        test_cmp hello actual.target
 431'
 432
 433test_expect_success 'deltas not supported' '
 434        {
 435                # (old) h + (inline) ello + (old) \n
 436                printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" |
 437                q_to_nul
 438        } >delta &&
 439        {
 440                properties \
 441                        svn:author author@example.com \
 442                        svn:date "1999-01-05T00:01:002.000000Z" \
 443                        svn:log "add greeting" &&
 444                echo PROPS-END
 445        } >props &&
 446        {
 447                properties \
 448                        svn:author author@example.com \
 449                        svn:date "1999-01-06T00:01:002.000000Z" \
 450                        svn:log "change it" &&
 451                echo PROPS-END
 452        } >props2 &&
 453        {
 454                echo SVN-fs-dump-format-version: 3 &&
 455                echo &&
 456                echo Revision-number: 1 &&
 457                echo Prop-content-length: $(wc -c <props) &&
 458                echo Content-length: $(wc -c <props) &&
 459                echo &&
 460                cat props &&
 461                cat <<-\EOF &&
 462
 463                Node-path: hello
 464                Node-kind: file
 465                Node-action: add
 466                Prop-content-length: 10
 467                Text-content-length: 3
 468                Content-length: 13
 469
 470                PROPS-END
 471                hi
 472
 473                EOF
 474                echo Revision-number: 2 &&
 475                echo Prop-content-length: $(wc -c <props2) &&
 476                echo Content-length: $(wc -c <props2) &&
 477                echo &&
 478                cat props2 &&
 479                cat <<-\EOF &&
 480
 481                Node-path: hello
 482                Node-kind: file
 483                Node-action: change
 484                Text-delta: true
 485                Prop-content-length: 10
 486                EOF
 487                echo Text-content-length: $(wc -c <delta) &&
 488                echo Content-length: $((10 + $(wc -c <delta))) &&
 489                echo &&
 490                echo PROPS-END &&
 491                cat delta
 492        } >delta.dump &&
 493        test_must_fail test-svn-fe delta.dump
 494'
 495
 496test_expect_success 'property deltas not supported' '
 497        {
 498                properties \
 499                        svn:author author@example.com \
 500                        svn:date "1999-03-06T00:01:002.000000Z" \
 501                        svn:log "make an executable, or chmod -x it" &&
 502                echo PROPS-END
 503        } >revprops &&
 504        {
 505                echo SVN-fs-dump-format-version: 3 &&
 506                echo &&
 507                echo Revision-number: 1 &&
 508                echo Prop-content-length: $(wc -c <revprops) &&
 509                echo Content-length: $(wc -c <revprops) &&
 510                echo &&
 511                cat revprops &&
 512                echo &&
 513                cat <<-\EOF &&
 514                Node-path: script.sh
 515                Node-kind: file
 516                Node-action: add
 517                Text-content-length: 0
 518                Prop-content-length: 39
 519                Content-length: 39
 520
 521                K 14
 522                svn:executable
 523                V 4
 524                true
 525                PROPS-END
 526
 527                EOF
 528                echo Revision-number: 2 &&
 529                echo Prop-content-length: $(wc -c <revprops) &&
 530                echo Content-length: $(wc -c <revprops) &&
 531                echo &&
 532                cat revprops &&
 533                echo &&
 534                cat <<-\EOF
 535                Node-path: script.sh
 536                Node-kind: file
 537                Node-action: change
 538                Prop-delta: true
 539                Prop-content-length: 30
 540                Content-length: 30
 541
 542                D 14
 543                svn:executable
 544                PROPS-END
 545                EOF
 546        } >propdelta.dump &&
 547        test_must_fail test-svn-fe propdelta.dump
 548'
 549
 550test_expect_success 't9135/svn.dump' '
 551        svnadmin create simple-svn &&
 552        svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
 553        svn_cmd export "file://$PWD/simple-svn" simple-svnco &&
 554        git init simple-git &&
 555        test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe &&
 556        (
 557                cd simple-git &&
 558                git fast-import <../simple.fe
 559        ) &&
 560        (
 561                cd simple-svnco &&
 562                git init &&
 563                git add . &&
 564                git fetch ../simple-git master &&
 565                git diff --exit-code FETCH_HEAD
 566        )
 567'
 568
 569test_done