~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(vila) Make all transport put_bytes() raises TypeError when given unicode
 strings rather than bytes (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
19
19
"""Black-box tests for bzr merge.
20
20
"""
21
21
 
 
22
import doctest
22
23
import os
23
24
 
 
25
from testtools import matchers
 
26
 
24
27
from bzrlib import (
25
28
    branch,
26
 
    bzrdir,
27
29
    conflicts,
28
 
    errors,
 
30
    controldir,
29
31
    merge_directive,
30
32
    osutils,
31
33
    tests,
32
34
    urlutils,
33
35
    workingtree,
34
36
    )
 
37
from bzrlib.tests import (
 
38
    scenarios,
 
39
    script,
 
40
    )
 
41
 
 
42
 
 
43
load_tests = scenarios.load_tests_apply_scenarios
35
44
 
36
45
 
37
46
class TestMerge(tests.TestCaseWithTransport):
66
75
        return tree, other
67
76
 
68
77
    def test_merge_reprocess(self):
69
 
        d = bzrdir.BzrDir.create_standalone_workingtree('.')
 
78
        d = controldir.ControlDir.create_standalone_workingtree('.')
70
79
        d.commit('h')
71
80
        self.run_bzr('merge . --reprocess --merge-type weave')
72
81
 
79
88
 
80
89
        self.build_tree_contents([('a/hello', 'quuux')])
81
90
        # We can't merge when there are in-tree changes
82
 
        os.chdir('a')
83
 
        self.run_bzr('merge ../b', retcode=3)
84
 
        a = workingtree.WorkingTree.open('.')
 
91
        self.run_bzr('merge ../b', retcode=3, working_dir='a')
 
92
        a = workingtree.WorkingTree.open('a')
85
93
        a_tip = a.commit("Like an epidemic of u's")
86
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
87
 
                    retcode=3)
88
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
89
 
        a_tree.revert(backups=False)
90
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
91
 
        a_tree.revert(backups=False)
92
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
93
 
        a_tree.revert(backups=False)
 
94
 
 
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)
 
98
            if retcode != 3:
 
99
                a_tree.revert(backups=False)
 
100
 
 
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'])
94
105
        self.run_bzr_error(['Show-base is not supported for this merge type'],
95
106
                           'merge ../b -r last:1..last:1 --merge-type weave'
96
 
                           ' --show-base')
97
 
        a_tree.revert(backups=False)
98
 
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
99
 
        a_tree.revert(backups=False)
100
 
        self.run_bzr('merge ../b -r last:1')
101
 
        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',
 
110
                     working_dir='a')
 
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')
102
114
        # Merging a branch pulls its revision into the tree
103
 
        b = branch.Branch.open('../b')
 
115
        b = branch.Branch.open('b')
104
116
        b_tip = b.last_revision()
105
 
        self.failUnless(a.branch.repository.has_revision(b_tip))
 
117
        self.assertTrue(a.branch.repository.has_revision(b_tip))
106
118
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
107
119
        a_tree.revert(backups=False)
108
 
        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,
 
121
                                working_dir='a')
109
122
        self.assertTrue("Not a branch" in err)
110
123
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
111
 
                    %(ancestor,b.revno()))
 
124
                    %(ancestor,b.revno()), working_dir='a')
112
125
        self.assertEquals(a.get_parent_ids(),
113
126
                          [a.branch.last_revision(), b.last_revision()])
114
 
        self.check_file_contents('goodbye', 'quux')
 
127
        self.check_file_contents('a/goodbye', 'quux')
115
128
        a_tree.revert(backups=False)
116
 
        self.run_bzr('merge -r revno:%d:../b'%b.revno())
 
129
        self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
117
130
        self.assertEquals(a.get_parent_ids(),
118
131
                          [a.branch.last_revision(), b.last_revision()])
119
132
        a_tip = a.commit('merged')
120
 
        self.run_bzr('merge ../b -r last:1')
 
133
        self.run_bzr('merge ../b -r last:1', working_dir='a')
121
134
        self.assertEqual([a_tip], a.get_parent_ids())
122
135
 
123
136
    def test_merge_defaults_to_reprocess(self):
202
215
            ('b/b.txt', 'hello\nsomething\n'),
