708
1178
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
710
1180
merge_type = _mod_merge.LCAMerger
1182
def test_merge_move_and_change(self):
1183
self.expectFailure("lca merge doesn't conflict for move and change",
1184
super(TestLCAMerge, self).test_merge_move_and_change)
1187
class LoggingMerger(object):
1188
# These seem to be the required attributes
1189
requires_base = False
1190
supports_reprocess = False
1191
supports_show_base = False
1192
supports_cherrypick = False
1193
# We intentionally do not define supports_lca_trees
1195
def __init__(self, *args, **kwargs):
1197
self.kwargs = kwargs
1200
class TestMergerBase(TestCaseWithMemoryTransport):
1201
"""Common functionality for Merger tests that don't write to disk."""
1203
def get_builder(self):
1204
builder = self.make_branch_builder('path')
1205
builder.start_series()
1206
self.addCleanup(builder.finish_series)
1209
def setup_simple_graph(self):
1210
"""Create a simple 3-node graph.
1212
:return: A BranchBuilder
1219
builder = self.get_builder()
1220
builder.build_snapshot('A-id', None,
1221
[('add', ('', None, 'directory', None))])
1222
builder.build_snapshot('C-id', ['A-id'], [])
1223
builder.build_snapshot('B-id', ['A-id'], [])
1226
def setup_criss_cross_graph(self):
1227
"""Create a 5-node graph with a criss-cross.
1229
:return: A BranchBuilder
1236
builder = self.setup_simple_graph()
1237
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1238
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1241
def make_Merger(self, builder, other_revision_id,
1242
interesting_files=None, interesting_ids=None):
1243
"""Make a Merger object from a branch builder"""
1244
mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1245
mem_tree.lock_write()
1246
self.addCleanup(mem_tree.unlock)
1247
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1248
mem_tree, other_revision_id)
1249
merger.set_interesting_files(interesting_files)
1250
# It seems there is no matching function for set_interesting_ids
1251
merger.interesting_ids = interesting_ids
1252
merger.merge_type = _mod_merge.Merge3Merger
1256
class TestMergerInMemory(TestMergerBase):
1258
def test_cache_trees_with_revision_ids_None(self):
1259
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1260
original_cache = dict(merger._cached_trees)
1261
merger.cache_trees_with_revision_ids([None])
1262
self.assertEqual(original_cache, merger._cached_trees)
1264
def test_cache_trees_with_revision_ids_no_revision_id(self):
1265
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1266
original_cache = dict(merger._cached_trees)
1267
tree = self.make_branch_and_memory_tree('tree')
1268
merger.cache_trees_with_revision_ids([tree])
1269
self.assertEqual(original_cache, merger._cached_trees)
1271
def test_cache_trees_with_revision_ids_having_revision_id(self):
1272
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1273
original_cache = dict(merger._cached_trees)
1274
tree = merger.this_branch.repository.revision_tree('B-id')
1275
original_cache['B-id'] = tree
1276
merger.cache_trees_with_revision_ids([tree])
1277
self.assertEqual(original_cache, merger._cached_trees)
1279
def test_find_base(self):
1280
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1281
self.assertEqual('A-id', merger.base_rev_id)
1282
self.assertFalse(merger._is_criss_cross)
1283
self.assertIs(None, merger._lca_trees)
1285
def test_find_base_criss_cross(self):
1286
builder = self.setup_criss_cross_graph()
1287
merger = self.make_Merger(builder, 'E-id')
1288
self.assertEqual('A-id', merger.base_rev_id)
1289
self.assertTrue(merger._is_criss_cross)
1290
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1291
for t in merger._lca_trees])
1292
# If we swap the order, we should get a different lca order
1293
builder.build_snapshot('F-id', ['E-id'], [])
1294
merger = self.make_Merger(builder, 'D-id')
1295
self.assertEqual(['C-id', 'B-id'], [t.get_revision_id()
1296
for t in merger._lca_trees])
1298
def test_find_base_triple_criss_cross(self):
1301
# B C F # F is merged into both branches
1308
builder = self.setup_criss_cross_graph()
1309
builder.build_snapshot('F-id', ['A-id'], [])
1310
builder.build_snapshot('H-id', ['E-id', 'F-id'], [])
1311
builder.build_snapshot('G-id', ['D-id', 'F-id'], [])
1312
merger = self.make_Merger(builder, 'H-id')
1313
self.assertEqual(['B-id', 'C-id', 'F-id'],
1314
[t.get_revision_id() for t in merger._lca_trees])
1316
def test_no_criss_cross_passed_to_merge_type(self):
1317
class LCATreesMerger(LoggingMerger):
1318
supports_lca_trees = True
1320
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1321
merger.merge_type = LCATreesMerger
1322
merge_obj = merger.make_merger()
1323
self.assertIsInstance(merge_obj, LCATreesMerger)
1324
self.assertFalse('lca_trees' in merge_obj.kwargs)
1326
def test_criss_cross_passed_to_merge_type(self):
1327
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1328
merger.merge_type = _mod_merge.Merge3Merger
1329
merge_obj = merger.make_merger()
1330
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1331
for t in merger._lca_trees])
1333
def test_criss_cross_not_supported_merge_type(self):
1334
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1335
# We explicitly do not define supports_lca_trees
1336
merger.merge_type = LoggingMerger
1337
merge_obj = merger.make_merger()
1338
self.assertIsInstance(merge_obj, LoggingMerger)
1339
self.assertFalse('lca_trees' in merge_obj.kwargs)
1341
def test_criss_cross_unsupported_merge_type(self):
1342
class UnsupportedLCATreesMerger(LoggingMerger):
1343
supports_lca_trees = False
1345
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1346
merger.merge_type = UnsupportedLCATreesMerger
1347
merge_obj = merger.make_merger()
1348
self.assertIsInstance(merge_obj, UnsupportedLCATreesMerger)
1349
self.assertFalse('lca_trees' in merge_obj.kwargs)
1352
class TestMergerEntriesLCA(TestMergerBase):
1354
def make_merge_obj(self, builder, other_revision_id,
1355
interesting_files=None, interesting_ids=None):
1356
merger = self.make_Merger(builder, other_revision_id,
1357
interesting_files=interesting_files,
1358
interesting_ids=interesting_ids)
1359
return merger.make_merger()
1361
def test_simple(self):
1362
builder = self.get_builder()
1363
builder.build_snapshot('A-id', None,
1364
[('add', (u'', 'a-root-id', 'directory', None)),
1365
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1366
builder.build_snapshot('C-id', ['A-id'],
1367
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1368
builder.build_snapshot('B-id', ['A-id'],
1369
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1370
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1371
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1372
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1373
[('modify', ('a-id', 'a\nB\nb\nC\nc\n'))])
1374
merge_obj = self.make_merge_obj(builder, 'E-id')
1376
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1377
for t in merge_obj._lca_trees])
1378
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1379
entries = list(merge_obj._entries_lca())
1381
# (file_id, changed, parents, names, executable)
1382
# BASE, lca1, lca2, OTHER, THIS
1383
root_id = 'a-root-id'
1384
self.assertEqual([('a-id', True,
1385
((root_id, [root_id, root_id]), root_id, root_id),
1386
((u'a', [u'a', u'a']), u'a', u'a'),
1387
((False, [False, False]), False, False)),
1390
def test_not_in_base(self):
1391
# LCAs all have the same last-modified revision for the file, as do
1392
# the tips, but the base has something different
1393
# A base, doesn't have the file
1395
# B C B introduces 'foo', C introduces 'bar'
1397
# D E D and E now both have 'foo' and 'bar'
1399
# F G the files are now in F, G, D and E, but not in A
1402
builder = self.get_builder()
1403
builder.build_snapshot('A-id', None,
1404
[('add', (u'', 'a-root-id', 'directory', None))])
1405
builder.build_snapshot('B-id', ['A-id'],
1406
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1407
builder.build_snapshot('C-id', ['A-id'],
1408
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1409
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1410
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1411
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1412
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1413
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1414
[('modify', (u'bar-id', 'd\ne\nf\nG\n'))])
1415
builder.build_snapshot('F-id', ['D-id', 'E-id'], [])
1416
merge_obj = self.make_merge_obj(builder, 'G-id')
1418
self.assertEqual(['D-id', 'E-id'], [t.get_revision_id()
1419
for t in merge_obj._lca_trees])
1420
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1421
entries = list(merge_obj._entries_lca())
1422
root_id = 'a-root-id'
1423
self.assertEqual([('bar-id', True,
1424
((None, [root_id, root_id]), root_id, root_id),
1425
((None, [u'bar', u'bar']), u'bar', u'bar'),
1426
((None, [False, False]), False, False)),
1429
def test_not_in_this(self):
1430
builder = self.get_builder()
1431
builder.build_snapshot('A-id', None,
1432
[('add', (u'', 'a-root-id', 'directory', None)),
1433
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1434
builder.build_snapshot('B-id', ['A-id'],
1435
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1436
builder.build_snapshot('C-id', ['A-id'],
1437
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1438
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1439
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1440
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1441
[('unversion', 'a-id')])
1442
merge_obj = self.make_merge_obj(builder, 'E-id')
1444
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1445
for t in merge_obj._lca_trees])
1446
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1448
entries = list(merge_obj._entries_lca())
1449
root_id = 'a-root-id'
1450
self.assertEqual([('a-id', True,
1451
((root_id, [root_id, root_id]), root_id, None),
1452
((u'a', [u'a', u'a']), u'a', None),
1453
((False, [False, False]), False, None)),
1456
def test_file_not_in_one_lca(self):
1459
# B C # B no file, C introduces a file
1461
# D E # D and E both have the file, unchanged from C
1462
builder = self.get_builder()
1463
builder.build_snapshot('A-id', None,
1464
[('add', (u'', 'a-root-id', 'directory', None))])
1465
builder.build_snapshot('B-id', ['A-id'], [])
1466
builder.build_snapshot('C-id', ['A-id'],
1467
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1468
builder.build_snapshot('E-id', ['C-id', 'B-id'], []) # Inherited from C
1469
builder.build_snapshot('D-id', ['B-id', 'C-id'], # Merged from C
1470
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1471
merge_obj = self.make_merge_obj(builder, 'E-id')
1473
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1474
for t in merge_obj._lca_trees])
1475
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1477
entries = list(merge_obj._entries_lca())
1478
self.assertEqual([], entries)
1480
def test_not_in_other(self):
1481
builder = self.get_builder()
1482
builder.build_snapshot('A-id', None,
1483
[('add', (u'', 'a-root-id', 'directory', None)),
1484
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1485
builder.build_snapshot('B-id', ['A-id'], [])
1486
builder.build_snapshot('C-id', ['A-id'], [])
1487
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1488
[('unversion', 'a-id')])
1489
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1490
merge_obj = self.make_merge_obj(builder, 'E-id')
1492
entries = list(merge_obj._entries_lca())
1493
root_id = 'a-root-id'
1494
self.assertEqual([('a-id', True,
1495
((root_id, [root_id, root_id]), None, root_id),
1496
((u'a', [u'a', u'a']), None, u'a'),
1497
((False, [False, False]), None, False)),
1500
def test_not_in_other_or_lca(self):
1501
# A base, introduces 'foo'
1503
# B C B nothing, C deletes foo
1505
# D E D restores foo (same as B), E leaves it deleted
1507
# A => B, no changes
1508
# A => C, delete foo (C should supersede B)
1509
# C => D, restore foo
1510
# C => E, no changes
1511
# D would then win 'cleanly' and no record would be given
1512
builder = self.get_builder()
1513
builder.build_snapshot('A-id', None,
1514
[('add', (u'', 'a-root-id', 'directory', None)),
1515
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1516
builder.build_snapshot('B-id', ['A-id'], [])
1517
builder.build_snapshot('C-id', ['A-id'],
1518
[('unversion', 'foo-id')])
1519
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1520
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1521
merge_obj = self.make_merge_obj(builder, 'E-id')
1523
entries = list(merge_obj._entries_lca())
1524
self.assertEqual([], entries)
1526
def test_not_in_other_mod_in_lca1_not_in_lca2(self):
1527
# A base, introduces 'foo'
1529
# B C B changes 'foo', C deletes foo
1531
# D E D restores foo (same as B), E leaves it deleted (as C)
1533
# A => B, modified foo
1534
# A => C, delete foo, C does not supersede B
1535
# B => D, no changes
1536
# C => D, resolve in favor of B
1537
# B => E, resolve in favor of E
1538
# C => E, no changes
1539
# In this case, we have a conflict of how the changes were resolved. E
1540
# picked C and D picked B, so we should issue a conflict
1541
builder = self.get_builder()
1542
builder.build_snapshot('A-id', None,
1543
[('add', (u'', 'a-root-id', 'directory', None)),
1544
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1545
builder.build_snapshot('B-id', ['A-id'], [
1546
('modify', ('foo-id', 'new-content\n'))])
1547
builder.build_snapshot('C-id', ['A-id'],
1548
[('unversion', 'foo-id')])
1549
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1550
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1551
merge_obj = self.make_merge_obj(builder, 'E-id')
1553
entries = list(merge_obj._entries_lca())
1554
root_id = 'a-root-id'
1555
self.assertEqual([('foo-id', True,
1556
((root_id, [root_id, None]), None, root_id),
1557
((u'foo', [u'foo', None]), None, 'foo'),
1558
((False, [False, None]), None, False)),
1561
def test_only_in_one_lca(self):
1564
# B C B nothing, C add file
1566
# D E D still has nothing, E removes file
1569
# C => D, removed the file
1571
# C => E, removed the file
1572
# Thus D & E have identical changes, and this is a no-op
1575
# A => C, add file, thus C supersedes B
1576
# w/ C=BASE, D=THIS, E=OTHER we have 'happy convergence'
1577
builder = self.get_builder()
1578
builder.build_snapshot('A-id', None,
1579
[('add', (u'', 'a-root-id', 'directory', None))])
1580
builder.build_snapshot('B-id', ['A-id'], [])
1581
builder.build_snapshot('C-id', ['A-id'],
1582
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1583
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1584
[('unversion', 'a-id')])
1585
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1586
merge_obj = self.make_merge_obj(builder, 'E-id')
1588
entries = list(merge_obj._entries_lca())
1589
self.assertEqual([], entries)
1591
def test_only_in_other(self):
1592
builder = self.get_builder()
1593
builder.build_snapshot('A-id', None,
1594
[('add', (u'', 'a-root-id', 'directory', None))])
1595
builder.build_snapshot('B-id', ['A-id'], [])
1596
builder.build_snapshot('C-id', ['A-id'], [])
1597
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1598
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1599
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1600
merge_obj = self.make_merge_obj(builder, 'E-id')
1602
entries = list(merge_obj._entries_lca())
1603
root_id = 'a-root-id'
1604
self.assertEqual([('a-id', True,
1605
((None, [None, None]), root_id, None),
1606
((None, [None, None]), u'a', None),
1607
((None, [None, None]), False, None)),
1610
def test_one_lca_supersedes(self):
1611
# One LCA supersedes the other LCAs last modified value, but the
1612
# value is not the same as BASE.
1613
# A base, introduces 'foo', last mod A
1615
# B C B modifies 'foo' (mod B), C does nothing (mod A)
1617
# D E D does nothing (mod B), E updates 'foo' (mod E)
1619
# F G F updates 'foo' (mod F). G does nothing (mod E)
1621
# At this point, G should not be considered to modify 'foo', even
1622
# though its LCAs disagree. This is because the modification in E
1623
# completely supersedes the value in D.
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
[('modify', ('foo-id', 'B content\n'))])
1631
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1632
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1633
[('modify', ('foo-id', 'E content\n'))])
1634
builder.build_snapshot('G-id', ['E-id', 'D-id'], [])
1635
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1636
[('modify', ('foo-id', 'F content\n'))])
1637
merge_obj = self.make_merge_obj(builder, 'G-id')
1639
self.assertEqual([], list(merge_obj._entries_lca()))
1641
def test_one_lca_supersedes_path(self):
1642
# Double-criss-cross merge, the ultimate base value is different from
1646
# B C B value 'bar', C = 'foo'
1648
# D E D = 'bar', E supersedes to 'bing'
1650
# F G F = 'bing', G supersedes to 'barry'
1652
# In this case, we technically should not care about the value 'bar' for
1653
# D, because it was clearly superseded by E's 'bing'. The
1654
# per-file/attribute graph would actually look like:
1663
# Because the other side of the merge never modifies the value, it just
1664
# takes the value from the merge.
1666
# ATM this fails because we will prune 'foo' from the LCAs, but we
1667
# won't prune 'bar'. This is getting far off into edge-case land, so we
1668
# aren't supporting it yet.
1670
builder = self.get_builder()
1671
builder.build_snapshot('A-id', None,
1672
[('add', (u'', 'a-root-id', 'directory', None)),
1673
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1674
builder.build_snapshot('C-id', ['A-id'], [])
1675
builder.build_snapshot('B-id', ['A-id'],
1676
[('rename', ('foo', 'bar'))])
1677
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1678
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1679
[('rename', ('foo', 'bing'))]) # override to bing
1680
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1681
[('rename', ('bing', 'barry'))]) # override to barry
1682
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1683
[('rename', ('bar', 'bing'))]) # Merge in E's change
1684
merge_obj = self.make_merge_obj(builder, 'G-id')
1686
self.expectFailure("We don't do an actual heads() check on lca values,"
1687
" or use the per-attribute graph",
1688
self.assertEqual, [], list(merge_obj._entries_lca()))
1690
def test_one_lca_accidentally_pruned(self):
1691
# Another incorrect resolution from the same basic flaw:
1694
# B C B value 'bar', C = 'foo'
1696
# D E D = 'bar', E reverts to 'foo'
1698
# F G F = 'bing', G switches to 'bar'
1700
# 'bar' will not be seen as an interesting change, because 'foo' will
1701
# be pruned from the LCAs, even though it was newly introduced by E
1703
builder = self.get_builder()
1704
builder.build_snapshot('A-id', None,
1705
[('add', (u'', 'a-root-id', 'directory', None)),
1706
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1707
builder.build_snapshot('C-id', ['A-id'], [])
1708
builder.build_snapshot('B-id', ['A-id'],
1709
[('rename', ('foo', 'bar'))])
1710
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1711
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1712
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1713
[('rename', ('foo', 'bar'))])
1714
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1715
[('rename', ('bar', 'bing'))]) # should end up conflicting
1716
merge_obj = self.make_merge_obj(builder, 'G-id')
1718
entries = list(merge_obj._entries_lca())
1719
root_id = 'a-root-id'
1720
self.expectFailure("We prune values from BASE even when relevant.",
1723
((root_id, [root_id, root_id]), root_id, root_id),
1724
((u'foo', [u'bar', u'foo']), u'bar', u'bing'),
1725
((False, [False, False]), False, False)),
1728
def test_both_sides_revert(self):
1729
# Both sides of a criss-cross revert the text to the lca
1730
# A base, introduces 'foo'
1732
# B C B modifies 'foo', C modifies 'foo'
1734
# D E D reverts to B, E reverts to C
1735
# This should conflict
1736
builder = self.get_builder()
1737
builder.build_snapshot('A-id', None,
1738
[('add', (u'', 'a-root-id', 'directory', None)),
1739
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1740
builder.build_snapshot('B-id', ['A-id'],
1741
[('modify', ('foo-id', 'B content\n'))])
1742
builder.build_snapshot('C-id', ['A-id'],
1743
[('modify', ('foo-id', 'C content\n'))])
1744
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1745
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1746
merge_obj = self.make_merge_obj(builder, 'E-id')
1748
entries = list(merge_obj._entries_lca())
1749
root_id = 'a-root-id'
1750
self.assertEqual([('foo-id', True,
1751
((root_id, [root_id, root_id]), root_id, root_id),
1752
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1753
((False, [False, False]), False, False)),
1756
def test_different_lca_resolve_one_side_updates_content(self):
1757
# Both sides converge, but then one side updates the text.
1758
# A base, introduces 'foo'
1760
# B C B modifies 'foo', C modifies 'foo'
1762
# D E D reverts to B, E reverts to C
1764
# F F updates to a new value
1765
# We need to emit an entry for 'foo', because D & E differed on the
1767
builder = self.get_builder()
1768
builder.build_snapshot('A-id', None,
1769
[('add', (u'', 'a-root-id', 'directory', None)),
1770
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1771
builder.build_snapshot('B-id', ['A-id'],
1772
[('modify', ('foo-id', 'B content\n'))])
1773
builder.build_snapshot('C-id', ['A-id'],
1774
[('modify', ('foo-id', 'C content\n'))])
1775
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1776
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1777
builder.build_snapshot('F-id', ['D-id'],
1778
[('modify', ('foo-id', 'F content\n'))])
1779
merge_obj = self.make_merge_obj(builder, 'E-id')
1781
entries = list(merge_obj._entries_lca())
1782
root_id = 'a-root-id'
1783
self.assertEqual([('foo-id', True,
1784
((root_id, [root_id, root_id]), root_id, root_id),
1785
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1786
((False, [False, False]), False, False)),
1789
def test_same_lca_resolution_one_side_updates_content(self):
1790
# Both sides converge, but then one side updates the text.
1791
# A base, introduces 'foo'
1793
# B C B modifies 'foo', C modifies 'foo'
1795
# D E D and E use C's value
1797
# F F updates to a new value
1798
# I think it is a bug that this conflicts, but we don't have a way to
1799
# detect otherwise. And because of:
1800
# test_different_lca_resolve_one_side_updates_content
1801
# We need to conflict.
1803
builder = self.get_builder()
1804
builder.build_snapshot('A-id', None,
1805
[('add', (u'', 'a-root-id', 'directory', None)),
1806
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1807
builder.build_snapshot('B-id', ['A-id'],
1808
[('modify', ('foo-id', 'B content\n'))])
1809
builder.build_snapshot('C-id', ['A-id'],
1810
[('modify', ('foo-id', 'C content\n'))])
1811
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1812
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1813
[('modify', ('foo-id', 'C content\n'))]) # Same as E
1814
builder.build_snapshot('F-id', ['D-id'],
1815
[('modify', ('foo-id', 'F content\n'))])
1816
merge_obj = self.make_merge_obj(builder, 'E-id')
1818
entries = list(merge_obj._entries_lca())
1819
self.expectFailure("We don't detect that LCA resolution was the"
1820
" same on both sides",
1821
self.assertEqual, [], entries)
1823
def test_only_path_changed(self):
1824
builder = self.get_builder()
1825
builder.build_snapshot('A-id', None,
1826
[('add', (u'', 'a-root-id', 'directory', None)),
1827
('add', (u'a', 'a-id', 'file', 'content\n'))])
1828
builder.build_snapshot('B-id', ['A-id'], [])
1829
builder.build_snapshot('C-id', ['A-id'], [])
1830
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1831
[('rename', (u'a', u'b'))])
1832
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1833
merge_obj = self.make_merge_obj(builder, 'E-id')
1834
entries = list(merge_obj._entries_lca())
1835
root_id = 'a-root-id'
1836
# The content was not changed, only the path
1837
self.assertEqual([('a-id', False,
1838
((root_id, [root_id, root_id]), root_id, root_id),
1839
((u'a', [u'a', u'a']), u'b', u'a'),
1840
((False, [False, False]), False, False)),
1843
def test_kind_changed(self):
1844
# Identical content, except 'D' changes a-id into a directory
1845
builder = self.get_builder()
1846
builder.build_snapshot('A-id', None,
1847
[('add', (u'', 'a-root-id', 'directory', None)),
1848
('add', (u'a', 'a-id', 'file', 'content\n'))])
1849
builder.build_snapshot('B-id', ['A-id'], [])
1850
builder.build_snapshot('C-id', ['A-id'], [])
1851
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1852
[('unversion', 'a-id'),
1853
('add', (u'a', 'a-id', 'directory', None))])
1854
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1855
merge_obj = self.make_merge_obj(builder, 'E-id')
1856
entries = list(merge_obj._entries_lca())
1857
root_id = 'a-root-id'
1858
# Only the kind was changed (content)
1859
self.assertEqual([('a-id', True,
1860
((root_id, [root_id, root_id]), root_id, root_id),
1861
((u'a', [u'a', u'a']), u'a', u'a'),
1862
((False, [False, False]), False, False)),
1865
def test_this_changed_kind(self):
1866
# Identical content, but THIS changes a file to a directory
1867
builder = self.get_builder()
1868
builder.build_snapshot('A-id', None,
1869
[('add', (u'', 'a-root-id', 'directory', None)),
1870
('add', (u'a', 'a-id', 'file', 'content\n'))])
1871
builder.build_snapshot('B-id', ['A-id'], [])
1872
builder.build_snapshot('C-id', ['A-id'], [])
1873
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1874
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1875
[('unversion', 'a-id'),
1876
('add', (u'a', 'a-id', 'directory', None))])
1877
merge_obj = self.make_merge_obj(builder, 'E-id')
1878
entries = list(merge_obj._entries_lca())
1879
# Only the kind was changed (content)
1880
self.assertEqual([], entries)
1882
def test_interesting_files(self):
1883
# Two files modified, but we should filter one of them
1884
builder = self.get_builder()
1885
builder.build_snapshot('A-id', None,
1886
[('add', (u'', 'a-root-id', 'directory', None)),
1887
('add', (u'a', 'a-id', 'file', 'content\n')),
1888
('add', (u'b', 'b-id', 'file', 'content\n'))])
1889
builder.build_snapshot('B-id', ['A-id'], [])
1890
builder.build_snapshot('C-id', ['A-id'], [])
1891
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1892
[('modify', ('a-id', 'new-content\n')),
1893
('modify', ('b-id', 'new-content\n'))])
1894
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1895
merge_obj = self.make_merge_obj(builder, 'E-id',
1896
interesting_files=['b'])
1897
entries = list(merge_obj._entries_lca())
1898
root_id = 'a-root-id'
1899
self.assertEqual([('b-id', True,
1900
((root_id, [root_id, root_id]), root_id, root_id),
1901
((u'b', [u'b', u'b']), u'b', u'b'),
1902
((False, [False, False]), False, False)),
1905
def test_interesting_file_in_this(self):
1906
# This renamed the file, but it should still match the entry in other
1907
builder = self.get_builder()
1908
builder.build_snapshot('A-id', None,
1909
[('add', (u'', 'a-root-id', 'directory', None)),
1910
('add', (u'a', 'a-id', 'file', 'content\n')),
1911
('add', (u'b', 'b-id', 'file', 'content\n'))])
1912
builder.build_snapshot('B-id', ['A-id'], [])
1913
builder.build_snapshot('C-id', ['A-id'], [])
1914
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1915
[('modify', ('a-id', 'new-content\n')),
1916
('modify', ('b-id', 'new-content\n'))])
1917
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1918
[('rename', ('b', 'c'))])
1919
merge_obj = self.make_merge_obj(builder, 'E-id',
1920
interesting_files=['c'])
1921
entries = list(merge_obj._entries_lca())
1922
root_id = 'a-root-id'
1923
self.assertEqual([('b-id', True,
1924
((root_id, [root_id, root_id]), root_id, root_id),
1925
((u'b', [u'b', u'b']), u'b', u'c'),
1926
((False, [False, False]), False, False)),
1929
def test_interesting_file_in_base(self):
1930
# This renamed the file, but it should still match the entry in BASE
1931
builder = self.get_builder()
1932
builder.build_snapshot('A-id', None,
1933
[('add', (u'', 'a-root-id', 'directory', None)),
1934
('add', (u'a', 'a-id', 'file', 'content\n')),
1935
('add', (u'c', 'c-id', 'file', 'content\n'))])
1936
builder.build_snapshot('B-id', ['A-id'],
1937
[('rename', ('c', 'b'))])
1938
builder.build_snapshot('C-id', ['A-id'],
1939
[('rename', ('c', 'b'))])
1940
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1941
[('modify', ('a-id', 'new-content\n')),
1942
('modify', ('c-id', 'new-content\n'))])
1943
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1944
merge_obj = self.make_merge_obj(builder, 'E-id',
1945
interesting_files=['c'])
1946
entries = list(merge_obj._entries_lca())
1947
root_id = 'a-root-id'
1948
self.assertEqual([('c-id', True,
1949
((root_id, [root_id, root_id]), root_id, root_id),
1950
((u'c', [u'b', u'b']), u'b', u'b'),
1951
((False, [False, False]), False, False)),
1954
def test_interesting_file_in_lca(self):
1955
# This renamed the file, but it should still match the entry in LCA
1956
builder = self.get_builder()
1957
builder.build_snapshot('A-id', None,
1958
[('add', (u'', 'a-root-id', 'directory', None)),
1959
('add', (u'a', 'a-id', 'file', 'content\n')),
1960
('add', (u'b', 'b-id', 'file', 'content\n'))])
1961
builder.build_snapshot('B-id', ['A-id'],
1962
[('rename', ('b', 'c'))])
1963
builder.build_snapshot('C-id', ['A-id'], [])
1964
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1965
[('modify', ('a-id', 'new-content\n')),
1966
('modify', ('b-id', 'new-content\n'))])
1967
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1968
[('rename', ('c', 'b'))])
1969
merge_obj = self.make_merge_obj(builder, 'E-id',
1970
interesting_files=['c'])
1971
entries = list(merge_obj._entries_lca())
1972
root_id = 'a-root-id'
1973
self.assertEqual([('b-id', True,
1974
((root_id, [root_id, root_id]), root_id, root_id),
1975
((u'b', [u'c', u'b']), u'b', u'b'),
1976
((False, [False, False]), False, False)),
1979
def test_interesting_ids(self):
1980
# Two files modified, but we should filter one of them
1981
builder = self.get_builder()
1982
builder.build_snapshot('A-id', None,
1983
[('add', (u'', 'a-root-id', 'directory', None)),
1984
('add', (u'a', 'a-id', 'file', 'content\n')),
1985
('add', (u'b', 'b-id', 'file', 'content\n'))])
1986
builder.build_snapshot('B-id', ['A-id'], [])
1987
builder.build_snapshot('C-id', ['A-id'], [])
1988
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1989
[('modify', ('a-id', 'new-content\n')),
1990
('modify', ('b-id', 'new-content\n'))])
1991
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1992
merge_obj = self.make_merge_obj(builder, 'E-id',
1993
interesting_ids=['b-id'])
1994
entries = list(merge_obj._entries_lca())
1995
root_id = 'a-root-id'
1996
self.assertEqual([('b-id', True,
1997
((root_id, [root_id, root_id]), root_id, root_id),
1998
((u'b', [u'b', u'b']), u'b', u'b'),
1999
((False, [False, False]), False, False)),
2004
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
2006
def get_builder(self):
2007
builder = self.make_branch_builder('path')
2008
builder.start_series()
2009
self.addCleanup(builder.finish_series)
2012
def get_wt_from_builder(self, builder):
2013
"""Get a real WorkingTree from the builder."""
2014
the_branch = builder.get_branch()
2015
wt = the_branch.bzrdir.create_workingtree()
2016
# Note: This is a little bit ugly, but we are holding the branch
2017
# write-locked as part of the build process, and we would like to
2018
# maintain that. So we just force the WT to re-use the same
2020
wt._branch = the_branch
2022
self.addCleanup(wt.unlock)
2025
def do_merge(self, builder, other_revision_id):
2026
wt = self.get_wt_from_builder(builder)
2027
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2028
wt, other_revision_id)
2029
merger.merge_type = _mod_merge.Merge3Merger
2030
return wt, merger.do_merge()
2032
def test_simple_lca(self):
2033
builder = self.get_builder()
2034
builder.build_snapshot('A-id', None,
2035
[('add', (u'', 'a-root-id', 'directory', None)),
2036
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
2037
builder.build_snapshot('C-id', ['A-id'], [])
2038
builder.build_snapshot('B-id', ['A-id'], [])
2039
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2040
builder.build_snapshot('D-id', ['B-id', 'C-id'],
2041
[('modify', ('a-id', 'a\nb\nc\nd\ne\nf\n'))])
2042
wt, conflicts = self.do_merge(builder, 'E-id')
2043
self.assertEqual(0, conflicts)
2044
# The merge should have simply update the contents of 'a'
2045
self.assertEqual('a\nb\nc\nd\ne\nf\n', wt.get_file_text('a-id'))
2047
def test_conflict_without_lca(self):
2048
# This test would cause a merge conflict, unless we use the lca trees
2049
# to determine the real ancestry
2052
# B C Path renamed to 'bar' in B
2056
# D E Path at 'bar' in D and E
2058
# F Path at 'baz' in F, which supersedes 'bar' and 'foo'
2059
builder = self.get_builder()
2060
builder.build_snapshot('A-id', None,
2061
[('add', (u'', 'a-root-id', 'directory', None)),
2062
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2063
builder.build_snapshot('C-id', ['A-id'], [])
2064
builder.build_snapshot('B-id', ['A-id'],
2065
[('rename', ('foo', 'bar'))])
2066
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2067
[('rename', ('foo', 'bar'))])
2068
builder.build_snapshot('F-id', ['E-id'],
2069
[('rename', ('bar', 'baz'))])
2070
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2071
wt, conflicts = self.do_merge(builder, 'F-id')
2072
self.assertEqual(0, conflicts)
2073
# The merge should simply recognize that the final rename takes
2075
self.assertEqual('baz', wt.id2path('foo-id'))
2077
def test_other_deletes_lca_renames(self):
2078
# This test would cause a merge conflict, unless we use the lca trees
2079
# to determine the real ancestry
2082
# B C Path renamed to 'bar' in B
2086
# D E Path at 'bar' in D and E
2089
builder = self.get_builder()
2090
builder.build_snapshot('A-id', None,
2091
[('add', (u'', 'a-root-id', 'directory', None)),
2092
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2093
builder.build_snapshot('C-id', ['A-id'], [])
2094
builder.build_snapshot('B-id', ['A-id'],
2095
[('rename', ('foo', 'bar'))])
2096
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2097
[('rename', ('foo', 'bar'))])
2098
builder.build_snapshot('F-id', ['E-id'],
2099
[('unversion', 'foo-id')])
2100
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2101
wt, conflicts = self.do_merge(builder, 'F-id')
2102
self.assertEqual(0, conflicts)
2103
self.assertRaises(errors.NoSuchId, wt.id2path, 'foo-id')
2105
def test_executable_changes(self):
2114
# F Executable bit changed
2115
builder = self.get_builder()
2116
builder.build_snapshot('A-id', None,
2117
[('add', (u'', 'a-root-id', 'directory', None)),
2118
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2119
builder.build_snapshot('C-id', ['A-id'], [])
2120
builder.build_snapshot('B-id', ['A-id'], [])
2121
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2122
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2123
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2124
wt = self.get_wt_from_builder(builder)
2125
tt = transform.TreeTransform(wt)
2127
tt.set_executability(True, tt.trans_id_tree_file_id('foo-id'))
2132
self.assertTrue(wt.is_executable('foo-id'))
2133
wt.commit('F-id', rev_id='F-id')
2134
# Reset to D, so that we can merge F
2135
wt.set_parent_ids(['D-id'])
2136
wt.branch.set_last_revision_info(3, 'D-id')
2138
self.assertFalse(wt.is_executable('foo-id'))
2139
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2140
self.assertEqual(0, conflicts)
2141
self.assertTrue(wt.is_executable('foo-id'))
2143
def test_create_symlink(self):
2144
self.requireFeature(tests.SymlinkFeature)
2153
# F Add a symlink 'foo' => 'bar'
2154
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2155
# have symlink support
2156
builder = self.get_builder()
2157
builder.build_snapshot('A-id', None,
2158
[('add', (u'', 'a-root-id', 'directory', None))])
2159
builder.build_snapshot('C-id', ['A-id'], [])
2160
builder.build_snapshot('B-id', ['A-id'], [])
2161
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2162
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2163
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2164
wt = self.get_wt_from_builder(builder)
2165
os.symlink('bar', 'path/foo')
2166
wt.add(['foo'], ['foo-id'])
2167
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2168
wt.commit('add symlink', rev_id='F-id')
2169
# Reset to D, so that we can merge F
2170
wt.set_parent_ids(['D-id'])
2171
wt.branch.set_last_revision_info(3, 'D-id')
2173
self.assertIs(None, wt.path2id('foo'))
2174
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2175
self.assertEqual(0, conflicts)
2176
self.assertEqual('foo-id', wt.path2id('foo'))
2177
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2179
def test_both_sides_revert(self):
2180
# Both sides of a criss-cross revert the text to the lca
2181
# A base, introduces 'foo'
2183
# B C B modifies 'foo', C modifies 'foo'
2185
# D E D reverts to B, E reverts to C
2186
# This should conflict
2187
# This must be done with a real WorkingTree, because normally their
2188
# inventory contains "None" rather than a real sha1
2189
builder = self.get_builder()
2190
builder.build_snapshot('A-id', None,
2191
[('add', (u'', 'a-root-id', 'directory', None)),
2192
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
2193
builder.build_snapshot('B-id', ['A-id'],
2194
[('modify', ('foo-id', 'B content\n'))])
2195
builder.build_snapshot('C-id', ['A-id'],
2196
[('modify', ('foo-id', 'C content\n'))])
2197
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2198
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2199
wt, conflicts = self.do_merge(builder, 'E-id')
2200
self.assertEqual(1, conflicts)
2201
self.assertEqualDiff('<<<<<<< TREE\n'
2205
'>>>>>>> MERGE-SOURCE\n',
2206
wt.get_file_text('foo-id'))
2208
def test_modified_symlink(self):
2209
self.requireFeature(tests.SymlinkFeature)
2210
# A Create symlink foo => bar
2212
# B C B relinks foo => baz
2216
# D E D & E have foo => baz
2218
# F F changes it to bing
2220
# Merging D & F should result in F cleanly overriding D, because D's
2221
# value actually comes from B
2223
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2224
# have symlink support
2225
wt = self.make_branch_and_tree('path')
2227
self.addCleanup(wt.unlock)
2228
os.symlink('bar', 'path/foo')
2229
wt.add(['foo'], ['foo-id'])
2230
wt.commit('add symlink', rev_id='A-id')
2231
os.remove('path/foo')
2232
os.symlink('baz', 'path/foo')
2233
wt.commit('foo => baz', rev_id='B-id')
2234
wt.set_last_revision('A-id')
2235
wt.branch.set_last_revision_info(1, 'A-id')
2237
wt.commit('C', rev_id='C-id')
2238
wt.merge_from_branch(wt.branch, 'B-id')
2239
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2240
wt.commit('E merges C & B', rev_id='E-id')
2241
os.remove('path/foo')
2242
os.symlink('bing', 'path/foo')
2243
wt.commit('F foo => bing', rev_id='F-id')
2244
wt.set_last_revision('B-id')
2245
wt.branch.set_last_revision_info(2, 'B-id')
2247
wt.merge_from_branch(wt.branch, 'C-id')
2248
wt.commit('D merges B & C', rev_id='D-id')
2249
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2250
self.assertEqual(0, conflicts)
2251
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2253
def test_renamed_symlink(self):
2254
self.requireFeature(tests.SymlinkFeature)
2255
# A Create symlink foo => bar
2257
# B C B renames foo => barry
2261
# D E D & E have barry
2263
# F F renames barry to blah
2265
# Merging D & F should result in F cleanly overriding D, because D's
2266
# value actually comes from B
2268
wt = self.make_branch_and_tree('path')
2270
self.addCleanup(wt.unlock)
2271
os.symlink('bar', 'path/foo')
2272
wt.add(['foo'], ['foo-id'])
2273
wt.commit('A add symlink', rev_id='A-id')
2274
wt.rename_one('foo', 'barry')
2275
wt.commit('B foo => barry', rev_id='B-id')
2276
wt.set_last_revision('A-id')
2277
wt.branch.set_last_revision_info(1, 'A-id')
2279
wt.commit('C', rev_id='C-id')
2280
wt.merge_from_branch(wt.branch, 'B-id')
2281
self.assertEqual('barry', wt.id2path('foo-id'))
2282
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2283
wt.commit('E merges C & B', rev_id='E-id')
2284
wt.rename_one('barry', 'blah')
2285
wt.commit('F barry => blah', rev_id='F-id')
2286
wt.set_last_revision('B-id')
2287
wt.branch.set_last_revision_info(2, 'B-id')
2289
wt.merge_from_branch(wt.branch, 'C-id')
2290
wt.commit('D merges B & C', rev_id='D-id')
2291
self.assertEqual('barry', wt.id2path('foo-id'))
2292
# Check the output of the Merger object directly
2293
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2295
merger.merge_type = _mod_merge.Merge3Merger
2296
merge_obj = merger.make_merger()
2297
root_id = wt.path2id('')
2298
entries = list(merge_obj._entries_lca())
2299
# No content change, just a path change
2300
self.assertEqual([('foo-id', False,
2301
((root_id, [root_id, root_id]), root_id, root_id),
2302
((u'foo', [u'barry', u'foo']), u'blah', u'barry'),
2303
((False, [False, False]), False, False)),
2305
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2306
self.assertEqual(0, conflicts)
2307
self.assertEqual('blah', wt.id2path('foo-id'))
2309
def test_symlink_no_content_change(self):
2310
self.requireFeature(tests.SymlinkFeature)
2311
# A Create symlink foo => bar
2313
# B C B relinks foo => baz
2317
# D E D & E have foo => baz
2319
# F F has foo => bing
2321
# Merging E into F should not cause a conflict, because E doesn't have
2322
# a content change relative to the LCAs (it does relative to A)
2323
wt = self.make_branch_and_tree('path')
2325
self.addCleanup(wt.unlock)
2326
os.symlink('bar', 'path/foo')
2327
wt.add(['foo'], ['foo-id'])
2328
wt.commit('add symlink', rev_id='A-id')
2329
os.remove('path/foo')
2330
os.symlink('baz', 'path/foo')
2331
wt.commit('foo => baz', rev_id='B-id')
2332
wt.set_last_revision('A-id')
2333
wt.branch.set_last_revision_info(1, 'A-id')
2335
wt.commit('C', rev_id='C-id')
2336
wt.merge_from_branch(wt.branch, 'B-id')
2337
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2338
wt.commit('E merges C & B', rev_id='E-id')
2339
wt.set_last_revision('B-id')
2340
wt.branch.set_last_revision_info(2, 'B-id')
2342
wt.merge_from_branch(wt.branch, 'C-id')
2343
wt.commit('D merges B & C', rev_id='D-id')
2344
os.remove('path/foo')
2345
os.symlink('bing', 'path/foo')
2346
wt.commit('F foo => bing', rev_id='F-id')
2348
# Check the output of the Merger object directly
2349
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2351
merger.merge_type = _mod_merge.Merge3Merger
2352
merge_obj = merger.make_merger()
2353
# Nothing interesting happened in OTHER relative to BASE
2354
self.assertEqual([], list(merge_obj._entries_lca()))
2355
# Now do a real merge, just to test the rest of the stack
2356
conflicts = wt.merge_from_branch(wt.branch, to_revision='E-id')
2357
self.assertEqual(0, conflicts)
2358
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2360
def test_symlink_this_changed_kind(self):
2361
self.requireFeature(tests.SymlinkFeature)
2364
# B C B creates symlink foo => bar
2368
# D E D changes foo into a file, E has foo => bing
2370
# Mostly, this is trying to test that we don't try to os.readlink() on
2371
# a file, or when there is nothing there
2372
wt = self.make_branch_and_tree('path')
2374
self.addCleanup(wt.unlock)
2375
wt.commit('base', rev_id='A-id')
2376
os.symlink('bar', 'path/foo')
2377
wt.add(['foo'], ['foo-id'])
2378
wt.commit('add symlink foo => bar', rev_id='B-id')
2379
wt.set_last_revision('A-id')
2380
wt.branch.set_last_revision_info(1, 'A-id')
2382
wt.commit('C', rev_id='C-id')
2383
wt.merge_from_branch(wt.branch, 'B-id')
2384
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2385
os.remove('path/foo')
2386
# We have to change the link in E, or it won't try to do a comparison
2387
os.symlink('bing', 'path/foo')
2388
wt.commit('E merges C & B, overrides to bing', rev_id='E-id')
2389
wt.set_last_revision('B-id')
2390
wt.branch.set_last_revision_info(2, 'B-id')
2392
wt.merge_from_branch(wt.branch, 'C-id')
2393
os.remove('path/foo')
2394
self.build_tree_contents([('path/foo', 'file content\n')])
2395
# XXX: workaround, WT doesn't detect kind changes unless you do
2397
list(wt.iter_changes(wt.basis_tree()))
2398
wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2400
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2402
merger.merge_type = _mod_merge.Merge3Merger
2403
merge_obj = merger.make_merger()
2404
entries = list(merge_obj._entries_lca())
2405
root_id = wt.path2id('')
2406
self.assertEqual([('foo-id', True,
2407
((None, [root_id, None]), root_id, root_id),
2408
((None, [u'foo', None]), u'foo', u'foo'),
2409
((None, [False, None]), False, False)),
2412
def test_symlink_all_wt(self):
2413
"""Check behavior if all trees are Working Trees."""
2414
self.requireFeature(tests.SymlinkFeature)
2415
# The big issue is that entry.symlink_target is None for WorkingTrees.
2416
# So we need to make sure we handle that case correctly.
2419
# B C B relinks foo => baz
2421
# D E D & E have foo => baz
2423
# F F changes it to bing
2424
# Merging D & F should result in F cleanly overriding D, because D's
2425
# value actually comes from B
2427
wt = self.make_branch_and_tree('path')
2429
self.addCleanup(wt.unlock)
2430
os.symlink('bar', 'path/foo')
2431
wt.add(['foo'], ['foo-id'])
2432
wt.commit('add symlink', rev_id='A-id')
2433
os.remove('path/foo')
2434
os.symlink('baz', 'path/foo')
2435
wt.commit('foo => baz', rev_id='B-id')
2436
wt.set_last_revision('A-id')
2437
wt.branch.set_last_revision_info(1, 'A-id')
2439
wt.commit('C', rev_id='C-id')
2440
wt.merge_from_branch(wt.branch, 'B-id')
2441
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2442
wt.commit('E merges C & B', rev_id='E-id')
2443
os.remove('path/foo')
2444
os.symlink('bing', 'path/foo')
2445
wt.commit('F foo => bing', rev_id='F-id')
2446
wt.set_last_revision('B-id')
2447
wt.branch.set_last_revision_info(2, 'B-id')
2449
wt.merge_from_branch(wt.branch, 'C-id')
2450
wt.commit('D merges B & C', rev_id='D-id')
2451
wt_base = wt.bzrdir.sprout('base', 'A-id').open_workingtree()
2453
self.addCleanup(wt_base.unlock)
2454
wt_lca1 = wt.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2456
self.addCleanup(wt_lca1.unlock)
2457
wt_lca2 = wt.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2459
self.addCleanup(wt_lca2.unlock)
2460
wt_other = wt.bzrdir.sprout('other', 'F-id').open_workingtree()
2461
wt_other.lock_read()
2462
self.addCleanup(wt_other.unlock)
2463
merge_obj = _mod_merge.Merge3Merger(wt, wt, wt_base,
2464
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2465
entries = list(merge_obj._entries_lca())
2466
root_id = wt.path2id('')
2467
self.assertEqual([('foo-id', True,
2468
((root_id, [root_id, root_id]), root_id, root_id),
2469
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2470
((False, [False, False]), False, False)),
2473
def test_other_reverted_path_to_base(self):
2476
# B C Path at 'bar' in B
2483
builder = self.get_builder()
2484
builder.build_snapshot('A-id', None,
2485
[('add', (u'', 'a-root-id', 'directory', None)),
2486
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2487
builder.build_snapshot('C-id', ['A-id'], [])
2488
builder.build_snapshot('B-id', ['A-id'],
2489
[('rename', ('foo', 'bar'))])
2490
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2491
[('rename', ('foo', 'bar'))]) # merge the rename
2492
builder.build_snapshot('F-id', ['E-id'],
2493
[('rename', ('bar', 'foo'))]) # Rename back to BASE
2494
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2495
wt, conflicts = self.do_merge(builder, 'F-id')
2496
self.assertEqual(0, conflicts)
2497
self.assertEqual('foo', wt.id2path('foo-id'))
2499
def test_other_reverted_content_to_base(self):
2500
builder = self.get_builder()
2501
builder.build_snapshot('A-id', None,
2502
[('add', (u'', 'a-root-id', 'directory', None)),
2503
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2504
builder.build_snapshot('C-id', ['A-id'], [])
2505
builder.build_snapshot('B-id', ['A-id'],
2506
[('modify', ('foo-id', 'B content\n'))])
2507
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2508
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2509
builder.build_snapshot('F-id', ['E-id'],
2510
[('modify', ('foo-id', 'base content\n'))]) # Revert back to BASE
2511
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2512
wt, conflicts = self.do_merge(builder, 'F-id')
2513
self.assertEqual(0, conflicts)
2514
# TODO: We need to use the per-file graph to properly select a BASE
2515
# before this will work. Or at least use the LCA trees to find
2516
# the appropriate content base. (which is B, not A).
2517
self.assertEqual('base content\n', wt.get_file_text('foo-id'))
2519
def test_other_modified_content(self):
2520
builder = self.get_builder()
2521
builder.build_snapshot('A-id', None,
2522
[('add', (u'', 'a-root-id', 'directory', None)),
2523
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2524
builder.build_snapshot('C-id', ['A-id'], [])
2525
builder.build_snapshot('B-id', ['A-id'],
2526
[('modify', ('foo-id', 'B content\n'))])
2527
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2528
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2529
builder.build_snapshot('F-id', ['E-id'],
2530
[('modify', ('foo-id', 'F content\n'))]) # Override B content
2531
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2532
wt, conflicts = self.do_merge(builder, 'F-id')
2533
self.assertEqual(0, conflicts)
2534
self.assertEqual('F content\n', wt.get_file_text('foo-id'))
2536
def test_all_wt(self):
2537
"""Check behavior if all trees are Working Trees."""
2538
# The big issue is that entry.revision is None for WorkingTrees. (as is
2539
# entry.text_sha1, etc. So we need to make sure we handle that case
2541
# A Content of 'foo', path of 'a'
2543
# B C B modifies content, C renames 'a' => 'b'
2545
# D E E updates content, renames 'b' => 'c'
2546
builder = self.get_builder()
2547
builder.build_snapshot('A-id', None,
2548
[('add', (u'', 'a-root-id', 'directory', None)),
2549
('add', (u'a', 'a-id', 'file', 'base content\n')),
2550
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2551
builder.build_snapshot('B-id', ['A-id'],
2552
[('modify', ('foo-id', 'B content\n'))])
2553
builder.build_snapshot('C-id', ['A-id'],
2554
[('rename', ('a', 'b'))])
2555
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2556
[('rename', ('b', 'c')),
2557
('modify', ('foo-id', 'E content\n'))])
2558
builder.build_snapshot('D-id', ['B-id', 'C-id'],
2559
[('rename', ('a', 'b'))]) # merged change
2560
wt_this = self.get_wt_from_builder(builder)
2561
wt_base = wt_this.bzrdir.sprout('base', 'A-id').open_workingtree()
2563
self.addCleanup(wt_base.unlock)
2564
wt_lca1 = wt_this.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2566
self.addCleanup(wt_lca1.unlock)
2567
wt_lca2 = wt_this.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2569
self.addCleanup(wt_lca2.unlock)
2570
wt_other = wt_this.bzrdir.sprout('other', 'E-id').open_workingtree()
2571
wt_other.lock_read()
2572
self.addCleanup(wt_other.unlock)
2573
merge_obj = _mod_merge.Merge3Merger(wt_this, wt_this, wt_base,
2574
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2575
entries = list(merge_obj._entries_lca())
2576
root_id = 'a-root-id'
2577
self.assertEqual([('a-id', False,
2578
((root_id, [root_id, root_id]), root_id, root_id),
2579
((u'a', [u'a', u'b']), u'c', u'b'),
2580
((False, [False, False]), False, False)),
2582
((root_id, [root_id, root_id]), root_id, root_id),
2583
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2584
((False, [False, False]), False, False)),
2587
def test_nested_tree_unmodified(self):
2588
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2590
wt = self.make_branch_and_tree('tree',
2591
format='dirstate-with-subtree')
2593
self.addCleanup(wt.unlock)
2594
sub_tree = self.make_branch_and_tree('tree/sub-tree',
2595
format='dirstate-with-subtree')
2596
wt.set_root_id('a-root-id')
2597
sub_tree.set_root_id('sub-tree-root')
2598
self.build_tree_contents([('tree/sub-tree/file', 'text1')])
2599
sub_tree.add('file')
2600
sub_tree.commit('foo', rev_id='sub-A-id')
2601
wt.add_reference(sub_tree)
2602
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2603
# Now create a criss-cross merge in the parent, without modifying the
2605
wt.commit('B', rev_id='B-id', recursive=None)
2606
wt.set_last_revision('A-id')
2607
wt.branch.set_last_revision_info(1, 'A-id')
2608
wt.commit('C', rev_id='C-id', recursive=None)
2609
wt.merge_from_branch(wt.branch, to_revision='B-id')
2610
wt.commit('E', rev_id='E-id', recursive=None)
2611
wt.set_parent_ids(['B-id', 'C-id'])
2612
wt.branch.set_last_revision_info(2, 'B-id')
2613
wt.commit('D', rev_id='D-id', recursive=None)
2615
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2617
merger.merge_type = _mod_merge.Merge3Merger
2618
merge_obj = merger.make_merger()
2619
entries = list(merge_obj._entries_lca())
2620
self.assertEqual([], entries)
2622
def test_nested_tree_subtree_modified(self):
2623
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2625
wt = self.make_branch_and_tree('tree',
2626
format='dirstate-with-subtree')
2628
self.addCleanup(wt.unlock)
2629
sub_tree = self.make_branch_and_tree('tree/sub',
2630
format='dirstate-with-subtree')
2631
wt.set_root_id('a-root-id')
2632
sub_tree.set_root_id('sub-tree-root')
2633
self.build_tree_contents([('tree/sub/file', 'text1')])
2634
sub_tree.add('file')
2635
sub_tree.commit('foo', rev_id='sub-A-id')
2636
wt.add_reference(sub_tree)
2637
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2638
# Now create a criss-cross merge in the parent, without modifying the
2640
wt.commit('B', rev_id='B-id', recursive=None)
2641
wt.set_last_revision('A-id')
2642
wt.branch.set_last_revision_info(1, 'A-id')
2643
wt.commit('C', rev_id='C-id', recursive=None)
2644
wt.merge_from_branch(wt.branch, to_revision='B-id')
2645
self.build_tree_contents([('tree/sub/file', 'text2')])
2646
sub_tree.commit('modify contents', rev_id='sub-B-id')
2647
wt.commit('E', rev_id='E-id', recursive=None)
2648
wt.set_parent_ids(['B-id', 'C-id'])
2649
wt.branch.set_last_revision_info(2, 'B-id')
2650
wt.commit('D', rev_id='D-id', recursive=None)
2652
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2654
merger.merge_type = _mod_merge.Merge3Merger
2655
merge_obj = merger.make_merger()
2656
entries = list(merge_obj._entries_lca())
2657
# Nothing interesting about this sub-tree, because content changes are
2658
# computed at a higher level
2659
self.assertEqual([], entries)
2661
def test_nested_tree_subtree_renamed(self):
2662
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2664
wt = self.make_branch_and_tree('tree',
2665
format='dirstate-with-subtree')
2667
self.addCleanup(wt.unlock)
2668
sub_tree = self.make_branch_and_tree('tree/sub',
2669
format='dirstate-with-subtree')
2670
wt.set_root_id('a-root-id')
2671
sub_tree.set_root_id('sub-tree-root')
2672
self.build_tree_contents([('tree/sub/file', 'text1')])
2673
sub_tree.add('file')
2674
sub_tree.commit('foo', rev_id='sub-A-id')
2675
wt.add_reference(sub_tree)
2676
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2677
# Now create a criss-cross merge in the parent, without modifying the
2679
wt.commit('B', rev_id='B-id', recursive=None)
2680
wt.set_last_revision('A-id')
2681
wt.branch.set_last_revision_info(1, 'A-id')
2682
wt.commit('C', rev_id='C-id', recursive=None)
2683
wt.merge_from_branch(wt.branch, to_revision='B-id')
2684
wt.rename_one('sub', 'alt_sub')
2685
wt.commit('E', rev_id='E-id', recursive=None)
2686
wt.set_last_revision('B-id')
2688
wt.set_parent_ids(['B-id', 'C-id'])
2689
wt.branch.set_last_revision_info(2, 'B-id')
2690
wt.commit('D', rev_id='D-id', recursive=None)
2692
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2694
merger.merge_type = _mod_merge.Merge3Merger
2695
merge_obj = merger.make_merger()
2696
entries = list(merge_obj._entries_lca())
2697
root_id = 'a-root-id'
2698
self.assertEqual([('sub-tree-root', False,
2699
((root_id, [root_id, root_id]), root_id, root_id),
2700
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2701
((False, [False, False]), False, False)),
2704
def test_nested_tree_subtree_renamed_and_modified(self):
2705
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2707
wt = self.make_branch_and_tree('tree',
2708
format='dirstate-with-subtree')
2710
self.addCleanup(wt.unlock)
2711
sub_tree = self.make_branch_and_tree('tree/sub',
2712
format='dirstate-with-subtree')
2713
wt.set_root_id('a-root-id')
2714
sub_tree.set_root_id('sub-tree-root')
2715
self.build_tree_contents([('tree/sub/file', 'text1')])
2716
sub_tree.add('file')
2717
sub_tree.commit('foo', rev_id='sub-A-id')
2718
wt.add_reference(sub_tree)
2719
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2720
# Now create a criss-cross merge in the parent, without modifying the
2722
wt.commit('B', rev_id='B-id', recursive=None)
2723
wt.set_last_revision('A-id')
2724
wt.branch.set_last_revision_info(1, 'A-id')
2725
wt.commit('C', rev_id='C-id', recursive=None)
2726
wt.merge_from_branch(wt.branch, to_revision='B-id')
2727
self.build_tree_contents([('tree/sub/file', 'text2')])
2728
sub_tree.commit('modify contents', rev_id='sub-B-id')
2729
wt.rename_one('sub', 'alt_sub')
2730
wt.commit('E', rev_id='E-id', recursive=None)
2731
wt.set_last_revision('B-id')
2733
wt.set_parent_ids(['B-id', 'C-id'])
2734
wt.branch.set_last_revision_info(2, 'B-id')
2735
wt.commit('D', rev_id='D-id', recursive=None)
2737
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2739
merger.merge_type = _mod_merge.Merge3Merger
2740
merge_obj = merger.make_merger()
2741
entries = list(merge_obj._entries_lca())
2742
root_id = 'a-root-id'
2743
self.assertEqual([('sub-tree-root', False,
2744
((root_id, [root_id, root_id]), root_id, root_id),
2745
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2746
((False, [False, False]), False, False)),
2750
class TestLCAMultiWay(tests.TestCase):
2752
def assertLCAMultiWay(self, expected, base, lcas, other, this,
2753
allow_overriding_lca=True):
2754
self.assertEqual(expected, _mod_merge.Merge3Merger._lca_multi_way(
2755
(base, lcas), other, this,
2756
allow_overriding_lca=allow_overriding_lca))
2758
def test_other_equal_equal_lcas(self):
2759
"""Test when OTHER=LCA and all LCAs are identical."""
2760
self.assertLCAMultiWay('this',
2761
'bval', ['bval', 'bval'], 'bval', 'bval')
2762
self.assertLCAMultiWay('this',
2763
'bval', ['lcaval', 'lcaval'], 'lcaval', 'bval')
2764
self.assertLCAMultiWay('this',
2765
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'bval')
2766
self.assertLCAMultiWay('this',
2767
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'tval')
2768
self.assertLCAMultiWay('this',
2769
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', None)
2771
def test_other_equal_this(self):
2772
"""Test when other and this are identical."""
2773
self.assertLCAMultiWay('this',
2774
'bval', ['bval', 'bval'], 'oval', 'oval')
2775
self.assertLCAMultiWay('this',
2776
'bval', ['lcaval', 'lcaval'], 'oval', 'oval')
2777
self.assertLCAMultiWay('this',
2778
'bval', ['cval', 'dval'], 'oval', 'oval')
2779
self.assertLCAMultiWay('this',
2780
'bval', [None, 'lcaval'], 'oval', 'oval')
2781
self.assertLCAMultiWay('this',
2782
None, [None, 'lcaval'], 'oval', 'oval')
2783
self.assertLCAMultiWay('this',
2784
None, ['lcaval', 'lcaval'], 'oval', 'oval')
2785
self.assertLCAMultiWay('this',
2786
None, ['cval', 'dval'], 'oval', 'oval')
2787
self.assertLCAMultiWay('this',
2788
None, ['cval', 'dval'], None, None)
2789
self.assertLCAMultiWay('this',
2790
None, ['cval', 'dval', 'eval', 'fval'], 'oval', 'oval')
2792
def test_no_lcas(self):
2793
self.assertLCAMultiWay('this',
2794
'bval', [], 'bval', 'tval')
2795
self.assertLCAMultiWay('other',
2796
'bval', [], 'oval', 'bval')
2797
self.assertLCAMultiWay('conflict',
2798
'bval', [], 'oval', 'tval')
2799
self.assertLCAMultiWay('this',
2800
'bval', [], 'oval', 'oval')
2802
def test_lca_supersedes_other_lca(self):
2803
"""If one lca == base, the other lca takes precedence"""
2804
self.assertLCAMultiWay('this',
2805
'bval', ['bval', 'lcaval'], 'lcaval', 'tval')
2806
self.assertLCAMultiWay('this',
2807
'bval', ['bval', 'lcaval'], 'lcaval', 'bval')
2808
# This is actually considered a 'revert' because the 'lcaval' in LCAS
2809
# supersedes the BASE val (in the other LCA) but then OTHER reverts it
2811
self.assertLCAMultiWay('other',
2812
'bval', ['bval', 'lcaval'], 'bval', 'lcaval')
2813
self.assertLCAMultiWay('conflict',
2814
'bval', ['bval', 'lcaval'], 'bval', 'tval')
2816
def test_other_and_this_pick_different_lca(self):
2817
# OTHER and THIS resolve the lca conflict in different ways
2818
self.assertLCAMultiWay('conflict',
2819
'bval', ['lca1val', 'lca2val'], 'lca1val', 'lca2val')
2820
self.assertLCAMultiWay('conflict',
2821
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'lca2val')
2822
self.assertLCAMultiWay('conflict',
2823
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'lca2val')
2825
def test_other_in_lca(self):
2826
# OTHER takes a value of one of the LCAs, THIS takes a new value, which
2827
# theoretically supersedes both LCA values and 'wins'
2828
self.assertLCAMultiWay('this',
2829
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval')
2830
self.assertLCAMultiWay('this',
2831
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval')
2832
self.assertLCAMultiWay('conflict',
2833
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval',
2834
allow_overriding_lca=False)
2835
self.assertLCAMultiWay('conflict',
2836
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval',
2837
allow_overriding_lca=False)
2838
# THIS reverted back to BASE, but that is an explicit supersede of all
2840
self.assertLCAMultiWay('this',
2841
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval')
2842
self.assertLCAMultiWay('this',
2843
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval')
2844
self.assertLCAMultiWay('conflict',
2845
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval',
2846
allow_overriding_lca=False)
2847
self.assertLCAMultiWay('conflict',
2848
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval',
2849
allow_overriding_lca=False)
2851
def test_this_in_lca(self):
2852
# THIS takes a value of one of the LCAs, OTHER takes a new value, which
2853
# theoretically supersedes both LCA values and 'wins'
2854
self.assertLCAMultiWay('other',
2855
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val')
2856
self.assertLCAMultiWay('other',
2857
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val')
2858
self.assertLCAMultiWay('conflict',
2859
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val',
2860
allow_overriding_lca=False)
2861
self.assertLCAMultiWay('conflict',
2862
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val',
2863
allow_overriding_lca=False)
2864
# OTHER reverted back to BASE, but that is an explicit supersede of all
2866
self.assertLCAMultiWay('other',
2867
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val')
2868
self.assertLCAMultiWay('conflict',
2869
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val',
2870
allow_overriding_lca=False)
2872
def test_all_differ(self):
2873
self.assertLCAMultiWay('conflict',
2874
'bval', ['lca1val', 'lca2val'], 'oval', 'tval')
2875
self.assertLCAMultiWay('conflict',
2876
'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2877
self.assertLCAMultiWay('conflict',
2878
'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')