~bzr-pqm/bzr/bzr.dev

4509.3.1 by Martin Pool
Initial failing test for 'reconfigure --stacked-on'
1
# Copyright (C) 2007, 2009 Canonical Ltd
2796.2.5 by Aaron Bentley
Implement reconfigure command
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2796.2.5 by Aaron Bentley
Implement reconfigure command
16
17
from bzrlib import (
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
18
    bzrdir,
2796.2.5 by Aaron Bentley
Implement reconfigure command
19
    errors,
20
    tests,
21
    workingtree,
22
    )
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
23
from bzrlib.branchbuilder import BranchBuilder
6123.8.1 by Martin von Gagern
Expose problems with multiple reconfigure requests.
24
from bzrlib.tests.script import TestCaseWithTransportAndScript
25
26
27
class TestReconfigure(TestCaseWithTransportAndScript):
2796.2.5 by Aaron Bentley
Implement reconfigure command
28
2796.2.15 by Aaron Bentley
More updates from review
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
2796.2.5 by Aaron Bentley
Implement reconfigure command
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
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
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')
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
62
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
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
2846.1.1 by Rob Weir
add blackbox test for 'bzr reconfigure', which now fails.
68
    def test_no_args(self):
69
        branch = self.make_branch('branch')
2846.1.3 by Rob Weir
add check of error text.
70
        self.run_bzr_error(['No target configuration specified'],
71
                           'reconfigure', working_dir='branch')
2796.2.22 by Aaron Bentley
Tweak from review
72
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
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')
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
77
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
78
    def test_standalone_to_use_shared(self):
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
79
        self.build_tree(['repo/'])
80
        tree = self.make_branch_and_tree('repo/tree')
81
        repo = self.make_repository('repo', shared=True)
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
82
        self.run_bzr('reconfigure --use-shared', working_dir='repo/tree')
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
83
        tree = workingtree.WorkingTree.open('repo/tree')
84
        self.assertNotEqual(tree.bzrdir.root_transport.base,
85
            tree.branch.repository.bzrdir.root_transport.base)
86
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
87
    def test_use_shared_to_standalone(self):
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
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)
3921.4.6 by Matthew Fuller
Add blackbox tests for reconfigure {--with-trees,--with-no-trees}.
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')
3921.4.7 by Matthew Fuller
Add a blackbox test for the expected failure trying to change --trees
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')
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
126
127
    def test_make_without_trees_leaves_tree_alone(self):
128
        repo = self.make_repository('repo', shared=True)
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
129
        branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
130
        tree = workingtree.WorkingTree.open('repo/branch')
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
131
        self.build_tree(['repo/branch/foo'])
132
        tree.add('foo')
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
133
        self.run_bzr('reconfigure --with-no-trees --force',
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
134
            working_dir='repo/branch')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
135
        self.assertPathExists('repo/branch/foo')
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
136
        tree = workingtree.WorkingTree.open('repo/branch')
4297.4.1 by Martin von Gagern
Added blackbox tests to expose LP bug #248932.
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')
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
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
6123.8.1 by Martin von Gagern
Expose problems with multiple reconfigure requests.
179
    def test_lightweight_knit_checkout_to_tree(self):
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
180
        self.test_lightweight_format_checkout_to_tree('knit')
181
6123.8.1 by Martin von Gagern
Expose problems with multiple reconfigure requests.
182
    def test_lightweight_pack092_checkout_to_tree(self):
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
183
        self.test_lightweight_format_checkout_to_tree('pack-0.92')
184
6123.8.1 by Martin von Gagern
Expose problems with multiple reconfigure requests.
185
    def test_lightweight_rich_root_pack_checkout_to_tree(self):
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
186
        self.test_lightweight_format_checkout_to_tree('rich-root-pack')
4509.3.1 by Martin Pool
Initial failing test for 'reconfigure --stacked-on'
187
6123.8.1 by Martin von Gagern
Expose problems with multiple reconfigure requests.
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
4509.3.1 by Martin Pool
Initial failing test for 'reconfigure --stacked-on'
218
219
class TestReconfigureStacking(tests.TestCaseWithTransport):
220
4509.3.3 by Martin Pool
Add reconfigure --unstacked command
221
    def test_reconfigure_stacking(self):
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
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
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
231
        See discussion in <https://bugs.launchpad.net/bzr/+bug/391411>
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
232
        """
4509.3.29 by Martin Pool
Correction to comments
233
        # there are also per_branch tests that exercise remote operation etc
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
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')
4509.3.2 by Martin Pool
Very basic support for 'reconfigure --stacked-on'
245
        self.assertContainsRe(out,
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
246
            '^.*/b2/ is now stacked on ../b1\n$')
4509.3.2 by Martin Pool
Very basic support for 'reconfigure --stacked-on'
247
        self.assertEquals('', err)
4509.3.31 by Martin Pool
Additional test for stacking from absolute URL
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)
4509.3.2 by Martin Pool
Very basic support for 'reconfigure --stacked-on'
255
        # It should be given a relative URL to the destination, if possible,
256
        # because that's most likely to work across different transports
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
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')
4509.3.3 by Martin Pool
Add reconfigure --unstacked command
262
        # Now turn it off again
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
263
        out, err = self.run_bzr('reconfigure --unstacked b2')
4509.3.3 by Martin Pool
Add reconfigure --unstacked command
264
        self.assertContainsRe(out,
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
265
            '^.*/b2/ is now not stacked\n$')
4509.3.3 by Martin Pool
Add reconfigure --unstacked command
266
        self.assertEquals('', err)
267
        self.assertRaises(errors.NotStacked,
4509.3.14 by Martin Pool
More realistic and now failing test_reconfigure_stacking
268
            branch_2.get_stacked_on_url)
4509.3.1 by Martin Pool
Initial failing test for 'reconfigure --stacked-on'
269
4509.3.2 by Martin Pool
Very basic support for 'reconfigure --stacked-on'
270
    # XXX: Needs a test for reconfiguring stacking and shape at the same time;
4509.3.29 by Martin Pool
Correction to comments
271
    # no branch at location; stacked-on is not a branch; quiet mode.
4509.3.1 by Martin Pool
Initial failing test for 'reconfigure --stacked-on'
272
    # -- mbp 20090706