~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for bzrlib.switch."""
18
18
 
70
70
        os.rename('branch-1', 'branch-2')
71
71
        to_branch = branch.Branch.open('branch-2')
72
72
        # Check fails without --force
73
 
        err = self.assertRaises((errors.NotBranchError,
74
 
            errors.BoundBranchConnectionFailure),
 
73
        err = self.assertRaises(
 
74
            (errors.BzrCommandError, errors.NotBranchError),
75
75
            switch.switch, checkout.bzrdir, to_branch)
 
76
        if isinstance(err, errors.BzrCommandError):
 
77
            self.assertContainsRe(str(err),
 
78
                'Unable to connect to current master branch .*'
 
79
                'To switch anyway, use --force.')
76
80
        switch.switch(checkout.bzrdir, to_branch, force=True)
77
81
        self.failIfExists('checkout/file-1')
78
82
        self.failUnlessExists('checkout/file-2')
96
100
        self.assertContainsRe(str(err),
97
101
            "Pending merges must be committed or reverted before using switch")
98
102
 
 
103
    def test_switch_with_revision(self):
 
104
        """Test switch when a revision is given."""
 
105
        # Create a tree with 2 revisions
 
106
        tree = self.make_branch_and_tree('branch-1')
 
107
        self.build_tree(['branch-1/file-1'])
 
108
        tree.add('file-1')
 
109
        tree.commit(rev_id='rev1', message='rev1')
 
110
        self.build_tree(['branch-1/file-2'])
 
111
        tree.add('file-2')
 
112
        tree.commit(rev_id='rev2', message='rev2')
 
113
        # Check it out and switch to revision 1
 
114
        checkout = tree.branch.create_checkout('checkout',
 
115
            lightweight=self.lightweight)
 
116
        switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
 
117
        self.failUnlessExists('checkout/file-1')
 
118
        self.failIfExists('checkout/file-2')
 
119
 
 
120
    def test_switch_changing_root_id(self):
 
121
        tree = self._setup_tree()
 
122
        tree2 = self.make_branch_and_tree('tree-2')
 
123
        tree2.set_root_id('custom-root-id')
 
124
        self.build_tree(['tree-2/file-2'])
 
125
        tree2.add(['file-2'])
 
126
        tree2.commit('rev1b')
 
127
        checkout = tree.branch.create_checkout('checkout',
 
128
            lightweight=self.lightweight)
 
129
        switch.switch(checkout.bzrdir, tree2.branch)
 
130
        self.assertEqual('custom-root-id', tree2.get_root_id())
 
131
 
99
132
 
100
133
class TestSwitchHeavyweight(TestSwitch):
101
134