~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_reconfigure.py

  • Committer: Ian Clatworthy
  • Date: 2007-08-13 14:33:10 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070813143310-twhj4la0qnupvze8
Added Quick Start Summary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from bzrlib import (
18
 
    bzrdir,
19
 
    errors,
20
 
    tests,
21
 
    workingtree,
22
 
    )
23
 
from bzrlib.branchbuilder import BranchBuilder
24
 
from bzrlib.tests.script import TestCaseWithTransportAndScript
25
 
 
26
 
 
27
 
class TestReconfigure(TestCaseWithTransportAndScript):
28
 
 
29
 
    def test_no_type(self):
30
 
        branch = self.make_branch('branch')
31
 
        self.run_bzr_error(['No target configuration specified'],
32
 
                           'reconfigure branch')
33
 
 
34
 
    def test_branch_to_tree(self):
35
 
        branch = self.make_branch('branch')
36
 
        self.run_bzr('reconfigure --tree branch')
37
 
        tree = workingtree.WorkingTree.open('branch')
38
 
 
39
 
    def test_tree_to_branch(self):
40
 
        tree = self.make_branch_and_tree('tree')
41
 
        self.run_bzr('reconfigure --branch tree')
42
 
        self.assertRaises(errors.NoWorkingTree,
43
 
                          workingtree.WorkingTree.open, 'tree')
44
 
 
45
 
    def test_branch_to_specified_checkout(self):
46
 
        branch = self.make_branch('branch')
47
 
        parent = self.make_branch('parent')
48
 
        self.run_bzr('reconfigure branch --checkout --bind-to parent')
49
 
 
50
 
    def test_force(self):
51
 
        tree = self.make_branch_and_tree('tree')
52
 
        self.build_tree(['tree/file'])
53
 
        tree.add('file')
54
 
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
55
 
                            'reconfigure --branch tree')
56
 
        self.run_bzr('reconfigure --force --branch tree')
57
 
 
58
 
    def test_lightweight_checkout_to_checkout(self):
59
 
        branch = self.make_branch('branch')
60
 
        checkout = branch.create_checkout('checkout', lightweight=True)
61
 
        self.run_bzr('reconfigure --checkout checkout')
62
 
 
63
 
    def test_lightweight_checkout_to_tree(self):
64
 
        branch = self.make_branch('branch')
65
 
        checkout = branch.create_checkout('checkout', lightweight=True)
66
 
        self.run_bzr('reconfigure --tree checkout')
67
 
 
68
 
    def test_no_args(self):
69
 
        branch = self.make_branch('branch')
70
 
        self.run_bzr_error(['No target configuration specified'],
71
 
                           'reconfigure', working_dir='branch')
72
 
 
73
 
    def test_checkout_to_lightweight_checkout(self):
74
 
        branch = self.make_branch('branch')
75
 
        checkout = branch.create_checkout('checkout')
76
 
        self.run_bzr('reconfigure --lightweight-checkout checkout')
77
 
 
78
 
    def test_standalone_to_use_shared(self):
79
 
        self.build_tree(['repo/'])
80
 
        tree = self.make_branch_and_tree('repo/tree')
81
 
        repo = self.make_repository('repo', shared=True)
82
 
        self.run_bzr('reconfigure --use-shared', working_dir='repo/tree')
83
 
        tree = workingtree.WorkingTree.open('repo/tree')
84
 
        self.assertNotEqual(tree.bzrdir.root_transport.base,
85
 
            tree.branch.repository.bzrdir.root_transport.base)
86
 
 
87
 
    def test_use_shared_to_standalone(self):
88
 
        repo = self.make_repository('repo', shared=True)
89
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
90
 
        self.assertNotEqual(branch.bzrdir.root_transport.base,
91
 
            branch.repository.bzrdir.root_transport.base)
92
 
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
93
 
        tree = workingtree.WorkingTree.open('repo/tree')
94
 
        self.assertEqual(tree.bzrdir.root_transport.base,
95
 
            tree.branch.repository.bzrdir.root_transport.base)
96
 
 
97
 
    def test_make_with_trees(self):
98
 
        repo = self.make_repository('repo', shared=True)
99
 
        repo.set_make_working_trees(False)
100
 
        self.run_bzr('reconfigure --with-trees', working_dir='repo')
101
 
        self.assertIs(True, repo.make_working_trees())
