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 (
40
41
TestCaseWithMemoryTransport,
41
42
TestCaseWithTransport,
90
91
os.chdir('branch2')
91
92
self.run_bzr('merge ../branch1/baz', retcode=3)
92
93
self.run_bzr('merge ../branch1/foo')
93
self.failUnlessExists('foo')
94
self.failIfExists('bar')
94
self.assertPathExists('foo')
95
self.assertPathDoesNotExist('bar')
95
96
wt2 = WorkingTree.open('.') # opens branch2
96
97
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)
124
151
def test_create_rename(self):
125
152
"""Rename an inventory entry while creating the file"""
126
153
tree =self.make_branch_and_tree('.')
158
185
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
159
186
this_tree=tree_b, ignore_zero=True)
160
self.failUnless('All changes applied successfully.\n' not in
187
self.assertTrue('All changes applied successfully.\n' not in
163
190
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
164
191
this_tree=tree_b, ignore_zero=False)
165
self.failUnless('All changes applied successfully.\n' in self.get_log())
192
self.assertTrue('All changes applied successfully.\n' in self.get_log())
167
194
def test_merge_inner_conflicts(self):
168
195
tree_a = self.make_branch_and_tree('a')
387
414
'>>>>>>> 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
tree.commit("added a")
424
first_rev = tree.branch.revision_history()[0]
425
merger = _mod_merge.Merger.from_revision_ids(None, tree,
426
_mod_revision.NULL_REVISION,
428
merger.merge_type = _mod_merge.Merge3Merger
429
merger.interesting_files = 'a'
430
conflict_count = merger.do_merge()
431
self.assertEqual(0, conflict_count)
433
self.assertPathDoesNotExist("a")
435
self.assertPathExists("a")
390
437
def test_make_merger(self):
391
438
this_tree = self.make_branch_and_tree('this')
392
439
this_tree.commit('rev1', rev_id='rev1')
457
504
tree_file.close()
506
def test_merge_require_tree_root(self):
507
tree = self.make_branch_and_tree(".")
509
self.addCleanup(tree.unlock)
510
self.build_tree(['a'])
512
tree.commit("added a")
513
old_root_id = tree.get_root_id()
514
first_rev = tree.branch.revision_history()[0]
515
merger = _mod_merge.Merger.from_revision_ids(None, tree,
516
_mod_revision.NULL_REVISION,
518
merger.merge_type = _mod_merge.Merge3Merger
519
conflict_count = merger.do_merge()
520
self.assertEqual(0, conflict_count)
521
self.assertEquals(set([old_root_id]), tree.all_file_ids())
522
tree.set_parent_ids([])
459
524
def test_merge_add_into_deleted_root(self):
460
525
# Yes, people actually do this. And report bugs if it breaks.
461
526
source = self.make_branch_and_tree('source', format='rich-root-pack')
1270
1335
self.assertEqual(['B-id', 'C-id', 'F-id'],
1271
1336
[t.get_revision_id() for t in merger._lca_trees])
1338
def test_find_base_new_root_criss_cross(self):
1345
builder = self.get_builder()
1346
builder.build_snapshot('A-id', None,
1347
[('add', ('', None, 'directory', None))])
1348
builder.build_snapshot('B-id', [],
1349
[('add', ('', None, 'directory', None))])
1350
builder.build_snapshot('D-id', ['A-id', 'B-id'], [])
1351
builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
1352
merger = self.make_Merger(builder, 'D-id')
1353
self.assertEqual('A-id', merger.base_rev_id)
1354
self.assertTrue(merger._is_criss_cross)
1355
self.assertEqual(['A-id', 'B-id'], [t.get_revision_id()
1356
for t in merger._lca_trees])
1273
1358
def test_no_criss_cross_passed_to_merge_type(self):
1274
1359
class LCATreesMerger(LoggingMerger):
1275
1360
supports_lca_trees = True
1807
1892
builder.build_snapshot('C-id', ['A-id'], [])
1808
1893
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1809
1894
[('unversion', 'a-id'),
1810
1896
('add', (u'a', 'a-id', 'directory', None))])
1811
1897
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1812
1898
merge_obj = self.make_merge_obj(builder, 'E-id')
1830
1916
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1831
1917
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1832
1918
[('unversion', 'a-id'),
1833
1920
('add', (u'a', 'a-id', 'directory', None))])
1834
1921
merge_obj = self.make_merge_obj(builder, 'E-id')
1835
1922
entries = list(merge_obj._entries_lca())
2163
2250
wt.get_file_text('foo-id'))
2165
2252
def test_modified_symlink(self):
2166
self.requireFeature(tests.SymlinkFeature)
2253
self.requireFeature(features.SymlinkFeature)
2167
2254
# A Create symlink foo => bar
2169
2256
# B C B relinks foo => baz
2208
2295
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2210
2297
def test_renamed_symlink(self):
2211
self.requireFeature(tests.SymlinkFeature)
2298
self.requireFeature(features.SymlinkFeature)
2212
2299
# A Create symlink foo => bar
2214
2301
# B C B renames foo => barry
2264
2351
self.assertEqual('blah', wt.id2path('foo-id'))
2266
2353
def test_symlink_no_content_change(self):
2267
self.requireFeature(tests.SymlinkFeature)
2354
self.requireFeature(features.SymlinkFeature)
2268
2355
# A Create symlink foo => bar
2270
2357
# B C B relinks foo => baz
2315
2402
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2317
2404
def test_symlink_this_changed_kind(self):
2318
self.requireFeature(tests.SymlinkFeature)
2405
self.requireFeature(features.SymlinkFeature)
2321
2408
# B C B creates symlink foo => bar
2369
2456
def test_symlink_all_wt(self):
2370
2457
"""Check behavior if all trees are Working Trees."""
2371
self.requireFeature(tests.SymlinkFeature)
2458
self.requireFeature(features.SymlinkFeature)
2372
2459
# The big issue is that entry.symlink_target is None for WorkingTrees.
2373
2460
# So we need to make sure we handle that case correctly.
2844
2931
def get_merger_factory(self):
2845
2932
# Allows the inner methods to access the test attributes
2848
2935
class FooMerger(_mod_merge.ConfigurableFileMerger):
2849
2936
name_prefix = "foo"
2850
2937
default_files = ['bar']
2852
2939
def merge_text(self, params):
2853
test.calls.append('merge_text')
2940
calls.append('merge_text')
2854
2941
return ('not_applicable', None)
2856
2943
def factory(merger):