/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2012 Canonical Ltd
2
2
#
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
16
16
#
17
17
# Author: Aaron Bentley <aaron.bentley@utoronto.ca>
18
18
 
19
 
"""Black-box tests for brz merge.
 
19
"""Black-box tests for bzr merge.
20
20
"""
21
21
 
22
22
import doctest
24
24
 
25
25
from testtools import matchers
26
26
 
27
 
from breezy import (
 
27
from bzrlib import (
28
28
    branch,
29
29
    conflicts,
30
30
    controldir,
34
34
    urlutils,
35
35
    workingtree,
36
36
    )
37
 
from breezy.tests import (
 
37
from bzrlib.tests import (
38
38
    scenarios,
39
39
    script,
40
40
    )
48
48
    def example_branch(self, path='.'):
49
49
        tree = self.make_branch_and_tree(path)
50
50
        self.build_tree_contents([
51
 
            (osutils.pathjoin(path, 'hello'), b'foo'),
52
 
            (osutils.pathjoin(path, 'goodbye'), b'baz')])
 
51
            (osutils.pathjoin(path, 'hello'), 'foo'),
 
52
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
53
53
        tree.add('hello')
54
54
        tree.commit(message='setup')
55
55
        tree.add('goodbye')
63
63
            conflict.
64
64
        """
65
65
        builder = self.make_branch_builder('branch')
66
 
        builder.build_snapshot(None,
 
66
        builder.build_snapshot('rev1', None,
67
67
            [('add', ('', 'root-id', 'directory', None)),
68
 
             ('add', ('fname', 'f-id', 'file', 'a\nb\nc\n'))],
69
 
            revision_id=b'rev1')
70
 
        builder.build_snapshot(['rev1'],
71
 
            [('modify', ('fname', b'a\nB\nD\n'))],
72
 
            revision_id=b'rev2other')
73
 
        other = builder.get_branch().controldir.sprout('other').open_branch()
74
 
        builder.build_snapshot(['rev1'],
75
 
            [('modify', ('fname', b'a\nB\nC\n'))], revision_id=b'rev2this')
 
68
             ('add', ('fname', 'f-id', 'file', 'a\nb\nc\n'))])
 
69
        builder.build_snapshot('rev2other', ['rev1'],
 
70
            [('modify', ('f-id', 'a\nB\nD\n'))])
 
71
        other = builder.get_branch().bzrdir.sprout('other').open_branch()
 
72
        builder.build_snapshot('rev2this', ['rev1'],
 
73
            [('modify', ('f-id', 'a\nB\nC\n'))])
76
74
        tree = builder.get_branch().create_checkout('tree', lightweight=True)
77
75
        return tree, other
78
76
 
84
82
    def test_merge(self):
85
83
        a_tree = self.example_branch('a')
86
84
        ancestor = a_tree.branch.revno()
87
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
88
 
        self.build_tree_contents([('b/goodbye', b'quux')])
 
85
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
86
        self.build_tree_contents([('b/goodbye', 'quux')])
89
87
        b_tree.commit(message="more u's are always good")
90
88
 
91
 
        self.build_tree_contents([('a/hello', b'quuux')])
 
89
        self.build_tree_contents([('a/hello', 'quuux')])
92
90
        # We can't merge when there are in-tree changes
93
91
        self.run_bzr('merge ../b', retcode=3, working_dir='a')
94
92
        a = workingtree.WorkingTree.open('a')
123
121
                                working_dir='a')
124
122
        self.assertTrue("Not a branch" in err)
125
123
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
126
 
                    %(ancestor, b.revno()), working_dir='a')
127
 
        self.assertEqual(a.get_parent_ids(),
 
124
                    %(ancestor,b.revno()), working_dir='a')
 
125
        self.assertEquals(a.get_parent_ids(),
128
126
                          [a.branch.last_revision(), b.last_revision()])
129
127
        self.check_file_contents('a/goodbye', 'quux')
130
128
        a_tree.revert(backups=False)
131
129
        self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