102
 
 
103
 
    def test_make_with_trees_already_trees(self):
104
 
        repo = self.make_repository('repo', shared=True)
105
 
        repo.set_make_working_trees(True)
106
 
        self.run_bzr_error([" already creates working trees"],
107
 
                            'reconfigure --with-trees repo')
108
 
 
109
 
    def test_make_without_trees(self):
110
 
        repo = self.make_repository('repo', shared=True)
111
 
        repo.set_make_working_trees(True)
112
 
        self.run_bzr('reconfigure --with-no-trees', working_dir='repo')
113
 
        self.assertIs(False, repo.make_working_trees())
114
 
 
115
 
    def test_make_without_trees_already_no_trees(self):
116
 
        repo = self.make_repository('repo', shared=True)
117
 
        repo.set_make_working_trees(False)
118
 
        self.run_bzr_error([" already doesn't create working trees"],
119
 
                            'reconfigure --with-no-trees repo')
120
 
 
121
 
    def test_make_with_trees_nonshared_repo(self):
122
 
        branch = self.make_branch('branch')
123
 
        self.run_bzr_error(
124
 
            ["Requested reconfiguration of '.*' is not supported"],
125
 
            'reconfigure --with-trees branch')
126
 
 
127
 
    def test_make_without_trees_leaves_tree_alone(self):
128
 
        repo = self.make_repository('repo', shared=True)
129
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
130
 
        tree = workingtree.WorkingTree.open('repo/branch')
131
 
        self.build_tree(['repo/branch/foo'])
132
 
        tree.add('foo')
133
 
        self.run_bzr('reconfigure --with-no-trees --force',
134
 
            working_dir='repo/branch')
135
 
        self.assertPathExists('repo/branch/foo')
136
 
        tree = workingtree.WorkingTree.open('repo/branch')
137
 
 
138
 
    def test_shared_format_to_standalone(self, format=None):
139
 
        repo = self.make_repository('repo', shared=True, format=format)
140
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
141
 
        self.assertNotEqual(branch.bzrdir.root_transport.base,
142
 
            branch.repository.bzrdir.root_transport.base)
143
 
        tree = workingtree.WorkingTree.open('repo/tree')
144
 
        self.build_tree_contents([('repo/tree/file', 'foo\n')]);
145
 
        tree.add(['file'])
146
 
        tree.commit('added file')
147
 
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
148
 
        tree = workingtree.WorkingTree.open('repo/tree')
149
 
        self.build_tree_contents([('repo/tree/file', 'bar\n')]);
150
 
        self.check_file_contents('repo/tree/file', 'bar\n')
151
 
        self.run_bzr('revert', working_dir='repo/tree')
152
 
        self.check_file_contents('repo/tree/file', 'foo\n')
153
 
        self.assertEqual(tree.bzrdir.root_transport.base,
154
 
            tree.branch.repository.bzrdir.root_transport.base)
155
 
 
156
 
    def test_shared_knit_to_standalone(self):
157
 
        self.test_shared_format_to_standalone('knit')
158
 
 
159
 
    def test_shared_pack092_to_standalone(self):
160
 
        self.test_shared_format_to_standalone('pack-0.92')
161
 
 
162
 
    def test_shared_rich_root_pack_to_standalone(self):
163
 
        self.test_shared_format_to_standalone('rich-root-pack')
164
 
 
165
 
    def test_lightweight_format_checkout_to_tree(self, format=None):
166
 
        branch = self.make_branch('branch', format=format)
167
 
        checkout = branch.create_checkout('checkout', lightweight=True)
168
 
        tree = workingtree.WorkingTree.open('checkout')
169
 
        self.build_tree_contents([('checkout/file', 'foo\n')]);
170
 
        tree.add(['file'])
171
 
        tree.commit('added file')
172
 
        self.run_bzr('reconfigure --tree', working_dir='checkout')
173
 
        tree = workingtree.WorkingTree.open('checkout')
174
 
        self.build_tree_contents([('checkout/file', 'bar\n')]);
175
 
        self.check_file_contents('checkout/file', 'bar\n')
176
 
        self.run_bzr('revert', working_dir='checkout')
177
 
        self.check_file_contents('checkout/file', 'foo\n')
178
 
 
179
 
    def test_lightweight_knit_checkout_to_tree(self):
180
 
        self.test_lightweight_format_checkout_to_tree('knit')
