~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

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