1596
)
1597
'
1598
1599
+# Setup:
1600
+# L1---L2---L3
1601
+# / \ / \ / \
1602
+# master X1 X2 ?
1603
+# \ / \ / \ /
1604
+# R1---R2---R3
1605
+#
1606
+# Where:
1607
+# master has one file named 'content'
1608
+# branches L1 and R1 both modify each of the two files in conflicting ways
1609
+#
1610
+# L<n> (n>1) is a merge of R<n-1> into L<n-1>
1611
+# R<n> (n>1) is a merge of L<n-1> into R<n-1>
1612
+# L<n> and R<n> resolve the conflicts differently.
1613
+#
1614
+# X<n> is an auto-generated merge-base used when merging L<n+1> and R<n+1>.
1615
+# By construction, X1 has conflict markers due to conflicting versions.
1616
+# X2, due to using merge.conflictstyle=3, has nested conflict markers.
1617
+#
1618
+# So, merging R3 into L3 using merge.conflictstyle=3 should show the
1619
+# nested conflict markers from X2 in the base version -- that means we
1620
+# have three levels of conflict markers. Can we distinguish all three?
1621
+
1622
+test_expect_success 'setup virtual merge base with nested conflicts' '
1623
+ test_create_repo virtual_merge_base_has_nested_conflicts &&
1624
+ (
1625
+ cd virtual_merge_base_has_nested_conflicts &&
1626
+
1627
+ # Create some related files now
1628
+ for i in $(test_seq 1 10)
1629
+ do
1630
+ echo Random base content line $i
1631
+ done >content &&
1632
+
1633
+ # Setup original commit
1634
+ git add content &&
1635
+ test_tick && git commit -m initial &&
1636
+
1637
+ git branch L &&
1638
+ git branch R &&
1639
+
1640
+ # Create L1
1641
+ git checkout L &&
1642
+ echo left >>content &&
1643
+ git add content &&
1644
+ test_tick && git commit -m "version L1 of content" &&
1645
+ git tag L1 &&
1646
+
1647
+ # Create R1
1648
+ git checkout R &&
1649
+ echo right >>content &&
1650
+ git add content &&
1651
+ test_tick && git commit -m "verson R1 of content" &&
1652
+ git tag R1 &&
1653
+
1654
+ # Create L2
1655
+ git checkout L &&
1656
+ test_must_fail git -c merge.conflictstyle=diff3 merge R1 &&
1657
+ git checkout L1 content &&
1658
+ test_tick && git commit -m "version L2 of content" &&
1659
+ git tag L2 &&
1660
+
1661
+ # Create R2
1662
+ git checkout R &&
1663
+ test_must_fail git -c merge.conflictstyle=diff3 merge L1 &&
1664
+ git checkout R1 content &&
1665
+ test_tick && git commit -m "version R2 of content" &&
1666
+ git tag R2 &&
1667
+
1668
+ # Create L3
1669
+ git checkout L &&
1670
+ test_must_fail git -c merge.conflictstyle=diff3 merge R2 &&
1671
+ git checkout L1 content &&
1672
+ test_tick && git commit -m "version L3 of content" &&
1673
+ git tag L3 &&
1674
+
1675
+ # Create R3
1676
+ git checkout R &&
1677
+ test_must_fail git -c merge.conflictstyle=diff3 merge L2 &&
1678
+ git checkout R1 content &&
1679
+ test_tick && git commit -m "version R3 of content" &&
1680
+ git tag R3
1681
+ )
1682
+'
1683
+
1684
+test_expect_success 'check virtual merge base with nested conflicts' '
1685
+ (
1686
+ cd virtual_merge_base_has_nested_conflicts &&
1687
+
1688
+ git checkout L3^0 &&
1689
+
1690
+ # Merge must fail; there is a conflict
1691
+ test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R3^0 &&
1692
+
1693
+ # Make sure the index has the right number of entries
1694
+ git ls-files -s >out &&
1695
+ test_line_count = 3 out &&
1696
+ git ls-files -u >out &&
1697
+ test_line_count = 3 out &&
1698
+ # Ensure we have the correct number of untracked files
1699
+ git ls-files -o >out &&
1700
+ test_line_count = 1 out &&
1701
+
1702
+ # Compare :[23]:content to expected values
1703
+ git rev-parse L1:content R1:content >expect &&
1704
+ git rev-parse :2:content :3:content >actual &&
1705
+ test_cmp expect actual &&
1706
+
1707
+ # Imitate X1 merge base, except without long enough conflict
1708
+ # markers because a subsequent sed will modify them. Put
1709
+ # result into vmb.
1710
+ git cat-file -p master:content >base &&
1711
+ git cat-file -p L:content >left &&
1712
+ git cat-file -p R:content >right &&
1713
+ cp left merged-once &&
1714
+ test_must_fail git merge-file --diff3 \
1715
+ -L "Temporary merge branch 1" \
1716
+ -L "merged common ancestors" \
1717
+ -L "Temporary merge branch 2" \
1718
+ merged-once \
1719
+ base \
1720
+ right &&
1721
+ sed -e "s/^\([<|=>]\)/\1\1\1/" merged-once >vmb &&
1722
+
1723
+ # Imitate X2 merge base, overwriting vmb. Note that we
1724
+ # extend both sets of conflict markers to make them longer
1725
+ # with the sed command.
1726
+ cp left merged-twice &&
1727
+ test_must_fail git merge-file --diff3 \
1728
+ -L "Temporary merge branch 1" \
1729
+ -L "merged common ancestors" \
1730
+ -L "Temporary merge branch 2" \
1731
+ merged-twice \
1732
+ vmb \
1733
+ right &&
1734
+ sed -e "s/^\([<|=>]\)/\1\1\1/" merged-twice >vmb &&
1735
+
1736
+ # Compare :1:content to expected value
1737
+ git cat-file -p :1:content >actual &&
1738
+ test_cmp vmb actual &&
1739
+
1740
+ # Determine expected content in final outer merge, compare to
1741
+ # what the merge generated.
1742
+ cp -f left expect &&
1743
+ test_must_fail git merge-file --diff3 \
1744
+ -L "HEAD" -L "merged common ancestors" -L "R3^0" \
1745
+ expect vmb right &&
1746
+ test_cmp expect content
1747
+ )
1748
+'
1749
+
1750
test_done