t / t6042-merge-rename-corner-cases.shon commit builtin rebase: support `--autostash` option (6defce2)
   1#!/bin/sh
   2
   3test_description="recursive merge corner cases w/ renames but not criss-crosses"
   4# t6036 has corner cases that involve both criss-cross merges and renames
   5
   6. ./test-lib.sh
   7
   8test_expect_success 'setup rename/delete + untracked file' '
   9        test_create_repo rename-delete-untracked &&
  10        (
  11                cd rename-delete-untracked &&
  12
  13                echo "A pretty inscription" >ring &&
  14                git add ring &&
  15                test_tick &&
  16                git commit -m beginning &&
  17
  18                git branch people &&
  19                git checkout -b rename-the-ring &&
  20                git mv ring one-ring-to-rule-them-all &&
  21                test_tick &&
  22                git commit -m fullname &&
  23
  24                git checkout people &&
  25                git rm ring &&
  26                echo gollum >owner &&
  27                git add owner &&
  28                test_tick &&
  29                git commit -m track-people-instead-of-objects &&
  30                echo "Myyy PRECIOUSSS" >ring
  31        )
  32'
  33
  34test_expect_success "Does git preserve Gollum's precious artifact?" '
  35        (
  36                cd rename-delete-untracked &&
  37
  38                test_must_fail git merge -s recursive rename-the-ring &&
  39
  40                # Make sure git did not delete an untracked file
  41                test_path_is_file ring
  42        )
  43'
  44
  45# Testcase setup for rename/modify/add-source:
  46#   Commit A: new file: a
  47#   Commit B: modify a slightly
  48#   Commit C: rename a->b, add completely different a
  49#
  50# We should be able to merge B & C cleanly
  51
  52test_expect_success 'setup rename/modify/add-source conflict' '
  53        test_create_repo rename-modify-add-source &&
  54        (
  55                cd rename-modify-add-source &&
  56
  57                printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
  58                git add a &&
  59                git commit -m A &&
  60                git tag A &&
  61
  62                git checkout -b B A &&
  63                echo 8 >>a &&
  64                git add a &&
  65                git commit -m B &&
  66
  67                git checkout -b C A &&
  68                git mv a b &&
  69                echo something completely different >a &&
  70                git add a &&
  71                git commit -m C
  72        )
  73'
  74
  75test_expect_failure 'rename/modify/add-source conflict resolvable' '
  76        (
  77                cd rename-modify-add-source &&
  78
  79                git checkout B^0 &&
  80
  81                git merge -s recursive C^0 &&
  82
  83                git rev-parse >expect \
  84                        B:a   C:a     &&
  85                git rev-parse >actual \
  86                        b     c       &&
  87                test_cmp expect actual
  88        )
  89'
  90
  91test_expect_success 'setup resolvable conflict missed if rename missed' '
  92        test_create_repo break-detection-1 &&
  93        (
  94                cd break-detection-1 &&
  95
  96                printf "1\n2\n3\n4\n5\n" >a &&
  97                echo foo >b &&
  98                git add a b &&
  99                git commit -m A &&
 100                git tag A &&
 101
 102                git checkout -b B A &&
 103                git mv a c &&
 104                echo "Completely different content" >a &&
 105                git add a &&
 106                git commit -m B &&
 107
 108                git checkout -b C A &&
 109                echo 6 >>a &&
 110                git add a &&
 111                git commit -m C
 112        )
 113'
 114
 115test_expect_failure 'conflict caused if rename not detected' '
 116        (
 117                cd break-detection-1 &&
 118
 119                git checkout -q C^0 &&
 120                git merge -s recursive B^0 &&
 121
 122                git ls-files -s >out &&
 123                test_line_count = 3 out &&
 124                git ls-files -u >out &&
 125                test_line_count = 0 out &&
 126                git ls-files -o >out &&
 127                test_line_count = 1 out &&
 128
 129                test_line_count = 6 c &&
 130                git rev-parse >expect \
 131                        B:a   A:b     &&
 132                git rev-parse >actual \
 133                        :0:a  :0:b    &&
 134                test_cmp expect actual
 135        )
 136'
 137
 138test_expect_success 'setup conflict resolved wrong if rename missed' '
 139        test_create_repo break-detection-2 &&
 140        (
 141                cd break-detection-2 &&
 142
 143                printf "1\n2\n3\n4\n5\n" >a &&
 144                echo foo >b &&
 145                git add a b &&
 146                git commit -m A &&
 147                git tag A &&
 148
 149                git checkout -b D A &&
 150                echo 7 >>a &&
 151                git add a &&
 152                git mv a c &&
 153                echo "Completely different content" >a &&
 154                git add a &&
 155                git commit -m D &&
 156
 157                git checkout -b E A &&
 158                git rm a &&
 159                echo "Completely different content" >>a &&
 160                git add a &&
 161                git commit -m E
 162        )
 163'
 164
 165test_expect_failure 'missed conflict if rename not detected' '
 166        (
 167                cd break-detection-2 &&
 168
 169                git checkout -q E^0 &&
 170                test_must_fail git merge -s recursive D^0
 171        )
 172'
 173
 174# Tests for undetected rename/add-source causing a file to erroneously be
 175# deleted (and for mishandled rename/rename(1to1) causing the same issue).
 176#
 177# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
 178# same file is renamed on both sides to the same thing; it should trigger
 179# the 1to2 logic, which it would do if the add-source didn't cause issues
 180# for git's rename detection):
 181#   Commit A: new file: a
 182#   Commit B: rename a->b
 183#   Commit C: rename a->b, add unrelated a
 184
 185test_expect_success 'setup undetected rename/add-source causes data loss' '
 186        test_create_repo break-detection-3 &&
 187        (
 188                cd break-detection-3 &&
 189
 190                printf "1\n2\n3\n4\n5\n" >a &&
 191                git add a &&
 192                git commit -m A &&
 193                git tag A &&
 194
 195                git checkout -b B A &&
 196                git mv a b &&
 197                git commit -m B &&
 198
 199                git checkout -b C A &&
 200                git mv a b &&
 201                echo foobar >a &&
 202                git add a &&
 203                git commit -m C
 204        )
 205'
 206
 207test_expect_failure 'detect rename/add-source and preserve all data' '
 208        (
 209                cd break-detection-3 &&
 210
 211                git checkout B^0 &&
 212
 213                git merge -s recursive C^0 &&
 214
 215                git ls-files -s >out &&
 216                test_line_count = 2 out &&
 217                git ls-files -u >out &&
 218                test_line_count = 2 out &&
 219                git ls-files -o >out &&
 220                test_line_count = 1 out &&
 221
 222                test_path_is_file a &&
 223                test_path_is_file b &&
 224
 225                git rev-parse >expect \
 226                        A:a   C:a     &&
 227                git rev-parse >actual \
 228                        :0:b  :0:a    &&
 229                test_cmp expect actual
 230        )
 231'
 232
 233test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
 234        (
 235                cd break-detection-3 &&
 236
 237                git checkout C^0 &&
 238
 239                git merge -s recursive B^0 &&
 240
 241                git ls-files -s >out &&
 242                test_line_count = 2 out &&
 243                git ls-files -u >out &&
 244                test_line_count = 2 out &&
 245                git ls-files -o >out &&
 246                test_line_count = 1 out &&
 247
 248                test_path_is_file a &&
 249                test_path_is_file b &&
 250
 251                git rev-parse >expect \
 252                        A:a   C:a     &&
 253                git rev-parse >actual \
 254                        :0:b  :0:a    &&
 255                test_cmp expect actual
 256        )
 257'
 258
 259test_expect_success 'setup content merge + rename/directory conflict' '
 260        test_create_repo rename-directory-1 &&
 261        (
 262                cd rename-directory-1 &&
 263
 264                printf "1\n2\n3\n4\n5\n6\n" >file &&
 265                git add file &&
 266                test_tick &&
 267                git commit -m base &&
 268                git tag base &&
 269
 270                git checkout -b right &&
 271                echo 7 >>file &&
 272                mkdir newfile &&
 273                echo junk >newfile/realfile &&
 274                git add file newfile/realfile &&
 275                test_tick &&
 276                git commit -m right &&
 277
 278                git checkout -b left-conflict base &&
 279                echo 8 >>file &&
 280                git add file &&
 281                git mv file newfile &&
 282                test_tick &&
 283                git commit -m left &&
 284
 285                git checkout -b left-clean base &&
 286                echo 0 >newfile &&
 287                cat file >>newfile &&
 288                git add newfile &&
 289                git rm file &&
 290                test_tick &&
 291                git commit -m left
 292        )
 293'
 294
 295test_expect_success 'rename/directory conflict + clean content merge' '
 296        (
 297                cd rename-directory-1 &&
 298
 299                git checkout left-clean^0 &&
 300
 301                test_must_fail git merge -s recursive right^0 &&
 302
 303                git ls-files -s >out &&
 304                test_line_count = 2 out &&
 305                git ls-files -u >out &&
 306                test_line_count = 1 out &&
 307                git ls-files -o >out &&
 308                test_line_count = 2 out &&
 309
 310                echo 0 >expect &&
 311                git cat-file -p base:file >>expect &&
 312                echo 7 >>expect &&
 313                test_cmp expect newfile~HEAD &&
 314
 315                test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
 316
 317                test_path_is_file newfile/realfile &&
 318                test_path_is_file newfile~HEAD
 319        )
 320'
 321
 322test_expect_success 'rename/directory conflict + content merge conflict' '
 323        (
 324                cd rename-directory-1 &&
 325
 326                git reset --hard &&
 327                git reset --hard &&
 328                git clean -fdqx &&
 329
 330                git checkout left-conflict^0 &&
 331
 332                test_must_fail git merge -s recursive right^0 &&
 333
 334                git ls-files -s >out &&
 335                test_line_count = 4 out &&
 336                git ls-files -u >out &&
 337                test_line_count = 3 out &&
 338                git ls-files -o >out &&
 339                test_line_count = 2 out &&
 340
 341                git cat-file -p left-conflict:newfile >left &&
 342                git cat-file -p base:file    >base &&
 343                git cat-file -p right:file   >right &&
 344                test_must_fail git merge-file \
 345                        -L "HEAD:newfile" \
 346                        -L "" \
 347                        -L "right^0:file" \
 348                        left base right &&
 349                test_cmp left newfile~HEAD &&
 350
 351                git rev-parse >expect                                 \
 352                        base:file   left-conflict:newfile  right:file &&
 353                git rev-parse >actual                                 \
 354                        :1:newfile  :2:newfile             :3:newfile &&
 355                test_cmp expect actual &&
 356
 357                test_path_is_file newfile/realfile &&
 358                test_path_is_file newfile~HEAD
 359        )
 360'
 361
 362test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
 363        test_create_repo rename-directory-2 &&
 364        (
 365                cd rename-directory-2 &&
 366
 367                mkdir sub &&
 368                printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
 369                git add sub/file &&
 370                test_tick &&
 371                git commit -m base &&
 372                git tag base &&
 373
 374                git checkout -b right &&
 375                echo 7 >>sub/file &&
 376                git add sub/file &&
 377                test_tick &&
 378                git commit -m right &&
 379
 380                git checkout -b left base &&
 381                echo 0 >newfile &&
 382                cat sub/file >>newfile &&
 383                git rm sub/file &&
 384                mv newfile sub &&
 385                git add sub &&
 386                test_tick &&
 387                git commit -m left
 388        )
 389'
 390
 391test_expect_success 'disappearing dir in rename/directory conflict handled' '
 392        (
 393                cd rename-directory-2 &&
 394
 395                git checkout left^0 &&
 396
 397                git merge -s recursive right^0 &&
 398
 399                git ls-files -s >out &&
 400                test_line_count = 1 out &&
 401                git ls-files -u >out &&
 402                test_line_count = 0 out &&
 403                git ls-files -o >out &&
 404                test_line_count = 1 out &&
 405
 406                echo 0 >expect &&
 407                git cat-file -p base:sub/file >>expect &&
 408                echo 7 >>expect &&
 409                test_cmp expect sub &&
 410
 411                test_path_is_file sub
 412        )
 413'
 414
 415# Test for all kinds of things that can go wrong with rename/rename (2to1):
 416#   Commit A: new files: a & b
 417#   Commit B: rename a->c, modify b
 418#   Commit C: rename b->c, modify a
 419#
 420# Merging of B & C should NOT be clean.  Questions:
 421#   * Both a & b should be removed by the merge; are they?
 422#   * The two c's should contain modifications to a & b; do they?
 423#   * The index should contain two files, both for c; does it?
 424#   * The working copy should have two files, both of form c~<unique>; does it?
 425#   * Nothing else should be present.  Is anything?
 426
 427test_expect_success 'setup rename/rename (2to1) + modify/modify' '
 428        test_create_repo rename-rename-2to1 &&
 429        (
 430                cd rename-rename-2to1 &&
 431
 432                printf "1\n2\n3\n4\n5\n" >a &&
 433                printf "5\n4\n3\n2\n1\n" >b &&
 434                git add a b &&
 435                git commit -m A &&
 436                git tag A &&
 437
 438                git checkout -b B A &&
 439                git mv a c &&
 440                echo 0 >>b &&
 441                git add b &&
 442                git commit -m B &&
 443
 444                git checkout -b C A &&
 445                git mv b c &&
 446                echo 6 >>a &&
 447                git add a &&
 448                git commit -m C
 449        )
 450'
 451
 452test_expect_success 'handle rename/rename (2to1) conflict correctly' '
 453        (
 454                cd rename-rename-2to1 &&
 455
 456                git checkout B^0 &&
 457
 458                test_must_fail git merge -s recursive C^0 >out &&
 459                test_i18ngrep "CONFLICT (rename/rename)" out &&
 460
 461                git ls-files -s >out &&
 462                test_line_count = 2 out &&
 463                git ls-files -u >out &&
 464                test_line_count = 2 out &&
 465                git ls-files -u c >out &&
 466                test_line_count = 2 out &&
 467                git ls-files -o >out &&
 468                test_line_count = 3 out &&
 469
 470                test_path_is_missing a &&
 471                test_path_is_missing b &&
 472                test_path_is_file c~HEAD &&
 473                test_path_is_file c~C^0 &&
 474
 475                git rev-parse >expect   \
 476                        C:a     B:b     &&
 477                git hash-object >actual \
 478                        c~HEAD  c~C^0   &&
 479                test_cmp expect actual
 480        )
 481'
 482
 483# Testcase setup for simple rename/rename (1to2) conflict:
 484#   Commit A: new file: a
 485#   Commit B: rename a->b
 486#   Commit C: rename a->c
 487test_expect_success 'setup simple rename/rename (1to2) conflict' '
 488        test_create_repo rename-rename-1to2 &&
 489        (
 490                cd rename-rename-1to2 &&
 491
 492                echo stuff >a &&
 493                git add a &&
 494                test_tick &&
 495                git commit -m A &&
 496                git tag A &&
 497
 498                git checkout -b B A &&
 499                git mv a b &&
 500                test_tick &&
 501                git commit -m B &&
 502
 503                git checkout -b C A &&
 504                git mv a c &&
 505                test_tick &&
 506                git commit -m C
 507        )
 508'
 509
 510test_expect_success 'merge has correct working tree contents' '
 511        (
 512                cd rename-rename-1to2 &&
 513
 514                git checkout C^0 &&
 515
 516                test_must_fail git merge -s recursive B^0 &&
 517
 518                git ls-files -s >out &&
 519                test_line_count = 3 out &&
 520                git ls-files -u >out &&
 521                test_line_count = 3 out &&
 522                git ls-files -o >out &&
 523                test_line_count = 1 out &&
 524
 525                test_path_is_missing a &&
 526                git rev-parse >expect   \
 527                        A:a   A:a   A:a \
 528                        A:a   A:a       &&
 529                git rev-parse >actual    \
 530                        :1:a  :3:b  :2:c &&
 531                git hash-object >>actual \
 532                        b     c          &&
 533                test_cmp expect actual
 534        )
 535'
 536
 537# Testcase setup for rename/rename(1to2)/add-source conflict:
 538#   Commit A: new file: a
 539#   Commit B: rename a->b
 540#   Commit C: rename a->c, add completely different a
 541#
 542# Merging of B & C should NOT be clean; there's a rename/rename conflict
 543
 544test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
 545        test_create_repo rename-rename-1to2-add-source-1 &&
 546        (
 547                cd rename-rename-1to2-add-source-1 &&
 548
 549                printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
 550                git add a &&
 551                git commit -m A &&
 552                git tag A &&
 553
 554                git checkout -b B A &&
 555                git mv a b &&
 556                git commit -m B &&
 557
 558                git checkout -b C A &&
 559                git mv a c &&
 560                echo something completely different >a &&
 561                git add a &&
 562                git commit -m C
 563        )
 564'
 565
 566test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
 567        (
 568                cd rename-rename-1to2-add-source-1 &&
 569
 570                git checkout B^0 &&
 571
 572                test_must_fail git merge -s recursive C^0 &&
 573
 574                git ls-files -s >out &&
 575                test_line_count = 4 out &&
 576                git ls-files -o >out &&
 577                test_line_count = 1 out &&
 578
 579                git rev-parse >expect         \
 580                        C:a   A:a   B:b   C:C &&
 581                git rev-parse >actual          \
 582                        :3:a  :1:a  :2:b  :3:c &&
 583                test_cmp expect actual &&
 584
 585                test_path_is_file a &&
 586                test_path_is_file b &&
 587                test_path_is_file c
 588        )
 589'
 590
 591test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
 592        test_create_repo rename-rename-1to2-add-source-2 &&
 593        (
 594                cd rename-rename-1to2-add-source-2 &&
 595
 596                >a &&
 597                git add a &&
 598                test_tick &&
 599                git commit -m base &&
 600                git tag A &&
 601
 602                git checkout -b B A &&
 603                git mv a b &&
 604                test_tick &&
 605                git commit -m one &&
 606
 607                git checkout -b C A &&
 608                git mv a b &&
 609                echo important-info >a &&
 610                git add a &&
 611                test_tick &&
 612                git commit -m two
 613        )
 614'
 615
 616test_expect_failure 'rename/rename/add-source still tracks new a file' '
 617        (
 618                cd rename-rename-1to2-add-source-2 &&
 619
 620                git checkout C^0 &&
 621                git merge -s recursive B^0 &&
 622
 623                git ls-files -s >out &&
 624                test_line_count = 2 out &&
 625                git ls-files -o >out &&
 626                test_line_count = 1 out &&
 627
 628                git rev-parse >expect \
 629                        C:a   A:a     &&
 630                git rev-parse >actual \
 631                        :0:a  :0:b    &&
 632                test_cmp expect actual
 633        )
 634'
 635
 636test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
 637        test_create_repo rename-rename-1to2-add-dest &&
 638        (
 639                cd rename-rename-1to2-add-dest &&
 640
 641                echo stuff >a &&
 642                git add a &&
 643                test_tick &&
 644                git commit -m base &&
 645                git tag A &&
 646
 647                git checkout -b B A &&
 648                git mv a b &&
 649                echo precious-data >c &&
 650                git add c &&
 651                test_tick &&
 652                git commit -m one &&
 653
 654                git checkout -b C A &&
 655                git mv a c &&
 656                echo important-info >b &&
 657                git add b &&
 658                test_tick &&
 659                git commit -m two
 660        )
 661'
 662
 663test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
 664        (
 665                cd rename-rename-1to2-add-dest &&
 666
 667                git checkout C^0 &&
 668                test_must_fail git merge -s recursive B^0 &&
 669
 670                git ls-files -s >out &&
 671                test_line_count = 5 out &&
 672                git ls-files -u b >out &&
 673                test_line_count = 2 out &&
 674                git ls-files -u c >out &&
 675                test_line_count = 2 out &&
 676                git ls-files -o >out &&
 677                test_line_count = 5 out &&
 678
 679                git rev-parse >expect               \
 680                        A:a   C:b   B:b   C:c   B:c &&
 681                git rev-parse >actual                \
 682                        :1:a  :2:b  :3:b  :2:c  :3:c &&
 683                test_cmp expect actual &&
 684
 685                git rev-parse >expect               \
 686                        C:c     B:c     C:b     B:b &&
 687                git hash-object >actual                \
 688                        c~HEAD  c~B\^0  b~HEAD  b~B\^0 &&
 689                test_cmp expect actual &&
 690
 691                test_path_is_missing b &&
 692                test_path_is_missing c
 693        )
 694'
 695
 696# Testcase rad, rename/add/delete
 697#   Commit O: foo
 698#   Commit A: rm foo, add different bar
 699#   Commit B: rename foo->bar
 700#   Expected: CONFLICT (rename/add/delete), two-way merged bar
 701
 702test_expect_success 'rad-setup: rename/add/delete conflict' '
 703        test_create_repo rad &&
 704        (
 705                cd rad &&
 706                echo "original file" >foo &&
 707                git add foo &&
 708                git commit -m "original" &&
 709
 710                git branch O &&
 711                git branch A &&
 712                git branch B &&
 713
 714                git checkout A &&
 715                git rm foo &&
 716                echo "different file" >bar &&
 717                git add bar &&
 718                git commit -m "Remove foo, add bar" &&
 719
 720                git checkout B &&
 721                git mv foo bar &&
 722                git commit -m "rename foo to bar"
 723        )
 724'
 725
 726test_expect_failure 'rad-check: rename/add/delete conflict' '
 727        (
 728                cd rad &&
 729
 730                git checkout B^0 &&
 731                test_must_fail git merge -s recursive A^0 >out 2>err &&
 732
 733                # Not sure whether the output should contain just one
 734                # "CONFLICT (rename/add/delete)" line, or if it should break
 735                # it into a pair of "CONFLICT (rename/delete)" and
 736                # "CONFLICT (rename/add)"; allow for either.
 737                test_i18ngrep "CONFLICT (rename.*add)" out &&
 738                test_i18ngrep "CONFLICT (rename.*delete)" out &&
 739                test_must_be_empty err &&
 740
 741                git ls-files -s >file_count &&
 742                test_line_count = 2 file_count &&
 743                git ls-files -u >file_count &&
 744                test_line_count = 2 file_count &&
 745                git ls-files -o >file_count &&
 746                test_line_count = 2 file_count &&
 747
 748                git rev-parse >actual \
 749                        :2:bar :3:bar &&
 750                git rev-parse >expect \
 751                        B:bar  A:bar  &&
 752
 753                test_cmp file_is_missing foo &&
 754                # bar should have two-way merged contents of the different
 755                # versions of bar; check that content from both sides is
 756                # present.
 757                grep original bar &&
 758                grep different bar
 759        )
 760'
 761
 762# Testcase rrdd, rename/rename(2to1)/delete/delete
 763#   Commit O: foo, bar
 764#   Commit A: rename foo->baz, rm bar
 765#   Commit B: rename bar->baz, rm foo
 766#   Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
 767
 768test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
 769        test_create_repo rrdd &&
 770        (
 771                cd rrdd &&
 772                echo foo >foo &&
 773                echo bar >bar &&
 774                git add foo bar &&
 775                git commit -m O &&
 776
 777                git branch O &&
 778                git branch A &&
 779                git branch B &&
 780
 781                git checkout A &&
 782                git mv foo baz &&
 783                git rm bar &&
 784                git commit -m "Rename foo, remove bar" &&
 785
 786                git checkout B &&
 787                git mv bar baz &&
 788                git rm foo &&
 789                git commit -m "Rename bar, remove foo"
 790        )
 791'
 792
 793test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
 794        (
 795                cd rrdd &&
 796
 797                git checkout A^0 &&
 798                test_must_fail git merge -s recursive B^0 >out 2>err &&
 799
 800                # Not sure whether the output should contain just one
 801                # "CONFLICT (rename/rename/delete/delete)" line, or if it
 802                # should break it into three: "CONFLICT (rename/rename)" and
 803                # two "CONFLICT (rename/delete)" lines; allow for either.
 804                test_i18ngrep "CONFLICT (rename/rename)" out &&
 805                test_i18ngrep "CONFLICT (rename.*delete)" out &&
 806                test_must_be_empty err &&
 807
 808                git ls-files -s >file_count &&
 809                test_line_count = 2 file_count &&
 810                git ls-files -u >file_count &&
 811                test_line_count = 2 file_count &&
 812                git ls-files -o >file_count &&
 813                test_line_count = 2 file_count &&
 814
 815                git rev-parse >actual \
 816                        :2:baz :3:baz &&
 817                git rev-parse >expect \
 818                        O:foo  O:bar  &&
 819
 820                test_cmp file_is_missing foo &&
 821                test_cmp file_is_missing bar &&
 822                # baz should have two-way merged contents of the original
 823                # contents of foo and bar; check that content from both sides
 824                # is present.
 825                grep foo baz &&
 826                grep bar baz
 827        )
 828'
 829
 830# Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
 831#   Commit O: one,      three,       five
 832#   Commit A: one->two, three->four, five->six
 833#   Commit B: one->six, three->two,  five->four
 834#   Expected: six CONFLICT(rename/rename) messages, each path in two of the
 835#             multi-way merged contents found in two, four, six
 836
 837test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
 838        test_create_repo mod6 &&
 839        (
 840                cd mod6 &&
 841                test_seq 11 19 >one &&
 842                test_seq 31 39 >three &&
 843                test_seq 51 59 >five &&
 844                git add . &&
 845                test_tick &&
 846                git commit -m "O" &&
 847
 848                git branch O &&
 849                git branch A &&
 850                git branch B &&
 851
 852                git checkout A &&
 853                test_seq 10 19 >one &&
 854                echo 40        >>three &&
 855                git add one three &&
 856                git mv  one   two  &&
 857                git mv  three four &&
 858                git mv  five  six  &&
 859                test_tick &&
 860                git commit -m "A" &&
 861
 862                git checkout B &&
 863                echo 20    >>one       &&
 864                echo forty >>three     &&
 865                echo 60    >>five      &&
 866                git add one three five &&
 867                git mv  one   six  &&
 868                git mv  three two  &&
 869                git mv  five  four &&
 870                test_tick &&
 871                git commit -m "B"
 872        )
 873'
 874
 875test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
 876        (
 877                cd mod6 &&
 878
 879                git checkout A^0 &&
 880
 881                test_must_fail git merge -s recursive B^0 >out 2>err &&
 882
 883                test_i18ngrep "CONFLICT (rename/rename)" out &&
 884                test_must_be_empty err &&
 885
 886                git ls-files -s >file_count &&
 887                test_line_count = 6 file_count &&
 888                git ls-files -u >file_count &&
 889                test_line_count = 6 file_count &&
 890                git ls-files -o >file_count &&
 891                test_line_count = 3 file_count &&
 892
 893                test_seq 10 20 >merged-one &&
 894                test_seq 51 60 >merged-five &&
 895                # Determine what the merge of three would give us.
 896                test_seq 30 40 >three-side-A &&
 897                test_seq 31 39 >three-side-B &&
 898                echo forty >three-side-B &&
 899                >empty &&
 900                test_must_fail git merge-file \
 901                        -L "HEAD" \
 902                        -L "" \
 903                        -L "B^0" \
 904                        three-side-A empty three-side-B &&
 905                sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
 906
 907                # Verify the index is as expected
 908                git rev-parse >actual         \
 909                        :2:two       :3:two   \
 910                        :2:four      :3:four  \
 911                        :2:six       :3:six   &&
 912                git hash-object >expect           \
 913                        merged-one   merged-three \
 914                        merged-three merged-five  \
 915                        merged-five  merged-one   &&
 916                test_cmp expect actual &&
 917
 918                git cat-file -p :2:two >expect &&
 919                git cat-file -p :3:two >other &&
 920                test_must_fail git merge-file    \
 921                        -L "HEAD"  -L ""  -L "B^0" \
 922                        expect     empty  other &&
 923                test_cmp expect two &&
 924
 925                git cat-file -p :2:four >expect &&
 926                git cat-file -p :3:four >other &&
 927                test_must_fail git merge-file    \
 928                        -L "HEAD"  -L ""  -L "B^0" \
 929                        expect     empty  other &&
 930                test_cmp expect four &&
 931
 932                git cat-file -p :2:six >expect &&
 933                git cat-file -p :3:six >other &&
 934                test_must_fail git merge-file    \
 935                        -L "HEAD"  -L ""  -L "B^0" \
 936                        expect     empty  other &&
 937                test_cmp expect six
 938        )
 939'
 940
 941test_done