1560
1377
((None, [None, None]), u'a', None),
1561
1378
((None, [None, None]), False, None)),
1564
def test_one_lca_supersedes(self):
1565
# One LCA supersedes the other LCAs last modified value, but the
1566
# value is not the same as BASE.
1567
# A base, introduces 'foo', last mod A
1569
# B C B modifies 'foo' (mod B), C does nothing (mod A)
1571
# D E D does nothing (mod B), E updates 'foo' (mod E)
1573
# F G F updates 'foo' (mod F). G does nothing (mod E)
1575
# At this point, G should not be considered to modify 'foo', even
1576
# though its LCAs disagree. This is because the modification in E
1577
# completely supersedes the value in D.
1578
builder = self.get_builder()
1579
builder.build_snapshot('A-id', None,
1580
[('add', (u'', 'a-root-id', 'directory', None)),
1581
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1582
builder.build_snapshot('C-id', ['A-id'], [])
1583
builder.build_snapshot('B-id', ['A-id'],
1584
[('modify', ('foo-id', 'B content\n'))])
1585
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1586
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1587
[('modify', ('foo-id', 'E content\n'))])
1588
builder.build_snapshot('G-id', ['E-id', 'D-id'], [])
1589
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1590
[('modify', ('foo-id', 'F content\n'))])
1591
merge_obj = self.make_merge_obj(builder, 'G-id')
1593
self.assertEqual([], list(merge_obj._entries_lca()))
1595
def test_one_lca_supersedes_path(self):
1596
# Double-criss-cross merge, the ultimate base value is different from
1600
# B C B value 'bar', C = 'foo'
1602
# D E D = 'bar', E supersedes to 'bing'
1604
# F G F = 'bing', G supersedes to 'barry'
1606
# In this case, we technically should not care about the value 'bar' for
1607
# D, because it was clearly superseded by E's 'bing'. The
1608
# per-file/attribute graph would actually look like:
1617
# Because the other side of the merge never modifies the value, it just
1618
# takes the value from the merge.
1620
# ATM this fails because we will prune 'foo' from the LCAs, but we
1621
# won't prune 'bar'. This is getting far off into edge-case land, so we
1622
# aren't supporting it yet.
1624
builder = self.get_builder()
1625
builder.build_snapshot('A-id', None,
1626
[('add', (u'', 'a-root-id', 'directory', None)),
1627
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1628
builder.build_snapshot('C-id', ['A-id'], [])
1629
builder.build_snapshot('B-id', ['A-id'],
1630
[('rename', ('foo', 'bar'))])
1631
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1632
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1633
[('rename', ('foo', 'bing'))]) # override to bing
1634
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1635
[('rename', ('bing', 'barry'))]) # override to barry
1636
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1637
[('rename', ('bar', 'bing'))]) # Merge in E's change
1638
merge_obj = self.make_merge_obj(builder, 'G-id')
1640
self.expectFailure("We don't do an actual heads() check on lca values,"
1641
" or use the per-attribute graph",
1642
self.assertEqual, [], list(merge_obj._entries_lca()))
1644
def test_one_lca_accidentally_pruned(self):
1645
# Another incorrect resolution from the same basic flaw:
1648
# B C B value 'bar', C = 'foo'
1650
# D E D = 'bar', E reverts to 'foo'
1652
# F G F = 'bing', G switches to 'bar'
1654
# 'bar' will not be seen as an interesting change, because 'foo' will
1655
# be pruned from the LCAs, even though it was newly introduced by E
1657
builder = self.get_builder()
1658
builder.build_snapshot('A-id', None,
1659
[('add', (u'', 'a-root-id', 'directory', None)),
1660
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1661
builder.build_snapshot('C-id', ['A-id'], [])
1662
builder.build_snapshot('B-id', ['A-id'],
1663
[('rename', ('foo', 'bar'))])
1664
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1665
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1666
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1667
[('rename', ('foo', 'bar'))])
1668
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1669
[('rename', ('bar', 'bing'))]) # should end up conflicting
1670
merge_obj = self.make_merge_obj(builder, 'G-id')
1672
entries = list(merge_obj._entries_lca())
1673
root_id = 'a-root-id'
1674
self.expectFailure("We prune values from BASE even when relevant.",
1677
((root_id, [root_id, root_id]), root_id, root_id),
1678
((u'foo', [u'bar', u'foo']), u'bar', u'bing'),
1679
((False, [False, False]), False, False)),
1682
def test_both_sides_revert(self):
1683
# Both sides of a criss-cross revert the text to the lca
1684
# A base, introduces 'foo'
1686
# B C B modifies 'foo', C modifies 'foo'
1688
# D E D reverts to B, E reverts to C
1689
# This should conflict
1690
builder = self.get_builder()
1691
builder.build_snapshot('A-id', None,
1692
[('add', (u'', 'a-root-id', 'directory', None)),
1693
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1694
builder.build_snapshot('B-id', ['A-id'],
1695
[('modify', ('foo-id', 'B content\n'))])
1696
builder.build_snapshot('C-id', ['A-id'],
1697
[('modify', ('foo-id', 'C content\n'))])
1698
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1699
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1700
merge_obj = self.make_merge_obj(builder, 'E-id')
1702
entries = list(merge_obj._entries_lca())
1703
root_id = 'a-root-id'
1704
self.assertEqual([('foo-id', True,
1705
((root_id, [root_id, root_id]), root_id, root_id),
1706
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1707
((False, [False, False]), False, False)),
1710
def test_different_lca_resolve_one_side_updates_content(self):
1711
# Both sides converge, but then one side updates the text.
1712
# A base, introduces 'foo'
1714
# B C B modifies 'foo', C modifies 'foo'
1716
# D E D reverts to B, E reverts to C
1718
# F F updates to a new value
1719
# We need to emit an entry for 'foo', because D & E differed on the
1721
builder = self.get_builder()
1722
builder.build_snapshot('A-id', None,
1723
[('add', (u'', 'a-root-id', 'directory', None)),
1724
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1725
builder.build_snapshot('B-id', ['A-id'],
1726
[('modify', ('foo-id', 'B content\n'))])
1727
builder.build_snapshot('C-id', ['A-id'],
1728
[('modify', ('foo-id', 'C content\n'))])
1729
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1730
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1731
builder.build_snapshot('F-id', ['D-id'],
1732
[('modify', ('foo-id', 'F content\n'))])
1733
merge_obj = self.make_merge_obj(builder, 'E-id')
1735
entries = list(merge_obj._entries_lca())
1736
root_id = 'a-root-id'
1737
self.assertEqual([('foo-id', True,
1738
((root_id, [root_id, root_id]), root_id, root_id),
1739
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1740
((False, [False, False]), False, False)),
1743
def test_same_lca_resolution_one_side_updates_content(self):
1744
# Both sides converge, but then one side updates the text.
1745
# A base, introduces 'foo'
1747
# B C B modifies 'foo', C modifies 'foo'
1749
# D E D and E use C's value
1751
# F F updates to a new value
1752
# I think it is a bug that this conflicts, but we don't have a way to
1753
# detect otherwise. And because of:
1754
# test_different_lca_resolve_one_side_updates_content
1755
# We need to conflict.
1757
builder = self.get_builder()
1758
builder.build_snapshot('A-id', None,
1759
[('add', (u'', 'a-root-id', 'directory', None)),
1760
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1761
builder.build_snapshot('B-id', ['A-id'],
1762
[('modify', ('foo-id', 'B content\n'))])
1763
builder.build_snapshot('C-id', ['A-id'],
1764
[('modify', ('foo-id', 'C content\n'))])
1765
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1766
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1767
[('modify', ('foo-id', 'C content\n'))]) # Same as E
1768
builder.build_snapshot('F-id', ['D-id'],
1769
[('modify', ('foo-id', 'F content\n'))])
1770
merge_obj = self.make_merge_obj(builder, 'E-id')
1772
entries = list(merge_obj._entries_lca())
1773
self.expectFailure("We don't detect that LCA resolution was the"
1774
" same on both sides",
1775
self.assertEqual, [], entries)
1777
def test_only_path_changed(self):
1778
builder = self.get_builder()
1779
builder.build_snapshot('A-id', None,
1780
[('add', (u'', 'a-root-id', 'directory', None)),
1781
('add', (u'a', 'a-id', 'file', 'content\n'))])
1782
builder.build_snapshot('B-id', ['A-id'], [])
1783
builder.build_snapshot('C-id', ['A-id'], [])
1784
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1785
[('rename', (u'a', u'b'))])
1786
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1787
merge_obj = self.make_merge_obj(builder, 'E-id')
1788
entries = list(merge_obj._entries_lca())
1789
root_id = 'a-root-id'
1790
# The content was not changed, only the path
1791
self.assertEqual([('a-id', False,
1792
((root_id, [root_id, root_id]), root_id, root_id),
1793
((u'a', [u'a', u'a']), u'b', u'a'),
1794
((False, [False, False]), False, False)),
1797
def test_kind_changed(self):
1798
# Identical content, except 'D' changes a-id into a directory
1799
builder = self.get_builder()
1800
builder.build_snapshot('A-id', None,
1801
[('add', (u'', 'a-root-id', 'directory', None)),
1802
('add', (u'a', 'a-id', 'file', 'content\n'))])
1803
builder.build_snapshot('B-id', ['A-id'], [])
1804
builder.build_snapshot('C-id', ['A-id'], [])
1805
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1806
[('unversion', 'a-id'),
1807
('add', (u'a', 'a-id', 'directory', None))])
1808
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1809
merge_obj = self.make_merge_obj(builder, 'E-id')
1810
entries = list(merge_obj._entries_lca())
1811
root_id = 'a-root-id'
1812
# Only the kind was changed (content)
1813
self.assertEqual([('a-id', True,
1814
((root_id, [root_id, root_id]), root_id, root_id),
1815
((u'a', [u'a', u'a']), u'a', u'a'),
1816
((False, [False, False]), False, False)),
1819
def test_this_changed_kind(self):
1820
# Identical content, but THIS changes a file to a directory
1821
builder = self.get_builder()
1822
builder.build_snapshot('A-id', None,
1823
[('add', (u'', 'a-root-id', 'directory', None)),
1824
('add', (u'a', 'a-id', 'file', 'content\n'))])
1825
builder.build_snapshot('B-id', ['A-id'], [])
1826
builder.build_snapshot('C-id', ['A-id'], [])
1827
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1828
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1829
[('unversion', 'a-id'),
1830
('add', (u'a', 'a-id', 'directory', None))])
1831
merge_obj = self.make_merge_obj(builder, 'E-id')
1832
entries = list(merge_obj._entries_lca())
1833
# Only the kind was changed (content)
1834
self.assertEqual([], entries)
1836
def test_interesting_files(self):
1837
# Two files modified, but we should filter one of them
1838
builder = self.get_builder()
1839
builder.build_snapshot('A-id', None,
1840
[('add', (u'', 'a-root-id', 'directory', None)),
1841
('add', (u'a', 'a-id', 'file', 'content\n')),
1842
('add', (u'b', 'b-id', 'file', 'content\n'))])
1843
builder.build_snapshot('B-id', ['A-id'], [])
1844
builder.build_snapshot('C-id', ['A-id'], [])
1845
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1846
[('modify', ('a-id', 'new-content\n')),
1847
('modify', ('b-id', 'new-content\n'))])
1848
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1849
merge_obj = self.make_merge_obj(builder, 'E-id',
1850
interesting_files=['b'])
1851
entries = list(merge_obj._entries_lca())
1852
root_id = 'a-root-id'
1853
self.assertEqual([('b-id', True,
1854
((root_id, [root_id, root_id]), root_id, root_id),
1855
((u'b', [u'b', u'b']), u'b', u'b'),
1856
((False, [False, False]), False, False)),
1859
def test_interesting_file_in_this(self):
1860
# This renamed the file, but it should still match the entry in other
1861
builder = self.get_builder()
1862
builder.build_snapshot('A-id', None,
1863
[('add', (u'', 'a-root-id', 'directory', None)),
1864
('add', (u'a', 'a-id', 'file', 'content\n')),
1865
('add', (u'b', 'b-id', 'file', 'content\n'))])
1866
builder.build_snapshot('B-id', ['A-id'], [])
1867
builder.build_snapshot('C-id', ['A-id'], [])
1868
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1869
[('modify', ('a-id', 'new-content\n')),
1870
('modify', ('b-id', 'new-content\n'))])
1871
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1872
[('rename', ('b', 'c'))])
1873
merge_obj = self.make_merge_obj(builder, 'E-id',
1874
interesting_files=['c'])
1875
entries = list(merge_obj._entries_lca())
1876
root_id = 'a-root-id'
1877
self.assertEqual([('b-id', True,
1878
((root_id, [root_id, root_id]), root_id, root_id),
1879
((u'b', [u'b', u'b']), u'b', u'c'),
1880
((False, [False, False]), False, False)),
1883
def test_interesting_file_in_base(self):
1884
# This renamed the file, but it should still match the entry in BASE
1885
builder = self.get_builder()
1886
builder.build_snapshot('A-id', None,
1887
[('add', (u'', 'a-root-id', 'directory', None)),
1888
('add', (u'a', 'a-id', 'file', 'content\n')),
1889
('add', (u'c', 'c-id', 'file', 'content\n'))])
1890
builder.build_snapshot('B-id', ['A-id'],
1891
[('rename', ('c', 'b'))])
1892
builder.build_snapshot('C-id', ['A-id'],
1893
[('rename', ('c', 'b'))])
1894
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1895
[('modify', ('a-id', 'new-content\n')),
1896
('modify', ('c-id', 'new-content\n'))])
1897
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1898
merge_obj = self.make_merge_obj(builder, 'E-id',
1899
interesting_files=['c'])
1900
entries = list(merge_obj._entries_lca())
1901
root_id = 'a-root-id'
1902
self.assertEqual([('c-id', True,
1903
((root_id, [root_id, root_id]), root_id, root_id),
1904
((u'c', [u'b', u'b']), u'b', u'b'),
1905
((False, [False, False]), False, False)),
1908
def test_interesting_file_in_lca(self):
1909
# This renamed the file, but it should still match the entry in LCA
1910
builder = self.get_builder()
1911
builder.build_snapshot('A-id', None,
1912
[('add', (u'', 'a-root-id', 'directory', None)),
1913
('add', (u'a', 'a-id', 'file', 'content\n')),
1914
('add', (u'b', 'b-id', 'file', 'content\n'))])
1915
builder.build_snapshot('B-id', ['A-id'],
1916
[('rename', ('b', 'c'))])
1917
builder.build_snapshot('C-id', ['A-id'], [])
1918
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1919
[('modify', ('a-id', 'new-content\n')),
1920
('modify', ('b-id', 'new-content\n'))])
1921
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1922
[('rename', ('c', 'b'))])
1923
merge_obj = self.make_merge_obj(builder, 'E-id',
1924
interesting_files=['c'])
1925
entries = list(merge_obj._entries_lca())
1926
root_id = 'a-root-id'
1927
self.assertEqual([('b-id', True,
1928
((root_id, [root_id, root_id]), root_id, root_id),
1929
((u'b', [u'c', u'b']), u'b', u'b'),
1930
((False, [False, False]), False, False)),
1933
def test_interesting_ids(self):
1934
# Two files modified, but we should filter one of them
1935
builder = self.get_builder()
1936
builder.build_snapshot('A-id', None,
1937
[('add', (u'', 'a-root-id', 'directory', None)),
1938
('add', (u'a', 'a-id', 'file', 'content\n')),
1939
('add', (u'b', 'b-id', 'file', 'content\n'))])
1940
builder.build_snapshot('B-id', ['A-id'], [])
1941
builder.build_snapshot('C-id', ['A-id'], [])
1942
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1943
[('modify', ('a-id', 'new-content\n')),
1944
('modify', ('b-id', 'new-content\n'))])
1945
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1946
merge_obj = self.make_merge_obj(builder, 'E-id',
1947
interesting_ids=['b-id'])
1948
entries = list(merge_obj._entries_lca())
1949
root_id = 'a-root-id'
1950
self.assertEqual([('b-id', True,
1951
((root_id, [root_id, root_id]), root_id, root_id),
1952
((u'b', [u'b', u'b']), u'b', u'b'),
1953
((False, [False, False]), False, False)),
1958
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
1960
def get_builder(self):
1961
builder = self.make_branch_builder('path')
1962
builder.start_series()
1963
self.addCleanup(builder.finish_series)
1966
def get_wt_from_builder(self, builder):
1967
"""Get a real WorkingTree from the builder."""
1968
the_branch = builder.get_branch()
1969
wt = the_branch.bzrdir.create_workingtree()
1970
# Note: This is a little bit ugly, but we are holding the branch
1971
# write-locked as part of the build process, and we would like to
1972
# maintain that. So we just force the WT to re-use the same
1974
wt._branch = the_branch
1976
self.addCleanup(wt.unlock)
1979
def do_merge(self, builder, other_revision_id):
1980
wt = self.get_wt_from_builder(builder)
1981
merger = _mod_merge.Merger.from_revision_ids(None,
1982
wt, other_revision_id)
1983
merger.merge_type = _mod_merge.Merge3Merger
1984
return wt, merger.do_merge()
1986
def test_simple_lca(self):
1987
builder = self.get_builder()
1988
builder.build_snapshot('A-id', None,
1989
[('add', (u'', 'a-root-id', 'directory', None)),
1990
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1991
builder.build_snapshot('C-id', ['A-id'], [])
1992
builder.build_snapshot('B-id', ['A-id'], [])
1993
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1994
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1995
[('modify', ('a-id', 'a\nb\nc\nd\ne\nf\n'))])
1996
wt, conflicts = self.do_merge(builder, 'E-id')
1997
self.assertEqual(0, conflicts)
1998
# The merge should have simply update the contents of 'a'
1999
self.assertEqual('a\nb\nc\nd\ne\nf\n', wt.get_file_text('a-id'))
2001
def test_conflict_without_lca(self):
2002
# This test would cause a merge conflict, unless we use the lca trees
2003
# to determine the real ancestry
2006
# B C Path renamed to 'bar' in B
2010
# D E Path at 'bar' in D and E
2012
# F Path at 'baz' in F, which supersedes 'bar' and 'foo'
2013
builder = self.get_builder()
2014
builder.build_snapshot('A-id', None,
2015
[('add', (u'', 'a-root-id', 'directory', None)),
2016
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2017
builder.build_snapshot('C-id', ['A-id'], [])
2018
builder.build_snapshot('B-id', ['A-id'],
2019
[('rename', ('foo', 'bar'))])
2020
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2021
[('rename', ('foo', 'bar'))])
2022
builder.build_snapshot('F-id', ['E-id'],
2023
[('rename', ('bar', 'baz'))])
2024
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2025
wt, conflicts = self.do_merge(builder, 'F-id')
2026
self.assertEqual(0, conflicts)
2027
# The merge should simply recognize that the final rename takes
2029
self.assertEqual('baz', wt.id2path('foo-id'))
2031
def test_other_deletes_lca_renames(self):
2032
# This test would cause a merge conflict, unless we use the lca trees
2033
# to determine the real ancestry
2036
# B C Path renamed to 'bar' in B
2040
# D E Path at 'bar' in D and E
2043
builder = self.get_builder()
2044
builder.build_snapshot('A-id', None,
2045
[('add', (u'', 'a-root-id', 'directory', None)),
2046
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2047
builder.build_snapshot('C-id', ['A-id'], [])
2048
builder.build_snapshot('B-id', ['A-id'],
2049
[('rename', ('foo', 'bar'))])
2050
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2051
[('rename', ('foo', 'bar'))])
2052
builder.build_snapshot('F-id', ['E-id'],
2053
[('unversion', 'foo-id')])
2054
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2055
wt, conflicts = self.do_merge(builder, 'F-id')
2056
self.assertEqual(0, conflicts)
2057
self.assertRaises(errors.NoSuchId, wt.id2path, 'foo-id')
2059
def test_executable_changes(self):
2068
# F Executable bit changed
2069
builder = self.get_builder()
2070
builder.build_snapshot('A-id', None,
2071
[('add', (u'', 'a-root-id', 'directory', None)),
2072
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2073
builder.build_snapshot('C-id', ['A-id'], [])
2074
builder.build_snapshot('B-id', ['A-id'], [])
2075
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2076
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2077
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2078
wt = self.get_wt_from_builder(builder)
2079
tt = transform.TreeTransform(wt)
2081
tt.set_executability(True, tt.trans_id_tree_file_id('foo-id'))
2086
self.assertTrue(wt.is_executable('foo-id'))
2087
wt.commit('F-id', rev_id='F-id')
2088
# Reset to D, so that we can merge F
2089
wt.set_parent_ids(['D-id'])
2090
wt.branch.set_last_revision_info(3, 'D-id')
2092
self.assertFalse(wt.is_executable('foo-id'))
2093
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2094
self.assertEqual(0, conflicts)
2095
self.assertTrue(wt.is_executable('foo-id'))
2097
def test_create_symlink(self):
2098
self.requireFeature(tests.SymlinkFeature)
2107
# F Add a symlink 'foo' => 'bar'
2108
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2109
# have symlink support
2110
builder = self.get_builder()
2111
builder.build_snapshot('A-id', None,
2112
[('add', (u'', 'a-root-id', 'directory', None))])
2113
builder.build_snapshot('C-id', ['A-id'], [])
2114
builder.build_snapshot('B-id', ['A-id'], [])
2115
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2116
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2117
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2118
wt = self.get_wt_from_builder(builder)
2119
os.symlink('bar', 'path/foo')
2120
wt.add(['foo'], ['foo-id'])
2121
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2122
wt.commit('add symlink', rev_id='F-id')
2123
# Reset to D, so that we can merge F
2124
wt.set_parent_ids(['D-id'])
2125
wt.branch.set_last_revision_info(3, 'D-id')
2127
self.assertIs(None, wt.path2id('foo'))
2128
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2129
self.assertEqual(0, conflicts)
2130
self.assertEqual('foo-id', wt.path2id('foo'))
2131
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2133
def test_both_sides_revert(self):
2134
# Both sides of a criss-cross revert the text to the lca
2135
# A base, introduces 'foo'
2137
# B C B modifies 'foo', C modifies 'foo'
2139
# D E D reverts to B, E reverts to C
2140
# This should conflict
2141
# This must be done with a real WorkingTree, because normally their
2142
# inventory contains "None" rather than a real sha1
2143
builder = self.get_builder()
2144
builder.build_snapshot('A-id', None,
2145
[('add', (u'', 'a-root-id', 'directory', None)),
2146
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
2147
builder.build_snapshot('B-id', ['A-id'],
2148
[('modify', ('foo-id', 'B content\n'))])
2149
builder.build_snapshot('C-id', ['A-id'],
2150
[('modify', ('foo-id', 'C content\n'))])
2151
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2152
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2153
wt, conflicts = self.do_merge(builder, 'E-id')
2154
self.assertEqual(1, conflicts)
2155
self.assertEqualDiff('<<<<<<< TREE\n'
2159
'>>>>>>> MERGE-SOURCE\n',
2160
wt.get_file_text('foo-id'))
2162
def test_modified_symlink(self):
2163
self.requireFeature(tests.SymlinkFeature)
2164
# A Create symlink foo => bar
2166
# B C B relinks foo => baz
2170
# D E D & E have foo => baz
2172
# F F changes it to bing
2174
# Merging D & F should result in F cleanly overriding D, because D's
2175
# value actually comes from B
2177
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2178
# have symlink support
2179
wt = self.make_branch_and_tree('path')
2181
self.addCleanup(wt.unlock)
2182
os.symlink('bar', 'path/foo')
2183
wt.add(['foo'], ['foo-id'])
2184
wt.commit('add symlink', rev_id='A-id')
2185
os.remove('path/foo')
2186
os.symlink('baz', 'path/foo')
2187
wt.commit('foo => baz', rev_id='B-id')
2188
wt.set_last_revision('A-id')
2189
wt.branch.set_last_revision_info(1, 'A-id')
2191
wt.commit('C', rev_id='C-id')
2192
wt.merge_from_branch(wt.branch, 'B-id')
2193
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2194
wt.commit('E merges C & B', rev_id='E-id')
2195
os.remove('path/foo')
2196
os.symlink('bing', 'path/foo')
2197
wt.commit('F foo => bing', rev_id='F-id')
2198
wt.set_last_revision('B-id')
2199
wt.branch.set_last_revision_info(2, 'B-id')
2201
wt.merge_from_branch(wt.branch, 'C-id')
2202
wt.commit('D merges B & C', rev_id='D-id')
2203
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2204
self.assertEqual(0, conflicts)
2205
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2207
def test_renamed_symlink(self):
2208
self.requireFeature(tests.SymlinkFeature)
2209
# A Create symlink foo => bar
2211
# B C B renames foo => barry
2215
# D E D & E have barry
2217
# F F renames barry to blah
2219
# Merging D & F should result in F cleanly overriding D, because D's
2220
# value actually comes from B
2222
wt = self.make_branch_and_tree('path')
2224
self.addCleanup(wt.unlock)
2225
os.symlink('bar', 'path/foo')
2226
wt.add(['foo'], ['foo-id'])
2227
wt.commit('A add symlink', rev_id='A-id')
2228
wt.rename_one('foo', 'barry')
2229
wt.commit('B foo => barry', rev_id='B-id')
2230
wt.set_last_revision('A-id')
2231
wt.branch.set_last_revision_info(1, 'A-id')
2233
wt.commit('C', rev_id='C-id')
2234
wt.merge_from_branch(wt.branch, 'B-id')
2235
self.assertEqual('barry', wt.id2path('foo-id'))
2236
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2237
wt.commit('E merges C & B', rev_id='E-id')
2238
wt.rename_one('barry', 'blah')
2239
wt.commit('F barry => blah', rev_id='F-id')
2240
wt.set_last_revision('B-id')
2241
wt.branch.set_last_revision_info(2, 'B-id')
2243
wt.merge_from_branch(wt.branch, 'C-id')
2244
wt.commit('D merges B & C', rev_id='D-id')
2245
self.assertEqual('barry', wt.id2path('foo-id'))
2246
# Check the output of the Merger object directly
2247
merger = _mod_merge.Merger.from_revision_ids(None,
2249
merger.merge_type = _mod_merge.Merge3Merger
2250
merge_obj = merger.make_merger()
2251
root_id = wt.path2id('')
2252
entries = list(merge_obj._entries_lca())
2253
# No content change, just a path change
2254
self.assertEqual([('foo-id', False,
2255
((root_id, [root_id, root_id]), root_id, root_id),
2256
((u'foo', [u'barry', u'foo']), u'blah', u'barry'),
2257
((False, [False, False]), False, False)),
2259
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2260
self.assertEqual(0, conflicts)
2261
self.assertEqual('blah', wt.id2path('foo-id'))
2263
def test_symlink_no_content_change(self):
2264
self.requireFeature(tests.SymlinkFeature)
2265
# A Create symlink foo => bar
2267
# B C B relinks foo => baz
2271
# D E D & E have foo => baz
2273
# F F has foo => bing
2275
# Merging E into F should not cause a conflict, because E doesn't have
2276
# a content change relative to the LCAs (it does relative to A)
2277
wt = self.make_branch_and_tree('path')
2279
self.addCleanup(wt.unlock)
2280
os.symlink('bar', 'path/foo')
2281
wt.add(['foo'], ['foo-id'])
2282
wt.commit('add symlink', rev_id='A-id')
2283
os.remove('path/foo')
2284
os.symlink('baz', 'path/foo')
2285
wt.commit('foo => baz', rev_id='B-id')
2286
wt.set_last_revision('A-id')
2287
wt.branch.set_last_revision_info(1, 'A-id')
2289
wt.commit('C', rev_id='C-id')
2290
wt.merge_from_branch(wt.branch, 'B-id')
2291
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2292
wt.commit('E merges C & B', rev_id='E-id')
2293
wt.set_last_revision('B-id')
2294
wt.branch.set_last_revision_info(2, 'B-id')
2296
wt.merge_from_branch(wt.branch, 'C-id')
2297
wt.commit('D merges B & C', rev_id='D-id')
2298
os.remove('path/foo')
2299
os.symlink('bing', 'path/foo')
2300
wt.commit('F foo => bing', rev_id='F-id')
2302
# Check the output of the Merger object directly
2303
merger = _mod_merge.Merger.from_revision_ids(None,
2305
merger.merge_type = _mod_merge.Merge3Merger
2306
merge_obj = merger.make_merger()
2307
# Nothing interesting happened in OTHER relative to BASE
2308
self.assertEqual([], list(merge_obj._entries_lca()))
2309
# Now do a real merge, just to test the rest of the stack
2310
conflicts = wt.merge_from_branch(wt.branch, to_revision='E-id')
2311
self.assertEqual(0, conflicts)
2312
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2314
def test_symlink_this_changed_kind(self):
2315
self.requireFeature(tests.SymlinkFeature)
2318
# B C B creates symlink foo => bar
2322
# D E D changes foo into a file, E has foo => bing
2324
# Mostly, this is trying to test that we don't try to os.readlink() on
2325
# a file, or when there is nothing there
2326
wt = self.make_branch_and_tree('path')
2328
self.addCleanup(wt.unlock)
2329
wt.commit('base', rev_id='A-id')
2330
os.symlink('bar', 'path/foo')
2331
wt.add(['foo'], ['foo-id'])
2332
wt.commit('add symlink foo => bar', rev_id='B-id')
2333
wt.set_last_revision('A-id')
2334
wt.branch.set_last_revision_info(1, 'A-id')
2336
wt.commit('C', rev_id='C-id')
2337
wt.merge_from_branch(wt.branch, 'B-id')
2338
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2339
os.remove('path/foo')
2340
# We have to change the link in E, or it won't try to do a comparison
2341
os.symlink('bing', 'path/foo')
2342
wt.commit('E merges C & B, overrides to bing', rev_id='E-id')
2343
wt.set_last_revision('B-id')
2344
wt.branch.set_last_revision_info(2, 'B-id')
2346
wt.merge_from_branch(wt.branch, 'C-id')
2347
os.remove('path/foo')
2348
self.build_tree_contents([('path/foo', 'file content\n')])
2349
# XXX: workaround, WT doesn't detect kind changes unless you do
2351
list(wt.iter_changes(wt.basis_tree()))
2352
wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2354
merger = _mod_merge.Merger.from_revision_ids(None,
2356
merger.merge_type = _mod_merge.Merge3Merger
2357
merge_obj = merger.make_merger()
2358
entries = list(merge_obj._entries_lca())
2359
root_id = wt.path2id('')
2360
self.assertEqual([('foo-id', True,
2361
((None, [root_id, None]), root_id, root_id),
2362
((None, [u'foo', None]), u'foo', u'foo'),
2363
((None, [False, None]), False, False)),
2366
def test_symlink_all_wt(self):
2367
"""Check behavior if all trees are Working Trees."""
2368
self.requireFeature(tests.SymlinkFeature)
2369
# The big issue is that entry.symlink_target is None for WorkingTrees.
2370
# So we need to make sure we handle that case correctly.
2373
# B C B relinks foo => baz
2375
# D E D & E have foo => baz
2377
# F F changes it to bing
2378
# Merging D & F should result in F cleanly overriding D, because D's
2379
# value actually comes from B
2381
wt = self.make_branch_and_tree('path')
2383
self.addCleanup(wt.unlock)
2384
os.symlink('bar', 'path/foo')
2385
wt.add(['foo'], ['foo-id'])
2386
wt.commit('add symlink', rev_id='A-id')
2387
os.remove('path/foo')
2388
os.symlink('baz', 'path/foo')
2389
wt.commit('foo => baz', rev_id='B-id')
2390
wt.set_last_revision('A-id')
2391
wt.branch.set_last_revision_info(1, 'A-id')
2393
wt.commit('C', rev_id='C-id')
2394
wt.merge_from_branch(wt.branch, 'B-id')
2395
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2396
wt.commit('E merges C & B', rev_id='E-id')
2397
os.remove('path/foo')
2398
os.symlink('bing', 'path/foo')
2399
wt.commit('F foo => bing', rev_id='F-id')
2400
wt.set_last_revision('B-id')
2401
wt.branch.set_last_revision_info(2, 'B-id')
2403
wt.merge_from_branch(wt.branch, 'C-id')
2404
wt.commit('D merges B & C', rev_id='D-id')
2405
wt_base = wt.bzrdir.sprout('base', 'A-id').open_workingtree()
2407
self.addCleanup(wt_base.unlock)
2408
wt_lca1 = wt.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2410
self.addCleanup(wt_lca1.unlock)
2411
wt_lca2 = wt.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2413
self.addCleanup(wt_lca2.unlock)
2414
wt_other = wt.bzrdir.sprout('other', 'F-id').open_workingtree()
2415
wt_other.lock_read()
2416
self.addCleanup(wt_other.unlock)
2417
merge_obj = _mod_merge.Merge3Merger(wt, wt, wt_base,
2418
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2419
entries = list(merge_obj._entries_lca())
2420
root_id = wt.path2id('')
2421
self.assertEqual([('foo-id', True,
2422
((root_id, [root_id, root_id]), root_id, root_id),
2423
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2424
((False, [False, False]), False, False)),
2427
def test_other_reverted_path_to_base(self):
2430
# B C Path at 'bar' in B
2437
builder = self.get_builder()
2438
builder.build_snapshot('A-id', None,
2439
[('add', (u'', 'a-root-id', 'directory', None)),
2440
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2441
builder.build_snapshot('C-id', ['A-id'], [])
2442
builder.build_snapshot('B-id', ['A-id'],
2443
[('rename', ('foo', 'bar'))])
2444
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2445
[('rename', ('foo', 'bar'))]) # merge the rename
2446
builder.build_snapshot('F-id', ['E-id'],
2447
[('rename', ('bar', 'foo'))]) # Rename back to BASE
2448
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2449
wt, conflicts = self.do_merge(builder, 'F-id')
2450
self.assertEqual(0, conflicts)
2451
self.assertEqual('foo', wt.id2path('foo-id'))
2453
def test_other_reverted_content_to_base(self):
2454
builder = self.get_builder()
2455
builder.build_snapshot('A-id', None,
2456
[('add', (u'', 'a-root-id', 'directory', None)),
2457
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2458
builder.build_snapshot('C-id', ['A-id'], [])
2459
builder.build_snapshot('B-id', ['A-id'],
2460
[('modify', ('foo-id', 'B content\n'))])
2461
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2462
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2463
builder.build_snapshot('F-id', ['E-id'],
2464
[('modify', ('foo-id', 'base content\n'))]) # Revert back to BASE
2465
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2466
wt, conflicts = self.do_merge(builder, 'F-id')
2467
self.assertEqual(0, conflicts)
2468
# TODO: We need to use the per-file graph to properly select a BASE
2469
# before this will work. Or at least use the LCA trees to find
2470
# the appropriate content base. (which is B, not A).
2471
self.assertEqual('base content\n', wt.get_file_text('foo-id'))
2473
def test_other_modified_content(self):
2474
builder = self.get_builder()
2475
builder.build_snapshot('A-id', None,
2476
[('add', (u'', 'a-root-id', 'directory', None)),
2477
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2478
builder.build_snapshot('C-id', ['A-id'], [])
2479
builder.build_snapshot('B-id', ['A-id'],
2480
[('modify', ('foo-id', 'B content\n'))])
2481
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2482
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2483
builder.build_snapshot('F-id', ['E-id'],
2484
[('modify', ('foo-id', 'F content\n'))]) # Override B content
2485
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2486
wt, conflicts = self.do_merge(builder, 'F-id')
2487
self.assertEqual(0, conflicts)
2488
self.assertEqual('F content\n', wt.get_file_text('foo-id'))
2490
def test_all_wt(self):
2491
"""Check behavior if all trees are Working Trees."""
2492
# The big issue is that entry.revision is None for WorkingTrees. (as is
2493
# entry.text_sha1, etc. So we need to make sure we handle that case
2495
# A Content of 'foo', path of 'a'
2497
# B C B modifies content, C renames 'a' => 'b'
2499
# D E E updates content, renames 'b' => 'c'
2500
builder = self.get_builder()
2501
builder.build_snapshot('A-id', None,
2502
[('add', (u'', 'a-root-id', 'directory', None)),
2503
('add', (u'a', 'a-id', 'file', 'base content\n')),
2504
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2505
builder.build_snapshot('B-id', ['A-id'],
2506
[('modify', ('foo-id', 'B content\n'))])
2507
builder.build_snapshot('C-id', ['A-id'],
2508
[('rename', ('a', 'b'))])
2509
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2510
[('rename', ('b', 'c')),
2511
('modify', ('foo-id', 'E content\n'))])
2512
builder.build_snapshot('D-id', ['B-id', 'C-id'],
2513
[('rename', ('a', 'b'))]) # merged change
2514
wt_this = self.get_wt_from_builder(builder)
2515
wt_base = wt_this.bzrdir.sprout('base', 'A-id').open_workingtree()
2517
self.addCleanup(wt_base.unlock)
2518
wt_lca1 = wt_this.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2520
self.addCleanup(wt_lca1.unlock)
2521
wt_lca2 = wt_this.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2523
self.addCleanup(wt_lca2.unlock)
2524
wt_other = wt_this.bzrdir.sprout('other', 'E-id').open_workingtree()
2525
wt_other.lock_read()
2526
self.addCleanup(wt_other.unlock)
2527
merge_obj = _mod_merge.Merge3Merger(wt_this, wt_this, wt_base,
2528
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2529
entries = list(merge_obj._entries_lca())
2530
root_id = 'a-root-id'
2531
self.assertEqual([('a-id', False,
2532
((root_id, [root_id, root_id]), root_id, root_id),
2533
((u'a', [u'a', u'b']), u'c', u'b'),
2534
((False, [False, False]), False, False)),
2536
((root_id, [root_id, root_id]), root_id, root_id),
2537
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2538
((False, [False, False]), False, False)),
2541
def test_nested_tree_unmodified(self):
2542
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2544
wt = self.make_branch_and_tree('tree',
2545
format='dirstate-with-subtree')
2547
self.addCleanup(wt.unlock)
2548
sub_tree = self.make_branch_and_tree('tree/sub-tree',
2549
format='dirstate-with-subtree')
2550
wt.set_root_id('a-root-id')
2551
sub_tree.set_root_id('sub-tree-root')
2552
self.build_tree_contents([('tree/sub-tree/file', 'text1')])
2553
sub_tree.add('file')
2554
sub_tree.commit('foo', rev_id='sub-A-id')
2555
wt.add_reference(sub_tree)
2556
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2557
# Now create a criss-cross merge in the parent, without modifying the
2559
wt.commit('B', rev_id='B-id', recursive=None)
2560
wt.set_last_revision('A-id')
2561
wt.branch.set_last_revision_info(1, 'A-id')
2562
wt.commit('C', rev_id='C-id', recursive=None)
2563
wt.merge_from_branch(wt.branch, to_revision='B-id')
2564
wt.commit('E', rev_id='E-id', recursive=None)
2565
wt.set_parent_ids(['B-id', 'C-id'])
2566
wt.branch.set_last_revision_info(2, 'B-id')
2567
wt.commit('D', rev_id='D-id', recursive=None)
2569
merger = _mod_merge.Merger.from_revision_ids(None,
2571
merger.merge_type = _mod_merge.Merge3Merger
2572
merge_obj = merger.make_merger()
2573
entries = list(merge_obj._entries_lca())
2574
self.assertEqual([], entries)
2576
def test_nested_tree_subtree_modified(self):
2577
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2579
wt = self.make_branch_and_tree('tree',
2580
format='dirstate-with-subtree')
2582
self.addCleanup(wt.unlock)
2583
sub_tree = self.make_branch_and_tree('tree/sub',
2584
format='dirstate-with-subtree')
2585
wt.set_root_id('a-root-id')
2586
sub_tree.set_root_id('sub-tree-root')
2587
self.build_tree_contents([('tree/sub/file', 'text1')])
2588
sub_tree.add('file')
2589
sub_tree.commit('foo', rev_id='sub-A-id')
2590
wt.add_reference(sub_tree)
2591
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2592
# Now create a criss-cross merge in the parent, without modifying the
2594
wt.commit('B', rev_id='B-id', recursive=None)
2595
wt.set_last_revision('A-id')
2596
wt.branch.set_last_revision_info(1, 'A-id')
2597
wt.commit('C', rev_id='C-id', recursive=None)
2598
wt.merge_from_branch(wt.branch, to_revision='B-id')
2599
self.build_tree_contents([('tree/sub/file', 'text2')])
2600
sub_tree.commit('modify contents', rev_id='sub-B-id')
2601
wt.commit('E', rev_id='E-id', recursive=None)
2602
wt.set_parent_ids(['B-id', 'C-id'])
2603
wt.branch.set_last_revision_info(2, 'B-id')
2604
wt.commit('D', rev_id='D-id', recursive=None)
2606
merger = _mod_merge.Merger.from_revision_ids(None,
2608
merger.merge_type = _mod_merge.Merge3Merger
2609
merge_obj = merger.make_merger()
2610
entries = list(merge_obj._entries_lca())
2611
# Nothing interesting about this sub-tree, because content changes are
2612
# computed at a higher level
2613
self.assertEqual([], entries)
2615
def test_nested_tree_subtree_renamed(self):
2616
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2618
wt = self.make_branch_and_tree('tree',
2619
format='dirstate-with-subtree')
2621
self.addCleanup(wt.unlock)
2622
sub_tree = self.make_branch_and_tree('tree/sub',
2623
format='dirstate-with-subtree')
2624
wt.set_root_id('a-root-id')
2625
sub_tree.set_root_id('sub-tree-root')
2626
self.build_tree_contents([('tree/sub/file', 'text1')])
2627
sub_tree.add('file')
2628
sub_tree.commit('foo', rev_id='sub-A-id')
2629
wt.add_reference(sub_tree)
2630
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2631
# Now create a criss-cross merge in the parent, without modifying the
2633
wt.commit('B', rev_id='B-id', recursive=None)
2634
wt.set_last_revision('A-id')
2635
wt.branch.set_last_revision_info(1, 'A-id')
2636
wt.commit('C', rev_id='C-id', recursive=None)
2637
wt.merge_from_branch(wt.branch, to_revision='B-id')
2638
wt.rename_one('sub', 'alt_sub')
2639
wt.commit('E', rev_id='E-id', recursive=None)
2640
wt.set_last_revision('B-id')
2642
wt.set_parent_ids(['B-id', 'C-id'])
2643
wt.branch.set_last_revision_info(2, 'B-id')
2644
wt.commit('D', rev_id='D-id', recursive=None)
2646
merger = _mod_merge.Merger.from_revision_ids(None,
2648
merger.merge_type = _mod_merge.Merge3Merger
2649
merge_obj = merger.make_merger()
2650
entries = list(merge_obj._entries_lca())
2651
root_id = 'a-root-id'
2652
self.assertEqual([('sub-tree-root', False,
2653
((root_id, [root_id, root_id]), root_id, root_id),
2654
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2655
((False, [False, False]), False, False)),
2658
def test_nested_tree_subtree_renamed_and_modified(self):
2659
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2661
wt = self.make_branch_and_tree('tree',
2662
format='dirstate-with-subtree')
2664
self.addCleanup(wt.unlock)
2665
sub_tree = self.make_branch_and_tree('tree/sub',
2666
format='dirstate-with-subtree')
2667
wt.set_root_id('a-root-id')
2668
sub_tree.set_root_id('sub-tree-root')
2669
self.build_tree_contents([('tree/sub/file', 'text1')])
2670
sub_tree.add('file')
2671
sub_tree.commit('foo', rev_id='sub-A-id')
2672
wt.add_reference(sub_tree)
2673
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2674
# Now create a criss-cross merge in the parent, without modifying the
2676
wt.commit('B', rev_id='B-id', recursive=None)
2677
wt.set_last_revision('A-id')
2678
wt.branch.set_last_revision_info(1, 'A-id')
2679
wt.commit('C', rev_id='C-id', recursive=None)
2680
wt.merge_from_branch(wt.branch, to_revision='B-id')
2681
self.build_tree_contents([('tree/sub/file', 'text2')])
2682
sub_tree.commit('modify contents', rev_id='sub-B-id')
2683
wt.rename_one('sub', 'alt_sub')
2684
wt.commit('E', rev_id='E-id', recursive=None)
2685
wt.set_last_revision('B-id')
2687
wt.set_parent_ids(['B-id', 'C-id'])
2688
wt.branch.set_last_revision_info(2, 'B-id')
2689
wt.commit('D', rev_id='D-id', recursive=None)
2691
merger = _mod_merge.Merger.from_revision_ids(None,
2693
merger.merge_type = _mod_merge.Merge3Merger
2694
merge_obj = merger.make_merger()
2695
entries = list(merge_obj._entries_lca())
2696
root_id = 'a-root-id'
2697
self.assertEqual([('sub-tree-root', False,
2698
((root_id, [root_id, root_id]), root_id, root_id),
2699
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2700
((False, [False, False]), False, False)),
2704
class TestLCAMultiWay(tests.TestCase):
2706
def assertLCAMultiWay(self, expected, base, lcas, other, this,
2707
allow_overriding_lca=True):
2708
self.assertEqual(expected, _mod_merge.Merge3Merger._lca_multi_way(
2709
(base, lcas), other, this,
2710
allow_overriding_lca=allow_overriding_lca))
2712
def test_other_equal_equal_lcas(self):
2713
"""Test when OTHER=LCA and all LCAs are identical."""
2714
self.assertLCAMultiWay('this',
2715
'bval', ['bval', 'bval'], 'bval', 'bval')
2716
self.assertLCAMultiWay('this',
2717
'bval', ['lcaval', 'lcaval'], 'lcaval', 'bval')
2718
self.assertLCAMultiWay('this',
2719
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'bval')
2720
self.assertLCAMultiWay('this',
2721
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'tval')
2722
self.assertLCAMultiWay('this',
2723
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', None)
2725
def test_other_equal_this(self):
2726
"""Test when other and this are identical."""
2727
self.assertLCAMultiWay('this',
2728
'bval', ['bval', 'bval'], 'oval', 'oval')
2729
self.assertLCAMultiWay('this',
2730
'bval', ['lcaval', 'lcaval'], 'oval', 'oval')
2731
self.assertLCAMultiWay('this',
2732
'bval', ['cval', 'dval'], 'oval', 'oval')
2733
self.assertLCAMultiWay('this',
2734
'bval', [None, 'lcaval'], 'oval', 'oval')
2735
self.assertLCAMultiWay('this',
2736
None, [None, 'lcaval'], 'oval', 'oval')
2737
self.assertLCAMultiWay('this',
2738
None, ['lcaval', 'lcaval'], 'oval', 'oval')
2739
self.assertLCAMultiWay('this',
2740
None, ['cval', 'dval'], 'oval', 'oval')
2741
self.assertLCAMultiWay('this',
2742
None, ['cval', 'dval'], None, None)
2743
self.assertLCAMultiWay('this',
2744
None, ['cval', 'dval', 'eval', 'fval'], 'oval', 'oval')
2746
def test_no_lcas(self):
2747
self.assertLCAMultiWay('this',
2748
'bval', [], 'bval', 'tval')
2749
self.assertLCAMultiWay('other',
2750
'bval', [], 'oval', 'bval')
2751
self.assertLCAMultiWay('conflict',
2752
'bval', [], 'oval', 'tval')
2753
self.assertLCAMultiWay('this',
2754
'bval', [], 'oval', 'oval')
2756
def test_lca_supersedes_other_lca(self):
2757
"""If one lca == base, the other lca takes precedence"""
2758
self.assertLCAMultiWay('this',
2759
'bval', ['bval', 'lcaval'], 'lcaval', 'tval')
2760
self.assertLCAMultiWay('this',
2761
'bval', ['bval', 'lcaval'], 'lcaval', 'bval')
2762
# This is actually considered a 'revert' because the 'lcaval' in LCAS
2763
# supersedes the BASE val (in the other LCA) but then OTHER reverts it
2765
self.assertLCAMultiWay('other',
2766
'bval', ['bval', 'lcaval'], 'bval', 'lcaval')
2767
self.assertLCAMultiWay('conflict',
2768
'bval', ['bval', 'lcaval'], 'bval', 'tval')
2770
def test_other_and_this_pick_different_lca(self):
2771
# OTHER and THIS resolve the lca conflict in different ways
2772
self.assertLCAMultiWay('conflict',
2773
'bval', ['lca1val', 'lca2val'], 'lca1val', 'lca2val')
2774
self.assertLCAMultiWay('conflict',
2775
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'lca2val')
2776
self.assertLCAMultiWay('conflict',
2777
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'lca2val')
2779
def test_other_in_lca(self):
2780
# OTHER takes a value of one of the LCAs, THIS takes a new value, which
2781
# theoretically supersedes both LCA values and 'wins'
2782
self.assertLCAMultiWay('this',
2783
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval')
2784
self.assertLCAMultiWay('this',
2785
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval')
2786
self.assertLCAMultiWay('conflict',
2787
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval',
2788
allow_overriding_lca=False)
2789
self.assertLCAMultiWay('conflict',
2790
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval',
2791
allow_overriding_lca=False)
2792
# THIS reverted back to BASE, but that is an explicit supersede of all
2794
self.assertLCAMultiWay('this',
2795
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval')
2796
self.assertLCAMultiWay('this',
2797
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval')
2798
self.assertLCAMultiWay('conflict',
2799
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval',
2800
allow_overriding_lca=False)
2801
self.assertLCAMultiWay('conflict',
2802
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval',
2803
allow_overriding_lca=False)
2805
def test_this_in_lca(self):
2806
# THIS takes a value of one of the LCAs, OTHER takes a new value, which
2807
# theoretically supersedes both LCA values and 'wins'
2808
self.assertLCAMultiWay('other',
2809
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val')
2810
self.assertLCAMultiWay('other',
2811
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val')
2812
self.assertLCAMultiWay('conflict',
2813
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val',
2814
allow_overriding_lca=False)
2815
self.assertLCAMultiWay('conflict',
2816
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val',
2817
allow_overriding_lca=False)
2818
# OTHER reverted back to BASE, but that is an explicit supersede of all
2820
self.assertLCAMultiWay('other',
2821
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val')
2822
self.assertLCAMultiWay('conflict',
2823
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val',
2824
allow_overriding_lca=False)
2826
def test_all_differ(self):
2827
self.assertLCAMultiWay('conflict',
2828
'bval', ['lca1val', 'lca2val'], 'oval', 'tval')
2829
self.assertLCAMultiWay('conflict',
2830
'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2831
self.assertLCAMultiWay('conflict',
2832
'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')
2835
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
2838
super(TestConfigurableFileMerger, self).setUp()
2841
def get_merger_factory(self):
2842
# Allows the inner methods to access the test attributes
2845
class FooMerger(_mod_merge.ConfigurableFileMerger):
2847
default_files = ['bar']
2849
def merge_text(self, params):
2850
test.calls.append('merge_text')
2851
return ('not_applicable', None)
2853
def factory(merger):
2854
result = FooMerger(merger)
2855
# Make sure we start with a clean slate
2856
self.assertEqual(None, result.affected_files)
2857
# Track the original merger
2858
self.merger = result
2863
def _install_hook(self, factory):
2864
_mod_merge.Merger.hooks.install_named_hook('merge_file_content',
2865
factory, 'test factory')
2867
def make_builder(self):
2868
builder = test_merge_core.MergeBuilder(self.test_base_dir)
2869
self.addCleanup(builder.cleanup)
2872
def make_text_conflict(self, file_name='bar'):
2873
factory = self.get_merger_factory()
2874
self._install_hook(factory)
2875
builder = self.make_builder()
2876
builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
2877
builder.change_contents('bar-id', other='text4', this='text3')
2880
def make_kind_change(self):
2881
factory = self.get_merger_factory()
2882
self._install_hook(factory)
2883
builder = self.make_builder()
2884
builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
2886
builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
2887
base=False, other=False)
2890
def test_uses_this_branch(self):
2891
builder = self.make_text_conflict()
2892
tt = builder.make_preview_transform()
2893
self.addCleanup(tt.finalize)
2895
def test_affected_files_cached(self):
2896
"""Ensures that the config variable is cached"""
2897
builder = self.make_text_conflict()
2898
conflicts = builder.merge()
2899
# The hook should set the variable
2900
self.assertEqual(['bar'], self.merger.affected_files)
2901
self.assertEqual(1, len(conflicts))
2903
def test_hook_called_for_text_conflicts(self):
2904
builder = self.make_text_conflict()
2905
conflicts = builder.merge()
2906
# The hook should call the merge_text() method
2907
self.assertEqual(['merge_text'], self.calls)
2909
def test_hook_not_called_for_kind_change(self):
2910
builder = self.make_kind_change()
2911
conflicts = builder.merge()
2912
# The hook should not call the merge_text() method
2913
self.assertEqual([], self.calls)
2915
def test_hook_not_called_for_other_files(self):
2916
builder = self.make_text_conflict('foobar')
2917
conflicts = builder.merge()
2918
# The hook should not call the merge_text() method
2919
self.assertEqual([], self.calls)
1380
# TODO: cases to test
1381
# simple criss-cross LCAS identical, BASE different
1382
# x-x changed from BASE but identical for all LCAs and tips
1383
# should be possible with the same trick of 'not-in-base'
1384
# using a double criss-cross
1385
# x-x Only renamed, no content or kind change
1386
# x-x LCAs differ, one in ancestry of other for a given file
1387
# x-x file missing in LCA
1388
# x-x Reverted back to BASE text