~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-07 03:30:29 UTC
  • mfrom: (3079.1.1 criss-cross)
  • Revision ID: pqm@pqm.ubuntu.com-20071207033029-7tx9ezbg3nlk3io1
(Alexander Belchenko) topic for criss-cross should have title,
        otherwise autogenerated bzr_man has problems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
from bzrlib import (
 
18
    branch as _mod_branch,
 
19
    errors,
 
20
    reconfigure,
 
21
    tests,
 
22
    workingtree,
 
23
    )
 
24
 
 
25
 
 
26
class TestReconfigure(tests.TestCaseWithTransport):
 
27
 
 
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,
 
33
                          'tree')
 
34
 
 
35
    def test_modified_tree_to_branch(self):
 
36
        tree = self.make_branch_and_tree('tree')
 
37
        self.build_tree(['tree/file'])
 
38
        tree.add('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,
 
43
                          'tree')
 
44
 
 
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)
 
49
 
 
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)
 
54
 
 
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())
 
61
 
 
62
    def test_lightweight_checkout_to_branch(self):
 
63
        branch = self.make_branch('branch')
 
64
        checkout = branch.create_checkout('checkout', lightweight=True)
 
65
        checkout.commit('first commit', rev_id='rev1')
 
66
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
67
        reconfiguration.apply()
 
68
        checkout_branch = checkout.bzrdir.open_branch()
 
69
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
 
70
                         checkout.bzrdir.root_transport.base)
 
71
        self.assertEqual('rev1', checkout_branch.last_revision())
 
72
        repo = checkout.bzrdir.open_repository()
 
73
        repo.get_revision('rev1')
 
74
 
 
75
    def test_lightweight_checkout_to_checkout(self):
 
76
        branch = self.make_branch('branch')
 
77
        checkout = branch.create_checkout('checkout', lightweight=True)
 
78
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
 
79
        reconfiguration.apply()
 
80
        checkout_branch = checkout.bzrdir.open_branch()
 
81
        self.assertIsNot(checkout_branch.get_bound_location(), None)
 
82
 
 
83
    def test_lightweight_conversion_uses_shared_repo(self):
 
84
        parent = self.make_branch('parent')
 
85
        shared_repo = self.make_repository('repo', shared=True)
 
86
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
 
87
        reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
 
88
        checkout_repo = checkout.bzrdir.open_branch().repository
 
89
        self.assertEqual(shared_repo.bzrdir.root_transport.base,
 
90
                         checkout_repo.bzrdir.root_transport.base)
 
91
 
 
92
    def test_branch_to_tree(self):
 
93
        branch = self.make_branch('branch')
 
94
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
 
95
        reconfiguration.apply()
 
96
        branch.bzrdir.open_workingtree()
 
97
 
 
98
    def test_tree_to_tree(self):
 
99
        tree = self.make_branch_and_tree('tree')
 
100
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
 
101
                          tree.bzrdir)
 
102
 
 
103
    def test_select_bind_location(self):
 
104
        branch = self.make_branch('branch')
 
105
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
106
        self.assertRaises(errors.NoBindLocation,
 
107
                          reconfiguration._select_bind_location)
 
108
        branch.set_parent('http://parent')
 
109
        self.assertEqual('http://parent',
 
110
                         reconfiguration._select_bind_location())
 
111
        branch.set_push_location('sftp://push')
 
112
        self.assertEqual('sftp://push',
 
113
                         reconfiguration._select_bind_location())
 
114
        branch.set_bound_location('bzr://foo/old-bound')
 
115
        branch.set_bound_location(None)
 
116
        self.assertEqual('bzr://foo/old-bound',
 
117
                         reconfiguration._select_bind_location())
 
118
        branch.set_bound_location('bzr://foo/cur-bound')
 
119
        self.assertEqual('bzr://foo/cur-bound',
 
120
                         reconfiguration._select_bind_location())
 
121
        reconfiguration.new_bound_location = 'ftp://user-specified'
 
122
        self.assertEqual('ftp://user-specified',
 
123
                         reconfiguration._select_bind_location())
 
124
 
 
125
    def test_select_reference_bind_location(self):
 
126
        branch = self.make_branch('branch')
 
127
        checkout = branch.create_checkout('checkout', lightweight=True)
 
128
        reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
 
129
        self.assertEqual(branch.base,
 
130
                         reconfiguration._select_bind_location())
 
131
 
 
132
    def test_tree_to_checkout(self):
 
133
        # A tree with no related branches and no supplied bind location cannot
 
134
        # become a checkout
 
135
        parent = self.make_branch('parent')
 
136
 
 
137
        tree = self.make_branch_and_tree('tree')
 
138
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
 
139
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
140
        # setting a parent allows it to become a checkout
 
141
        tree.branch.set_parent(parent.base)
 
142
        reconfiguration.apply()
 
143
        # supplying a location allows it to become a checkout
 
144
        tree2 = self.make_branch_and_tree('tree2')
 
145
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
 
146
                                                              parent.base)
 
147
        reconfiguration.apply()
 
148
 
 
149
    def test_checkout_to_checkout(self):
 
150
        parent = self.make_branch('parent')
 
151
        checkout = parent.create_checkout('checkout')
 
152
        self.assertRaises(errors.AlreadyCheckout,
 
153
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
 
154
 
 
155
    def test_checkout_to_lightweight(self):
 
156
        parent = self.make_branch('parent')
 
157
        checkout = parent.create_checkout('checkout')
 
158
        checkout.commit('test', rev_id='new-commit', local=True)
 
159
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
160
            checkout.bzrdir)
 
161
        reconfiguration.apply()
 
162
        wt = checkout.bzrdir.open_workingtree()
 
163
        self.assertTrue(parent.repository.has_same_location(
 
164
            wt.branch.repository))
 
165
        parent.repository.get_revision('new-commit')
 
166
        self.assertRaises(errors.NoRepositoryPresent,
 
167
                          checkout.bzrdir.open_repository)
 
168
 
 
169
    def test_branch_to_lightweight_checkout(self):
 
170
        parent = self.make_branch('parent')
 
171
        child = parent.bzrdir.sprout('child').open_workingtree()
 
172
        child.commit('test', rev_id='new-commit')
 
173
        child.bzrdir.destroy_workingtree()
 
174
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
175
            child.bzrdir)
 
176
        reconfiguration.apply()
 
177
        wt = child.bzrdir.open_workingtree()
 
178
        self.assertTrue(parent.repository.has_same_location(
 
179
            wt.branch.repository))
 
180
        parent.repository.get_revision('new-commit')
 
181
        self.assertRaises(errors.NoRepositoryPresent,
 
182
                          child.bzrdir.open_repository)
 
183
 
 
184
    def test_lightweight_checkout_to_lightweight_checkout(self):
 
185
        parent = self.make_branch('parent')
 
186
        checkout = parent.create_checkout('checkout', lightweight=True)
 
187
        self.assertRaises(errors.AlreadyLightweightCheckout,
 
188
                          reconfigure.Reconfigure.to_lightweight_checkout,
 
189
                          checkout.bzrdir)