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
18
branch as _mod_branch,
26
class TestReconfigure(tests.TestCaseWithTransport):
28
def test_tree_to_branch(self):
29
tree = self.make_branch_and_tree('tree')
30
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
31
reconfiguration.apply()
32
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
35
def test_modified_tree_to_branch(self):
36
tree = self.make_branch_and_tree('tree')
37
self.build_tree(['tree/file'])
39
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
40
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
41
reconfiguration.apply(force=True)
42
self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
45
def test_branch_to_branch(self):
46
branch = self.make_branch('branch')
47
self.assertRaises(errors.AlreadyBranch,
48
reconfigure.Reconfigure.to_branch, branch.bzrdir)
50
def test_repo_to_branch(self):
51
repo = self.make_repository('repo')
52
self.assertRaises(errors.ReconfigurationNotSupported,
53
reconfigure.Reconfigure.to_branch, repo.bzrdir)
55
def test_checkout_to_branch(self):
56
branch = self.make_branch('branch')
57
checkout = branch.create_checkout('checkout')
58
reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
59
reconfiguration.apply()
60
self.assertIs(None, checkout.branch.get_bound_location())
62
def test_lightweight_checkout_to_branch(self):
63
branch = self.make_branch('branch')
64
checkout = branch.create_checkout('checkout', lightweight=True)
65
self.assertRaises(errors.ReconfigurationNotSupported,
66
reconfigure.Reconfigure.to_branch, checkout.bzrdir)
68
def test_branch_to_tree(self):
69
branch = self.make_branch('branch')
70
reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
71
reconfiguration.apply()
72
branch.bzrdir.open_workingtree()
74
def test_tree_to_tree(self):
75
tree = self.make_branch_and_tree('tree')
76
self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
79
def test_select_bind_location(self):
80
branch = self.make_branch('branch')
81
reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
82
self.assertRaises(errors.NoBindLocation,
83
reconfiguration._select_bind_location)
84
branch.set_parent('http://parent')
85
self.assertEqual('http://parent',
86
reconfiguration._select_bind_location())
87
branch.set_push_location('sftp://push')
88
self.assertEqual('sftp://push',
89
reconfiguration._select_bind_location())
90
branch.set_bound_location('bzr:old-bound')
91
branch.set_bound_location(None)
92
self.assertEqual('bzr:old-bound',
93
reconfiguration._select_bind_location())
95
def test_tree_to_checkout(self):
96
# A tree with no related branches and no supplied bind location cannot
98
parent = self.make_branch('parent')
100
tree = self.make_branch_and_tree('tree')
101
reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
102
self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
103
# setting a parent allows it to become a checkout
104
tree.branch.set_parent(parent.base)
105
reconfiguration.apply()
106
# supplying a location allows it to become a checkout
107
tree2 = self.make_branch_and_tree('tree2')
108
reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
110
reconfiguration.apply()
112
def test_checkout_to_checkout(self):
113
parent = self.make_branch('parent')
114
checkout = parent.create_checkout('checkout')
115
self.assertRaises(errors.AlreadyCheckout,
116
reconfigure.Reconfigure.to_checkout, checkout.bzrdir)