203
216
            ('b/sub/c.txt', 'hello\nsomething\n')])
204
217
        b_tree.commit(message='Modified a.txt')
205
 
        os.chdir('b')
206
 
        self.run_bzr('merge ../a/', retcode=1)
207
 
        self.failUnlessExists('sub/a.txt.THIS')
208
 
        self.failUnlessExists('sub/a.txt.BASE')
209
 
        os.chdir('../a')
210
 
        self.run_bzr('merge ../b/', retcode=1)
211
 
        self.failUnlessExists('sub/a.txt.OTHER')
212
 
        self.failUnlessExists('sub/a.txt.BASE')
 
218
 
 
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')
 
222
 
 
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')
213
226
 
214
227
    def test_conflict_leaves_base_this_other_files(self):
215
228
        tree, other = self.create_conflicting_branches()
249
262
        branch_b.set_parent(None)
250
263
        self.assertEqual(None, branch_b.get_parent())
251
264
        # test merge for failure without parent set
252
 
        os.chdir('branch_b')
253
 
        out = self.run_bzr('merge', retcode=3)
 
265
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
254
266
        self.assertEquals(out,
255
267
                ('','bzr: ERROR: No location specified or remembered\n'))
256
268
 
257
269
        # test uncommitted changes
258
 
        self.build_tree(['d'])
 
270
        self.build_tree(['branch_b/d'])
259
271
        tree_b.add('d')
260
272
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
261
 
                           'merge')
 
273
                           'merge', working_dir='branch_b')
262
274
 
263
275
        # merge should now pass and implicitly remember merge location
264
276
        tree_b.commit('commit d')
265
 
        out, err = self.run_bzr('merge ../branch_a')
 
277
        out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
266
278
 
267
279
        base = urlutils.local_path_from_url(branch_a.base)
268
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()
269
283
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
270
284
                          osutils.abspath(parent))
271
285
        # test implicit --remember when committing new file
272
 
        self.build_tree(['e'])
 
286
        self.build_tree(['branch_b/e'])
273
287
        tree_b.add('e')
274
288
        tree_b.commit('commit e')
275
 
        out, err = self.run_bzr('merge')
276
 
        self.assertStartsWith(err,
277
 
                          '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,))
278
292
        # re-open tree as external run_bzr modified it
279
293
        tree_b = branch_b.bzrdir.open_workingtree()
280
294
        tree_b.commit('merge branch_a')
281
295
        # test explicit --remember
282
 
        out, err = self.run_bzr('merge ../branch_c --remember')
 
296
        out, err = self.run_bzr('merge ../branch_c --remember',
 
297
                                working_dir='branch_b')
283
298
        self.assertEquals(out, '')
284
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()
285
302
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
286
303
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
287
304
        # re-open tree as external run_bzr modified it
301
318
 
302
319
        self.build_tree_contents([('branch_b/a', 'goodbye')])
303
320
        tree_b.commit('message')
304
 
        os.chdir('branch_b')
305
 
        self.run_bzr('bundle ../branch_a -o ../bundle')
306
 
        os.chdir('../branch_a')
307
 
        self.run_bzr('merge ../bundle', retcode=1)
 
321
        self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b')
 
322
        self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a')
308
323
        testament_a = Testament.from_revision(tree_a.branch.repository,
309
324
                                              tree_b.get_parent_ids()[0])
310
325
        testament_b = Testament.from_revision(tree_b.branch.repository,
314
329
        tree_a.set_conflicts(conflicts.ConflictList())
315
330
        tree_a.commit('message')
316
331
        # it is legal to attempt to merge an already-merged bundle
317
 
        output = self.run_bzr('merge ../bundle')[1]
 
332
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
318
333
        # but it does nothing
319
334
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
320
 
        self.assertEqual('Nothing to do.\n', output)
 
335
        self.assertEqual('Nothing to do.\n', err)
321
336
 
322
337
    def test_merge_uncommitted(self):
323
338
        """Check that merge --uncommitted behaves properly"""
326
341
        tree_a.add(['file_1', 'file_2'])
327
342
        tree_a.commit('commit 1')
328
343
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
329
 
        self.failUnlessExists('b/file_1')
 
344
        self.assertPathExists('b/file_1')
330
345
        tree_a.rename_one('file_1', 'file_i')
331
346
        tree_a.commit('commit 2')
332
347
        tree_a.rename_one('file_2', 'file_ii')
333
 
        ## os.chdir('b')
334
348
        self.run_bzr('merge a --uncommitted -d b')
335
 
        self.failUnlessExists('b/file_1')
336
 
        self.failUnlessExists('b/file_ii')
 
349
        self.assertPathExists('b/file_1')
 
350
        self.assertPathExists('b/file_ii')
337
351
        tree_b.revert()
338
352
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
339
353
                           'merge /a --uncommitted -r1 -d b')
345
359
        tree_a.bzrdir.sprout('tree_b')
346
360
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
347
361
        tree_a.add(['file1', 'file2'])
348
 
        os.chdir('tree_b')
349
 
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
350
 
        self.failUnlessExists('file1')
351
 
        self.failIfExists('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')
 
366
 
 
367
    def test_merge_nonexistent_file(self):
 
368
        """It should not be possible to merge changes from a file which
 
369
        does not exist."""
 
370
        tree_a = self.make_branch_and_tree('tree_a')
 
371
        self.build_tree_contents([('tree_a/file', 'bar\n')])
 
372
        tree_a.add(['file'])
 
373
        tree_a.commit('commit 1')
 
374
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
 
375
                           ['merge', 'non/existing'], working_dir='tree_a')
