695
1155
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
697
1157
merge_type = _mod_merge.LCAMerger
1159
def test_merge_move_and_change(self):
1160
self.expectFailure("lca merge doesn't conflict for move and change",
1161
super(TestLCAMerge, self).test_merge_move_and_change)
1164
class LoggingMerger(object):
1165
# These seem to be the required attributes
1166
requires_base = False
1167
supports_reprocess = False
1168
supports_show_base = False
1169
supports_cherrypick = False
1170
# We intentionally do not define supports_lca_trees
1172
def __init__(self, *args, **kwargs):
1174
self.kwargs = kwargs
1177
class TestMergerBase(TestCaseWithMemoryTransport):
1178
"""Common functionality for Merger tests that don't write to disk."""
1180
def get_builder(self):
1181
builder = self.make_branch_builder('path')
1182
builder.start_series()
1183
self.addCleanup(builder.finish_series)
1186
def setup_simple_graph(self):
1187
"""Create a simple 3-node graph.
1189
:return: A BranchBuilder
1196
builder = self.get_builder()
1197
builder.build_snapshot('A-id', None,
1198
[('add', ('', None, 'directory', None))])
1199
builder.build_snapshot('C-id', ['A-id'], [])
1200
builder.build_snapshot('B-id', ['A-id'], [])
1203
def setup_criss_cross_graph(self):
1204
"""Create a 5-node graph with a criss-cross.
1206
:return: A BranchBuilder
1213
builder = self.setup_simple_graph()
1214
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1215
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1218
def make_Merger(self, builder, other_revision_id,
1219
interesting_files=None, interesting_ids=None):
1220
"""Make a Merger object from a branch builder"""
1221
mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1222
mem_tree.lock_write()
1223
self.addCleanup(mem_tree.unlock)
1224
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1225
mem_tree, other_revision_id)
1226
merger.set_interesting_files(interesting_files)
1227
# It seems there is no matching function for set_interesting_ids
1228
merger.interesting_ids = interesting_ids
1229
merger.merge_type = _mod_merge.Merge3Merger
1233
class TestMergerInMemory(TestMergerBase):
1235
def test_find_base(self):
1236
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1237
self.assertEqual('A-id', merger.base_rev_id)
1238
self.assertFalse(merger._is_criss_cross)
1239
self.assertIs(None, merger._lca_trees)
1241
def test_find_base_criss_cross(self):
1242
builder = self.setup_criss_cross_graph()
1243
merger = self.make_Merger(builder, 'E-id')
1244
self.assertEqual('A-id', merger.base_rev_id)
1245
self.assertTrue(merger._is_criss_cross)
1246
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1247
for t in merger._lca_trees])
1248
# If we swap the order, we should get a different lca order
1249
builder.build_snapshot('F-id', ['E-id'], [])
1250
merger = self.make_Merger(builder, 'D-id')
1251
self.assertEqual(['C-id', 'B-id'], [t.get_revision_id()
1252
for t in merger._lca_trees])
1254
def test_find_base_triple_criss_cross(self):
1257
# B C F # F is merged into both branches
1264
builder = self.setup_criss_cross_graph()
1265
builder.build_snapshot('F-id', ['A-id'], [])
1266
builder.build_snapshot('H-id', ['E-id', 'F-id'], [])
1267
builder.build_snapshot('G-id', ['D-id', 'F-id'], [])
1268
merger = self.make_Merger(builder, 'H-id')
1269
self.assertEqual(['B-id', 'C-id', 'F-id'],
1270
[t.get_revision_id() for t in merger._lca_trees])
1272
def test_no_criss_cross_passed_to_merge_type(self):
1273
class LCATreesMerger(LoggingMerger):
1274
supports_lca_trees = True
1276
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1277
merger.merge_type = LCATreesMerger
1278
merge_obj = merger.make_merger()
1279
self.assertIsInstance(merge_obj, LCATreesMerger)
1280
self.assertFalse('lca_trees' in merge_obj.kwargs)
1282
def test_criss_cross_passed_to_merge_type(self):
1283
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1284
merger.merge_type = _mod_merge.Merge3Merger
1285
merge_obj = merger.make_merger()
1286
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1287
for t in merger._lca_trees])
1289
def test_criss_cross_not_supported_merge_type(self):
1290
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1291
# We explicitly do not define supports_lca_trees
1292
merger.merge_type = LoggingMerger
1293
merge_obj = merger.make_merger()
1294
self.assertIsInstance(merge_obj, LoggingMerger)
1295
self.assertFalse('lca_trees' in merge_obj.kwargs)
1297
def test_criss_cross_unsupported_merge_type(self):
1298
class UnsupportedLCATreesMerger(LoggingMerger):
1299
supports_lca_trees = False
1301
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1302
merger.merge_type = UnsupportedLCATreesMerger
1303
merge_obj = merger.make_merger()
1304
self.assertIsInstance(merge_obj, UnsupportedLCATreesMerger)
1305
self.assertFalse('lca_trees' in merge_obj.kwargs)
1308
class TestMergerEntriesLCA(TestMergerBase):
1310
def make_merge_obj(self, builder, other_revision_id,
1311
interesting_files=None, interesting_ids=None):
1312
merger = self.make_Merger(builder, other_revision_id,
1313
interesting_files=interesting_files,
1314
interesting_ids=interesting_ids)
1315
return merger.make_merger()
1317
def test_simple(self):
1318
builder = self.get_builder()
1319
builder.build_snapshot('A-id', None,
1320
[('add', (u'', 'a-root-id', 'directory', None)),
1321
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1322
builder.build_snapshot('C-id', ['A-id'],
1323
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1324
builder.build_snapshot('B-id', ['A-id'],
1325
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1326
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1327
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1328
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1329
[('modify', ('a-id', 'a\nB\nb\nC\nc\n'))])
1330
merge_obj = self.make_merge_obj(builder, 'E-id')
1332
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1333
for t in merge_obj._lca_trees])
1334
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1335
entries = list(merge_obj._entries_lca())
1337
# (file_id, changed, parents, names, executable)
1338
# BASE, lca1, lca2, OTHER, THIS
1339
root_id = 'a-root-id'
1340
self.assertEqual([('a-id', True,
1341
((root_id, [root_id, root_id]), root_id, root_id),
1342
((u'a', [u'a', u'a']), u'a', u'a'),
1343
((False, [False, False]), False, False)),
1346
def test_not_in_base(self):
1347
# LCAs all have the same last-modified revision for the file, as do
1348
# the tips, but the base has something different
1349
# A base, doesn't have the file
1351
# B C B introduces 'foo', C introduces 'bar'
1353
# D E D and E now both have 'foo' and 'bar'
1355
# F G the files are now in F, G, D and E, but not in A
1358
builder = self.get_builder()
1359
builder.build_snapshot('A-id', None,
1360
[('add', (u'', 'a-root-id', 'directory', None))])
1361
builder.build_snapshot('B-id', ['A-id'],
1362
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1363
builder.build_snapshot('C-id', ['A-id'],
1364
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1365
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1366
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1367
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1368
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1369
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1370
[('modify', (u'bar-id', 'd\ne\nf\nG\n'))])
1371
builder.build_snapshot('F-id', ['D-id', 'E-id'], [])
1372
merge_obj = self.make_merge_obj(builder, 'G-id')
1374
self.assertEqual(['D-id', 'E-id'], [t.get_revision_id()
1375
for t in merge_obj._lca_trees])
1376
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1377
entries = list(merge_obj._entries_lca())
1378
root_id = 'a-root-id'
1379
self.assertEqual([('bar-id', True,
1380
((None, [root_id, root_id]), root_id, root_id),
1381
((None, [u'bar', u'bar']), u'bar', u'bar'),
1382
((None, [False, False]), False, False)),
1385
def test_not_in_this(self):
1386
builder = self.get_builder()
1387
builder.build_snapshot('A-id', None,
1388
[('add', (u'', 'a-root-id', 'directory', None)),
1389
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1390
builder.build_snapshot('B-id', ['A-id'],
1391
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1392
builder.build_snapshot('C-id', ['A-id'],
1393
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1394
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1395
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1396
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1397
[('unversion', 'a-id')])
1398
merge_obj = self.make_merge_obj(builder, 'E-id')
1400
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1401
for t in merge_obj._lca_trees])
1402
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1404
entries = list(merge_obj._entries_lca())
1405
root_id = 'a-root-id'
1406
self.assertEqual([('a-id', True,
1407
((root_id, [root_id, root_id]), root_id, None),
1408
((u'a', [u'a', u'a']), u'a', None),
1409
((False, [False, False]), False, None)),
1412
def test_file_not_in_one_lca(self):
1415
# B C # B no file, C introduces a file
1417
# D E # D and E both have the file, unchanged from C
1418
builder = self.get_builder()
1419
builder.build_snapshot('A-id', None,
1420
[('add', (u'', 'a-root-id', 'directory', None))])
1421
builder.build_snapshot('B-id', ['A-id'], [])
1422
builder.build_snapshot('C-id', ['A-id'],
1423
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1424
builder.build_snapshot('E-id', ['C-id', 'B-id'], []) # Inherited from C
1425
builder.build_snapshot('D-id', ['B-id', 'C-id'], # Merged from C
1426
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1427
merge_obj = self.make_merge_obj(builder, 'E-id')
1429
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1430
for t in merge_obj._lca_trees])
1431
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1433
entries = list(merge_obj._entries_lca())
1434
self.assertEqual([], entries)
1436
def test_not_in_other(self):
1437
builder = self.get_builder()
1438
builder.build_snapshot('A-id', None,
1439
[('add', (u'', 'a-root-id', 'directory', None)),
1440
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1441
builder.build_snapshot('B-id', ['A-id'], [])
1442
builder.build_snapshot('C-id', ['A-id'], [])
1443
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1444
[('unversion', 'a-id')])
1445
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1446
merge_obj = self.make_merge_obj(builder, 'E-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]), None, root_id),
1452
((u'a', [u'a', u'a']), None, u'a'),
1453
((False, [False, False]), None, False)),
1456
def test_not_in_other_or_lca(self):
1457
# A base, introduces 'foo'
1459
# B C B nothing, C deletes foo
1461
# D E D restores foo (same as B), E leaves it deleted
1463
# A => B, no changes
1464
# A => C, delete foo (C should supersede B)
1465
# C => D, restore foo
1466
# C => E, no changes
1467
# D would then win 'cleanly' and no record would be given
1468
builder = self.get_builder()
1469
builder.build_snapshot('A-id', None,
1470
[('add', (u'', 'a-root-id', 'directory', None)),
1471
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1472
builder.build_snapshot('B-id', ['A-id'], [])
1473
builder.build_snapshot('C-id', ['A-id'],
1474
[('unversion', 'foo-id')])
1475
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1476
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1477
merge_obj = self.make_merge_obj(builder, 'E-id')
1479
entries = list(merge_obj._entries_lca())
1480
self.assertEqual([], entries)
1482
def test_not_in_other_mod_in_lca1_not_in_lca2(self):
1483
# A base, introduces 'foo'
1485
# B C B changes 'foo', C deletes foo
1487
# D E D restores foo (same as B), E leaves it deleted (as C)
1489
# A => B, modified foo
1490
# A => C, delete foo, C does not supersede B
1491
# B => D, no changes
1492
# C => D, resolve in favor of B
1493
# B => E, resolve in favor of E
1494
# C => E, no changes
1495
# In this case, we have a conflict of how the changes were resolved. E
1496
# picked C and D picked B, so we should issue a conflict
1497
builder = self.get_builder()
1498
builder.build_snapshot('A-id', None,
1499
[('add', (u'', 'a-root-id', 'directory', None)),
1500
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1501
builder.build_snapshot('B-id', ['A-id'], [
1502
('modify', ('foo-id', 'new-content\n'))])
1503
builder.build_snapshot('C-id', ['A-id'],
1504
[('unversion', 'foo-id')])
1505
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1506
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1507
merge_obj = self.make_merge_obj(builder, 'E-id')
1509
entries = list(merge_obj._entries_lca())
1510
root_id = 'a-root-id'
1511
self.assertEqual([('foo-id', True,
1512
((root_id, [root_id, None]), None, root_id),
1513
((u'foo', [u'foo', None]), None, 'foo'),
1514
((False, [False, None]), None, False)),
1517
def test_only_in_one_lca(self):
1520
# B C B nothing, C add file
1522
# D E D still has nothing, E removes file
1525
# C => D, removed the file
1527
# C => E, removed the file
1528
# Thus D & E have identical changes, and this is a no-op
1531
# A => C, add file, thus C supersedes B
1532
# w/ C=BASE, D=THIS, E=OTHER we have 'happy convergence'
1533
builder = self.get_builder()
1534
builder.build_snapshot('A-id', None,
1535
[('add', (u'', 'a-root-id', 'directory', None))])
1536
builder.build_snapshot('B-id', ['A-id'], [])
1537
builder.build_snapshot('C-id', ['A-id'],
1538
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1539
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1540
[('unversion', 'a-id')])
1541
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1542
merge_obj = self.make_merge_obj(builder, 'E-id')
1544
entries = list(merge_obj._entries_lca())
1545
self.assertEqual([], entries)
1547
def test_only_in_other(self):
1548
builder = self.get_builder()
1549
builder.build_snapshot('A-id', None,
1550
[('add', (u'', 'a-root-id', 'directory', None))])
1551
builder.build_snapshot('B-id', ['A-id'], [])
1552
builder.build_snapshot('C-id', ['A-id'], [])
1553
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1554
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1555
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1556
merge_obj = self.make_merge_obj(builder, 'E-id')
1558
entries = list(merge_obj._entries_lca())
1559
root_id = 'a-root-id'
1560
self.assertEqual([('a-id', True,
1561
((None, [None, None]), root_id, None),
1562
((None, [None, None]), u'a', None),
1563
((None, [None, None]), False, None)),
1566
def test_one_lca_supersedes(self):
1567
# One LCA supersedes the other LCAs last modified value, but the
1568
# value is not the same as BASE.
1569
# A base, introduces 'foo', last mod A
1571
# B C B modifies 'foo' (mod B), C does nothing (mod A)
1573
# D E D does nothing (mod B), E updates 'foo' (mod E)
1575
# F G F updates 'foo' (mod F). G does nothing (mod E)
1577
# At this point, G should not be considered to modify 'foo', even
1578
# though its LCAs disagree. This is because the modification in E
1579
# completely supersedes the value in D.
1580
builder = self.get_builder()
1581
builder.build_snapshot('A-id', None,
1582
[('add', (u'', 'a-root-id', 'directory', None)),
1583
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1584
builder.build_snapshot('C-id', ['A-id'], [])
1585
builder.build_snapshot('B-id', ['A-id'],
1586
[('modify', ('foo-id', 'B content\n'))])
1587
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1588
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1589
[('modify', ('foo-id', 'E content\n'))])
1590
builder.build_snapshot('G-id', ['E-id', 'D-id'], [])
1591
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1592
[('modify', ('foo-id', 'F content\n'))])
1593
merge_obj = self.make_merge_obj(builder, 'G-id')
1595
self.assertEqual([], list(merge_obj._entries_lca()))
1597
def test_one_lca_supersedes_path(self):
1598
# Double-criss-cross merge, the ultimate base value is different from
1602
# B C B value 'bar', C = 'foo'
1604
# D E D = 'bar', E supersedes to 'bing'
1606
# F G F = 'bing', G supersedes to 'barry'
1608
# In this case, we technically should not care about the value 'bar' for
1609
# D, because it was clearly superseded by E's 'bing'. The
1610
# per-file/attribute graph would actually look like:
1619
# Because the other side of the merge never modifies the value, it just
1620
# takes the value from the merge.
1622
# ATM this fails because we will prune 'foo' from the LCAs, but we
1623
# won't prune 'bar'. This is getting far off into edge-case land, so we
1624
# aren't supporting it yet.
1626
builder = self.get_builder()
1627
builder.build_snapshot('A-id', None,
1628
[('add', (u'', 'a-root-id', 'directory', None)),
1629
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1630
builder.build_snapshot('C-id', ['A-id'], [])
1631
builder.build_snapshot('B-id', ['A-id'],
1632
[('rename', ('foo', 'bar'))])
1633
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1634
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1635
[('rename', ('foo', 'bing'))]) # override to bing
1636
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1637
[('rename', ('bing', 'barry'))]) # override to barry
1638
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1639
[('rename', ('bar', 'bing'))]) # Merge in E's change
1640
merge_obj = self.make_merge_obj(builder, 'G-id')
1642
self.expectFailure("We don't do an actual heads() check on lca values,"
1643
" or use the per-attribute graph",
1644
self.assertEqual, [], list(merge_obj._entries_lca()))
1646
def test_one_lca_accidentally_pruned(self):
1647
# Another incorrect resolution from the same basic flaw:
1650
# B C B value 'bar', C = 'foo'
1652
# D E D = 'bar', E reverts to 'foo'
1654
# F G F = 'bing', G switches to 'bar'
1656
# 'bar' will not be seen as an interesting change, because 'foo' will
1657
# be pruned from the LCAs, even though it was newly introduced by E
1659
builder = self.get_builder()
1660
builder.build_snapshot('A-id', None,
1661
[('add', (u'', 'a-root-id', 'directory', None)),
1662
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1663
builder.build_snapshot('C-id', ['A-id'], [])
1664
builder.build_snapshot('B-id', ['A-id'],
1665
[('rename', ('foo', 'bar'))])
1666
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1667
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1668
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1669
[('rename', ('foo', 'bar'))])
1670
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1671
[('rename', ('bar', 'bing'))]) # should end up conflicting
1672
merge_obj = self.make_merge_obj(builder, 'G-id')
1674
entries = list(merge_obj._entries_lca())
1675
root_id = 'a-root-id'
1676
self.expectFailure("We prune values from BASE even when relevant.",
1679
((root_id, [root_id, root_id]), root_id, root_id),
1680
((u'foo', [u'bar', u'foo']), u'bar', u'bing'),
1681
((False, [False, False]), False, False)),
1684
def test_both_sides_revert(self):
1685
# Both sides of a criss-cross revert the text to the lca
1686
# A base, introduces 'foo'
1688
# B C B modifies 'foo', C modifies 'foo'
1690
# D E D reverts to B, E reverts to C
1691
# This should conflict
1692
builder = self.get_builder()
1693
builder.build_snapshot('A-id', None,
1694
[('add', (u'', 'a-root-id', 'directory', None)),
1695
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1696
builder.build_snapshot('B-id', ['A-id'],
1697
[('modify', ('foo-id', 'B content\n'))])
1698
builder.build_snapshot('C-id', ['A-id'],
1699
[('modify', ('foo-id', 'C content\n'))])
1700
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1701
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1702
merge_obj = self.make_merge_obj(builder, 'E-id')
1704
entries = list(merge_obj._entries_lca())
1705
root_id = 'a-root-id'
1706
self.assertEqual([('foo-id', True,
1707
((root_id, [root_id, root_id]), root_id, root_id),
1708
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1709
((False, [False, False]), False, False)),
1712
def test_different_lca_resolve_one_side_updates_content(self):
1713
# Both sides converge, but then one side updates the text.
1714
# A base, introduces 'foo'
1716
# B C B modifies 'foo', C modifies 'foo'
1718
# D E D reverts to B, E reverts to C
1720
# F F updates to a new value
1721
# We need to emit an entry for 'foo', because D & E differed on the
1723
builder = self.get_builder()
1724
builder.build_snapshot('A-id', None,
1725
[('add', (u'', 'a-root-id', 'directory', None)),
1726
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1727
builder.build_snapshot('B-id', ['A-id'],
1728
[('modify', ('foo-id', 'B content\n'))])
1729
builder.build_snapshot('C-id', ['A-id'],
1730
[('modify', ('foo-id', 'C content\n'))])
1731
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1732
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1733
builder.build_snapshot('F-id', ['D-id'],
1734
[('modify', ('foo-id', 'F content\n'))])
1735
merge_obj = self.make_merge_obj(builder, 'E-id')
1737
entries = list(merge_obj._entries_lca())
1738
root_id = 'a-root-id'
1739
self.assertEqual([('foo-id', True,
1740
((root_id, [root_id, root_id]), root_id, root_id),
1741
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1742
((False, [False, False]), False, False)),
1745
def test_same_lca_resolution_one_side_updates_content(self):
1746
# Both sides converge, but then one side updates the text.
1747
# A base, introduces 'foo'
1749
# B C B modifies 'foo', C modifies 'foo'
1751
# D E D and E use C's value
1753
# F F updates to a new value
1754
# I think it is a bug that this conflicts, but we don't have a way to
1755
# detect otherwise. And because of:
1756
# test_different_lca_resolve_one_side_updates_content
1757
# We need to conflict.
1759
builder = self.get_builder()
1760
builder.build_snapshot('A-id', None,
1761
[('add', (u'', 'a-root-id', 'directory', None)),
1762
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1763
builder.build_snapshot('B-id', ['A-id'],
1764
[('modify', ('foo-id', 'B content\n'))])
1765
builder.build_snapshot('C-id', ['A-id'],
1766
[('modify', ('foo-id', 'C content\n'))])
1767
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1768
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1769
[('modify', ('foo-id', 'C content\n'))]) # Same as E
1770
builder.build_snapshot('F-id', ['D-id'],
1771
[('modify', ('foo-id', 'F content\n'))])
1772
merge_obj = self.make_merge_obj(builder, 'E-id')
1774
entries = list(merge_obj._entries_lca())
1775
self.expectFailure("We don't detect that LCA resolution was the"
1776
" same on both sides",
1777
self.assertEqual, [], entries)
1779
def test_only_path_changed(self):
1780
builder = self.get_builder()
1781
builder.build_snapshot('A-id', None,
1782
[('add', (u'', 'a-root-id', 'directory', None)),
1783
('add', (u'a', 'a-id', 'file', 'content\n'))])
1784
builder.build_snapshot('B-id', ['A-id'], [])
1785
builder.build_snapshot('C-id', ['A-id'], [])
1786
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1787
[('rename', (u'a', u'b'))])
1788
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1789
merge_obj = self.make_merge_obj(builder, 'E-id')
1790
entries = list(merge_obj._entries_lca())
1791
root_id = 'a-root-id'
1792
# The content was not changed, only the path
1793
self.assertEqual([('a-id', False,
1794
((root_id, [root_id, root_id]), root_id, root_id),
1795
((u'a', [u'a', u'a']), u'b', u'a'),
1796
((False, [False, False]), False, False)),
1799
def test_kind_changed(self):
1800
# Identical content, except 'D' changes a-id into a directory
1801
builder = self.get_builder()
1802
builder.build_snapshot('A-id', None,
1803
[('add', (u'', 'a-root-id', 'directory', None)),
1804
('add', (u'a', 'a-id', 'file', 'content\n'))])
1805
builder.build_snapshot('B-id', ['A-id'], [])
1806
builder.build_snapshot('C-id', ['A-id'], [])
1807
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1808
[('unversion', 'a-id'),
1809
('add', (u'a', 'a-id', 'directory', None))])
1810
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1811
merge_obj = self.make_merge_obj(builder, 'E-id')
1812
entries = list(merge_obj._entries_lca())
1813
root_id = 'a-root-id'
1814
# Only the kind was changed (content)
1815
self.assertEqual([('a-id', True,
1816
((root_id, [root_id, root_id]), root_id, root_id),
1817
((u'a', [u'a', u'a']), u'a', u'a'),
1818
((False, [False, False]), False, False)),
1821
def test_this_changed_kind(self):
1822
# Identical content, but THIS changes a file to a directory
1823
builder = self.get_builder()
1824
builder.build_snapshot('A-id', None,
1825
[('add', (u'', 'a-root-id', 'directory', None)),
1826
('add', (u'a', 'a-id', 'file', 'content\n'))])
1827
builder.build_snapshot('B-id', ['A-id'], [])
1828
builder.build_snapshot('C-id', ['A-id'], [])
1829
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1830
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1831
[('unversion', 'a-id'),
1832
('add', (u'a', 'a-id', 'directory', None))])
1833
merge_obj = self.make_merge_obj(builder, 'E-id')
1834
entries = list(merge_obj._entries_lca())
1835
# Only the kind was changed (content)
1836
self.assertEqual([], entries)
1838
def test_interesting_files(self):
1839
# Two files modified, but we should filter one of them
1840
builder = self.get_builder()
1841
builder.build_snapshot('A-id', None,
1842
[('add', (u'', 'a-root-id', 'directory', None)),
1843
('add', (u'a', 'a-id', 'file', 'content\n')),
1844
('add', (u'b', 'b-id', 'file', 'content\n'))])
1845
builder.build_snapshot('B-id', ['A-id'], [])
1846
builder.build_snapshot('C-id', ['A-id'], [])
1847
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1848
[('modify', ('a-id', 'new-content\n')),
1849
('modify', ('b-id', 'new-content\n'))])
1850
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1851
merge_obj = self.make_merge_obj(builder, 'E-id',
1852
interesting_files=['b'])
1853
entries = list(merge_obj._entries_lca())
1854
root_id = 'a-root-id'
1855
self.assertEqual([('b-id', True,
1856
((root_id, [root_id, root_id]), root_id, root_id),
1857
((u'b', [u'b', u'b']), u'b', u'b'),
1858
((False, [False, False]), False, False)),
1861
def test_interesting_file_in_this(self):
1862
# This renamed the file, but it should still match the entry in other
1863
builder = self.get_builder()
1864
builder.build_snapshot('A-id', None,
1865
[('add', (u'', 'a-root-id', 'directory', None)),
1866
('add', (u'a', 'a-id', 'file', 'content\n')),
1867
('add', (u'b', 'b-id', 'file', 'content\n'))])
1868
builder.build_snapshot('B-id', ['A-id'], [])
1869
builder.build_snapshot('C-id', ['A-id'], [])
1870
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1871
[('modify', ('a-id', 'new-content\n')),
1872
('modify', ('b-id', 'new-content\n'))])
1873
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1874
[('rename', ('b', 'c'))])
1875
merge_obj = self.make_merge_obj(builder, 'E-id',
1876
interesting_files=['c'])
1877
entries = list(merge_obj._entries_lca())
1878
root_id = 'a-root-id'
1879
self.assertEqual([('b-id', True,
1880
((root_id, [root_id, root_id]), root_id, root_id),
1881
((u'b', [u'b', u'b']), u'b', u'c'),
1882
((False, [False, False]), False, False)),
1885
def test_interesting_file_in_base(self):
1886
# This renamed the file, but it should still match the entry in BASE
1887
builder = self.get_builder()
1888
builder.build_snapshot('A-id', None,
1889
[('add', (u'', 'a-root-id', 'directory', None)),
1890
('add', (u'a', 'a-id', 'file', 'content\n')),
1891
('add', (u'c', 'c-id', 'file', 'content\n'))])
1892
builder.build_snapshot('B-id', ['A-id'],
1893
[('rename', ('c', 'b'))])
1894
builder.build_snapshot('C-id', ['A-id'],
1895
[('rename', ('c', 'b'))])
1896
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1897
[('modify', ('a-id', 'new-content\n')),
1898
('modify', ('c-id', 'new-content\n'))])
1899
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1900
merge_obj = self.make_merge_obj(builder, 'E-id',
1901
interesting_files=['c'])
1902
entries = list(merge_obj._entries_lca())
1903
root_id = 'a-root-id'
1904
self.assertEqual([('c-id', True,
1905
((root_id, [root_id, root_id]), root_id, root_id),
1906
((u'c', [u'b', u'b']), u'b', u'b'),
1907
((False, [False, False]), False, False)),
1910
def test_interesting_file_in_lca(self):
1911
# This renamed the file, but it should still match the entry in LCA
1912
builder = self.get_builder()
1913
builder.build_snapshot('A-id', None,
1914
[('add', (u'', 'a-root-id', 'directory', None)),
1915
('add', (u'a', 'a-id', 'file', 'content\n')),
1916
('add', (u'b', 'b-id', 'file', 'content\n'))])
1917
builder.build_snapshot('B-id', ['A-id'],
1918
[('rename', ('b', 'c'))])
1919
builder.build_snapshot('C-id', ['A-id'], [])
1920
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1921
[('modify', ('a-id', 'new-content\n')),
1922
('modify', ('b-id', 'new-content\n'))])
1923
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1924
[('rename', ('c', 'b'))])
1925
merge_obj = self.make_merge_obj(builder, 'E-id',
1926
interesting_files=['c'])
1927
entries = list(merge_obj._entries_lca())
1928
root_id = 'a-root-id'
1929
self.assertEqual([('b-id', True,
1930
((root_id, [root_id, root_id]), root_id, root_id),
1931
((u'b', [u'c', u'b']), u'b', u'b'),
1932
((False, [False, False]), False, False)),
1935
def test_interesting_ids(self):
1936
# Two files modified, but we should filter one of them
1937
builder = self.get_builder()
1938
builder.build_snapshot('A-id', None,
1939
[('add', (u'', 'a-root-id', 'directory', None)),
1940
('add', (u'a', 'a-id', 'file', 'content\n')),
1941
('add', (u'b', 'b-id', 'file', 'content\n'))])
1942
builder.build_snapshot('B-id', ['A-id'], [])
1943
builder.build_snapshot('C-id', ['A-id'], [])
1944
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1945
[('modify', ('a-id', 'new-content\n')),
1946
('modify', ('b-id', 'new-content\n'))])
1947
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1948
merge_obj = self.make_merge_obj(builder, 'E-id',
1949
interesting_ids=['b-id'])
1950
entries = list(merge_obj._entries_lca())
1951
root_id = 'a-root-id'
1952
self.assertEqual([('b-id', True,
1953
((root_id, [root_id, root_id]), root_id, root_id),
1954
((u'b', [u'b', u'b']), u'b', u'b'),
1955
((False, [False, False]), False, False)),
1960
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
1962
def get_builder(self):
1963
builder = self.make_branch_builder('path')
1964
builder.start_series()
1965
self.addCleanup(builder.finish_series)
1968
def get_wt_from_builder(self, builder):
1969
"""Get a real WorkingTree from the builder."""
1970
the_branch = builder.get_branch()
1971
wt = the_branch.bzrdir.create_workingtree()
1972
# Note: This is a little bit ugly, but we are holding the branch
1973
# write-locked as part of the build process, and we would like to
1974
# maintain that. So we just force the WT to re-use the same
1976
wt._branch = the_branch
1978
self.addCleanup(wt.unlock)
1981
def do_merge(self, builder, other_revision_id):
1982
wt = self.get_wt_from_builder(builder)
1983
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1984
wt, other_revision_id)
1985
merger.merge_type = _mod_merge.Merge3Merger
1986
return wt, merger.do_merge()
1988
def test_simple_lca(self):
1989
builder = self.get_builder()
1990
builder.build_snapshot('A-id', None,
1991
[('add', (u'', 'a-root-id', 'directory', None)),
1992
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1993
builder.build_snapshot('C-id', ['A-id'], [])
1994
builder.build_snapshot('B-id', ['A-id'], [])
1995
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1996
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1997
[('modify', ('a-id', 'a\nb\nc\nd\ne\nf\n'))])
1998
wt, conflicts = self.do_merge(builder, 'E-id')
1999
self.assertEqual(0, conflicts)
2000
# The merge should have simply update the contents of 'a'
2001
self.assertEqual('a\nb\nc\nd\ne\nf\n', wt.get_file_text('a-id'))
2003
def test_conflict_without_lca(self):
2004
# This test would cause a merge conflict, unless we use the lca trees
2005
# to determine the real ancestry
2008
# B C Path renamed to 'bar' in B
2012
# D E Path at 'bar' in D and E
2014
# F Path at 'baz' in F, which supersedes 'bar' and 'foo'
2015
builder = self.get_builder()
2016
builder.build_snapshot('A-id', None,
2017
[('add', (u'', 'a-root-id', 'directory', None)),
2018
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2019
builder.build_snapshot('C-id', ['A-id'], [])
2020
builder.build_snapshot('B-id', ['A-id'],
2021
[('rename', ('foo', 'bar'))])
2022
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2023
[('rename', ('foo', 'bar'))])
2024
builder.build_snapshot('F-id', ['E-id'],
2025
[('rename', ('bar', 'baz'))])
2026
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2027
wt, conflicts = self.do_merge(builder, 'F-id')
2028
self.assertEqual(0, conflicts)
2029
# The merge should simply recognize that the final rename takes
2031
self.assertEqual('baz', wt.id2path('foo-id'))
2033
def test_other_deletes_lca_renames(self):
2034
# This test would cause a merge conflict, unless we use the lca trees
2035
# to determine the real ancestry
2038
# B C Path renamed to 'bar' in B
2042
# D E Path at 'bar' in D and E
2045
builder = self.get_builder()
2046
builder.build_snapshot('A-id', None,
2047
[('add', (u'', 'a-root-id', 'directory', None)),
2048
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2049
builder.build_snapshot('C-id', ['A-id'], [])
2050
builder.build_snapshot('B-id', ['A-id'],
2051
[('rename', ('foo', 'bar'))])
2052
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2053
[('rename', ('foo', 'bar'))])
2054
builder.build_snapshot('F-id', ['E-id'],
2055
[('unversion', 'foo-id')])
2056
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2057
wt, conflicts = self.do_merge(builder, 'F-id')
2058
self.assertEqual(0, conflicts)
2059
self.assertRaises(errors.NoSuchId, wt.id2path, 'foo-id')
2061
def test_executable_changes(self):
2070
# F Executable bit changed
2071
builder = self.get_builder()
2072
builder.build_snapshot('A-id', None,
2073
[('add', (u'', 'a-root-id', 'directory', None)),
2074
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2075
builder.build_snapshot('C-id', ['A-id'], [])
2076
builder.build_snapshot('B-id', ['A-id'], [])
2077
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2078
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2079
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2080
wt = self.get_wt_from_builder(builder)
2081
tt = transform.TreeTransform(wt)
2083
tt.set_executability(True, tt.trans_id_tree_file_id('foo-id'))
2088
self.assertTrue(wt.is_executable('foo-id'))
2089
wt.commit('F-id', rev_id='F-id')
2090
# Reset to D, so that we can merge F
2091
wt.set_parent_ids(['D-id'])
2092
wt.branch.set_last_revision_info(3, 'D-id')
2094
self.assertFalse(wt.is_executable('foo-id'))
2095
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2096
self.assertEqual(0, conflicts)
2097
self.assertTrue(wt.is_executable('foo-id'))
2099
def test_create_symlink(self):
2100
self.requireFeature(tests.SymlinkFeature)
2109
# F Add a symlink 'foo' => 'bar'
2110
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2111
# have symlink support
2112
builder = self.get_builder()
2113
builder.build_snapshot('A-id', None,
2114
[('add', (u'', 'a-root-id', 'directory', None))])
2115
builder.build_snapshot('C-id', ['A-id'], [])
2116
builder.build_snapshot('B-id', ['A-id'], [])
2117
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2118
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2119
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2120
wt = self.get_wt_from_builder(builder)
2121
os.symlink('bar', 'path/foo')
2122
wt.add(['foo'], ['foo-id'])
2123
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2124
wt.commit('add symlink', rev_id='F-id')
2125
# Reset to D, so that we can merge F
2126
wt.set_parent_ids(['D-id'])
2127
wt.branch.set_last_revision_info(3, 'D-id')
2129
self.assertIs(None, wt.path2id('foo'))
2130
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2131
self.assertEqual(0, conflicts)
2132
self.assertEqual('foo-id', wt.path2id('foo'))
2133
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2135
def test_both_sides_revert(self):
2136
# Both sides of a criss-cross revert the text to the lca
2137
# A base, introduces 'foo'
2139
# B C B modifies 'foo', C modifies 'foo'
2141
# D E D reverts to B, E reverts to C
2142
# This should conflict
2143
# This must be done with a real WorkingTree, because normally their
2144
# inventory contains "None" rather than a real sha1
2145
builder = self.get_builder()
2146
builder.build_snapshot('A-id', None,
2147
[('add', (u'', 'a-root-id', 'directory', None)),
2148
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
2149
builder.build_snapshot('B-id', ['A-id'],
2150
[('modify', ('foo-id', 'B content\n'))])
2151
builder.build_snapshot('C-id', ['A-id'],
2152
[('modify', ('foo-id', 'C content\n'))])
2153
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2154
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2155
wt, conflicts = self.do_merge(builder, 'E-id')
2156
self.assertEqual(1, conflicts)
2157
self.assertEqualDiff('<<<<<<< TREE\n'
2161
'>>>>>>> MERGE-SOURCE\n',
2162
wt.get_file_text('foo-id'))
2164
def test_modified_symlink(self):
2165
self.requireFeature(tests.SymlinkFeature)
2166
# A Create symlink foo => bar
2168
# B C B relinks foo => baz
2172
# D E D & E have foo => baz
2174
# F F changes it to bing
2176
# Merging D & F should result in F cleanly overriding D, because D's
2177
# value actually comes from B
2179
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2180
# have symlink support
2181
wt = self.make_branch_and_tree('path')
2183
self.addCleanup(wt.unlock)
2184
os.symlink('bar', 'path/foo')
2185
wt.add(['foo'], ['foo-id'])
2186
wt.commit('add symlink', rev_id='A-id')
2187
os.remove('path/foo')
2188
os.symlink('baz', 'path/foo')
2189
wt.commit('foo => baz', rev_id='B-id')
2190
wt.set_last_revision('A-id')
2191
wt.branch.set_last_revision_info(1, 'A-id')
2193
wt.commit('C', rev_id='C-id')
2194
wt.merge_from_branch(wt.branch, 'B-id')
2195
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2196
wt.commit('E merges C & B', rev_id='E-id')
2197
os.remove('path/foo')
2198
os.symlink('bing', 'path/foo')
2199
wt.commit('F foo => bing', rev_id='F-id')
2200
wt.set_last_revision('B-id')
2201
wt.branch.set_last_revision_info(2, 'B-id')
2203
wt.merge_from_branch(wt.branch, 'C-id')
2204
wt.commit('D merges B & C', rev_id='D-id')
2205
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2206
self.assertEqual(0, conflicts)
2207
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2209
def test_renamed_symlink(self):
2210
self.requireFeature(tests.SymlinkFeature)
2211
# A Create symlink foo => bar
2213
# B C B renames foo => barry
2217
# D E D & E have barry
2219
# F F renames barry to blah
2221
# Merging D & F should result in F cleanly overriding D, because D's
2222
# value actually comes from B
2224
wt = self.make_branch_and_tree('path')
2226
self.addCleanup(wt.unlock)
2227
os.symlink('bar', 'path/foo')
2228
wt.add(['foo'], ['foo-id'])
2229
wt.commit('A add symlink', rev_id='A-id')
2230
wt.rename_one('foo', 'barry')
2231
wt.commit('B foo => barry', rev_id='B-id')
2232
wt.set_last_revision('A-id')
2233
wt.branch.set_last_revision_info(1, 'A-id')
2235
wt.commit('C', rev_id='C-id')
2236
wt.merge_from_branch(wt.branch, 'B-id')
2237
self.assertEqual('barry', wt.id2path('foo-id'))
2238
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2239
wt.commit('E merges C & B', rev_id='E-id')
2240
wt.rename_one('barry', 'blah')
2241
wt.commit('F barry => blah', rev_id='F-id')
2242
wt.set_last_revision('B-id')
2243
wt.branch.set_last_revision_info(2, 'B-id')
2245
wt.merge_from_branch(wt.branch, 'C-id')
2246
wt.commit('D merges B & C', rev_id='D-id')
2247
self.assertEqual('barry', wt.id2path('foo-id'))
2248
# Check the output of the Merger object directly
2249
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2251
merger.merge_type = _mod_merge.Merge3Merger
2252
merge_obj = merger.make_merger()
2253
root_id = wt.path2id('')
2254
entries = list(merge_obj._entries_lca())
2255
# No content change, just a path change
2256
self.assertEqual([('foo-id', False,
2257
((root_id, [root_id, root_id]), root_id, root_id),
2258
((u'foo', [u'barry', u'foo']), u'blah', u'barry'),
2259
((False, [False, False]), False, False)),
2261
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2262
self.assertEqual(0, conflicts)
2263
self.assertEqual('blah', wt.id2path('foo-id'))
2265
def test_symlink_no_content_change(self):
2266
self.requireFeature(tests.SymlinkFeature)
2267
# A Create symlink foo => bar
2269
# B C B relinks foo => baz
2273
# D E D & E have foo => baz
2275
# F F has foo => bing
2277
# Merging E into F should not cause a conflict, because E doesn't have
2278
# a content change relative to the LCAs (it does relative to A)
2279
wt = self.make_branch_and_tree('path')
2281
self.addCleanup(wt.unlock)
2282
os.symlink('bar', 'path/foo')
2283
wt.add(['foo'], ['foo-id'])
2284
wt.commit('add symlink', rev_id='A-id')
2285
os.remove('path/foo')
2286
os.symlink('baz', 'path/foo')
2287
wt.commit('foo => baz', rev_id='B-id')
2288
wt.set_last_revision('A-id')
2289
wt.branch.set_last_revision_info(1, 'A-id')
2291
wt.commit('C', rev_id='C-id')
2292
wt.merge_from_branch(wt.branch, 'B-id')
2293
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2294
wt.commit('E merges C & B', rev_id='E-id')
2295
wt.set_last_revision('B-id')
2296
wt.branch.set_last_revision_info(2, 'B-id')
2298
wt.merge_from_branch(wt.branch, 'C-id')
2299
wt.commit('D merges B & C', rev_id='D-id')
2300
os.remove('path/foo')
2301
os.symlink('bing', 'path/foo')
2302
wt.commit('F foo => bing', rev_id='F-id')
2304
# Check the output of the Merger object directly
2305
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2307
merger.merge_type = _mod_merge.Merge3Merger
2308
merge_obj = merger.make_merger()
2309
# Nothing interesting happened in OTHER relative to BASE
2310
self.assertEqual([], list(merge_obj._entries_lca()))
2311
# Now do a real merge, just to test the rest of the stack
2312
conflicts = wt.merge_from_branch(wt.branch, to_revision='E-id')
2313
self.assertEqual(0, conflicts)
2314
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2316
def test_symlink_this_changed_kind(self):
2317
self.requireFeature(tests.SymlinkFeature)
2320
# B C B creates symlink foo => bar
2324
# D E D changes foo into a file, E has foo => bing
2326
# Mostly, this is trying to test that we don't try to os.readlink() on
2327
# a file, or when there is nothing there
2328
wt = self.make_branch_and_tree('path')
2330
self.addCleanup(wt.unlock)
2331
wt.commit('base', rev_id='A-id')
2332
os.symlink('bar', 'path/foo')
2333
wt.add(['foo'], ['foo-id'])
2334
wt.commit('add symlink foo => bar', rev_id='B-id')
2335
wt.set_last_revision('A-id')
2336
wt.branch.set_last_revision_info(1, 'A-id')
2338
wt.commit('C', rev_id='C-id')
2339
wt.merge_from_branch(wt.branch, 'B-id')
2340
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2341
os.remove('path/foo')
2342
# We have to change the link in E, or it won't try to do a comparison
2343
os.symlink('bing', 'path/foo')
2344
wt.commit('E merges C & B, overrides to bing', rev_id='E-id')
2345
wt.set_last_revision('B-id')
2346
wt.branch.set_last_revision_info(2, 'B-id')
2348
wt.merge_from_branch(wt.branch, 'C-id')
2349
os.remove('path/foo')
2350
self.build_tree_contents([('path/foo', 'file content\n')])
2351
# XXX: workaround, WT doesn't detect kind changes unless you do
2353
list(wt.iter_changes(wt.basis_tree()))
2354
wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2356
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2358
merger.merge_type = _mod_merge.Merge3Merger
2359
merge_obj = merger.make_merger()
2360
entries = list(merge_obj._entries_lca())
2361
root_id = wt.path2id('')
2362
self.assertEqual([('foo-id', True,
2363
((None, [root_id, None]), root_id, root_id),
2364
((None, [u'foo', None]), u'foo', u'foo'),
2365
((None, [False, None]), False, False)),
2368
def test_symlink_all_wt(self):
2369
"""Check behavior if all trees are Working Trees."""
2370
self.requireFeature(tests.SymlinkFeature)
2371
# The big issue is that entry.symlink_target is None for WorkingTrees.
2372
# So we need to make sure we handle that case correctly.
2375
# B C B relinks foo => baz
2377
# D E D & E have foo => baz
2379
# F F changes it to bing
2380
# Merging D & F should result in F cleanly overriding D, because D's
2381
# value actually comes from B
2383
wt = self.make_branch_and_tree('path')
2385
self.addCleanup(wt.unlock)
2386
os.symlink('bar', 'path/foo')
2387
wt.add(['foo'], ['foo-id'])
2388
wt.commit('add symlink', rev_id='A-id')
2389
os.remove('path/foo')
2390
os.symlink('baz', 'path/foo')
2391
wt.commit('foo => baz', rev_id='B-id')
2392
wt.set_last_revision('A-id')
2393
wt.branch.set_last_revision_info(1, 'A-id')
2395
wt.commit('C', rev_id='C-id')
2396
wt.merge_from_branch(wt.branch, 'B-id')
2397
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2398
wt.commit('E merges C & B', rev_id='E-id')
2399
os.remove('path/foo')
2400
os.symlink('bing', 'path/foo')
2401
wt.commit('F foo => bing', rev_id='F-id')
2402
wt.set_last_revision('B-id')
2403
wt.branch.set_last_revision_info(2, 'B-id')
2405
wt.merge_from_branch(wt.branch, 'C-id')
2406
wt.commit('D merges B & C', rev_id='D-id')
2407
wt_base = wt.bzrdir.sprout('base', 'A-id').open_workingtree()
2409
self.addCleanup(wt_base.unlock)
2410
wt_lca1 = wt.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2412
self.addCleanup(wt_lca1.unlock)
2413
wt_lca2 = wt.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2415
self.addCleanup(wt_lca2.unlock)
2416
wt_other = wt.bzrdir.sprout('other', 'F-id').open_workingtree()
2417
wt_other.lock_read()
2418
self.addCleanup(wt_other.unlock)
2419
merge_obj = _mod_merge.Merge3Merger(wt, wt, wt_base,
2420
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2421
entries = list(merge_obj._entries_lca())
2422
root_id = wt.path2id('')
2423
self.assertEqual([('foo-id', True,
2424
((root_id, [root_id, root_id]), root_id, root_id),
2425
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2426
((False, [False, False]), False, False)),
2429
def test_other_reverted_path_to_base(self):
2432
# B C Path at 'bar' in B
2439
builder = self.get_builder()
2440
builder.build_snapshot('A-id', None,
2441
[('add', (u'', 'a-root-id', 'directory', None)),
2442
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2443
builder.build_snapshot('C-id', ['A-id'], [])
2444
builder.build_snapshot('B-id', ['A-id'],
2445
[('rename', ('foo', 'bar'))])
2446
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2447
[('rename', ('foo', 'bar'))]) # merge the rename
2448
builder.build_snapshot('F-id', ['E-id'],
2449
[('rename', ('bar', 'foo'))]) # Rename back to BASE
2450
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2451
wt, conflicts = self.do_merge(builder, 'F-id')
2452
self.assertEqual(0, conflicts)
2453
self.assertEqual('foo', wt.id2path('foo-id'))
2455
def test_other_reverted_content_to_base(self):
2456
builder = self.get_builder()
2457
builder.build_snapshot('A-id', None,
2458
[('add', (u'', 'a-root-id', 'directory', None)),
2459
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2460
builder.build_snapshot('C-id', ['A-id'], [])
2461
builder.build_snapshot('B-id', ['A-id'],
2462
[('modify', ('foo-id', 'B content\n'))])
2463
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2464
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2465
builder.build_snapshot('F-id', ['E-id'],
2466
[('modify', ('foo-id', 'base content\n'))]) # Revert back to BASE
2467
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2468
wt, conflicts = self.do_merge(builder, 'F-id')
2469
self.assertEqual(0, conflicts)
2470
# TODO: We need to use the per-file graph to properly select a BASE
2471
# before this will work. Or at least use the LCA trees to find
2472
# the appropriate content base. (which is B, not A).
2473
self.assertEqual('base content\n', wt.get_file_text('foo-id'))
2475
def test_other_modified_content(self):
2476
builder = self.get_builder()
2477
builder.build_snapshot('A-id', None,
2478
[('add', (u'', 'a-root-id', 'directory', None)),
2479
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2480
builder.build_snapshot('C-id', ['A-id'], [])
2481
builder.build_snapshot('B-id', ['A-id'],
2482
[('modify', ('foo-id', 'B content\n'))])
2483
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2484
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2485
builder.build_snapshot('F-id', ['E-id'],
2486
[('modify', ('foo-id', 'F content\n'))]) # Override B content
2487
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2488
wt, conflicts = self.do_merge(builder, 'F-id')
2489
self.assertEqual(0, conflicts)
2490
self.assertEqual('F content\n', wt.get_file_text('foo-id'))
2492
def test_all_wt(self):
2493
"""Check behavior if all trees are Working Trees."""
2494
# The big issue is that entry.revision is None for WorkingTrees. (as is
2495
# entry.text_sha1, etc. So we need to make sure we handle that case
2497
# A Content of 'foo', path of 'a'
2499
# B C B modifies content, C renames 'a' => 'b'
2501
# D E E updates content, renames 'b' => 'c'
2502
builder = self.get_builder()
2503
builder.build_snapshot('A-id', None,
2504
[('add', (u'', 'a-root-id', 'directory', None)),
2505
('add', (u'a', 'a-id', 'file', 'base content\n')),
2506
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2507
builder.build_snapshot('B-id', ['A-id'],
2508
[('modify', ('foo-id', 'B content\n'))])
2509
builder.build_snapshot('C-id', ['A-id'],
2510
[('rename', ('a', 'b'))])
2511
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2512
[('rename', ('b', 'c')),
2513
('modify', ('foo-id', 'E content\n'))])
2514
builder.build_snapshot('D-id', ['B-id', 'C-id'],
2515
[('rename', ('a', 'b'))]) # merged change
2516
wt_this = self.get_wt_from_builder(builder)
2517
wt_base = wt_this.bzrdir.sprout('base', 'A-id').open_workingtree()
2519
self.addCleanup(wt_base.unlock)
2520
wt_lca1 = wt_this.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2522
self.addCleanup(wt_lca1.unlock)
2523
wt_lca2 = wt_this.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2525
self.addCleanup(wt_lca2.unlock)
2526
wt_other = wt_this.bzrdir.sprout('other', 'E-id').open_workingtree()
2527
wt_other.lock_read()
2528
self.addCleanup(wt_other.unlock)
2529
merge_obj = _mod_merge.Merge3Merger(wt_this, wt_this, wt_base,
2530
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2531
entries = list(merge_obj._entries_lca())
2532
root_id = 'a-root-id'
2533
self.assertEqual([('a-id', False,
2534
((root_id, [root_id, root_id]), root_id, root_id),
2535
((u'a', [u'a', u'b']), u'c', u'b'),
2536
((False, [False, False]), False, False)),
2538
((root_id, [root_id, root_id]), root_id, root_id),
2539
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2540
((False, [False, False]), False, False)),
2543
def test_nested_tree_unmodified(self):
2544
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2546
wt = self.make_branch_and_tree('tree',
2547
format='dirstate-with-subtree')
2549
self.addCleanup(wt.unlock)
2550
sub_tree = self.make_branch_and_tree('tree/sub-tree',
2551
format='dirstate-with-subtree')
2552
wt.set_root_id('a-root-id')
2553
sub_tree.set_root_id('sub-tree-root')
2554
self.build_tree_contents([('tree/sub-tree/file', 'text1')])
2555
sub_tree.add('file')
2556
sub_tree.commit('foo', rev_id='sub-A-id')
2557
wt.add_reference(sub_tree)
2558
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2559
# Now create a criss-cross merge in the parent, without modifying the
2561
wt.commit('B', rev_id='B-id', recursive=None)
2562
wt.set_last_revision('A-id')
2563
wt.branch.set_last_revision_info(1, 'A-id')
2564
wt.commit('C', rev_id='C-id', recursive=None)
2565
wt.merge_from_branch(wt.branch, to_revision='B-id')
2566
wt.commit('E', rev_id='E-id', recursive=None)
2567
wt.set_parent_ids(['B-id', 'C-id'])
2568
wt.branch.set_last_revision_info(2, 'B-id')
2569
wt.commit('D', rev_id='D-id', recursive=None)
2571
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2573
merger.merge_type = _mod_merge.Merge3Merger
2574
merge_obj = merger.make_merger()
2575
entries = list(merge_obj._entries_lca())
2576
self.assertEqual([], entries)
2578
def test_nested_tree_subtree_modified(self):
2579
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2581
wt = self.make_branch_and_tree('tree',
2582
format='dirstate-with-subtree')
2584
self.addCleanup(wt.unlock)
2585
sub_tree = self.make_branch_and_tree('tree/sub',
2586
format='dirstate-with-subtree')
2587
wt.set_root_id('a-root-id')
2588
sub_tree.set_root_id('sub-tree-root')
2589
self.build_tree_contents([('tree/sub/file', 'text1')])
2590
sub_tree.add('file')
2591
sub_tree.commit('foo', rev_id='sub-A-id')
2592
wt.add_reference(sub_tree)
2593
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2594
# Now create a criss-cross merge in the parent, without modifying the
2596
wt.commit('B', rev_id='B-id', recursive=None)
2597
wt.set_last_revision('A-id')
2598
wt.branch.set_last_revision_info(1, 'A-id')
2599
wt.commit('C', rev_id='C-id', recursive=None)
2600
wt.merge_from_branch(wt.branch, to_revision='B-id')
2601
self.build_tree_contents([('tree/sub/file', 'text2')])
2602
sub_tree.commit('modify contents', rev_id='sub-B-id')
2603
wt.commit('E', rev_id='E-id', recursive=None)
2604
wt.set_parent_ids(['B-id', 'C-id'])
2605
wt.branch.set_last_revision_info(2, 'B-id')
2606
wt.commit('D', rev_id='D-id', recursive=None)
2608
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2610
merger.merge_type = _mod_merge.Merge3Merger
2611
merge_obj = merger.make_merger()
2612
entries = list(merge_obj._entries_lca())
2613
# Nothing interesting about this sub-tree, because content changes are
2614
# computed at a higher level
2615
self.assertEqual([], entries)
2617
def test_nested_tree_subtree_renamed(self):
2618
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2620
wt = self.make_branch_and_tree('tree',
2621
format='dirstate-with-subtree')
2623
self.addCleanup(wt.unlock)
2624
sub_tree = self.make_branch_and_tree('tree/sub',
2625
format='dirstate-with-subtree')
2626
wt.set_root_id('a-root-id')
2627
sub_tree.set_root_id('sub-tree-root')
2628
self.build_tree_contents([('tree/sub/file', 'text1')])
2629
sub_tree.add('file')
2630
sub_tree.commit('foo', rev_id='sub-A-id')
2631
wt.add_reference(sub_tree)
2632
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2633
# Now create a criss-cross merge in the parent, without modifying the
2635
wt.commit('B', rev_id='B-id', recursive=None)
2636
wt.set_last_revision('A-id')
2637
wt.branch.set_last_revision_info(1, 'A-id')
2638
wt.commit('C', rev_id='C-id', recursive=None)
2639
wt.merge_from_branch(wt.branch, to_revision='B-id')
2640
wt.rename_one('sub', 'alt_sub')
2641
wt.commit('E', rev_id='E-id', recursive=None)
2642
wt.set_last_revision('B-id')
2644
wt.set_parent_ids(['B-id', 'C-id'])
2645
wt.branch.set_last_revision_info(2, 'B-id')
2646
wt.commit('D', rev_id='D-id', recursive=None)
2648
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2650
merger.merge_type = _mod_merge.Merge3Merger
2651
merge_obj = merger.make_merger()
2652
entries = list(merge_obj._entries_lca())
2653
root_id = 'a-root-id'
2654
self.assertEqual([('sub-tree-root', False,
2655
((root_id, [root_id, root_id]), root_id, root_id),
2656
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2657
((False, [False, False]), False, False)),
2660
def test_nested_tree_subtree_renamed_and_modified(self):
2661
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2663
wt = self.make_branch_and_tree('tree',
2664
format='dirstate-with-subtree')
2666
self.addCleanup(wt.unlock)
2667
sub_tree = self.make_branch_and_tree('tree/sub',
2668
format='dirstate-with-subtree')
2669
wt.set_root_id('a-root-id')
2670
sub_tree.set_root_id('sub-tree-root')
2671
self.build_tree_contents([('tree/sub/file', 'text1')])
2672
sub_tree.add('file')
2673
sub_tree.commit('foo', rev_id='sub-A-id')
2674
wt.add_reference(sub_tree)
2675
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2676
# Now create a criss-cross merge in the parent, without modifying the
2678
wt.commit('B', rev_id='B-id', recursive=None)
2679
wt.set_last_revision('A-id')
2680
wt.branch.set_last_revision_info(1, 'A-id')
2681
wt.commit('C', rev_id='C-id', recursive=None)
2682
wt.merge_from_branch(wt.branch, to_revision='B-id')
2683
self.build_tree_contents([('tree/sub/file', 'text2')])
2684
sub_tree.commit('modify contents', rev_id='sub-B-id')
2685
wt.rename_one('sub', 'alt_sub')
2686
wt.commit('E', rev_id='E-id', recursive=None)
2687
wt.set_last_revision('B-id')
2689
wt.set_parent_ids(['B-id', 'C-id'])
2690
wt.branch.set_last_revision_info(2, 'B-id')
2691
wt.commit('D', rev_id='D-id', recursive=None)
2693
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2695
merger.merge_type = _mod_merge.Merge3Merger
2696
merge_obj = merger.make_merger()
2697
entries = list(merge_obj._entries_lca())
2698
root_id = 'a-root-id'
2699
self.assertEqual([('sub-tree-root', False,
2700
((root_id, [root_id, root_id]), root_id, root_id),
2701
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2702
((False, [False, False]), False, False)),
2706
class TestLCAMultiWay(tests.TestCase):
2708
def assertLCAMultiWay(self, expected, base, lcas, other, this,
2709
allow_overriding_lca=True):
2710
self.assertEqual(expected, _mod_merge.Merge3Merger._lca_multi_way(
2711
(base, lcas), other, this,
2712
allow_overriding_lca=allow_overriding_lca))
2714
def test_other_equal_equal_lcas(self):
2715
"""Test when OTHER=LCA and all LCAs are identical."""
2716
self.assertLCAMultiWay('this',
2717
'bval', ['bval', 'bval'], 'bval', 'bval')
2718
self.assertLCAMultiWay('this',
2719
'bval', ['lcaval', 'lcaval'], 'lcaval', 'bval')
2720
self.assertLCAMultiWay('this',
2721
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'bval')
2722
self.assertLCAMultiWay('this',
2723
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'tval')
2724
self.assertLCAMultiWay('this',
2725
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', None)
2727
def test_other_equal_this(self):
2728
"""Test when other and this are identical."""
2729
self.assertLCAMultiWay('this',
2730
'bval', ['bval', 'bval'], 'oval', 'oval')
2731
self.assertLCAMultiWay('this',
2732
'bval', ['lcaval', 'lcaval'], 'oval', 'oval')
2733
self.assertLCAMultiWay('this',
2734
'bval', ['cval', 'dval'], 'oval', 'oval')
2735
self.assertLCAMultiWay('this',
2736
'bval', [None, 'lcaval'], 'oval', 'oval')
2737
self.assertLCAMultiWay('this',
2738
None, [None, 'lcaval'], 'oval', 'oval')
2739
self.assertLCAMultiWay('this',
2740
None, ['lcaval', 'lcaval'], 'oval', 'oval')
2741
self.assertLCAMultiWay('this',
2742
None, ['cval', 'dval'], 'oval', 'oval')
2743
self.assertLCAMultiWay('this',
2744
None, ['cval', 'dval'], None, None)
2745
self.assertLCAMultiWay('this',
2746
None, ['cval', 'dval', 'eval', 'fval'], 'oval', 'oval')
2748
def test_no_lcas(self):
2749
self.assertLCAMultiWay('this',
2750
'bval', [], 'bval', 'tval')
2751
self.assertLCAMultiWay('other',
2752
'bval', [], 'oval', 'bval')
2753
self.assertLCAMultiWay('conflict',
2754
'bval', [], 'oval', 'tval')
2755
self.assertLCAMultiWay('this',
2756
'bval', [], 'oval', 'oval')
2758
def test_lca_supersedes_other_lca(self):
2759
"""If one lca == base, the other lca takes precedence"""
2760
self.assertLCAMultiWay('this',
2761
'bval', ['bval', 'lcaval'], 'lcaval', 'tval')
2762
self.assertLCAMultiWay('this',
2763
'bval', ['bval', 'lcaval'], 'lcaval', 'bval')
2764
# This is actually considered a 'revert' because the 'lcaval' in LCAS
2765
# supersedes the BASE val (in the other LCA) but then OTHER reverts it
2767
self.assertLCAMultiWay('other',
2768
'bval', ['bval', 'lcaval'], 'bval', 'lcaval')
2769
self.assertLCAMultiWay('conflict',
2770
'bval', ['bval', 'lcaval'], 'bval', 'tval')
2772
def test_other_and_this_pick_different_lca(self):
2773
# OTHER and THIS resolve the lca conflict in different ways
2774
self.assertLCAMultiWay('conflict',
2775
'bval', ['lca1val', 'lca2val'], 'lca1val', 'lca2val')
2776
self.assertLCAMultiWay('conflict',
2777
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'lca2val')
2778
self.assertLCAMultiWay('conflict',
2779
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'lca2val')
2781
def test_other_in_lca(self):
2782
# OTHER takes a value of one of the LCAs, THIS takes a new value, which
2783
# theoretically supersedes both LCA values and 'wins'
2784
self.assertLCAMultiWay('this',
2785
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval')
2786
self.assertLCAMultiWay('this',
2787
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval')
2788
self.assertLCAMultiWay('conflict',
2789
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval',
2790
allow_overriding_lca=False)
2791
self.assertLCAMultiWay('conflict',
2792
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval',
2793
allow_overriding_lca=False)
2794
# THIS reverted back to BASE, but that is an explicit supersede of all
2796
self.assertLCAMultiWay('this',
2797
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval')
2798
self.assertLCAMultiWay('this',
2799
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval')
2800
self.assertLCAMultiWay('conflict',
2801
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval',
2802
allow_overriding_lca=False)
2803
self.assertLCAMultiWay('conflict',
2804
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval',
2805
allow_overriding_lca=False)
2807
def test_this_in_lca(self):
2808
# THIS takes a value of one of the LCAs, OTHER takes a new value, which
2809
# theoretically supersedes both LCA values and 'wins'
2810
self.assertLCAMultiWay('other',
2811
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val')
2812
self.assertLCAMultiWay('other',
2813
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val')
2814
self.assertLCAMultiWay('conflict',
2815
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val',
2816
allow_overriding_lca=False)
2817
self.assertLCAMultiWay('conflict',
2818
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val',
2819
allow_overriding_lca=False)
2820
# OTHER reverted back to BASE, but that is an explicit supersede of all
2822
self.assertLCAMultiWay('other',
2823
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val')
2824
self.assertLCAMultiWay('conflict',
2825
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val',
2826
allow_overriding_lca=False)
2828
def test_all_differ(self):
2829
self.assertLCAMultiWay('conflict',
2830
'bval', ['lca1val', 'lca2val'], 'oval', 'tval')
2831
self.assertLCAMultiWay('conflict',
2832
'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2833
self.assertLCAMultiWay('conflict',
2834
'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')