~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

Merge repository so I dont trample on myself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        """See BzrDir.create_repository."""
67
67
        return "A repository"
68
68
 
 
69
    def open_repository(self):
 
70
        """See BzrDir.open_repository."""
 
71
        return "A repository"
 
72
 
69
73
    def create_branch(self):
70
74
        """See BzrDir.create_branch."""
71
75
        return SampleBranch(self)
157
161
        finally:
158
162
            bzrdir.BzrDirFormat.set_default_format(old_format)
159
163
 
160
 
    def test_create_branch_and_repo(self):
 
164
    def test_create_repository_under_shared(self):
 
165
        # an explicit create_repository always does so.
 
166
        # we trust the format is right from the 'create_repository test'
 
167
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
168
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
169
        try:
 
170
            self.make_repository('.', shared=True)
 
171
            repo = bzrdir.BzrDir.create_repository(self.get_url('child'))
 
172
            self.assertTrue(isinstance(repo, repository.Repository))
 
173
            self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
 
174
        finally:
 
175
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
176
 
 
177
    def test_create_branch_and_repo_uses_default(self):
161
178
        format = SampleBzrDirFormat()
162
179
        old_format = bzrdir.BzrDirFormat.get_default_format()
163
180
        bzrdir.BzrDirFormat.set_default_format(format)
167
184
        finally:
168
185
            bzrdir.BzrDirFormat.set_default_format(old_format)
169
186
 
 
187
    def test_create_branch_and_repo_under_shared(self):
 
188
        # creating a branch and repo in a shared repo uses the
 
189
        # shared repository
 
190
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
191
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
192
        try:
 
193
            self.make_repository('.', shared=True)
 
194
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'))
 
195
            self.assertRaises(errors.NoRepositoryPresent,
 
196
                              branch.bzrdir.open_repository)
 
197
        finally:
 
198
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
199
 
 
200
    def test_create_branch_and_repo_under_shared_force_new(self):
 
201
        # creating a branch and repo in a shared repo can be forced to 
 
202
        # make a new repo
 
203
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
204
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
205
        try:
 
206
            self.make_repository('.', shared=True)
 
207
            branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
 
208
                                                          force_new_repo=True)
 
209
            branch.bzrdir.open_repository()
 
210
        finally:
 
211
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
212
 
170
213
    def test_create_standalone_working_tree(self):
171
214
        format = SampleBzrDirFormat()
172
215
        old_format = bzrdir.BzrDirFormat.get_default_format()
182
225
        finally:
183
226
            bzrdir.BzrDirFormat.set_default_format(old_format)
184
227
 
 
228
    def test_create_standalone_working_tree_under_shared_repo(self):
 
229
        # create standalone working tree always makes a repo.
 
230
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
231
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
232
        try:
 
233
            self.make_repository('.', shared=True)
 
234
            # note this is deliberately readonly, as this failure should 
 
235
            # occur before any writes.
 
236
            self.assertRaises(errors.NotLocalUrl,
 
237
                              bzrdir.BzrDir.create_standalone_workingtree,
 
238
                              self.get_readonly_url('child'))
 
239
            tree = bzrdir.BzrDir.create_standalone_workingtree('child')
 
240
            tree.bzrdir.open_repository()
 
241
        finally:
 
242
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
243
 
 
244
    def test_create_branch_convenience(self):
 
245
        # outside a repo the default conveniencec output is a repo+branch_tree
 
246
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
247
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
248
        try:
 
249
            branch = bzrdir.BzrDir.create_branch_convenience('.')
 
250
            branch.bzrdir.open_workingtree()
 
251
            branch.bzrdir.open_repository()
 
252
        finally:
 
253
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
254
 
 
255
    def test_create_branch_convenience_under_shared_repo(self):
 
256
        # inside a repo the default convenience output is a branch+ follow the
 
257
        # repo tree policy
 
258
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
259
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
260
        try:
 
261
            self.make_repository('.', shared=True)
 
262
            branch = bzrdir.BzrDir.create_branch_convenience('child')
 
263
            branch.bzrdir.open_workingtree()
 
264
            self.assertRaises(errors.NoRepositoryPresent,
 
265
                              branch.bzrdir.open_repository)
 
266
        finally:
 
267
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
268
            
 
269
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
 
270
        # inside a repo the default convenience output is a branch+ follow the
 
271
        # repo tree policy but we can override that
 
272
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
273
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
274
        try:
 
275
            self.make_repository('.', shared=True)
 
276
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
277
                force_new_tree=False)
 
278
            self.assertRaises(errors.NoWorkingTree,
 
279
                              branch.bzrdir.open_workingtree)
 
280
            self.assertRaises(errors.NoRepositoryPresent,
 
281
                              branch.bzrdir.open_repository)
 
282
        finally:
 
283
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
284
            
 
285
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
 
286
        # inside a repo the default convenience output is a branch+ follow the
 
287
        # repo tree policy
 
288
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
289
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
290
        try:
 
291
            repo = self.make_repository('.', shared=True)
 
292
            repo.set_make_working_trees(False)
 
293
            branch = bzrdir.BzrDir.create_branch_convenience('child')
 
294
            self.assertRaises(errors.NoWorkingTree,
 
295
                              branch.bzrdir.open_workingtree)
 
296
            self.assertRaises(errors.NoRepositoryPresent,
 
297
                              branch.bzrdir.open_repository)
 
298
        finally:
 
299
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
300
 
 
301
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
 
302
        # inside a repo the default convenience output is a branch+ follow the
 
303
        # repo tree policy but we can override that
 
304
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
305
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
306
        try:
 
307
            repo = self.make_repository('.', shared=True)
 
308
            repo.set_make_working_trees(False)
 
309
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
310
                force_new_tree=True)
 
311
            branch.bzrdir.open_workingtree()
 
312
            self.assertRaises(errors.NoRepositoryPresent,
 
313
                              branch.bzrdir.open_repository)
 
314
        finally:
 
315
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
316
 
 
317
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
 
318
        # inside a repo the default convenience output is overridable to give
 
319
        # repo+branch+tree
 
320
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
321
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
322
        try:
 
323
            self.make_repository('.', shared=True)
 
324
            branch = bzrdir.BzrDir.create_branch_convenience('child',
 
325
                force_new_repo=True)
 
326
            branch.bzrdir.open_repository()
 
327
            branch.bzrdir.open_workingtree()
 
328
        finally:
 
329
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
330
 
185
331
 
186
332
class ChrootedTests(TestCaseWithTransport):
187
333
    """A support class that provides readonly urls outside the local namespace.
207
353
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
208
354
        self.assertEqual('g/p/q', relpath)
209
355
 
 
356
    def test_open_containing_transport(self):
 
357
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_transport,
 
358
                          get_transport(self.get_readonly_url('')))
 
359
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_transport,
 
360
                          get_transport(self.get_readonly_url('g/p/q')))
 
361
        control = bzrdir.BzrDir.create(self.get_url())
 
362
        branch, relpath = bzrdir.BzrDir.open_containing_transport(
 
363
            get_transport(self.get_readonly_url('')))
 
364
        self.assertEqual('', relpath)
 
365
        branch, relpath = bzrdir.BzrDir.open_containing_transport(
 
366
            get_transport(self.get_readonly_url('g/p/q')))
 
367
        self.assertEqual('g/p/q', relpath)
 
368
 
210
369
 
211
370
class TestMeta1DirFormat(TestCaseWithTransport):
212
371
    """Tests specific to the meta1 dir format."""