132
 
        self.assertEqual(a.get_parent_ids(),
 
130
        self.assertEquals(a.get_parent_ids(),
133
131
                          [a.branch.last_revision(), b.last_revision()])
134
132
        a_tip = a.commit('merged')
135
133
        self.run_bzr('merge ../b -r last:1', working_dir='a')
148
146
                             '=======\n'
149
147
                             'D\n'
150
148
                             '>>>>>>> MERGE-SOURCE\n',
151
 
                             tree.get_file_text('fname'))
 
149
                             tree.get_file_text('f-id'))
152
150
 
153
151
    def test_merge_explicit_reprocess_show_base(self):
154
152
        tree, other = self.create_conflicting_branches()
170
168
                             'B\n'
171
169
                             'D\n'
172
170
                             '>>>>>>> MERGE-SOURCE\n',
173
 
                             tree.get_file_text('fname'))
 
171
                             tree.get_file_text('f-id'))
174
172
 
175
173
    def test_merge_override_show_base(self):
176
174
        tree, other = self.create_conflicting_branches()
188
186
                             'B\n'
189
187
                             'D\n'
190
188
                             '>>>>>>> MERGE-SOURCE\n',
191
 
                             tree.get_file_text('fname'))
 
189
                             tree.get_file_text('f-id'))
192
190
 
193
191
    def test_merge_with_missing_file(self):
194
192
        """Merge handles missing file conflicts"""
195
193
        self.build_tree_contents([
196
194
            ('a/',),
197
195
            ('a/sub/',),
198
 
            ('a/sub/a.txt', b'hello\n'),
199
 
            ('a/b.txt', b'hello\n'),
200
 
            ('a/sub/c.txt', b'hello\n')])
 
196
            ('a/sub/a.txt', 'hello\n'),
 
197
            ('a/b.txt', 'hello\n'),
 
198
            ('a/sub/c.txt', 'hello\n')])
201
199
        a_tree = self.make_branch_and_tree('a')
202
200
        a_tree.add(['sub', 'b.txt', 'sub/c.txt', 'sub/a.txt'])
203
201
        a_tree.commit(message='added a')
204
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
202
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
205
203
        self.build_tree_contents([
206
 
            ('a/sub/a.txt', b'hello\nthere\n'),
207
 
            ('a/b.txt', b'hello\nthere\n'),
208
 
            ('a/sub/c.txt', b'hello\nthere\n')])
 
204
            ('a/sub/a.txt', 'hello\nthere\n'),
 
205
            ('a/b.txt', 'hello\nthere\n'),
 
206
            ('a/sub/c.txt', 'hello\nthere\n')])
209
207
        a_tree.commit(message='Added there')
210
208
        os.remove('a/sub/a.txt')
211
209
        os.remove('a/sub/c.txt')
213
211
        os.remove('a/b.txt')
214
212
        a_tree.commit(message='Removed a.txt')
215
213
        self.build_tree_contents([
216
 
            ('b/sub/a.txt', b'hello\nsomething\n'),
217
 
            ('b/b.txt', b'hello\nsomething\n'),
218
 
            ('b/sub/c.txt', b'hello\nsomething\n')])
 
214
            ('b/sub/a.txt', 'hello\nsomething\n'),
 
215
            ('b/b.txt', 'hello\nsomething\n'),
 
216
            ('b/sub/c.txt', 'hello\nsomething\n')])
219
217
        b_tree.commit(message='Modified a.txt')
220
218
 
221
219
        self.run_bzr('merge ../a/', retcode=1, working_dir='b')
249
247
        self.build_tree(['branch_a/a'])
250
248
        tree_a.add('a')
251
249
        tree_a.commit('commit a')
252
 
        branch_b = branch_a.controldir.sprout('branch_b').open_branch()
253
 
        tree_b = branch_b.controldir.open_workingtree()
254
 
        branch_c = branch_a.controldir.sprout('branch_c').open_branch()
255
 
        tree_c = branch_c.controldir.open_workingtree()
 
250
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
 
251
        tree_b = branch_b.bzrdir.open_workingtree()
 
252
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
 
