~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2010-01-20 22:32:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4977.
  • Revision ID: jelmer@samba.org-20100120223207-pfz89u161ahyzvnt
Add FileTimestampUnavailable exception.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
23
22
import os
24
23
 
25
 
from testtools import matchers
26
 
 
27
24
from bzrlib import (
28
25
    branch,
 
26
    bzrdir,
29
27
    conflicts,
30
 
    controldir,
 
28
    errors,
31
29
    merge_directive,
32
30
    osutils,
33
31
    tests,
34
32
    urlutils,
35
33
    workingtree,
36
34
    )
37
 
from bzrlib.tests import (
38
 
    scenarios,
39
 
    script,
40
 
    )
41
 
 
42
 
 
43
 
load_tests = scenarios.load_tests_apply_scenarios
44
35
 
45
36
 
46
37
class TestMerge(tests.TestCaseWithTransport):
75
66
        return tree, other
76
67
 
77
68
    def test_merge_reprocess(self):
78
 
        d = controldir.ControlDir.create_standalone_workingtree('.')
 
69
        d = bzrdir.BzrDir.create_standalone_workingtree('.')
79
70
        d.commit('h')
80
71
        self.run_bzr('merge . --reprocess --merge-type weave')
81
72
 
88
79
 
89
80
        self.build_tree_contents([('a/hello', 'quuux')])
90
81
        # We can't merge when there are in-tree changes
91
 
        self.run_bzr('merge ../b', retcode=3, working_dir='a')
92
 
        a = workingtree.WorkingTree.open('a')
 
82
        os.chdir('a')
 
83
        self.run_bzr('merge ../b', retcode=3)
 
84
        a = workingtree.WorkingTree.open('.')
93
85
        a_tip = a.commit("Like an epidemic of u's")
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'])
 
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)
105
94
        self.run_bzr_error(['Show-base is not supported for this merge type'],
106
95
                           'merge ../b -r last:1..last:1 --merge-type weave'
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')
 
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')
114
102
        # Merging a branch pulls its revision into the tree
115
 
        b = branch.Branch.open('b')
 
103
        b = branch.Branch.open('../b')
116
104
        b_tip = b.last_revision()
117
 
        self.assertTrue(a.branch.repository.has_revision(b_tip))
 
105
        self.failUnless(a.branch.repository.has_revision(b_tip))
118
106
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
119
107
        a_tree.revert(backups=False)
120
 
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3,
121
 
                                working_dir='a')
 
108
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
122
109
        self.assertTrue("Not a branch" in err)
123
110
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
124
 
                    %(ancestor,b.revno()), working_dir='a')
 
111
                    %(ancestor,b.revno()))
125
112
        self.assertEquals(a.get_parent_ids(),
126
113
                          [a.branch.last_revision(), b.last_revision()])
127
 
        self.check_file_contents('a/goodbye', 'quux')
 
114
        self.check_file_contents('goodbye', 'quux')
128
115
        a_tree.revert(backups=False)
129
 
        self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
 
116
        self.run_bzr('merge -r revno:%d:../b'%b.revno())
130
117
        self.assertEquals(a.get_parent_ids(),
131
118
                          [a.branch.last_revision(), b.last_revision()])
132
119
        a_tip = a.commit('merged')
133
 
        self.run_bzr('merge ../b -r last:1', working_dir='a')
 
120
        self.run_bzr('merge ../b -r last:1')
134
121
        self.assertEqual([a_tip], a.get_parent_ids())
135
122
 
136
123
    def test_merge_defaults_to_reprocess(self):
215
202
            ('b/b.txt', 'hello\nsomething\n'),
216
203
            ('b/sub/c.txt', 'hello\nsomething\n')])
217
204
        b_tree.commit(message='Modified a.txt')
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')
 
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')
226
213
 
227
214
    def test_conflict_leaves_base_this_other_files(self):
228
215
        tree, other = self.create_conflicting_branches()
262
249
        branch_b.set_parent(None)
