1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005-2012 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
83
83
tip = wt1.commit('empty commit')
84
84
wt2 = self.make_branch_and_tree('branch2')
85
85
wt2.pull(wt1.branch)
86
file('branch1/foo', 'wb').write('foo')
87
file('branch1/bar', 'wb').write('bar')
86
with file('branch1/foo', 'wb') as f:
88
with file('branch1/bar', 'wb') as f:
90
92
wt1.commit('add foobar')
92
self.run_bzr('merge ../branch1/baz', retcode=3)
93
self.run_bzr('merge ../branch1/foo')
94
self.assertPathExists('foo')
95
self.assertPathDoesNotExist('bar')
96
wt2 = WorkingTree.open('.') # opens branch2
93
self.run_bzr('merge ../branch1/baz', retcode=3, working_dir='branch2')
94
self.run_bzr('merge ../branch1/foo', working_dir='branch2')
95
self.assertPathExists('branch2/foo')
96
self.assertPathDoesNotExist('branch2/bar')
97
wt2 = WorkingTree.open('branch2')
97
98
self.assertEqual([tip], wt2.get_parent_ids())
99
100
def test_pending_with_null(self):
446
447
merger.merge_type = _mod_merge.Merge3Merger
447
448
tree_merger = merger.make_merger()
448
449
self.assertIs(_mod_merge.Merge3Merger, tree_merger.__class__)
449
self.assertEqual('rev2b', tree_merger.other_tree.get_revision_id())
450
self.assertEqual('rev1', tree_merger.base_tree.get_revision_id())
450
self.assertEqual('rev2b',
451
tree_merger.other_tree.get_revision_id())
452
self.assertEqual('rev1',
453
tree_merger.base_tree.get_revision_id())
454
self.assertEqual(other_tree.branch, tree_merger.other_branch)
452
456
def test_make_preview_transform(self):
453
457
this_tree = self.make_branch_and_tree('this')
3242
3246
# The dest tree is unmodified.
3243
3247
self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3244
3248
self.assertTreeEntriesEqual([('', 'dest-root-id')], dest_wt)
3251
class TestMergeHooks(TestCaseWithTransport):
3254
super(TestMergeHooks, self).setUp()
3255
self.tree_a = self.make_branch_and_tree('tree_a')
3256
self.build_tree_contents([('tree_a/file', 'content_1')])
3257
self.tree_a.add('file', 'file-id')
3258
self.tree_a.commit('added file')
3260
self.tree_b = self.tree_a.bzrdir.sprout('tree_b').open_workingtree()
3261
self.build_tree_contents([('tree_b/file', 'content_2')])
3262
self.tree_b.commit('modify file')
3264
def test_pre_merge_hook_inject_different_tree(self):
3265
tree_c = self.tree_b.bzrdir.sprout('tree_c').open_workingtree()
3266
self.build_tree_contents([('tree_c/file', 'content_3')])
3267
tree_c.commit("more content")
3269
def factory(merger):
3270
self.assertIsInstance(merger, _mod_merge.Merge3Merger)
3271
merger.other_tree = tree_c
3272
calls.append(merger)
3273
_mod_merge.Merger.hooks.install_named_hook('pre_merge',
3274
factory, 'test factory')
3275
self.tree_a.merge_from_branch(self.tree_b.branch)
3277
self.assertFileEqual("content_3", 'tree_a/file')
3278
self.assertLength(1, calls)
3280
def test_post_merge_hook_called(self):
3282
def factory(merger):
3283
self.assertIsInstance(merger, _mod_merge.Merge3Merger)
3284
calls.append(merger)
3285
_mod_merge.Merger.hooks.install_named_hook('post_merge',
3286
factory, 'test factory')
3288
self.tree_a.merge_from_branch(self.tree_b.branch)
3290
self.assertFileEqual("content_2", 'tree_a/file')
3291
self.assertLength(1, calls)