1
# Copyright (C) 2007, 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
from bzrlib.branchbuilder import BranchBuilder
24
from bzrlib.tests.script import TestCaseWithTransportAndScript
27
class TestReconfigure(TestCaseWithTransportAndScript):
29
def test_no_type(self):
30
branch = self.make_branch('branch')
31
self.run_bzr_error(['No target configuration specified'],
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')
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')
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')
51
tree = self.make_branch_and_tree('tree')
52
self.build_tree(['tree/file'])
54
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
55
'reconfigure --branch tree')
56
self.run_bzr('reconfigure --force --branch tree')
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')
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')
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')
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')
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)
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)
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())
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')
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())
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')
121
def test_make_with_trees_nonshared_repo(self):
122
branch = self.make_branch('branch')
124
["Requested reconfiguration of '.*' is not supported"],
125
'reconfigure --with-trees branch')
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'])
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')
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')]);
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)
156
def test_shared_knit_to_standalone(self):
157
self.test_shared_format_to_standalone('knit')
159
def test_shared_pack092_to_standalone(self):
160
self.test_shared_format_to_standalone('pack-0.92')
162
def test_shared_rich_root_pack_to_standalone(self):
163
self.test_shared_format_to_standalone('rich-root-pack')
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')]);
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')
179
def test_lightweight_knit_checkout_to_tree(self):
180
self.test_lightweight_format_checkout_to_tree('knit')
182
def test_lightweight_pack092_checkout_to_tree(self):
183
self.test_lightweight_format_checkout_to_tree('pack-0.92')
185
def test_lightweight_rich_root_pack_checkout_to_tree(self):
186
self.test_lightweight_format_checkout_to_tree('rich-root-pack')
188
def test_branch_and_use_shared(self):
191
$ echo foo > branch/foo
192
$ bzr add -q branch/foo
193
$ bzr commit -q -m msg branch
195
$ bzr reconfigure --branch --use-shared branch
197
Repository branch (format: ...)
200
repository branch: branch
203
def test_use_shared_and_branch(self):
206
$ echo foo > branch/foo
207
$ bzr add -q branch/foo
208
$ bzr commit -q -m msg branch
210
$ bzr reconfigure --use-shared --branch branch
212
Repository branch (format: ...)
215
repository branch: branch
219
class TestReconfigureStacking(tests.TestCaseWithTransport):
221
def test_reconfigure_stacking(self):
222
"""Test a fairly realistic scenario for stacking:
224
* make a branch with some history
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
231
See discussion in <https://bugs.launchpad.net/bzr/+bug/391411>
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'])
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(),
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)
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.