37
37
from bzrlib.merge import transform_tree, merge_inner, _PlanMerge
38
38
from bzrlib.osutils import basename, pathjoin, file_kind
39
39
from bzrlib.tests import (
41
40
TestCaseWithMemoryTransport,
42
41
TestCaseWithTransport,
91
90
os.chdir('branch2')
92
91
self.run_bzr('merge ../branch1/baz', retcode=3)
93
92
self.run_bzr('merge ../branch1/foo')
94
self.assertPathExists('foo')
95
self.assertPathDoesNotExist('bar')
93
self.failUnlessExists('foo')
94
self.failIfExists('bar')
96
95
wt2 = WorkingTree.open('.') # opens branch2
97
96
self.assertEqual([tip], wt2.get_parent_ids())
125
def test_merge_into_null_tree(self):
126
wt = self.make_branch_and_tree('tree')
127
null_tree = wt.basis_tree()
128
self.build_tree(['tree/file'])
130
wt.commit('tree with root')
131
merger = _mod_merge.Merge3Merger(null_tree, null_tree, null_tree, wt,
132
this_branch=wt.branch,
134
with merger.make_preview_transform() as tt:
135
self.assertEqual([], tt.find_conflicts())
136
preview = tt.get_preview_tree()
137
self.assertEqual(wt.get_root_id(), preview.get_root_id())
139
def test_merge_unrelated_retains_root(self):
140
wt = self.make_branch_and_tree('tree')
141
other_tree = self.make_branch_and_tree('other')
142
self.addCleanup(other_tree.lock_read().unlock)
143
merger = _mod_merge.Merge3Merger(wt, wt, wt.basis_tree(), other_tree,
144
this_branch=wt.branch,
146
with transform.TransformPreview(wt) as merger.tt:
147
merger._compute_transform()
148
new_root_id = merger.tt.final_file_id(merger.tt.root)
149
self.assertEqual(wt.get_root_id(), new_root_id)
151
124
def test_create_rename(self):
152
125
"""Rename an inventory entry while creating the file"""
153
126
tree =self.make_branch_and_tree('.')
185
158
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
186
159
this_tree=tree_b, ignore_zero=True)
187
self.assertTrue('All changes applied successfully.\n' not in
160
self.failUnless('All changes applied successfully.\n' not in
190
163
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
191
164
this_tree=tree_b, ignore_zero=False)
192
self.assertTrue('All changes applied successfully.\n' in self.get_log())
165
self.failUnless('All changes applied successfully.\n' in self.get_log())
194
167
def test_merge_inner_conflicts(self):
195
168
tree_a = self.make_branch_and_tree('a')
414
387
'>>>>>>> MERGE-SOURCE\n',
417
def test_merge_reverse_revision_range(self):
418
tree = self.make_branch_and_tree(".")
420
self.addCleanup(tree.unlock)
421
self.build_tree(['a'])
423
first_rev = tree.commit("added a")
424
merger = _mod_merge.Merger.from_revision_ids(None, tree,
425
_mod_revision.NULL_REVISION,
427
merger.merge_type = _mod_merge.Merge3Merger
428
merger.interesting_files = 'a'
429
conflict_count = merger.do_merge()
430
self.assertEqual(0, conflict_count)
432
self.assertPathDoesNotExist("a")
434
self.assertPathExists("a")
436
390
def test_make_merger(self):
437
391
this_tree = self.make_branch_and_tree('this')
438
392
this_tree.commit('rev1', rev_id='rev1')
503
457
tree_file.close()
505
def test_merge_require_tree_root(self):
506
tree = self.make_branch_and_tree(".")
508
self.addCleanup(tree.unlock)
509
self.build_tree(['a'])
511
first_rev = tree.commit("added a")
512
old_root_id = tree.get_root_id()
513
merger = _mod_merge.Merger.from_revision_ids(None, tree,
514
_mod_revision.NULL_REVISION,
516
merger.merge_type = _mod_merge.Merge3Merger
517
conflict_count = merger.do_merge()
518
self.assertEqual(0, conflict_count)
519
self.assertEquals(set([old_root_id]), tree.all_file_ids())
520
tree.set_parent_ids([])
522
459
def test_merge_add_into_deleted_root(self):
523
460
# Yes, people actually do this. And report bugs if it breaks.
524
461
source = self.make_branch_and_tree('source', format='rich-root-pack')
1333
1270
self.assertEqual(['B-id', 'C-id', 'F-id'],
1334
1271
[t.get_revision_id() for t in merger._lca_trees])
1336
def test_find_base_new_root_criss_cross(self):
1343
builder = self.get_builder()
1344
builder.build_snapshot('A-id', None,
1345
[('add', ('', None, 'directory', None))])
1346
builder.build_snapshot('B-id', [],
1347
[('add', ('', None, 'directory', None))])
1348
builder.build_snapshot('D-id', ['A-id', 'B-id'], [])
1349
builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
1350
merger = self.make_Merger(builder, 'D-id')
1351
self.assertEqual('A-id', merger.base_rev_id)
1352
self.assertTrue(merger._is_criss_cross)
1353
self.assertEqual(['A-id', 'B-id'], [t.get_revision_id()
1354
for t in merger._lca_trees])
1356
1273
def test_no_criss_cross_passed_to_merge_type(self):
1357
1274
class LCATreesMerger(LoggingMerger):
1358
1275
supports_lca_trees = True
1890
1807
builder.build_snapshot('C-id', ['A-id'], [])
1891
1808
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1892
1809
[('unversion', 'a-id'),
1894
1810
('add', (u'a', 'a-id', 'directory', None))])
1895
1811
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1896
1812
merge_obj = self.make_merge_obj(builder, 'E-id')
1914
1830
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1915
1831
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1916
1832
[('unversion', 'a-id'),
1918
1833
('add', (u'a', 'a-id', 'directory', None))])
1919
1834
merge_obj = self.make_merge_obj(builder, 'E-id')
1920
1835
entries = list(merge_obj._entries_lca())
2248
2163
wt.get_file_text('foo-id'))
2250
2165
def test_modified_symlink(self):
2251
self.requireFeature(features.SymlinkFeature)
2166
self.requireFeature(tests.SymlinkFeature)
2252
2167
# A Create symlink foo => bar
2254
2169
# B C B relinks foo => baz
2293
2208
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2295
2210
def test_renamed_symlink(self):
2296
self.requireFeature(features.SymlinkFeature)
2211
self.requireFeature(tests.SymlinkFeature)
2297
2212
# A Create symlink foo => bar
2299
2214
# B C B renames foo => barry
2349
2264
self.assertEqual('blah', wt.id2path('foo-id'))
2351
2266
def test_symlink_no_content_change(self):
2352
self.requireFeature(features.SymlinkFeature)
2267
self.requireFeature(tests.SymlinkFeature)
2353
2268
# A Create symlink foo => bar
2355
2270
# B C B relinks foo => baz
2400
2315
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2402
2317
def test_symlink_this_changed_kind(self):
2403
self.requireFeature(features.SymlinkFeature)
2318
self.requireFeature(tests.SymlinkFeature)
2406
2321
# B C B creates symlink foo => bar
2454
2369
def test_symlink_all_wt(self):
2455
2370
"""Check behavior if all trees are Working Trees."""
2456
self.requireFeature(features.SymlinkFeature)
2371
self.requireFeature(tests.SymlinkFeature)
2457
2372
# The big issue is that entry.symlink_target is None for WorkingTrees.
2458
2373
# So we need to make sure we handle that case correctly.
2929
2844
def get_merger_factory(self):
2930
2845
# Allows the inner methods to access the test attributes
2933
2848
class FooMerger(_mod_merge.ConfigurableFileMerger):
2934
2849
name_prefix = "foo"
2935
2850
default_files = ['bar']
2937
2852
def merge_text(self, params):
2938
calls.append('merge_text')
2853
test.calls.append('merge_text')
2939
2854
return ('not_applicable', None)
2941
2856
def factory(merger):