~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-09-09 15:16:27 UTC
  • mfrom: (4679.2.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090909151627-572a71uyxs8evrex
(vila)(trivial) Cleanup imports in blackbox/test_merge.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import os
23
23
 
24
 
from bzrlib import merge_directive
25
 
from bzrlib.branch import Branch
26
 
from bzrlib.bzrdir import BzrDir
27
 
from bzrlib.conflicts import ConflictList, ContentsConflict
28
 
from bzrlib.osutils import abspath, file_kind, pathjoin
29
 
from bzrlib.tests.blackbox import ExternalBase
30
 
import bzrlib.urlutils as urlutils
31
 
from bzrlib.workingtree import WorkingTree
32
 
 
33
 
 
34
 
class TestMerge(ExternalBase):
 
24
from bzrlib import (
 
25
    branch,
 
26
    bzrdir,
 
27
    conflicts,
 
28
    merge_directive,
 
29
    osutils,
 
30
    tests,
 
31
    urlutils,
 
32
    workingtree,
 
33
    )
 
34
 
 
35
 
 
36
class TestMerge(tests.TestCaseWithTransport):
35
37
 
36
38
    def example_branch(self, path='.'):
37
39
        tree = self.make_branch_and_tree(path)
38
40
        self.build_tree_contents([
39
 
            (pathjoin(path, 'hello'), 'foo'),
40
 
            (pathjoin(path, 'goodbye'), 'baz')])
 
41
            (osutils.pathjoin(path, 'hello'), 'foo'),
 
42
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
41
43
        tree.add('hello')
42
44
        tree.commit(message='setup')
43
45
        tree.add('goodbye')
63
65
        return tree, other
64
66
 
65
67
    def test_merge_reprocess(self):
66
 
        d = BzrDir.create_standalone_workingtree('.')
 
68
        d = bzrdir.BzrDir.create_standalone_workingtree('.')
67
69
        d.commit('h')
68
70
        self.run_bzr('merge . --reprocess --merge-type weave')
69
71
 
70
72
    def test_merge(self):
71
 
        from bzrlib.branch import Branch
72
 
 
73
73
        a_tree = self.example_branch('a')
74
74
        ancestor = a_tree.branch.revno()
75
75
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
80
80
        # We can't merge when there are in-tree changes
81
81
        os.chdir('a')
82
82
        self.run_bzr('merge ../b', retcode=3)
83
 
        a = WorkingTree.open('.')
 
83
        a = workingtree.WorkingTree.open('.')
84
84
        a_tip = a.commit("Like an epidemic of u's")
85
85
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
86
86
                    retcode=3)
99
99
        self.run_bzr('merge ../b -r last:1')
100
100
        self.check_file_contents('goodbye', 'quux')
101
101
        # Merging a branch pulls its revision into the tree
102
 
        b = Branch.open('../b')
 
102
        b = branch.Branch.open('../b')
103
103
        b_tip = b.last_revision()
104
104
        self.failUnless(a.branch.repository.has_revision(b_tip))
105
105
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
249
249
 
250
250
        base = urlutils.local_path_from_url(branch_a.base)
251
251
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
252
 
        self.assertEquals(abspath(branch_b.get_submit_branch()),
253
 
                          abspath(parent))
 
252
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
 
253
                          osutils.abspath(parent))
254
254
        # test implicit --remember when committing new file
255
255
        self.build_tree(['e'])
256
256
        tree_b.add('e')
265
265
        out, err = self.run_bzr('merge ../branch_c --remember')
266
266
        self.assertEquals(out, '')
267
267
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
268
 
        self.assertEquals(abspath(branch_b.get_submit_branch()),
269
 
                          abspath(branch_c.bzrdir.root_transport.base))
 
268
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
 
269
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
270
270
        # re-open tree as external run_bzr modified it
271
271
        tree_b = branch_b.bzrdir.open_workingtree()
272
272
        tree_b.commit('merge branch_c')
294
294
                                              tree_b.get_parent_ids()[0])
295
295
        self.assertEqualDiff(testament_a.as_text(),
296
296
                         testament_b.as_text())
297
 
        tree_a.set_conflicts(ConflictList())
 
297
        tree_a.set_conflicts(conflicts.ConflictList())
