~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

Merge with shallow-branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
        self.make_branch_and_tree('bar')
201
201
 
202
202
 
203
 
class TestBranch6(TestCaseWithTransport):
 
203
class TestBranch67(object):
 
204
    """Common tests for both branch 6 and 7 which are mostly the same."""
 
205
 
 
206
    def get_format_name(self):
 
207
        raise NotImplementedError(self.get_format_name)
 
208
 
 
209
    def get_format_name_subtree(self):
 
210
        raise NotImplementedError(self.get_format_name)
 
211
 
 
212
    def get_class(self):
 
213
        raise NotImplementedError(self.get_class)
204
214
 
205
215
    def test_creation(self):
206
216
        format = BzrDirMetaFormat1()
207
217
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
208
218
        branch = self.make_branch('a', format=format)
209
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
210
 
        branch = self.make_branch('b', format='dirstate-tags')
211
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
219
        self.assertIsInstance(branch, self.get_class())
 
220
        branch = self.make_branch('b', format=self.get_format_name())
 
221
        self.assertIsInstance(branch, self.get_class())
212
222
        branch = _mod_branch.Branch.open('a')
213
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
223
        self.assertIsInstance(branch, self.get_class())
214
224
 
215
225
    def test_layout(self):
216
 
        branch = self.make_branch('a', format='dirstate-tags')
 
226
        branch = self.make_branch('a', format=self.get_format_name())
217
227
        self.failUnlessExists('a/.bzr/branch/last-revision')
218
228
        self.failIfExists('a/.bzr/branch/revision-history')
219
229
 
220
230
    def test_config(self):
221
231
        """Ensure that all configuration data is stored in the branch"""
222
 
        branch = self.make_branch('a', format='dirstate-tags')
 
232
        branch = self.make_branch('a', format=self.get_format_name())
223
233
        branch.set_parent('http://bazaar-vcs.org')
224
234
        self.failIfExists('a/.bzr/branch/parent')
225
235
        self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
233
243
 
234
244
    def test_set_revision_history(self):
235
245
        tree = self.make_branch_and_memory_tree('.',
236
 
            format='dirstate-tags')
 
246
            format=self.get_format_name())
237
247
        tree.lock_write()
238
248
        try:
239
249
            tree.add('.')
247
257
            tree.unlock()
248
258
 
249
259
    def do_checkout_test(self, lightweight=False):
250
 
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
 
260
        tree = self.make_branch_and_tree('source',
 
261
            format=self.get_format_name_subtree())
251
262
        subtree = self.make_branch_and_tree('source/subtree',
252
 
            format='dirstate-with-subtree')
 
263
            format=self.get_format_name_subtree())
253
264
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
254
 
            format='dirstate-with-subtree')
 
265
            format=self.get_format_name_subtree())
255
266
        self.build_tree(['source/subtree/file',
256
267
                         'source/subtree/subsubtree/file'])
257
268
        subsubtree.add('file')
279
290
        self.do_checkout_test(lightweight=True)
280
291
 
281
292
    def test_set_push(self):
282
 
        branch = self.make_branch('source', format='dirstate-tags')
 
293
        branch = self.make_branch('source', format=self.get_format_name())
283
294
        branch.get_config().set_user_option('push_location', 'old',
284
295
            store=config.STORE_LOCATION)
285
296
        warnings = []
294
305
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
295
306
                         'locations.conf')
296
307
 
 
308
 
 
309
class TestBranch6(TestBranch67, TestCaseWithTransport):
 
310
 
 
311
    def get_class(self):
 
312
        return _mod_branch.BzrBranch6
 
313
 
 
314
    def get_format_name(self):
 
315
        return "dirstate-tags"
 
316
 
 
317
    def get_format_name_subtree(self):
 
318
        return "dirstate-with-subtree"
 
319
 
 
320
    def test_set_stacked_on_errors(self):
 
321
        branch = self.make_branch('a', format=self.get_format_name())
 
322
        self.assertRaises(errors.UnstackableBranchFormat,
 
323
            branch.set_stacked_on, None)
 
324
 
 
325
    def test_default_stacked_location(self):
 
326
        branch = self.make_branch('a', format=self.get_format_name())
 
327
        self.assertRaises(errors.UnstackableBranchFormat, branch.get_stacked_on)
 
328
 
 
329
 
 
330
class TestBranch7(TestBranch67, TestCaseWithTransport):
 
331
 
 
332
    def get_class(self):
 
333
        return _mod_branch.BzrBranch7
 
334
 
 
335
    def get_format_name(self):
 
336
        return "development"
 
337
 
 
338
    def get_format_name_subtree(self):
 
339
        return "development-subtree"
 
340
 
 
341
    def test_set_stacked_on_unstackable_repo(self):
 
342
        repo = self.make_repository('a', format='dirstate-tags')
 
343
        control = repo.bzrdir
 
344
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
 
345
        target = self.make_branch('b')
 
346
        self.assertRaises(errors.UnstackableRepositoryFormat,
 
347
            branch.set_stacked_on, target.base)
 
348
 
 
349
    def _test_default_stacked_location(self):
 
350
        branch = self.make_branch('a', format=self.get_format_name())
 
351
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
352
 
 
353
    def test_stacked_location_file(self):
 
354
        branch = self.make_branch('a', format=self.get_format_name())
 
355
        self.assertFileEqual('\n', 'a/.bzr/branch/stacked-on')
 
356
 
 
357
    def test_stack_and_unstack(self):
 
358
        branch = self.make_branch('a', format=self.get_format_name())
 
359
        target = self.make_branch_and_tree('b', format=self.get_format_name())
 
360
        branch.set_stacked_on(target.branch.base)
 
361
        self.assertEqual(target.branch.base, branch.get_stacked_on())
 
362
        revid = target.commit('foo')
 
363
        self.assertTrue(branch.repository.has_revision(revid))
 
364
        branch.set_stacked_on(None)
 
365
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
366
        self.assertFalse(branch.repository.has_revision(revid))
 
367
 
 
368
    def test_open_opens_stacked_reference(self):
 
369
        branch = self.make_branch('a', format=self.get_format_name())
 
370
        target = self.make_branch_and_tree('b', format=self.get_format_name())
 
371
        branch.set_stacked_on(target.branch.base)
 
372
        branch = branch.bzrdir.open_branch()
 
373
        revid = target.commit('foo')
 
374
        self.assertTrue(branch.repository.has_revision(revid))
 
375
 
 
376
 
297
377
class TestBranchReference(TestCaseWithTransport):
298
378
    """Tests for the branch reference facility."""
299
379