~bzr-pqm/bzr/bzr.dev

1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19
"""Black-box tests for bzr merge.
20
"""
21
22
import os
23
24
from bzrlib.branch import Branch
25
from bzrlib.tests.blackbox import ExternalBase
26
from bzrlib.osutils import abspath
27
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
28
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
29
class TestMerge(ExternalBase):
30
31
    def test_merge_remember(self):
32
        """Merge changes from one branch to another and test parent location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
33
        tree_a = self.make_branch_and_tree('branch_a')
34
        branch_a = tree_a.branch
35
        self.build_tree(['branch_a/a'])
36
        tree_a.add('a')
37
        tree_a.commit('commit a')
38
        branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
39
        tree_b = branch_b.bzrdir.open_workingtree()
40
        branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
41
        tree_c = branch_c.bzrdir.open_workingtree()
42
        self.build_tree(['branch_a/b'])
43
        tree_a.add('b')
44
        tree_a.commit('commit b')
45
        self.build_tree(['branch_c/c'])
46
        tree_c.add('c')
47
        tree_c.commit('commit c')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
48
        # reset parent
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
49
        parent = branch_b.get_parent()
50
        branch_b.set_parent(None)
51
        self.assertEqual(None, branch_b.get_parent())
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
52
        # test merge for failure without parent set
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
53
        os.chdir('branch_b')
1614.2.5 by Olaf Conradi
Added testcase for bzr merge --remember.
54
        out = self.runbzr('merge', retcode=3)
55
        self.assertEquals(out,
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
56
                ('','bzr: ERROR: No merge branch known or specified.\n'))
57
        # test implicit --remember when no parent set, this merge conflicts
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
58
        self.build_tree(['d'])
59
        tree_b.add('d')
60
        out = self.runbzr('merge ../branch_a', retcode=3)
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
61
        self.assertEquals(out,
62
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
63
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
64
        # test implicit --remember after resolving conflict
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
65
        tree_b.commit('commit d')
66
        out, err = self.runbzr('merge')
67
        self.assertEquals(out, 'Using saved branch: ../branch_a\n')
68
        self.assertEquals(err, 'All changes applied successfully.\n')
69
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
70
        # re-open tree as external runbzr modified it
71
        tree_b = branch_b.bzrdir.open_workingtree()
72
        tree_b.commit('merge branch_a')
1614.2.6 by Olaf Conradi
Add testcase for --remember when merge fails. It should still remember
73
        # test explicit --remember
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
74
        out, err = self.runbzr('merge ../branch_c --remember')
75
        self.assertEquals(out, '')
76
        self.assertEquals(err, 'All changes applied successfully.\n')
77
        self.assertEquals(abspath(branch_b.get_parent()),
78
                          abspath(branch_c.bzrdir.root_transport.base))
79
        # re-open tree as external runbzr modified it
80
        tree_b = branch_b.bzrdir.open_workingtree()
81
        tree_b.commit('merge branch_c')