253
        tree_c = branch_c.bzrdir.open_workingtree()
256
254
        self.build_tree(['branch_a/b'])
257
255
        tree_a.add('b')
258
256
        tree_a.commit('commit b')
265
263
        self.assertEqual(None, branch_b.get_parent())
266
264
        # test merge for failure without parent set
267
265
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
268
 
        self.assertEqual(out,
269
 
                ('', 'brz: ERROR: No location specified or remembered\n'))
 
266
        self.assertEquals(out,
 
267
                ('','bzr: ERROR: No location specified or remembered\n'))
270
268
 
271
269
        # test uncommitted changes
272
270
        self.build_tree(['branch_b/d'])
280
278
 
281
279
        base = urlutils.local_path_from_url(branch_a.base)
282
280
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
283
 
        # re-open branch as external run_brz modified it
284
 
        branch_b = branch_b.controldir.open_branch()
285
 
        self.assertEqual(osutils.abspath(branch_b.get_submit_branch()),
 
281
        # re-open branch as external run_bzr modified it
 
282
        branch_b = branch_b.bzrdir.open_branch()
 
283
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
286
284
                          osutils.abspath(parent))
287
285
        # test implicit --remember when committing new file
288
286
        self.build_tree(['branch_b/e'])
291
289
        out, err = self.run_bzr('merge', working_dir='branch_b')
292
290
        self.assertStartsWith(
293
291
            err, 'Merging from remembered submit location %s\n' % (base,))
294
 
        # re-open tree as external run_brz modified it
295
 
        tree_b = branch_b.controldir.open_workingtree()
 
292
        # re-open tree as external run_bzr modified it
 
293
        tree_b = branch_b.bzrdir.open_workingtree()
296
294
        tree_b.commit('merge branch_a')
297
295
        # test explicit --remember
298
296
        out, err = self.run_bzr('merge ../branch_c --remember',
299
297
                                working_dir='branch_b')
300
 
        self.assertEqual(out, '')
301
 
        self.assertEqual(err, '+N  c\nAll changes applied successfully.\n')
302
 
        # re-open branch as external run_brz modified it
303
 
        branch_b = branch_b.controldir.open_branch()
304
 
        self.assertEqual(osutils.abspath(branch_b.get_submit_branch()),
305
 
                          osutils.abspath(branch_c.controldir.root_transport.base))
306
 
        # re-open tree as external run_brz modified it
307
 
        tree_b = branch_b.controldir.open_workingtree()
 
298
        self.assertEquals(out, '')
 
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()
 
302
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
 
303
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
 
304
        # re-open tree as external run_bzr modified it
 
305
        tree_b = branch_b.bzrdir.open_workingtree()
308
306
        tree_b.commit('merge branch_c')
309
307
 
310
308
    def test_merge_bundle(self):
311
 
        from breezy.testament import Testament
 
309
        from bzrlib.testament import Testament
312
310
        tree_a = self.make_branch_and_tree('branch_a')
313
 
        self.build_tree_contents([('branch_a/a', b'hello')])
 
311
        self.build_tree_contents([('branch_a/a', 'hello')])
314
312
        tree_a.add('a')
315
313
        tree_a.commit('message')
316
314
 
317
 
        tree_b = tree_a.controldir.sprout('branch_b').open_workingtree()
318
 
        self.build_tree_contents([('branch_a/a', b'hey there')])
 
315
        tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
 
316
        self.build_tree_contents([('branch_a/a', 'hey there')])
319
317
        tree_a.commit('message')
320
318
 
321
 
        self.build_tree_contents([('branch_b/a', b'goodbye')])
 
319
        self.build_tree_contents([('branch_b/a', 'goodbye')])
322
320
        tree_b.commit('message')
323
321
        self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b')
324
322
        self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a')
342
340
        self.build_tree(['a/file_1', 'a/file_2'])
343
341
        tree_a.add(['file_1', 'file_2'])
344
342
        tree_a.commit('commit 1')
345
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
 
343
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
346
344
        self.assertPathExists('b/file_1')
347
345
        tree_a.rename_one('file_1', 'file_i')
