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