263
250
        self.assertEqual(None, branch_b.get_parent())
264
251
        # test merge for failure without parent set
265
 
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
 
252
        os.chdir('branch_b')
 
253
        out = self.run_bzr('merge', retcode=3)
266
254
        self.assertEquals(out,
267
255
                ('','bzr: ERROR: No location specified or remembered\n'))
268
256
 
269
257
        # test uncommitted changes
270
 
        self.build_tree(['branch_b/d'])
 
258
        self.build_tree(['d'])
271
259
        tree_b.add('d')
272
260
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
273
 
                           'merge', working_dir='branch_b')
 
261
                           'merge')
274
262
 
275
263
        # merge should now pass and implicitly remember merge location
276
264
        tree_b.commit('commit d')
277
 
        out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
 
265
        out, err = self.run_bzr('merge ../branch_a')
278
266
 
279
267
        base = urlutils.local_path_from_url(branch_a.base)
280
268
        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()
283
269
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
284
270
                          osutils.abspath(parent))
285
271
        # test implicit --remember when committing new file
286
 
        self.build_tree(['branch_b/e'])
 
272
        self.build_tree(['e'])
287
273
        tree_b.add('e')
288
274
        tree_b.commit('commit e')
289
 
        out, err = self.run_bzr('merge', working_dir='branch_b')
290
 
        self.assertStartsWith(
291
 
            err, 'Merging from remembered submit location %s\n' % (base,))
 
275
        out, err = self.run_bzr('merge')
 
276
        self.assertStartsWith(err,
 
277
                          'Merging from remembered submit location %s\n' % (base,))
292
278
        # re-open tree as external run_bzr modified it
293
279
        tree_b = branch_b.bzrdir.open_workingtree()
294
280
        tree_b.commit('merge branch_a')
295
281
        # test explicit --remember
296
 
        out, err = self.run_bzr('merge ../branch_c --remember',
297
 
                                working_dir='branch_b')
 
282
        out, err = self.run_bzr('merge ../branch_c --remember')
298
283
        self.assertEquals(out, '')
299
284
        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
285
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
303
286
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
304
287
        # re-open tree as external run_bzr modified it
318
301
 
319
302
        self.build_tree_contents([('branch_b/a', 'goodbye')])
320
303
        tree_b.commit('message')
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')
 
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)
323
308
        testament_a = Testament.from_revision(tree_a.branch.repository,
324
309
                                              tree_b.get_parent_ids()[0])
325
310
        testament_b = Testament.from_revision(tree_b.branch.repository,
329
314
        tree_a.set_conflicts(conflicts.ConflictList())
330
315
        tree_a.commit('message')
331
316
        # it is legal to attempt to merge an already-merged bundle
332
 
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
 
317
        output = self.run_bzr('merge ../bundle')[1]
333
318
        # but it does nothing
334
319
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
335
 
        self.assertEqual('Nothing to do.\n', err)
 
320
        self.assertEqual('Nothing to do.\n', output)
336
321
 
337
322
    def test_merge_uncommitted(self):
338
323
        """Check that merge --uncommitted behaves properly"""
341
326
        tree_a.add(['file_1', 'file_2'])
342
327
        tree_a.commit('commit 1')
343
328
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
344
 
        self.assertPathExists('b/file_1')
 
329
        self.failUnlessExists('b/file_1')
345
330
        tree_a.rename_one('file_1', 'file_i')
346
331
        tree_a.commit('commit 2')
347
332
        tree_a.rename_one('file_2', 'file_ii')
 
333
        ## os.chdir('b')
348
334
        self.run_bzr('merge a --uncommitted -d b')
349
 
        self.assertPathExists('b/file_1')
350
 
        self.assertPathExists('b/file_ii')
 
335
        self.failUnlessExists('b/file_1')
 
336
        self.failUnlessExists('b/file_ii')
351
337
        tree_b.revert()
352
338
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
353
339
                           'merge /a --uncommitted -r1 -d b')