348
346
        tree_a.commit('commit 2')
358
356
        """It should be possible to merge changes from a single file."""
359
357
        tree_a = self.make_branch_and_tree('tree_a')
360
358
        tree_a.commit('initial commit')
361
 
        tree_a.controldir.sprout('tree_b')
 
359
        tree_a.bzrdir.sprout('tree_b')
362
360
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
363
361
        tree_a.add(['file1', 'file2'])
364
362
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
370
368
        """It should not be possible to merge changes from a file which
371
369
        does not exist."""
372
370
        tree_a = self.make_branch_and_tree('tree_a')
373
 
        self.build_tree_contents([('tree_a/file', b'bar\n')])
 
371
        self.build_tree_contents([('tree_a/file', 'bar\n')])
374
372
        tree_a.add(['file'])
375
373
        tree_a.commit('commit 1')
376
374
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
378
376
 
379
377
    def pullable_branch(self):
380
378
        tree_a = self.make_branch_and_tree('a')
381
 
        self.build_tree_contents([('a/file', b'bar\n')])
 
379
        self.build_tree_contents([('a/file', 'bar\n')])
382
380
        tree_a.add(['file'])
383
381
        self.id1 = tree_a.commit('commit 1')
384
382
 
385
383
        tree_b = self.make_branch_and_tree('b')
386
384
        tree_b.pull(tree_a.branch)
387
 
        self.build_tree_contents([('b/file', b'foo\n')])
 
385
        self.build_tree_contents([('b/file', 'foo\n')])
388
386
        self.id2 = tree_b.commit('commit 2')
389
387
 
390
388
    def test_merge_pull(self):
411
409
 
412
410
    def test_merge_kind_change(self):
413
411
        tree_a = self.make_branch_and_tree('tree_a')
414
 
        self.build_tree_contents([('tree_a/file', b'content_1')])
415
 
        tree_a.add('file', b'file-id')
 
412
        self.build_tree_contents([('tree_a/file', 'content_1')])
 
413
        tree_a.add('file', 'file-id')
416
414
        tree_a.commit('added file')
417
 
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
 
415
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
418
416
        os.unlink('tree_a/file')
419
417
        self.build_tree(['tree_a/file/'])
420
418
        tree_a.commit('changed file to directory')
422
420
        self.assertEqual('directory', osutils.file_kind('tree_b/file'))
423
421
        tree_b.revert()
424
422
        self.assertEqual('file', osutils.file_kind('tree_b/file'))
425
 
        self.build_tree_contents([('tree_b/file', b'content_2')])
 
423
        self.build_tree_contents([('tree_b/file', 'content_2')])
426
424
        tree_b.commit('content change')
427
425
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
428
426
        self.assertEqual(tree_b.conflicts(),
436
434
        # cherrypick from one branch into another unrelated branch with a
437
435
        # different root id will give shape conflicts.  as a workaround we
438
436
        # make sure they share the same root id.
439
 
        target = source.controldir.sprout('target').open_workingtree()
 
437
        target = source.bzrdir.sprout('target').open_workingtree()
440
438
        self.build_tree(['source/a'])
441
439
        source.add('a')
442
 
        source.commit('Added a', rev_id=b'rev1')
 
440
        source.commit('Added a', rev_id='rev1')
443
441
        self.build_tree(['source/b'])
444
442
        source.add('b')
445
 
        source.commit('Added b', rev_id=b'rev2')
 
443
        source.commit('Added b', rev_id='rev2')
446
444
        target.commit('empty commit')
447
445
        self.write_directive('directive', source.branch, 'target', 'rev2',
448
446
                             'rev1')
458
456
            base_revision_id=base_revision_id)
459
457
        if mangle_patch:
460
458
            md.patch = 'asdf\n'
461
 
        self.build_tree_contents([(filename, b''.join(md.to_lines()))])
 
459
        self.build_tree_contents([(filename, ''.join(md.to_lines()))])
462
460
 
463
461
    def test_directive_verify_warning(self):
464
462
        source = self.make_branch_and_tree('source')
