t / t3030-merge-recursive.shon commit Merge branch 'kk/maint-prefix-in-config-mak' (8cee0f1)
   1#!/bin/sh
   2
   3test_description='merge-recursive backend test'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup 1' '
   8
   9        echo hello >a &&
  10        o0=$(git hash-object a) &&
  11        cp a b &&
  12        cp a c &&
  13        mkdir d &&
  14        cp a d/e &&
  15
  16        test_tick &&
  17        git add a b c d/e &&
  18        git commit -m initial &&
  19        c0=$(git rev-parse --verify HEAD) &&
  20        git branch side &&
  21        git branch df-1 &&
  22        git branch df-2 &&
  23        git branch df-3 &&
  24        git branch remove &&
  25        git branch submod &&
  26        git branch copy &&
  27        git branch rename &&
  28        if test_have_prereq SYMLINKS
  29        then
  30                git branch rename-ln
  31        fi &&
  32
  33        echo hello >>a &&
  34        cp a d/e &&
  35        o1=$(git hash-object a) &&
  36
  37        git add a d/e &&
  38
  39        test_tick &&
  40        git commit -m "master modifies a and d/e" &&
  41        c1=$(git rev-parse --verify HEAD) &&
  42        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  43        (
  44                echo "100644 blob $o1   a"
  45                echo "100644 blob $o0   b"
  46                echo "100644 blob $o0   c"
  47                echo "100644 blob $o1   d/e"
  48                echo "100644 $o1 0      a"
  49                echo "100644 $o0 0      b"
  50                echo "100644 $o0 0      c"
  51                echo "100644 $o1 0      d/e"
  52        ) >expected &&
  53        test_cmp expected actual
  54'
  55
  56test_expect_success 'setup 2' '
  57
  58        rm -rf [abcd] &&
  59        git checkout side &&
  60        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  61        (
  62                echo "100644 blob $o0   a"
  63                echo "100644 blob $o0   b"
  64                echo "100644 blob $o0   c"
  65                echo "100644 blob $o0   d/e"
  66                echo "100644 $o0 0      a"
  67                echo "100644 $o0 0      b"
  68                echo "100644 $o0 0      c"
  69                echo "100644 $o0 0      d/e"
  70        ) >expected &&
  71        test_cmp expected actual &&
  72
  73        echo goodbye >>a &&
  74        o2=$(git hash-object a) &&
  75
  76        git add a &&
  77
  78        test_tick &&
  79        git commit -m "side modifies a" &&
  80        c2=$(git rev-parse --verify HEAD) &&
  81        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  82        (
  83                echo "100644 blob $o2   a"
  84                echo "100644 blob $o0   b"
  85                echo "100644 blob $o0   c"
  86                echo "100644 blob $o0   d/e"
  87                echo "100644 $o2 0      a"
  88                echo "100644 $o0 0      b"
  89                echo "100644 $o0 0      c"
  90                echo "100644 $o0 0      d/e"
  91        ) >expected &&
  92        test_cmp expected actual
  93'
  94
  95test_expect_success 'setup 3' '
  96
  97        rm -rf [abcd] &&
  98        git checkout df-1 &&
  99        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 100        (
 101                echo "100644 blob $o0   a"
 102                echo "100644 blob $o0   b"
 103                echo "100644 blob $o0   c"
 104                echo "100644 blob $o0   d/e"
 105                echo "100644 $o0 0      a"
 106                echo "100644 $o0 0      b"
 107                echo "100644 $o0 0      c"
 108                echo "100644 $o0 0      d/e"
 109        ) >expected &&
 110        test_cmp expected actual &&
 111
 112        rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
 113        o3=$(git hash-object b/c) &&
 114
 115        test_tick &&
 116        git commit -m "df-1 makes b/c" &&
 117        c3=$(git rev-parse --verify HEAD) &&
 118        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 119        (
 120                echo "100644 blob $o0   a"
 121                echo "100644 blob $o3   b/c"
 122                echo "100644 blob $o0   c"
 123                echo "100644 blob $o0   d/e"
 124                echo "100644 $o0 0      a"
 125                echo "100644 $o3 0      b/c"
 126                echo "100644 $o0 0      c"
 127                echo "100644 $o0 0      d/e"
 128        ) >expected &&
 129        test_cmp expected actual
 130'
 131
 132test_expect_success 'setup 4' '
 133
 134        rm -rf [abcd] &&
 135        git checkout df-2 &&
 136        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 137        (
 138                echo "100644 blob $o0   a"
 139                echo "100644 blob $o0   b"
 140                echo "100644 blob $o0   c"
 141                echo "100644 blob $o0   d/e"
 142                echo "100644 $o0 0      a"
 143                echo "100644 $o0 0      b"
 144                echo "100644 $o0 0      c"
 145                echo "100644 $o0 0      d/e"
 146        ) >expected &&
 147        test_cmp expected actual &&
 148
 149        rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
 150        o4=$(git hash-object a/c) &&
 151
 152        test_tick &&
 153        git commit -m "df-2 makes a/c" &&
 154        c4=$(git rev-parse --verify HEAD) &&
 155        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 156        (
 157                echo "100644 blob $o4   a/c"
 158                echo "100644 blob $o0   b"
 159                echo "100644 blob $o0   c"
 160                echo "100644 blob $o0   d/e"
 161                echo "100644 $o4 0      a/c"
 162                echo "100644 $o0 0      b"
 163                echo "100644 $o0 0      c"
 164                echo "100644 $o0 0      d/e"
 165        ) >expected &&
 166        test_cmp expected actual
 167'
 168
 169test_expect_success 'setup 5' '
 170
 171        rm -rf [abcd] &&
 172        git checkout remove &&
 173        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 174        (
 175                echo "100644 blob $o0   a"
 176                echo "100644 blob $o0   b"
 177                echo "100644 blob $o0   c"
 178                echo "100644 blob $o0   d/e"
 179                echo "100644 $o0 0      a"
 180                echo "100644 $o0 0      b"
 181                echo "100644 $o0 0      c"
 182                echo "100644 $o0 0      d/e"
 183        ) >expected &&
 184        test_cmp expected actual &&
 185
 186        rm -f b &&
 187        echo remove-conflict >a &&
 188
 189        git add a &&
 190        git rm b &&
 191        o5=$(git hash-object a) &&
 192
 193        test_tick &&
 194        git commit -m "remove removes b and modifies a" &&
 195        c5=$(git rev-parse --verify HEAD) &&
 196        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 197        (
 198                echo "100644 blob $o5   a"
 199                echo "100644 blob $o0   c"
 200                echo "100644 blob $o0   d/e"
 201                echo "100644 $o5 0      a"
 202                echo "100644 $o0 0      c"
 203                echo "100644 $o0 0      d/e"
 204        ) >expected &&
 205        test_cmp expected actual
 206
 207'
 208
 209test_expect_success 'setup 6' '
 210
 211        rm -rf [abcd] &&
 212        git checkout df-3 &&
 213        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 214        (
 215                echo "100644 blob $o0   a"
 216                echo "100644 blob $o0   b"
 217                echo "100644 blob $o0   c"
 218                echo "100644 blob $o0   d/e"
 219                echo "100644 $o0 0      a"
 220                echo "100644 $o0 0      b"
 221                echo "100644 $o0 0      c"
 222                echo "100644 $o0 0      d/e"
 223        ) >expected &&
 224        test_cmp expected actual &&
 225
 226        rm -fr d && echo df-3 >d && git add d &&
 227        o6=$(git hash-object d) &&
 228
 229        test_tick &&
 230        git commit -m "df-3 makes d" &&
 231        c6=$(git rev-parse --verify HEAD) &&
 232        ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 233        (
 234                echo "100644 blob $o0   a"
 235                echo "100644 blob $o0   b"
 236                echo "100644 blob $o0   c"
 237                echo "100644 blob $o6   d"
 238                echo "100644 $o0 0      a"
 239                echo "100644 $o0 0      b"
 240                echo "100644 $o0 0      c"
 241                echo "100644 $o6 0      d"
 242        ) >expected &&
 243        test_cmp expected actual
 244'
 245
 246test_expect_success 'setup 7' '
 247
 248        git checkout submod &&
 249        git rm d/e &&
 250        test_tick &&
 251        git commit -m "remove d/e" &&
 252        git update-index --add --cacheinfo 160000 $c1 d &&
 253        test_tick &&
 254        git commit -m "make d/ a submodule"
 255'
 256
 257test_expect_success 'setup 8' '
 258        git checkout rename &&
 259        git mv a e &&
 260        git add e &&
 261        test_tick &&
 262        git commit -m "rename a->e" &&
 263        if test_have_prereq SYMLINKS
 264        then
 265                git checkout rename-ln &&
 266                git mv a e &&
 267                ln -s e a &&
 268                git add a e &&
 269                test_tick &&
 270                git commit -m "rename a->e, symlink a->e"
 271        fi
 272'
 273
 274test_expect_success 'setup 9' '
 275        git checkout copy &&
 276        cp a e &&
 277        git add e &&
 278        test_tick &&
 279        git commit -m "copy a->e"
 280'
 281
 282test_expect_success 'merge-recursive simple' '
 283
 284        rm -fr [abcd] &&
 285        git checkout -f "$c2" &&
 286
 287        git merge-recursive "$c0" -- "$c2" "$c1"
 288        status=$?
 289        case "$status" in
 290        1)
 291                : happy
 292                ;;
 293        *)
 294                echo >&2 "why status $status!!!"
 295                false
 296                ;;
 297        esac
 298'
 299
 300test_expect_success 'merge-recursive result' '
 301
 302        git ls-files -s >actual &&
 303        (
 304                echo "100644 $o0 1      a"
 305                echo "100644 $o2 2      a"
 306                echo "100644 $o1 3      a"
 307                echo "100644 $o0 0      b"
 308                echo "100644 $o0 0      c"
 309                echo "100644 $o1 0      d/e"
 310        ) >expected &&
 311        test_cmp expected actual
 312
 313'
 314
 315test_expect_success 'fail if the index has unresolved entries' '
 316
 317        rm -fr [abcd] &&
 318        git checkout -f "$c1" &&
 319
 320        test_must_fail git merge "$c5" &&
 321        test_must_fail git merge "$c5" 2> out &&
 322        test_i18ngrep "not possible because you have unmerged files" out &&
 323        git add -u &&
 324        test_must_fail git merge "$c5" 2> out &&
 325        test_i18ngrep "You have not concluded your merge" out &&
 326        rm -f .git/MERGE_HEAD &&
 327        test_must_fail git merge "$c5" 2> out &&
 328        test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
 329'
 330
 331test_expect_success 'merge-recursive remove conflict' '
 332
 333        rm -fr [abcd] &&
 334        git checkout -f "$c1" &&
 335
 336        git merge-recursive "$c0" -- "$c1" "$c5"
 337        status=$?
 338        case "$status" in
 339        1)
 340                : happy
 341                ;;
 342        *)
 343                echo >&2 "why status $status!!!"
 344                false
 345                ;;
 346        esac
 347'
 348
 349test_expect_success 'merge-recursive remove conflict' '
 350
 351        git ls-files -s >actual &&
 352        (
 353                echo "100644 $o0 1      a"
 354                echo "100644 $o1 2      a"
 355                echo "100644 $o5 3      a"
 356                echo "100644 $o0 0      c"
 357                echo "100644 $o1 0      d/e"
 358        ) >expected &&
 359        test_cmp expected actual
 360
 361'
 362
 363test_expect_success 'merge-recursive d/f simple' '
 364        rm -fr [abcd] &&
 365        git reset --hard &&
 366        git checkout -f "$c1" &&
 367
 368        git merge-recursive "$c0" -- "$c1" "$c3"
 369'
 370
 371test_expect_success 'merge-recursive result' '
 372
 373        git ls-files -s >actual &&
 374        (
 375                echo "100644 $o1 0      a"
 376                echo "100644 $o3 0      b/c"
 377                echo "100644 $o0 0      c"
 378                echo "100644 $o1 0      d/e"
 379        ) >expected &&
 380        test_cmp expected actual
 381
 382'
 383
 384test_expect_success 'merge-recursive d/f conflict' '
 385
 386        rm -fr [abcd] &&
 387        git reset --hard &&
 388        git checkout -f "$c1" &&
 389
 390        git merge-recursive "$c0" -- "$c1" "$c4"
 391        status=$?
 392        case "$status" in
 393        1)
 394                : happy
 395                ;;
 396        *)
 397                echo >&2 "why status $status!!!"
 398                false
 399                ;;
 400        esac
 401'
 402
 403test_expect_success 'merge-recursive d/f conflict result' '
 404
 405        git ls-files -s >actual &&
 406        (
 407                echo "100644 $o0 1      a"
 408                echo "100644 $o1 2      a"
 409                echo "100644 $o4 0      a/c"
 410                echo "100644 $o0 0      b"
 411                echo "100644 $o0 0      c"
 412                echo "100644 $o1 0      d/e"
 413        ) >expected &&
 414        test_cmp expected actual
 415
 416'
 417
 418test_expect_success 'merge-recursive d/f conflict the other way' '
 419
 420        rm -fr [abcd] &&
 421        git reset --hard &&
 422        git checkout -f "$c4" &&
 423
 424        git merge-recursive "$c0" -- "$c4" "$c1"
 425        status=$?
 426        case "$status" in
 427        1)
 428                : happy
 429                ;;
 430        *)
 431                echo >&2 "why status $status!!!"
 432                false
 433                ;;
 434        esac
 435'
 436
 437test_expect_success 'merge-recursive d/f conflict result the other way' '
 438
 439        git ls-files -s >actual &&
 440        (
 441                echo "100644 $o0 1      a"
 442                echo "100644 $o1 3      a"
 443                echo "100644 $o4 0      a/c"
 444                echo "100644 $o0 0      b"
 445                echo "100644 $o0 0      c"
 446                echo "100644 $o1 0      d/e"
 447        ) >expected &&
 448        test_cmp expected actual
 449
 450'
 451
 452test_expect_success 'merge-recursive d/f conflict' '
 453
 454        rm -fr [abcd] &&
 455        git reset --hard &&
 456        git checkout -f "$c1" &&
 457
 458        git merge-recursive "$c0" -- "$c1" "$c6"
 459        status=$?
 460        case "$status" in
 461        1)
 462                : happy
 463                ;;
 464        *)
 465                echo >&2 "why status $status!!!"
 466                false
 467                ;;
 468        esac
 469'
 470
 471test_expect_success 'merge-recursive d/f conflict result' '
 472
 473        git ls-files -s >actual &&
 474        (
 475                echo "100644 $o1 0      a"
 476                echo "100644 $o0 0      b"
 477                echo "100644 $o0 0      c"
 478                echo "100644 $o6 3      d"
 479                echo "100644 $o0 1      d/e"
 480                echo "100644 $o1 2      d/e"
 481        ) >expected &&
 482        test_cmp expected actual
 483
 484'
 485
 486test_expect_success 'merge-recursive d/f conflict' '
 487
 488        rm -fr [abcd] &&
 489        git reset --hard &&
 490        git checkout -f "$c6" &&
 491
 492        git merge-recursive "$c0" -- "$c6" "$c1"
 493        status=$?
 494        case "$status" in
 495        1)
 496                : happy
 497                ;;
 498        *)
 499                echo >&2 "why status $status!!!"
 500                false
 501                ;;
 502        esac
 503'
 504
 505test_expect_success 'merge-recursive d/f conflict result' '
 506
 507        git ls-files -s >actual &&
 508        (
 509                echo "100644 $o1 0      a"
 510                echo "100644 $o0 0      b"
 511                echo "100644 $o0 0      c"
 512                echo "100644 $o6 2      d"
 513                echo "100644 $o0 1      d/e"
 514                echo "100644 $o1 3      d/e"
 515        ) >expected &&
 516        test_cmp expected actual
 517
 518'
 519
 520test_expect_success 'reset and 3-way merge' '
 521
 522        git reset --hard "$c2" &&
 523        git read-tree -m "$c0" "$c2" "$c1"
 524
 525'
 526
 527test_expect_success 'reset and bind merge' '
 528
 529        git reset --hard master &&
 530        git read-tree --prefix=M/ master &&
 531        git ls-files -s >actual &&
 532        (
 533                echo "100644 $o1 0      M/a"
 534                echo "100644 $o0 0      M/b"
 535                echo "100644 $o0 0      M/c"
 536                echo "100644 $o1 0      M/d/e"
 537                echo "100644 $o1 0      a"
 538                echo "100644 $o0 0      b"
 539                echo "100644 $o0 0      c"
 540                echo "100644 $o1 0      d/e"
 541        ) >expected &&
 542        test_cmp expected actual &&
 543
 544        git read-tree --prefix=a1/ master &&
 545        git ls-files -s >actual &&
 546        (
 547                echo "100644 $o1 0      M/a"
 548                echo "100644 $o0 0      M/b"
 549                echo "100644 $o0 0      M/c"
 550                echo "100644 $o1 0      M/d/e"
 551                echo "100644 $o1 0      a"
 552                echo "100644 $o1 0      a1/a"
 553                echo "100644 $o0 0      a1/b"
 554                echo "100644 $o0 0      a1/c"
 555                echo "100644 $o1 0      a1/d/e"
 556                echo "100644 $o0 0      b"
 557                echo "100644 $o0 0      c"
 558                echo "100644 $o1 0      d/e"
 559        ) >expected &&
 560        test_cmp expected actual &&
 561
 562        git read-tree --prefix=z/ master &&
 563        git ls-files -s >actual &&
 564        (
 565                echo "100644 $o1 0      M/a"
 566                echo "100644 $o0 0      M/b"
 567                echo "100644 $o0 0      M/c"
 568                echo "100644 $o1 0      M/d/e"
 569                echo "100644 $o1 0      a"
 570                echo "100644 $o1 0      a1/a"
 571                echo "100644 $o0 0      a1/b"
 572                echo "100644 $o0 0      a1/c"
 573                echo "100644 $o1 0      a1/d/e"
 574                echo "100644 $o0 0      b"
 575                echo "100644 $o0 0      c"
 576                echo "100644 $o1 0      d/e"
 577                echo "100644 $o1 0      z/a"
 578                echo "100644 $o0 0      z/b"
 579                echo "100644 $o0 0      z/c"
 580                echo "100644 $o1 0      z/d/e"
 581        ) >expected &&
 582        test_cmp expected actual
 583
 584'
 585
 586test_expect_success 'merge removes empty directories' '
 587
 588        git reset --hard master &&
 589        git checkout -b rm &&
 590        git rm d/e &&
 591        git commit -mremoved-d/e &&
 592        git checkout master &&
 593        git merge -s recursive rm &&
 594        test_must_fail test -d d
 595'
 596
 597test_expect_failure 'merge-recursive simple w/submodule' '
 598
 599        git checkout submod &&
 600        git merge remove
 601'
 602
 603test_expect_failure 'merge-recursive simple w/submodule result' '
 604
 605        git ls-files -s >actual &&
 606        (
 607                echo "100644 $o5 0      a"
 608                echo "100644 $o0 0      c"
 609                echo "160000 $c1 0      d"
 610        ) >expected &&
 611        test_cmp expected actual
 612'
 613
 614test_expect_success 'merge-recursive copy vs. rename' '
 615        git checkout -f copy &&
 616        git merge rename &&
 617        ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
 618        (
 619                echo "100644 blob $o0   b"
 620                echo "100644 blob $o0   c"
 621                echo "100644 blob $o0   d/e"
 622                echo "100644 blob $o0   e"
 623                echo "100644 $o0 0      b"
 624                echo "100644 $o0 0      c"
 625                echo "100644 $o0 0      d/e"
 626                echo "100644 $o0 0      e"
 627        ) >expected &&
 628        test_cmp expected actual
 629'
 630
 631if test_have_prereq SYMLINKS
 632then
 633        test_expect_success 'merge-recursive rename vs. rename/symlink' '
 634
 635                git checkout -f rename &&
 636                git merge rename-ln &&
 637                ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
 638                (
 639                        echo "100644 blob $o0   b"
 640                        echo "100644 blob $o0   c"
 641                        echo "100644 blob $o0   d/e"
 642                        echo "100644 blob $o0   e"
 643                        echo "100644 $o0 0      b"
 644                        echo "100644 $o0 0      c"
 645                        echo "100644 $o0 0      d/e"
 646                        echo "100644 $o0 0      e"
 647                ) >expected &&
 648                test_cmp expected actual
 649        '
 650fi
 651
 652
 653test_done