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
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")
437
390
def test_make_merger(self):
438
391
this_tree = self.make_branch_and_tree('this')
439
392
this_tree.commit('rev1', rev_id='rev1')
504
457
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([])
524
459
def test_merge_add_into_deleted_root(self):
525
460
# Yes, people actually do this. And report bugs if it breaks.
526
461
source = self.make_branch_and_tree('source', format='rich-root-pack')
1892
1827
builder.build_snapshot('C-id', ['A-id'], [])
1893
1828
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1894
1829
[('unversion', 'a-id'),
1896
1830
('add', (u'a', 'a-id', 'directory', None))])
1897
1831
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1898
1832
merge_obj = self.make_merge_obj(builder, 'E-id')
1916
1850
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1917
1851
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1918
1852
[('unversion', 'a-id'),
1920
1853
('add', (u'a', 'a-id', 'directory', None))])
1921
1854
merge_obj = self.make_merge_obj(builder, 'E-id')
1922
1855
entries = list(merge_obj._entries_lca())
2250
2183
wt.get_file_text('foo-id'))
2252
2185
def test_modified_symlink(self):
2253
self.requireFeature(features.SymlinkFeature)
2186
self.requireFeature(tests.SymlinkFeature)
2254
2187
# A Create symlink foo => bar
2256
2189
# B C B relinks foo => baz
2295
2228
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2297
2230
def test_renamed_symlink(self):
2298
self.requireFeature(features.SymlinkFeature)
2231
self.requireFeature(tests.SymlinkFeature)
2299
2232
# A Create symlink foo => bar
2301
2234
# B C B renames foo => barry
2351
2284
self.assertEqual('blah', wt.id2path('foo-id'))
2353
2286
def test_symlink_no_content_change(self):
2354
self.requireFeature(features.SymlinkFeature)
2287
self.requireFeature(tests.SymlinkFeature)
2355
2288
# A Create symlink foo => bar
2357
2290
# B C B relinks foo => baz
2402
2335
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2404
2337
def test_symlink_this_changed_kind(self):
2405
self.requireFeature(features.SymlinkFeature)
2338
self.requireFeature(tests.SymlinkFeature)
2408
2341
# B C B creates symlink foo => bar
2456
2389
def test_symlink_all_wt(self):
2457
2390
"""Check behavior if all trees are Working Trees."""
2458
self.requireFeature(features.SymlinkFeature)
2391
self.requireFeature(tests.SymlinkFeature)
2459
2392
# The big issue is that entry.symlink_target is None for WorkingTrees.
2460
2393
# So we need to make sure we handle that case correctly.
2931
2864
def get_merger_factory(self):
2932
2865
# Allows the inner methods to access the test attributes
2935
2868
class FooMerger(_mod_merge.ConfigurableFileMerger):
2936
2869
name_prefix = "foo"
2937
2870
default_files = ['bar']
2939
2872
def merge_text(self, params):
2940
calls.append('merge_text')
2873
test.calls.append('merge_text')
2941
2874
return ('not_applicable', None)
2943
2876
def factory(merger):