465
463
        self.build_tree(['source/a'])
466
464
        source.add('a')
467
 
        source.commit('Added a', rev_id=b'rev1')
 
465
        source.commit('Added a', rev_id='rev1')
468
466
        target = self.make_branch_and_tree('target')
469
467
        target.commit('empty commit')
470
468
        self.write_directive('directive', source.branch, 'target', 'rev1')
480
478
        target = self.make_branch_and_tree('target')
481
479
        target.commit('empty')
482
480
        # We need a revision that has no integer revno
483
 
        branch_a = target.controldir.sprout('branch_a').open_workingtree()
 
481
        branch_a = target.bzrdir.sprout('branch_a').open_workingtree()
484
482
        self.build_tree(['branch_a/file1'])
485
483
        branch_a.add('file1')
486
 
        branch_a.commit('added file1', rev_id=b'rev2a')
487
 
        branch_b = target.controldir.sprout('branch_b').open_workingtree()
 
484
        branch_a.commit('added file1', rev_id='rev2a')
 
485
        branch_b = target.bzrdir.sprout('branch_b').open_workingtree()
488
486
        self.build_tree(['branch_b/file2'])
489
487
        branch_b.add('file2')
490
 
        branch_b.commit('added file2', rev_id=b'rev2b')
 
488
        branch_b.commit('added file2', rev_id='rev2b')
491
489
        branch_b.merge_from_branch(branch_a.branch)
492
490
        self.assertPathExists('branch_b/file1')
493
 
        branch_b.commit('merged branch_a', rev_id=b'rev3b')
 
491
        branch_b.commit('merged branch_a', rev_id='rev3b')
494
492
 
495
493
        # It works if the revid has an interger revno
496
494
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
523
521
        for f in ('a', 'b', 'c', 'd'):
524
522
            self.build_tree(['source/'+f])
525
523
            source.add(f)
526
 
            source.commit('added '+f, rev_id=b'rev_'+f)
 
524
            source.commit('added '+f, rev_id='rev_'+f)
527
525
        # target branch
528
 
        target = source.controldir.sprout('target', 'rev_a').open_workingtree()
 
526
        target = source.bzrdir.sprout('target', 'rev_a').open_workingtree()
529
527
        self.assertDirectoryContent('target', ['.bzr', 'a'])
530
528
        # pick 1 revision
531
529
        self.run_bzr('merge -d target -r revid:rev_b..revid:rev_c source')
541
539
 
542
540
    def test_merge_criss_cross(self):
543
541
        tree_a = self.make_branch_and_tree('a')
544
 
        tree_a.commit('', rev_id=b'rev1')
545
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
546
 
        tree_a.commit('', rev_id=b'rev2a')
547
 
        tree_b.commit('', rev_id=b'rev2b')
 
542
        tree_a.commit('', rev_id='rev1')
 
543
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
544
        tree_a.commit('', rev_id='rev2a')
 
545
        tree_b.commit('', rev_id='rev2b')
548
546
        tree_a.merge_from_branch(tree_b.branch)
549
547
        tree_b.merge_from_branch(tree_a.branch)
550
 
        tree_a.commit('', rev_id=b'rev3a')
551
 
        tree_b.commit('', rev_id=b'rev3b')
 
548
        tree_a.commit('', rev_id='rev3a')
 
549
        tree_b.commit('', rev_id='rev3b')
552
550
        graph = tree_a.branch.repository.get_graph(tree_b.branch.repository)
553
551
        out, err = self.run_bzr(['merge', '-d', 'a', 'b'])
554
552
        self.assertContainsRe(err, 'Warning: criss-cross merge encountered.')
556
554
    def test_merge_from_submit(self):
557
555
        tree_a = self.make_branch_and_tree('a')
558
556
        tree_a.commit('test')
559
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
560
 
        tree_c = tree_a.controldir.sprout('c').open_workingtree()
 
557
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
558
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
561
559
        out, err = self.run_bzr(['merge', '-d', 'c'])
562
560
        self.assertContainsRe(err,
563
561
                              'Merging from remembered parent location .*a\/')