181
 
 
182
 
    def test_lightweight_pack092_checkout_to_tree(self):
183
 
        self.test_lightweight_format_checkout_to_tree('pack-0.92')
184
 
 
185
 
    def test_lightweight_rich_root_pack_checkout_to_tree(self):
186
 
        self.test_lightweight_format_checkout_to_tree('rich-root-pack')
187
 
 
188
 
    def test_branch_and_use_shared(self):
189
 
        self.run_script("""\
190
 
$ bzr init -q branch
191
 
$ echo foo > branch/foo
192
 
$ bzr add -q branch/foo
193
 
$ bzr commit -q -m msg branch
194
 
$ bzr init-repo -q .
195
 
$ bzr reconfigure --branch --use-shared branch
196
 
$ bzr info branch
197
 
Repository branch (format: ...)
198
 
Location:
199
 
  shared repository: .
200
 
  repository branch: branch
201
 
""")
202
 
 
203
 
    def test_use_shared_and_branch(self):
204
 
        self.run_script("""\
205
 
$ bzr init -q branch
206
 
$ echo foo > branch/foo
207
 
$ bzr add -q branch/foo
208
 
$ bzr commit -q -m msg branch
209
 
$ bzr init-repo -q .
210
 
$ bzr reconfigure --use-shared --branch branch
211
 
$ bzr info branch
212
 
Repository branch (format: ...)
213
 
Location:
214
 
  shared repository: .
215
 
  repository branch: branch
216
 
""")
217
 
 
218
 
 
219
 
class TestReconfigureStacking(tests.TestCaseWithTransport):
220
 
 
221
 
    def test_reconfigure_stacking(self):
222
 
        """Test a fairly realistic scenario for stacking:
223
 
 
224
 
         * make a branch with some history
225
 
         * branch it
226
 
         * make the second branch stacked on the first
227
 
         * commit in the second
228
 
         * then make the second unstacked, so it has to fill in history from
229
 
           the original fallback lying underneath its original content
230
 
 
231
 
        See discussion in <https://bugs.launchpad.net/bzr/+bug/391411>
232
 
        """
233
 
        # there are also per_branch tests that exercise remote operation etc
234
 
        tree_1 = self.make_branch_and_tree('b1', format='2a')
235
 
        self.build_tree(['b1/foo'])
236
 
        tree_1.add(['foo'])
237
 
        tree_1.commit('add foo')
238
 
        branch_1 = tree_1.branch
239
 
        # now branch and commit again
240
 
        bzrdir_2 = tree_1.bzrdir.sprout('b2')
241
 
        tree_2 = bzrdir_2.open_workingtree()
242
 
        branch_2 = tree_2.branch
243
 
        # now reconfigure to be stacked
244
 
        out, err = self.run_bzr('reconfigure --stacked-on b1 b2')
245
 
        self.assertContainsRe(out,
246
 
            '^.*/b2/ is now stacked on ../b1\n$')
247
 
        self.assertEquals('', err)
248
 
        # can also give the absolute URL of the branch, and it gets stored 
249
 
        # as a relative path if possible
250
 
        out, err = self.run_bzr('reconfigure --stacked-on %s b2'
251
 
            % (self.get_url('b1'),))
252
 
        self.assertContainsRe(out,
253
 
            '^.*/b2/ is now stacked on ../b1\n$')
254
 
        self.assertEquals('', err)
255
 
        # It should be given a relative URL to the destination, if possible,
256
 
        # because that's most likely to work across different transports
257
 
        self.assertEquals(branch_2.get_stacked_on_url(),
258
 
            '../b1')
259
 
        # commit, and it should be stored into b2's repo
260
 
        self.build_tree_contents([('foo', 'new foo')])
261
 
        tree_2.commit('update foo')
262
 
        # Now turn it off again
263
 
        out, err = self.run_bzr('reconfigure --unstacked b2')
264
 
        self.assertContainsRe(out,
265
 
            '^.*/b2/ is now not stacked\n$')
266
 
        self.assertEquals('', err)
267
 
        self.assertRaises(errors.NotStacked,
268
 
            branch_2.get_stacked_on_url)
269
 
 
270
 
    # XXX: Needs a test for reconfiguring stacking and shape at the same time;
271
 
    # no branch at location; stacked-on is not a branch; quiet mode.
272
 
    # -- mbp 20090706