~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: 2006-04-13 23:16:57 UTC
  • mfrom: (1662.1.1 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060413231657-bce3d67d3e7a4f2b
(mbp/olaf) push/pull/merge --remember improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
28
 
 
29
class TestMerge(ExternalBase):
 
30
 
 
31
    def test_merge_remember(self):
 
32
        """Merge changes from one branch to another and test parent location."""
 
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')
 
48
        # reset parent
 
49
        parent = branch_b.get_parent()
 
50
        branch_b.set_parent(None)
 
51
        self.assertEqual(None, branch_b.get_parent())
 
52
        # test merge for failure without parent set
 
53
        os.chdir('branch_b')
 
54
        out = self.runbzr('merge', retcode=3)
 
55
        self.assertEquals(out,
 
56
                ('','bzr: ERROR: No merge branch known or specified.\n'))
 
57
        # test implicit --remember when no parent set, this merge conflicts
 
58
        self.build_tree(['d'])
 
59
        tree_b.add('d')
 
60
        out = self.runbzr('merge ../branch_a', retcode=3)
 
61
        self.assertEquals(out,
 
62
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
 
63
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
64
        # test implicit --remember after resolving conflict
 
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')
 
73
        # test explicit --remember
 
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')