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')
281
# re-open branch as external run_bzr modified it
282
branch_b = branch_b.bzrdir.open_branch()
278
283
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
279
284
osutils.abspath(parent))
280
285
# test implicit --remember when committing new file
281
self.build_tree(['e'])
286
self.build_tree(['branch_b/e'])
283
288
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,))
289
out, err = self.run_bzr('merge', working_dir='branch_b')
290
self.assertStartsWith(
291
err, 'Merging from remembered submit location %s\n' % (base,))
287
292
# re-open tree as external run_bzr modified it
288
293
tree_b = branch_b.bzrdir.open_workingtree()
289
294
tree_b.commit('merge branch_a')
290
295
# test explicit --remember
291
out, err = self.run_bzr('merge ../branch_c --remember')
296
out, err = self.run_bzr('merge ../branch_c --remember',
297
working_dir='branch_b')
292
298
self.assertEquals(out, '')
293
299
self.assertEquals(err, '+N c\nAll changes applied successfully.\n')
300
# re-open branch as external run_bzr modified it
301
branch_b = branch_b.bzrdir.open_branch()
294
302
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
295
303
osutils.abspath(branch_c.bzrdir.root_transport.base))
296
304
# re-open tree as external run_bzr modified it
354
359
tree_a.bzrdir.sprout('tree_b')
355
360
self.build_tree(['tree_a/file1', 'tree_a/file2'])
356
361
tree_a.add(['file1', 'file2'])
358
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
359
self.assertPathExists('file1')
360
self.assertPathDoesNotExist('file2')
362
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
363
working_dir='tree_b')
364
self.assertPathExists('tree_b/file1')
365
self.assertPathDoesNotExist('tree_b/file2')
362
367
def test_merge_nonexistent_file(self):
363
368
"""It should not be possible to merge changes from a file which
413
416
os.unlink('tree_a/file')
414
417
self.build_tree(['tree_a/file/'])
415
418
tree_a.commit('changed file to directory')
417
self.run_bzr('merge ../tree_a')
418
self.assertEqual('directory', osutils.file_kind('file'))
419
self.run_bzr('merge ../tree_a', working_dir='tree_b')
420
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')])
422
self.assertEqual('file', osutils.file_kind('tree_b/file'))
423
self.build_tree_contents([('tree_b/file', 'content_2')])
422
424
tree_b.commit('content change')
423
self.run_bzr('merge ../tree_a', retcode=1)
425
self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
424
426
self.assertEqual(tree_b.conflicts(),
425
427
[conflicts.ContentsConflict('file',
426
428
file_id='file-id')])
555
557
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
556
558
tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
557
559
out, err = self.run_bzr(['merge', '-d', 'c'])
558
self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
559
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
560
self.assertContainsRe(err,
561
'Merging from remembered parent location .*a\/')
562
tree_c.branch.lock_write()
564
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
566
tree_c.branch.unlock()
560
567
out, err = self.run_bzr(['merge', '-d', 'c'])
561
self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
568
self.assertContainsRe(err,
569
'Merging from remembered submit location .*b\/')
563
571
def test_remember_sets_submit(self):
564
572
tree_a = self.make_branch_and_tree('a')
569
577
# Remember should not happen if using default from parent
570
578
out, err = self.run_bzr(['merge', '-d', 'b'])
571
self.assertIs(tree_b.branch.get_submit_branch(), None)
579
refreshed = workingtree.WorkingTree.open('b')
580
self.assertIs(refreshed.branch.get_submit_branch(), None)
573
582
# Remember should happen if user supplies location
574
583
out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
575
self.assertEqual(tree_b.branch.get_submit_branch(),
584
refreshed = workingtree.WorkingTree.open('b')
585
self.assertEqual(refreshed.branch.get_submit_branch(),
576
586
tree_a.bzrdir.root_transport.base)
578
588
def test_no_remember_dont_set_submit(self):