564
562
        tree_c.branch.lock_write()
565
563
        try:
566
 
            tree_c.branch.set_submit_branch(tree_b.controldir.root_transport.base)
 
564
            tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
567
565
        finally:
568
566
            tree_c.branch.unlock()
569
567
        out, err = self.run_bzr(['merge', '-d', 'c'])
573
571
    def test_remember_sets_submit(self):
574
572
        tree_a = self.make_branch_and_tree('a')
575
573
        tree_a.commit('rev1')
576
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
 
574
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
577
575
        self.assertIs(tree_b.branch.get_submit_branch(), None)
578
576
 
579
577
        # Remember should not happen if using default from parent
585
583
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
586
584
        refreshed = workingtree.WorkingTree.open('b')
587
585
        self.assertEqual(refreshed.branch.get_submit_branch(),
588
 
                         tree_a.controldir.root_transport.base)
 
586
                         tree_a.bzrdir.root_transport.base)
589
587
 
590
588
    def test_no_remember_dont_set_submit(self):
591
589
        tree_a = self.make_branch_and_tree('a')
592
 
        self.build_tree_contents([('a/file', b"a\n")])
 
590
        self.build_tree_contents([('a/file', "a\n")])
593
591
        tree_a.add('file')
594
592
        tree_a.commit('rev1')
595
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
 
593
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
596
594
        self.assertIs(tree_b.branch.get_submit_branch(), None)
597
595
 
598
596
        # Remember should not happen if using default from parent
599
597
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
600
 
        self.assertEqual(None, tree_b.branch.get_submit_branch())
 
598
        self.assertEquals(None, tree_b.branch.get_submit_branch())
601
599
 
602
600
        # Remember should not happen if user supplies location but ask for not
603
601
        # remembering it
606
604
 
607
605
    def test_weave_cherrypick(self):
608
606
        this_tree = self.make_branch_and_tree('this')
609
 
        self.build_tree_contents([('this/file', b"a\n")])
 
607
        self.build_tree_contents([('this/file', "a\n")])
610
608
        this_tree.add('file')
611
609
        this_tree.commit('rev1')
612
 
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
613
 
        self.build_tree_contents([('other/file', b"a\nb\n")])
 
610
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
611
        self.build_tree_contents([('other/file', "a\nb\n")])
614
612
        other_tree.commit('rev2b')
615
 
        self.build_tree_contents([('other/file', b"c\na\nb\n")])
 
613
        self.build_tree_contents([('other/file', "c\na\nb\n")])
616
614
        other_tree.commit('rev3b')
617
615
        self.run_bzr('merge --weave -d this other -r -2..-1')
618
616
        self.assertFileEqual('c\na\n', 'this/file')
619
617
 
620
618
    def test_lca_merge_criss_cross(self):
621
619
        tree_a = self.make_branch_and_tree('a')
622
 
        self.build_tree_contents([('a/file', b'base-contents\n')])
 
620
        self.build_tree_contents([('a/file', 'base-contents\n')])
623
621
        tree_a.add('file')
624
 
        tree_a.commit('', rev_id=b'rev1')
625
 
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
 
622
        tree_a.commit('', rev_id='rev1')
 
623
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
626
624
        self.build_tree_contents([('a/file',
627
 
                                   b'base-contents\nthis-contents\n')])
628
 
        tree_a.commit('', rev_id=b'rev2a')
 
625
                                   'base-contents\nthis-contents\n')])
 
626
        tree_a.commit('', rev_id='rev2a')
629
627
        self.build_tree_contents([('b/file',
630
 
                                   b'base-contents\nother-contents\n')])
631
 
        tree_b.commit('', rev_id=b'rev2b')
 
628
                                   'base-contents\nother-contents\n')])
 
629
        tree_b.commit('', rev_id='rev2b')
632
630
        tree_a.merge_from_branch(tree_b.branch)
633
631
        self.build_tree_contents([('a/file',
634
 
                                   b'base-contents\nthis-contents\n')])
 
632
                                   'base-contents\nthis-contents\n')])