298
298
        tree_a.commit('message')
299
299
        # it is legal to attempt to merge an already-merged bundle
300
300
        output = self.run_bzr('merge ../bundle')[1]
349
349
        os.chdir('a')
350
350
        (out, err) = self.run_bzr('merge --pull ../b')
351
351
        self.assertContainsRe(out, 'Now on revision 2\\.')
352
 
        tree_a = WorkingTree.open('.')
 
352
        tree_a = workingtree.WorkingTree.open('.')
353
353
        self.assertEqual([self.id2], tree_a.get_parent_ids())
354
354
 
355
355
    def test_merge_kind_change(self):
363
363
        tree_a.commit('changed file to directory')
364
364
        os.chdir('tree_b')
365
365
        self.run_bzr('merge ../tree_a')
366
 
        self.assertEqual('directory', file_kind('file'))
 
366
        self.assertEqual('directory', osutils.file_kind('file'))
367
367
        tree_b.revert()
368
 
        self.assertEqual('file', file_kind('file'))
 
368
        self.assertEqual('file', osutils.file_kind('file'))
369
369
        self.build_tree_contents([('file', 'content_2')])
370
370
        tree_b.commit('content change')
371
371
        self.run_bzr('merge ../tree_a', retcode=1)
372
372
        self.assertEqual(tree_b.conflicts(),
373
 
                         [ContentsConflict('file', file_id='file-id')])
 
373
                         [conflicts.ContentsConflict('file',
 
374
                                                     file_id='file-id')])
374
375
 
375
376
    def test_directive_cherrypick(self):
376
377
        source = self.make_branch_and_tree('source')
496
497
        out, err = self.run_bzr(['merge', '-d', 'a', 'b'])
497
498
        self.assertContainsRe(err, 'Warning: criss-cross merge encountered.')
498
499
 
499
 
    def test_merge_force(self):
500
 
        tree_a = self.make_branch_and_tree('a')
501
 
        self.build_tree(['a/foo'])
502
 
        tree_a.add(['foo'])
503
 
        tree_a.commit('add file')
504
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
505
 
        self.build_tree_contents([('a/foo', 'change 1')])
506
 
        tree_a.commit('change file')
507
 
        tree_b.merge_from_branch(tree_a.branch)
508
 
        tree_a.commit('empty change to allow merge to run')
509
 
        self.run_bzr(['merge', '../a', '--force'], working_dir='b')
510
 
 
511
500
    def test_merge_from_submit(self):
512
501
        tree_a = self.make_branch_and_tree('a')
513
502
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
560
549
        tree_a.merge_from_branch(tree_b.branch)
561
550
        self.build_tree_contents([('a/file',
562
551
                                   'base-contents\nthis-contents\n')])
563
 
        tree_a.set_conflicts(ConflictList())
 
552
        tree_a.set_conflicts(conflicts.ConflictList())
564
553
        tree_b.merge_from_branch(tree_a.branch)
565
554
        self.build_tree_contents([('b/file',
566
555
                                   'base-contents\nother-contents\n')])
567
 
        tree_b.set_conflicts(ConflictList())
 
556
        tree_b.set_conflicts(conflicts.ConflictList())
568
557
        tree_a.commit('', rev_id='rev3a')
569
558
        tree_b.commit('', rev_id='rev3b')
570
559
        out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
598
587
        other.commit('rev1b')
599
588
        self.run_bzr('merge -d this other -r0..')
600
589
        self.failUnlessExists('this/other_file')
 
590
 
 
591
 
 
592
class TestMergeForce(tests.TestCaseWithTransport):
 
593
 
 
594
    def test_merge_force(self):
 
595
        tree_a = self.make_branch_and_tree('a')
 
596
        self.build_tree(['a/foo'])
 
597
        tree_a.add(['foo'])
 
598
        tree_a.commit('add file')
 
599
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
600
        self.build_tree_contents([('a/foo', 'change 1')])
 
601
        tree_a.commit('change file')
 
602
        tree_b.merge_from_branch(tree_a.branch)
 
603
        tree_a.commit('empty change to allow merge to run')
 
604
        self.run_bzr(['merge', '../a', '--force'], working_dir='b')
 
605
 
 
606