1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
17
"""Tests for bzrlib.switch."""
22
from bzrlib import branch, errors, switch, tests
25
class TestSwitch(tests.TestCaseWithTransport):
27
def test_switch_moved(self):
28
tree = self.make_branch_and_tree('branch-1')
29
self.build_tree(['branch-1/file-1'])
32
checkout = tree.branch.create_checkout('checkout', lightweight=True)
33
self.build_tree(['branch-1/file-2'])
37
os.rename('branch-1', 'branch-2')
38
to_branch = branch.Branch.open('branch-2')
39
self.build_tree(['checkout/file-3'])
40
checkout.add('file-3')
41
switch.switch(checkout.bzrdir, to_branch)
42
self.failIfExists('checkout/file-1')
43
self.failUnlessExists('checkout/file-2')
44
self.failUnlessExists('checkout/file-3')
46
def test_switch_old(self):
47
tree = self.make_branch_and_tree('branch-1')
48
self.build_tree(['branch-1/file-1'])
51
to_branch = tree.bzrdir.sprout('branch-2').open_branch()
52
self.build_tree(['branch-1/file-2'])
56
checkout = tree.branch.create_checkout('checkout', lightweight=True)
57
self.build_tree(['checkout/file-3'])
58
checkout.add('file-3')
59
self.failIfExists('checkout/file-1')
60
self.failUnlessExists('checkout/file-2')
61
switch.switch(checkout.bzrdir, to_branch)
62
self.failUnlessExists('checkout/file-1')
63
self.failIfExists('checkout/file-2')
64
self.failUnlessExists('checkout/file-3')
66
def test_switch_heavy_checkout(self):
67
tree = self.make_branch_and_tree('branch-1')
68
self.build_tree(['branch-1/file-1'])
71
tree.branch.create_checkout('checkout-1', lightweight=False)
72
branch2 = self.make_branch('branch-2')
73
err = self.assertRaises(errors.BzrCommandError,
74
switch.switch, tree.bzrdir, branch2)
75
self.assertContainsRe(str(err),
76
"The switch command can only be used on a lightweight checkout")