89
89
self.build_tree_contents([('a/hello', 'quuux')])
90
90
# We can't merge when there are in-tree changes
92
self.run_bzr('merge ../b', retcode=3)
93
a = workingtree.WorkingTree.open('.')
91
self.run_bzr('merge ../b', retcode=3, working_dir='a')
92
a = workingtree.WorkingTree.open('a')
94
93
a_tip = a.commit("Like an epidemic of u's")
95
self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
97
self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
98
a_tree.revert(backups=False)
99
self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
100
a_tree.revert(backups=False)
101
self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
102
a_tree.revert(backups=False)
95
def run_merge_then_revert(args, retcode=None, working_dir='a'):
96
self.run_bzr(['merge', '../b', '-r', 'last:1..last:1'] + args,
97
retcode=retcode, working_dir=working_dir)
99
a_tree.revert(backups=False)
101
run_merge_then_revert(['--merge-type', 'bloof'], retcode=3)
102
run_merge_then_revert(['--merge-type', 'merge3'])
103
run_merge_then_revert(['--merge-type', 'weave'])
104
run_merge_then_revert(['--merge-type', 'lca'])
103
105
self.run_bzr_error(['Show-base is not supported for this merge type'],
104
106
'merge ../b -r last:1..last:1 --merge-type weave'
106
a_tree.revert(backups=False)
107
self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
108
a_tree.revert(backups=False)
109
self.run_bzr('merge ../b -r last:1')
110
self.check_file_contents('goodbye', 'quux')
107
' --show-base', working_dir='a')
108
a_tree.revert(backups=False)
109
self.run_bzr('merge ../b -r last:1..last:1 --reprocess',
111
a_tree.revert(backups=False)
112
self.run_bzr('merge ../b -r last:1', working_dir='a')
113
self.check_file_contents('a/goodbye', 'quux')
111
114
# Merging a branch pulls its revision into the tree
112
b = branch.Branch.open('../b')
115
b = branch.Branch.open('b')
113
116
b_tip = b.last_revision()
114
117
self.assertTrue(a.branch.repository.has_revision(b_tip))
115
118
self.assertEqual([a_tip, b_tip], a.get_parent_ids())
116
119
a_tree.revert(backups=False)
117
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
120
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3,
118
122
self.assertTrue("Not a branch" in err)
119
123
self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
120
%(ancestor,b.revno()))
124
%(ancestor,b.revno()), working_dir='a')
121
125
self.assertEquals(a.get_parent_ids(),
122
126
[a.branch.last_revision(), b.last_revision()])
123
self.check_file_contents('goodbye', 'quux')
127
self.check_file_contents('a/goodbye', 'quux')
124
128
a_tree.revert(backups=False)
125
self.run_bzr('merge -r revno:%d:../b'%b.revno())
129
self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
126
130
self.assertEquals(a.get_parent_ids(),
127
131
[a.branch.last_revision(), b.last_revision()])
128
132
a_tip = a.commit('merged')
129
self.run_bzr('merge ../b -r last:1')
133
self.run_bzr('merge ../b -r last:1', working_dir='a')
130
134
self.assertEqual([a_tip], a.get_parent_ids())
132
136
def test_merge_defaults_to_reprocess(self):
211
215
('b/b.txt', 'hello\nsomething\n'),
212
216
('b/sub/c.txt', 'hello\nsomething\n')])
213
217
b_tree.commit(message='Modified a.txt')
215
self.run_bzr('merge ../a/', retcode=1)
216
self.assertPathExists('sub/a.txt.THIS')
217
self.assertPathExists('sub/a.txt.BASE')
219
self.run_bzr('merge ../b/', retcode=1)
220
self.assertPathExists('sub/a.txt.OTHER')
221
self.assertPathExists('sub/a.txt.BASE')
219
self.run_bzr('merge ../a/', retcode=1, working_dir='b')
220
self.assertPathExists('b/sub/a.txt.THIS')
221
self.assertPathExists('b/sub/a.txt.BASE')
223
self.run_bzr('merge ../b/', retcode=1, working_dir='a')
224
self.assertPathExists('a/sub/a.txt.OTHER')
225
self.assertPathExists('a/sub/a.txt.BASE')
223
227
def test_conflict_leaves_base_this_other_files(self):
224
228
tree, other = self.create_conflicting_branches()
258
262
branch_b.set_parent(None)
259
263
self.assertEqual(None, branch_b.get_parent())
260
264
# test merge for failure without parent set
262
out = self.run_bzr('merge', retcode=3)
265
out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
263
266
self.assertEquals(out,
264
267
('','bzr: ERROR: No location specified or remembered\n'))
266
269
# test uncommitted changes
267
self.build_tree(['d'])
270
self.build_tree(['branch_b/d'])
269
272
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
273
'merge', working_dir='branch_b')
272
275
# merge should now pass and implicitly remember merge location
273
276
tree_b.commit('commit d')
274
out, err = self.run_bzr('merge ../branch_a')
277
out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
276
279
base = urlutils.local_path_from_url(branch_a.base)
277
280
self.assertEndsWith(err, '+N b\nAll changes applied successfully.\n')
278
281
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
279
282
osutils.abspath(parent))
280
283
# test implicit --remember when committing new file
281
self.build_tree(['e'])
284
self.build_tree(['branch_b/e'])
283
286
tree_b.commit('commit e')
284
out, err = self.run_bzr('merge')
285
self.assertStartsWith(err,
286
'Merging from remembered submit location %s\n' % (base,))
287
out, err = self.run_bzr('merge', working_dir='branch_b')
288
self.assertStartsWith(
289
err, 'Merging from remembered submit location %s\n' % (base,))
287
290
# re-open tree as external run_bzr modified it
288
291
tree_b = branch_b.bzrdir.open_workingtree()
289
292
tree_b.commit('merge branch_a')
290
293
# test explicit --remember
291
out, err = self.run_bzr('merge ../branch_c --remember')
294
out, err = self.run_bzr('merge ../branch_c --remember',
295
working_dir='branch_b')
292
296
self.assertEquals(out, '')
293
297
self.assertEquals(err, '+N c\nAll changes applied successfully.\n')
294
298
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
354
355
tree_a.bzrdir.sprout('tree_b')
355
356
self.build_tree(['tree_a/file1', 'tree_a/file2'])
356
357
tree_a.add(['file1', 'file2'])
358
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
359
self.assertPathExists('file1')
360
self.assertPathDoesNotExist('file2')
358
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
359
working_dir='tree_b')
360
self.assertPathExists('tree_b/file1')
361
self.assertPathDoesNotExist('tree_b/file2')
362
363
def test_merge_nonexistent_file(self):
363
364
"""It should not be possible to merge changes from a file which
413
412
os.unlink('tree_a/file')
414
413
self.build_tree(['tree_a/file/'])
415
414
tree_a.commit('changed file to directory')
417
self.run_bzr('merge ../tree_a')
418
self.assertEqual('directory', osutils.file_kind('file'))
415
self.run_bzr('merge ../tree_a', working_dir='tree_b')
416
self.assertEqual('directory', osutils.file_kind('tree_b/file'))
420
self.assertEqual('file', osutils.file_kind('file'))
421
self.build_tree_contents([('file', 'content_2')])
418
self.assertEqual('file', osutils.file_kind('tree_b/file'))
419
self.build_tree_contents([('tree_b/file', 'content_2')])
422
420
tree_b.commit('content change')
423
self.run_bzr('merge ../tree_a', retcode=1)
421
self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
424
422
self.assertEqual(tree_b.conflicts(),
425
423
[conflicts.ContentsConflict('file',
426
424
file_id='file-id')])