635
633
        tree_a.set_conflicts(conflicts.ConflictList())
636
634
        tree_b.merge_from_branch(tree_a.branch)
637
635
        self.build_tree_contents([('b/file',
638
 
                                   b'base-contents\nother-contents\n')])
 
636
                                   'base-contents\nother-contents\n')])
639
637
        tree_b.set_conflicts(conflicts.ConflictList())
640
 
        tree_a.commit('', rev_id=b'rev3a')
641
 
        tree_b.commit('', rev_id=b'rev3b')
 
638
        tree_a.commit('', rev_id='rev3a')
 
639
        tree_b.commit('', rev_id='rev3b')
642
640
        out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
643
641
        self.assertFileEqual('base-contents\n<<<<<<< TREE\nthis-contents\n'
644
642
                             '=======\nother-contents\n>>>>>>> MERGE-SOURCE\n',
647
645
    def test_merge_preview(self):
648
646
        this_tree = self.make_branch_and_tree('this')
649
647
        this_tree.commit('rev1')
650
 
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
651
 
        self.build_tree_contents([('other/file', b'new line')])
 
648
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
649
        self.build_tree_contents([('other/file', 'new line')])
652
650
        other_tree.add('file')
653
651
        other_tree.commit('rev2a')
654
652
        this_tree.commit('rev2b')
674
672
    def test_merge_interactive_unlocks_branch(self):
675
673
        this = self.make_branch_and_tree('this')
676
674
        this.commit('empty commit')
677
 
        other = this.controldir.sprout('other').open_workingtree()
 
675
        other = this.bzrdir.sprout('other').open_workingtree()
678
676
        other.commit('empty commit 2')
679
677
        self.run_bzr('merge -i -d this other')
680
678
        this.lock_write()
686
684
        """
687
685
        # Make a source, sprout a target off it
688
686
        builder = self.make_branch_builder('source')
689
 
        builder.build_commit(message="Rev 1", rev_id=b'rev-1')
 
687
        builder.build_commit(message="Rev 1", rev_id='rev-1')
690
688
        source = builder.get_branch()
691
 
        target_bzrdir = source.controldir.sprout('target')
 
689
        target_bzrdir = source.bzrdir.sprout('target')
692
690
        # Add a non-ancestry tag to source
693
 
        builder.build_commit(message="Rev 2a", rev_id=b'rev-2a')
 
691
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
694
692
        source.tags.set_tag('tag-a', 'rev-2a')
695
693
        source.set_last_revision_info(1, 'rev-1')
696
694
        source.get_config_stack().set('branch.fetch_tags', True)
697
 
        builder.build_commit(message="Rev 2b", rev_id=b'rev-2b')
 
695
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
698
696
        # Merge from source
699
697
        self.run_bzr('merge -d target source')
700
698
        target = target_bzrdir.open_branch()
728
726
        source = self.make_branch_and_tree('source')
729
727
        self.build_tree(['source/a'])
730
728
        source.add('a')
731
 
        source.commit('Added a', rev_id=b'rev1')
 
729
        source.commit('Added a', rev_id='rev1')
732
730
        target = self.make_branch_and_tree('target')
733
731
        self.run_script("""\
734
 
$ brz merge -d target source
735
 
2>brz: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
 
732
$ bzr merge -d target source
 
733
2>bzr: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
736
734
""")
737
735
 
738
736
class TestMergeForce(tests.TestCaseWithTransport):
743
741
        self.build_tree(['a/foo'])
744
742
        self.tree_a.add(['foo'])
745
743
        self.tree_a.commit('add file')
746
 
        self.tree_b = self.tree_a.controldir.sprout('b').open_workingtree()
747
 
        self.build_tree_contents([('a/foo', b'change 1')])
 
744
        self.tree_b = self.tree_a.bzrdir.sprout('b').open_workingtree()
 
745
        self.build_tree_contents([('a/foo', 'change 1')])
748
746
        self.tree_a.commit('change file')
749
747
        self.tree_b.merge_from_branch(self.tree_a.branch)
750
748