~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from bzrlib import (
18
18
    bzrdir,
20
20
    tests,
21
21
    workingtree,
22
22
    )
23
 
 
24
 
 
25
 
class TestReconfigure(tests.TestCaseWithTransport):
 
23
from bzrlib.branchbuilder import BranchBuilder
 
24
from bzrlib.tests.script import TestCaseWithTransportAndScript
 
25
 
 
26
 
 
27
class TestReconfigure(TestCaseWithTransportAndScript):
26
28
 
27
29
    def test_no_type(self):
28
30
        branch = self.make_branch('branch')
58
60
        checkout = branch.create_checkout('checkout', lightweight=True)
59
61
        self.run_bzr('reconfigure --checkout checkout')
60
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
 
61
68
    def test_no_args(self):
62
69
        branch = self.make_branch('branch')
63
70
        self.run_bzr_error(['No target configuration specified'],
86
93
        tree = workingtree.WorkingTree.open('repo/tree')
87
94
        self.assertEqual(tree.bzrdir.root_transport.base,
88
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