359
345
        tree_a.bzrdir.sprout('tree_b')
360
346
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
361
347
        tree_a.add(['file1', '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')
 
348
        os.chdir('tree_b')
 
349
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
 
350
        self.failUnlessExists('file1')
 
351
        self.failIfExists('file2')
376
352
 
377
353
    def pullable_branch(self):
378
354
        tree_a = self.make_branch_and_tree('a')
379
 
        self.build_tree_contents([('a/file', 'bar\n')])
 
355
        self.build_tree(['a/file'])
380
356
        tree_a.add(['file'])
381
357
        self.id1 = tree_a.commit('commit 1')
382
358
 
383
359
        tree_b = self.make_branch_and_tree('b')
384
360
        tree_b.pull(tree_a.branch)
385
 
        self.build_tree_contents([('b/file', 'foo\n')])
 
361
        file('b/file', 'wb').write('foo')
386
362
        self.id2 = tree_b.commit('commit 2')
387
363
 
388
364
    def test_merge_pull(self):
389
365
        self.pullable_branch()
390
 
        (out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
 
366
        os.chdir('a')
 
367
        (out, err) = self.run_bzr('merge --pull ../b')
391
368
        self.assertContainsRe(out, 'Now on revision 2\\.')
392
 
        tree_a = workingtree.WorkingTree.open('a')
 
369
        tree_a = workingtree.WorkingTree.open('.')
393
370
        self.assertEqual([self.id2], tree_a.get_parent_ids())
394
371
 
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
 
 
410
372
    def test_merge_kind_change(self):
411
373
        tree_a = self.make_branch_and_tree('tree_a')
412
374
        self.build_tree_contents([('tree_a/file', 'content_1')])
416
378
        os.unlink('tree_a/file')
417
379
        self.build_tree(['tree_a/file/'])
418
380
        tree_a.commit('changed file to directory')
419
 
        self.run_bzr('merge ../tree_a', working_dir='tree_b')
420
 
        self.assertEqual('directory', osutils.file_kind('tree_b/file'))
 
381
        os.chdir('tree_b')
 
382
        self.run_bzr('merge ../tree_a')
 
383
        self.assertEqual('directory', osutils.file_kind('file'))
421
384
        tree_b.revert()
422
 
        self.assertEqual('file', osutils.file_kind('tree_b/file'))
423
 
        self.build_tree_contents([('tree_b/file', 'content_2')])
 
385
        self.assertEqual('file', osutils.file_kind('file'))
 
386
        self.build_tree_contents([('file', 'content_2')])
424
387
        tree_b.commit('content change')
425
 
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
 
388
        self.run_bzr('merge ../tree_a', retcode=1)
426
389
        self.assertEqual(tree_b.conflicts(),
427
390
                         [conflicts.ContentsConflict('file',
428
391
                                                     file_id='file-id')])
430
393
    def test_directive_cherrypick(self):
431
394
        source = self.make_branch_and_tree('source')
432
395
        source.commit("nothing")
433
 
        # see https://bugs.launchpad.net/bzr/+bug/409688 - trying to
 
396
        # see https://bugs.edge.launchpad.net/bzr/+bug/409688 - trying to
434
397
        # cherrypick from one branch into another unrelated branch with a
435
398
        # different root id will give shape conflicts.  as a workaround we
436
399
        # make sure they share the same root id.
445
408
        self.write_directive('directive', source.branch, 'target', 'rev2',
446
409
                             'rev1')
447
410
        out, err = self.run_bzr('merge -d target directive')
448
 
        self.assertPathDoesNotExist('target/a')
449
 
        self.assertPathExists('target/b')
 
411
        self.failIfExists('target/a')
 
412
        self.failUnlessExists('target/b')
450
413
        self.assertContainsRe(err, 'Performing cherrypick')
451
414
 
452
415
    def write_directive(self, filename, source, target, revision_id,
487
450
        branch_b.add('file2')
488
451
        branch_b.commit('added file2', rev_id='rev2b')
489
452
        branch_b.merge_from_branch(branch_a.branch)
490
 
        self.assertPathExists('branch_b/file1')
 
453
        self.failUnlessExists('branch_b/file1')
491
454
        branch_b.commit('merged branch_a', rev_id='rev3b')
492
455
 
493
456
        # It works if the revid has an interger revno
494
457
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
495
 
        self.assertPathExists('target/file1')
496
 
        self.assertPathDoesNotExist('target/file2')
 
458
        self.failUnlessExists('target/file1')
 
459
        self.failIfExists('target/file2')
497
460
        target.revert()
498
461
 
499
462
        # It should work if the revid has no integer revno
500
463
        self.run_bzr('merge -d target -r revid:rev2a branch_b')
501
 
        self.assertPathExists('target/file1')
502
 
        self.assertPathDoesNotExist('target/file2')
 
464
        self.failUnlessExists('target/file1')
 
465
        self.failIfExists('target/file2')
503
466
 
504
467
    def assertDirectoryContent(self, directory, entries, message=''):
505
468
        """Assert whether entries (file or directories) exist in a directory.
553
516
 
554
517
    def test_merge_from_submit(self):
555
518
        tree_a = self.make_branch_and_tree('a')
556
 
        tree_a.commit('test')
557
519
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
558
520
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
559
521
        out, err = self.run_bzr(['merge', '-d', 'c'])
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()
 
522
        self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
 
523
        tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
567
524
        out, err = self.run_bzr(['merge', '-d', 'c'])
568
 
        self.assertContainsRe(err,
569
 
                              'Merging from remembered submit location .*b\/')
 
525
        self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
570
526
 
571
527
    def test_remember_sets_submit(self):
572
528
        tree_a = self.make_branch_and_tree('a')
573
 
        tree_a.commit('rev1')
574
529
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
575
530
        self.assertIs(tree_b.branch.get_submit_branch(), None)
576
531
 
577
532
        # Remember should not happen if using default from parent
578
533
        out, err = self.run_bzr(['merge', '-d', 'b'])
579
 
        refreshed = workingtree.WorkingTree.open('b')
580
 
        self.assertIs(refreshed.branch.get_submit_branch(), None)
 
534
        self.assertIs(tree_b.branch.get_submit_branch(), None)
581
535
 
582
536
        # Remember should happen if user supplies location
583
537
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
584
 
        refreshed = workingtree.WorkingTree.open('b')
585
 
        self.assertEqual(refreshed.branch.get_submit_branch(),
 
538
        self.assertEqual(tree_b.branch.get_submit_branch(),
586
539
                         tree_a.bzrdir.root_transport.base)
587
540
 
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
 
 
605
541
    def test_weave_cherrypick(self):
606
542
        this_tree = self.make_branch_and_tree('this')
607
543
        self.build_tree_contents([('this/file', "a\n")])
667
603
        other.add('other_file')
668
604
        other.commit('rev1b')
669
605
        self.run_bzr('merge -d this other -r0..')
670
 
        self.assertPathExists('this/other_file')
 
606
        self.failUnlessExists('this/other_file')
671
607
 
672
608
    def test_merge_interactive_unlocks_branch(self):
673
609
        this = self.make_branch_and_tree('this')
674
 
        this.commit('empty commit')
675
 
        other = this.bzrdir.sprout('other').open_workingtree()
676
 
        other.commit('empty commit 2')
 
610
        other = self.make_branch_and_tree('other')
 
611
        other.commit('empty commit')
677
612
        self.run_bzr('merge -i -d this other')
678
613
        this.lock_write()
679
614
        this.unlock()
680
615
 
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')
 
616
    def test_merge_reversed_revision_range(self):
 
617
        tree = self.make_branch_and_tree(".")
713
618
        for f in ("a", "b"):
714
619
            self.build_tree([f])
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
 
""")
 
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
 
735
628
 
736
629
class TestMergeForce(tests.TestCaseWithTransport):
737
630