352
376
 
353
377
    def pullable_branch(self):
354
378
        tree_a = self.make_branch_and_tree('a')
355
 
        self.build_tree(['a/file'])
 
379
        self.build_tree_contents([('a/file', 'bar\n')])
356
380
        tree_a.add(['file'])
357
381
        self.id1 = tree_a.commit('commit 1')
358
382
 
359
383
        tree_b = self.make_branch_and_tree('b')
360
384
        tree_b.pull(tree_a.branch)
361
 
        file('b/file', 'wb').write('foo')
 
385
        self.build_tree_contents([('b/file', 'foo\n')])
362
386
        self.id2 = tree_b.commit('commit 2')
363
387
 
364
388
    def test_merge_pull(self):
365
389
        self.pullable_branch()
366
 
        os.chdir('a')
367
 
        (out, err) = self.run_bzr('merge --pull ../b')
 
390
        (out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
368
391
        self.assertContainsRe(out, 'Now on revision 2\\.')
369
 
        tree_a = workingtree.WorkingTree.open('.')
 
392
        tree_a = workingtree.WorkingTree.open('a')
370
393
        self.assertEqual([self.id2], tree_a.get_parent_ids())
371
394
 
 
395
    def test_merge_pull_preview(self):
 
396
        self.pullable_branch()
 
397
        (out, err) = self.run_bzr('merge --pull --preview -d a b')
 
398
        self.assertThat(out, matchers.DocTestMatches(
 
399
"""=== modified file 'file'
 
400
--- file\t...
 
401
+++ file\t...
 
402
@@ -1,1 +1,1 @@
 
403
-bar
 
404
+foo
 
405
 
 
406
""", doctest.ELLIPSIS | doctest.REPORT_UDIFF))
 
407
        tree_a = workingtree.WorkingTree.open('a')
 
408
        self.assertEqual([self.id1], tree_a.get_parent_ids())
 
409
 
372
410
    def test_merge_kind_change(self):
373
411
        tree_a = self.make_branch_and_tree('tree_a')
374
412
        self.build_tree_contents([('tree_a/file', 'content_1')])
378
416
        os.unlink('tree_a/file')
379
417
        self.build_tree(['tree_a/file/'])
380
418
        tree_a.commit('changed file to directory')
381
 
        os.chdir('tree_b')
382
 
        self.run_bzr('merge ../tree_a')
383
 
        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'))
384
421
        tree_b.revert()
385
 
        self.assertEqual('file', osutils.file_kind('file'))
386
 
        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')])
387
424
        tree_b.commit('content change')
388
 
        self.run_bzr('merge ../tree_a', retcode=1)
 
425
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
389
426
        self.assertEqual(tree_b.conflicts(),
390
427
                         [conflicts.ContentsConflict('file',
391
428
                                                     file_id='file-id')])
393
430
    def test_directive_cherrypick(self):
394
431
        source = self.make_branch_and_tree('source')
395
432
        source.commit("nothing")
396
 
        # see https://bugs.edge.launchpad.net/bzr/+bug/409688 - trying to
 
433
        # see https://bugs.launchpad.net/bzr/+bug/409688 - trying to
397
434
        # cherrypick from one branch into another unrelated branch with a
398
435
        # different root id will give shape conflicts.  as a workaround we
399
436
        # make sure they share the same root id.
408
445
        self.write_directive('directive', source.branch, 'target', 'rev2',
409
446
                             'rev1')
410
447
        out, err = self.run_bzr('merge -d target directive')
411
 
        self.failIfExists('target/a')
412
 
        self.failUnlessExists('target/b')
 
448
        self.assertPathDoesNotExist('target/a')
 
449
        self.assertPathExists('target/b')
413
450
        self.assertContainsRe(err, 'Performing cherrypick')
414
451
 
415
452
    def write_directive(self, filename, source, target, revision_id,
450
487
        branch_b.add('file2')
451
488
        branch_b.commit('added file2', rev_id='rev2b')
452
489
        branch_b.merge_from_branch(branch_a.branch)
453
 
        self.failUnlessExists('branch_b/file1')
 
490
        self.assertPathExists('branch_b/file1')
454
491
        branch_b.commit('merged branch_a', rev_id='rev3b')
455
492
 
456
493
        # It works if the revid has an interger revno
457
494
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
458
 
        self.failUnlessExists('target/file1')
459
 
        self.failIfExists('target/file2')
 
495
        self.assertPathExists('target/file1')
 
496
        self.assertPathDoesNotExist('target/file2')
460
497
        target.revert()
461
498
 
462
499
        # It should work if the revid has no integer revno
463
500
        self.run_bzr('merge -d target -r revid:rev2a branch_b')
464
 
        self.failUnlessExists('target/file1')
465
 
        self.failIfExists('target/file2')
 
501
        self.assertPathExists('target/file1')
 
502
        self.assertPathDoesNotExist('target/file2')
466
503
 
467
504
    def assertDirectoryContent(self, directory, entries, message=''):
468
505
        """Assert whether entries (file or directories) exist in a directory.
516
553
 
517
554
    def test_merge_from_submit(self):
518
555
        tree_a = self.make_branch_and_tree('a')
 
556
        tree_a.commit('test')
519
557
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
520
558
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
521
559
        out, err = self.run_bzr(['merge', '-d', 'c'])
522
 
        self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
523
 
        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()
 
563
        try:
 
564
            tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
 
565
        finally:
 
566
            tree_c.branch.unlock()
524
567
        out, err = self.run_bzr(['merge', '-d', 'c'])
525
 
        self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
 
568
        self.assertContainsRe(err,
 
569
                              'Merging from remembered submit location .*b\/')
526
570
 
527
571
    def test_remember_sets_submit(self):
528
572
        tree_a = self.make_branch_and_tree('a')
 
573
        tree_a.commit('rev1')
529
574
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
530
575
        self.assertIs(tree_b.branch.get_submit_branch(), None)
531
576
 
532
577
        # Remember should not happen if using default from parent
533
578
        out, err = self.run_bzr(['merge', '-d', 'b'])
534
 
        self.assertIs(tree_b.branch.get_submit_branch(), None)
 
579
        refreshed = workingtree.WorkingTree.open('b')
 
580
        self.assertIs(refreshed.branch.get_submit_branch(), None)
535
581
 
536
582
        # Remember should happen if user supplies location
537
583
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
538
 
        self.assertEqual(tree_b.branch.get_submit_branch(),
 
584
        refreshed = workingtree.WorkingTree.open('b')
 
585
        self.assertEqual(refreshed.branch.get_submit_branch(),
539
586
                         tree_a.bzrdir.root_transport.base)
540
587
 
 
588
    def test_no_remember_dont_set_submit(self):
 
589
        tree_a = self.make_branch_and_tree('a')
 
590
        self.build_tree_contents([('a/file', "a\n")])
 
591
        tree_a.add('file')
 
592
        tree_a.commit('rev1')
 
593
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
594
        self.assertIs(tree_b.branch.get_submit_branch(), None)
 
595
 
 
596
        # Remember should not happen if using default from parent
 
597
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
 
598
        self.assertEquals(None, tree_b.branch.get_submit_branch())
 
599
 
 
600
        # Remember should not happen if user supplies location but ask for not
 
601
        # remembering it
 
602
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember', 'a'])
 
603
        self.assertEqual(None, tree_b.branch.get_submit_branch())
 
604
 
541
605
    def test_weave_cherrypick(self):
542
606
        this_tree = self.make_branch_and_tree('this')
543
607
        self.build_tree_contents([('this/file', "a\n")])
603
667
        other.add('other_file')
604
668
        other.commit('rev1b')
605
669
        self.run_bzr('merge -d this other -r0..')
606
 
        self.failUnlessExists('this/other_file')
 
670
        self.assertPathExists('this/other_file')
607
671
 
608
672
    def test_merge_interactive_unlocks_branch(self):
609
673
        this = self.make_branch_and_tree('this')
610
 
        other = self.make_branch_and_tree('other')
611
 
        other.commit('empty commit')
 
674
        this.commit('empty commit')
 
675
        other = this.bzrdir.sprout('other').open_workingtree()
 
676
        other.commit('empty commit 2')
612
677
        self.run_bzr('merge -i -d this other')
613
678
        this.lock_write()
614
679
        this.unlock()
615
680
 
616
 
    def test_merge_reversed_revision_range(self):
617
 
        tree = self.make_branch_and_tree(".")
 
681
    def test_merge_fetches_tags(self):
 
682
        """Tags are updated by merge, and revisions named in those tags are
 
683
        fetched.
 
684
        """
 
685
        # Make a source, sprout a target off it
 
686
        builder = self.make_branch_builder('source')
 
687
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
688
        source = builder.get_branch()
 
689
        target_bzrdir = source.bzrdir.sprout('target')
 
690
        # Add a non-ancestry tag to source
 
691
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
 
692
        source.tags.set_tag('tag-a', 'rev-2a')
 
693
        source.set_last_revision_info(1, 'rev-1')
 
694
        source.get_config_stack().set('branch.fetch_tags', True)
 
695
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
 
696
        # Merge from source
 
697
        self.run_bzr('merge -d target source')
 
698
        target = target_bzrdir.open_branch()
 
699
        # The tag is present, and so is its revision.
 
700
        self.assertEqual('rev-2a', target.tags.lookup_tag('tag-a'))
 
701
        target.repository.get_revision('rev-2a')
 
702
 
 
703
 
 
704
class TestMergeRevisionRange(tests.TestCaseWithTransport):
 
705
 
 
706
    scenarios = (('whole-tree', dict(context='.')),
 
707
                 ('file-only', dict(context='a')))
 
708
 
 
709
    def setUp(self):
 
710
        super(TestMergeRevisionRange, self).setUp()
 
711
        self.tree = self.make_branch_and_tree(".")
 
712
        self.tree.commit('initial commit')
618
713
        for f in ("a", "b"):
619
714
            self.build_tree([f])
620
 
            tree.add(f)
621
 
            tree.commit("added "+f)
622
 
        for context in (".", "", "a"):
623
 
            self.run_bzr("merge -r 1..0 " + context)
624
 
            self.failIfExists("a")
625
 
            tree.revert()
626
 
            self.failUnlessExists("a")
627
 
 
 
715
            self.tree.add(f)
 
716
            self.tree.commit("added " + f)
 
717
 
 
718
    def test_merge_reversed_revision_range(self):
 
719
        self.run_bzr("merge -r 2..1 " + self.context)
 
720
        self.assertPathDoesNotExist("a")
 
721
        self.assertPathExists("b")
 
722
 
 
723
 
 
724
class TestMergeScript(script.TestCaseWithTransportAndScript):
 
725
    def test_merge_empty_branch(self):
 
726
        source = self.make_branch_and_tree('source')
 
727
        self.build_tree(['source/a'])
 
728
        source.add('a')
 
729
        source.commit('Added a', rev_id='rev1')
 
730
        target = self.make_branch_and_tree('target')
 
731
        self.run_script("""\
 
732
$ bzr merge -d target source
 
733
2>bzr: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
 
734
""")
628
735
 
629
736
class TestMergeForce(tests.TestCaseWithTransport):
630
737