~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_branch.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    errors,
25
25
    gpg,
26
26
    merge,
 
27
    osutils,
27
28
    urlutils,
28
29
    transport,
29
30
    remote,
76
77
        br = self.get_branch()
77
78
        br.fetch(wt.branch)
78
79
        br.generate_revision_history('rev3')
79
 
        rh = br.revision_history()
80
 
        self.assertEqual(['rev1', 'rev2', 'rev3'], rh)
81
 
        for revision_id in rh:
 
80
        for revision_id in ['rev3', 'rev2', 'rev1']:
82
81
            self.assertIsInstance(revision_id, str)
83
82
        last = br.last_revision()
84
83
        self.assertEqual('rev3', last)
114
113
        tree_a.add('vla', 'file2')
115
114
        tree_a.commit('rev2', rev_id='rev2')
116
115
 
117
 
        delta = tree_a.branch.get_revision_delta(1)
 
116
        delta = self.applyDeprecated(symbol_versioning.deprecated_in(
 
117
            (2, 5, 0)), tree_a.branch.get_revision_delta, 1)
118
118
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
119
119
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
120
 
        delta = tree_a.branch.get_revision_delta(2)
 
120
        delta = self.applyDeprecated(symbol_versioning.deprecated_in(
 
121
            (2, 5, 0)), tree_a.branch.get_revision_delta, 2)
121
122
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
122
123
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
123
124
 
215
216
    def test_record_initial_ghost(self):
216
217
        """Branches should support having ghosts."""
217
218
        wt = self.make_branch_and_tree('.')
 
219
        if not wt.branch.repository._format.supports_ghosts:
 
220
            raise tests.TestNotApplicable("repository format does not "
 
221
                "support ghosts")
218
222
        wt.set_parent_ids(['non:existent@rev--ision--0--2'],
219
223
            allow_leftmost_as_ghost=True)
220
224
        self.assertEqual(['non:existent@rev--ision--0--2'],
228
232
    def test_record_two_ghosts(self):
229
233
        """Recording with all ghosts works."""
230
234
        wt = self.make_branch_and_tree('.')
 
235
        if not wt.branch.repository._format.supports_ghosts:
 
236
            raise tests.TestNotApplicable("repository format does not "
 
237
                "support ghosts")
231
238
        wt.set_parent_ids([
232
239
                'foo@azkhazan-123123-abcabc',
233
240
                'wibble@fofof--20050401--1928390812',
245
252
                          self.get_branch().repository.get_revision,
246
253
                          None)
247
254
 
248
 
# TODO 20051003 RBC:
249
 
# compare the gpg-to-sign info for a commit with a ghost and
250
 
#     an identical tree without a ghost
251
 
# fetch missing should rewrite the TOC of weaves to list newly available parents.
252
 
 
253
 
    def test_sign_existing_revision(self):
254
 
        wt = self.make_branch_and_tree('.')
255
 
        branch = wt.branch
256
 
        wt.commit("base", allow_pointless=True, rev_id='A')
257
 
        from bzrlib.testament import Testament
258
 
        strategy = gpg.LoopbackGPGStrategy(None)
259
 
        branch.repository.lock_write()
260
 
        branch.repository.start_write_group()
261
 
        branch.repository.sign_revision('A', strategy)
262
 
        branch.repository.commit_write_group()
263
 
        branch.repository.unlock()
264
 
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
265
 
                         Testament.from_revision(branch.repository,
266
 
                         'A').as_short_text() +
267
 
                         '-----END PSEUDO-SIGNED CONTENT-----\n',
268
 
                         branch.repository.get_signature_text('A'))
269
 
 
270
 
    def test_store_signature(self):
271
 
        wt = self.make_branch_and_tree('.')
272
 
        branch = wt.branch
273
 
        branch.lock_write()
274
 
        try:
275
 
            branch.repository.start_write_group()
276
 
            try:
277
 
                branch.repository.store_revision_signature(
278
 
                    gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
279
 
            except:
280
 
                branch.repository.abort_write_group()
281
 
                raise
282
 
            else:
283
 
                branch.repository.commit_write_group()
284
 
        finally:
285
 
            branch.unlock()
286
 
        # A signature without a revision should not be accessible.
287
 
        self.assertRaises(errors.NoSuchRevision,
288
 
                          branch.repository.has_signature_for_revision_id,
289
 
                          'A')
290
 
        wt.commit("base", allow_pointless=True, rev_id='A')
291
 
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
292
 
                         'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
293
 
                         branch.repository.get_signature_text('A'))
294
 
 
295
 
    def test_branch_keeps_signatures(self):
296
 
        wt = self.make_branch_and_tree('source')
297
 
        wt.commit('A', allow_pointless=True, rev_id='A')
298
 
        repo = wt.branch.repository
299
 
        repo.lock_write()
300
 
        repo.start_write_group()
301
 
        repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
302
 
        repo.commit_write_group()
303
 
        repo.unlock()
304
 
        #FIXME: clone should work to urls,
305
 
        # wt.clone should work to disks.
306
 
        self.build_tree(['target/'])
307
 
        d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
308
 
        self.assertEqual(repo.get_signature_text('A'),
309
 
                         d2.open_repository().get_signature_text('A'))
310
 
 
311
 
    def test_nicks(self):
312
 
        """Test explicit and implicit branch nicknames.
 
255
    def test_nicks_bzr(self):
 
256
        """Test the behaviour of branch nicks specific to bzr branches.
313
257
 
314
258
        Nicknames are implicitly the name of the branch's directory, unless an
315
259
        explicit nickname is set.  That is, an explicit nickname always
316
260
        overrides the implicit one.
 
261
 
317
262
        """
318
263
        t = self.get_transport()
319
264
        branch = self.make_branch('bzr.dev')
 
265
        if not isinstance(branch, _mod_branch.BzrBranch):
 
266
            raise tests.TestNotApplicable("not a bzr branch format")
320
267
        # The nick will be 'bzr.dev', because there is no explicit nick set.
321
268
        self.assertEqual(branch.nick, 'bzr.dev')
322
269
        # Move the branch to a different directory, 'bzr.ab'.  Now that branch
338
285
        branch.nick = u"\u1234"
339
286
        self.assertEqual(branch.nick, u"\u1234")
340
287
 
 
288
    def test_nicks(self):
 
289
        """Test explicit and implicit branch nicknames.
 
290
 
 
291
        A nickname is always available, whether set explicitly or not.
 
292
        """
 
293
        t = self.get_transport()
 
294
        branch = self.make_branch('bzr.dev')
 
295
        # An implicit nick name is set; what it is exactly depends on the
 
296
        # format.
 
297
        self.assertIsInstance(branch.nick, basestring)
 
298
        # Set the branch nick explicitly.
 
299
        branch.nick = "Aaron's branch"
 
300
        # Because the nick has been set explicitly, the nick is now always
 
301
        # "Aaron's branch".
 
302
        self.assertEqual(branch.nick, "Aaron's branch")
 
303
        branch.nick = u"\u1234"
 
304
        self.assertEqual(branch.nick, u"\u1234")
 
305
 
341
306
    def test_commit_nicks(self):
342
307
        """Nicknames are committed to the revision"""
343
308
        wt = self.make_branch_and_tree('bzr.dev')
365
330
        self.branch_format.initialize(repo.bzrdir, name='branch2')
366
331
        self.assertEquals(2, len(repo.bzrdir.list_branches()))
367
332
 
 
333
    def test_create_append_revisions_only(self):
 
334
        try:
 
335
            repo = self.make_repository('.', shared=True)
 
336
        except errors.IncompatibleFormat:
 
337
            return
 
338
        for val in (True, False):
 
339
            try:
 
340
                branch = self.branch_format.initialize(repo.bzrdir,
 
341
                    append_revisions_only=True)
 
342
            except (errors.UninitializableFormat, errors.UpgradeRequired):
 
343
                # branch references are not default init'able and
 
344
                # not all branches support append_revisions_only
 
345
                return
 
346
            self.assertEquals(True, branch.get_append_revisions_only())
 
347
            repo.bzrdir.destroy_branch()
 
348
 
 
349
    def test_get_set_append_revisions_only(self):
 
350
        branch = self.make_branch('.')
 
351
        if branch._format.supports_set_append_revisions_only():
 
352
            branch.set_append_revisions_only(True)
 
353
            self.assertTrue(branch.get_append_revisions_only())
 
354
            branch.set_append_revisions_only(False)
 
355
            self.assertFalse(branch.get_append_revisions_only())
 
356
        else:
 
357
            self.assertRaises(errors.UpgradeRequired,
 
358
                branch.set_append_revisions_only, True)
 
359
            self.assertFalse(branch.get_append_revisions_only())
 
360
 
368
361
    def test_create_open_branch_uses_repository(self):
369
362
        try:
370
363
            repo = self.make_repository('.', shared=True)
371
364
        except errors.IncompatibleFormat:
372
 
            return
 
365
            raise tests.TestNotApplicable("requires shared repository support")
373
366
        child_transport = repo.bzrdir.root_transport.clone('child')
374
367
        child_transport.mkdir('.')
375
 
        child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
 
368
        try:
 
369
            child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
 
370
        except errors.UninitializableFormat:
 
371
            raise tests.TestNotApplicable("control dir format not initializable")
376
372
        try:
377
373
            child_branch = self.branch_format.initialize(child_dir)
378
374
        except errors.UninitializableFormat:
401
397
        """Create a fake revision history easily."""
402
398
        tree = self.make_branch_and_tree('.')
403
399
        rev1 = tree.commit('foo')
404
 
        orig_history = tree.branch.revision_history()
 
400
        tree.lock_write()
 
401
        self.addCleanup(tree.unlock)
 
402
        graph = tree.branch.repository.get_graph()
 
403
        orig_history = list(
 
404
            graph.iter_lefthand_ancestry(
 
405
                tree.branch.last_revision(), [revision.NULL_REVISION]))
405
406
        rev2 = tree.commit('bar', allow_pointless=True)
406
407
        tree.branch.generate_revision_history(rev1)
407
 
        self.assertEqual(orig_history, tree.branch.revision_history())
 
408
        self.assertEqual(orig_history, list(
 
409
            graph.iter_lefthand_ancestry(
 
410
                tree.branch.last_revision(), [revision.NULL_REVISION])))
408
411
 
409
412
    def test_generate_revision_history_NULL_REVISION(self):
410
413
        tree = self.make_branch_and_tree('.')
411
414
        rev1 = tree.commit('foo')
 
415
        tree.lock_write()
 
416
        self.addCleanup(tree.unlock)
412
417
        tree.branch.generate_revision_history(revision.NULL_REVISION)
413
 
        self.assertEqual([], tree.branch.revision_history())
 
418
        self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
414
419
 
415
420
    def test_create_checkout(self):
416
421
        tree_a = self.make_branch_and_tree('a')
437
442
        tree_a = self.make_branch_and_tree('a')
438
443
        rev_id = tree_a.commit('put some content in the branch')
439
444
        # open the branch via a readonly transport
440
 
        source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
 
445
        url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
 
446
        t = transport.get_transport_from_url(url)
 
447
        if not tree_a.branch.bzrdir._format.supports_transport(t):
 
448
            raise tests.TestNotApplicable("format does not support transport")
 
449
        source_branch = _mod_branch.Branch.open(url)
441
450
        # sanity check that the test will be valid
442
451
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
443
452
            source_branch.lock_write)
449
458
        tree_a = self.make_branch_and_tree('a')
450
459
        rev_id = tree_a.commit('put some content in the branch')
451
460
        # open the branch via a readonly transport
452
 
        source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
 
461
        url = self.get_readonly_url(
 
462
            osutils.basename(tree_a.branch.base.rstrip('/')))
 
463
        t = transport.get_transport_from_url(url)
 
464
        if not tree_a.branch.bzrdir._format.supports_transport(t):
 
465
            raise tests.TestNotApplicable("format does not support transport")
 
466
        source_branch = _mod_branch.Branch.open(url)
453
467
        # sanity check that the test will be valid
454
468
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
455
469
            source_branch.lock_write)
462
476
        br = tree.branch
463
477
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
464
478
            br.set_revision_history, ["rev1"])
465
 
        self.assertEquals(br.revision_history(), ["rev1"])
 
479
        self.assertEquals(br.last_revision(), "rev1")
466
480
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
467
481
            br.set_revision_history, [])
468
 
        self.assertEquals(br.revision_history(), [])
 
482
        self.assertEquals(br.last_revision(), 'null:')
469
483
 
470
484
    def test_heads_to_fetch(self):
471
485
        # heads_to_fetch is a method that returns a collection of revids that
509
523
            looked_up_format = registry.get(network_name)
510
524
            self.assertEqual(format.__class__, looked_up_format.__class__)
511
525
 
 
526
    def get_get_config_calls(self):
 
527
        # Smoke test that all branch succeed getting a config
 
528
        br = self.make_branch('.')
 
529
        br.get_config()
 
530
        br.get_config_stack()
 
531
 
512
532
 
513
533
class ChrootedTests(per_branch.TestCaseWithBranch):
514
534
    """A support class that provides readonly urls outside the local namespace.
531
551
                          _mod_branch.Branch.open_containing,
532
552
                          self.get_readonly_url('g/p/q'))
533
553
        branch = self.make_branch('.')
 
554
        if not branch.bzrdir._format.supports_transport(
 
555
            transport.get_transport_from_url(self.get_readonly_url('.'))):
 
556
            raise tests.TestNotApplicable("format does not support transport")
534
557
        branch, relpath = _mod_branch.Branch.open_containing(
535
558
            self.get_readonly_url(''))
536
559
        self.assertEqual('', relpath)
622
645
class TestChildSubmitFormats(per_branch.TestCaseWithBranch):
623
646
 
624
647
    def test_get_child_submit_format_default(self):
625
 
        self.assertEqual(None, self.get_branch().get_child_submit_format())
 
648
        submit_format = self.get_branch().get_child_submit_format()
 
649
        self.assertTrue(submit_format is None or
 
650
                        isinstance(submit_format, str))
626
651
 
627
652
    def test_get_child_submit_format(self):
628
653
        branch = self.get_branch()
673
698
            return
674
699
        # supported formats must be able to init and open
675
700
        t = self.get_transport()
676
 
        readonly_t = transport.get_transport(self.get_readonly_url())
 
701
        readonly_t = transport.get_transport_from_url(self.get_readonly_url())
677
702
        made_branch = self.make_branch('.')
678
703
        self.assertIsInstance(made_branch, _mod_branch.Branch)
679
704
 
835
860
    def test_fallbacks_not_opened(self):
836
861
        stacked = self.make_branch_with_fallback()
837
862
        self.get_transport('').rename('fallback', 'moved')
838
 
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
 
863
        reopened_dir = bzrdir.BzrDir.open(stacked.base)
 
864
        reopened = reopened_dir.open_branch(ignore_fallbacks=True)
839
865
        self.assertEqual([], reopened.repository._fallback_repositories)
840
866
 
841
867
    def test_fallbacks_are_opened(self):
842
868
        stacked = self.make_branch_with_fallback()
843
 
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
 
869
        reopened_dir = bzrdir.BzrDir.open(stacked.base)
 
870
        reopened = reopened_dir.open_branch(ignore_fallbacks=False)
844
871
        self.assertLength(1, reopened.repository._fallback_repositories)
845
872
 
846
873
 
854
881
            tree.add_reference(subtree)
855
882
        except errors.UnsupportedOperation:
856
883
            raise tests.TestNotApplicable('Tree cannot hold references.')
857
 
        reference_parent = tree.branch.reference_parent('subtree-id',
858
 
                                                        'subtree')
 
884
        reference_parent = tree.branch.reference_parent(
 
885
            'subtree-id',
 
886
            urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url))
859
887
        self.assertEqual(subtree.branch.base, reference_parent.base)
860
888
 
861
889
    def test_reference_parent_accepts_possible_transports(self):
867
895
        except errors.UnsupportedOperation:
868
896
            raise tests.TestNotApplicable('Tree cannot hold references.')
869
897
        reference_parent = tree.branch.reference_parent('subtree-id',
870
 
            'subtree', possible_transports=[subtree.bzrdir.root_transport])
 
898
            urlutils.relative_url(
 
899
                tree.branch.user_url, subtree.branch.user_url),
 
900
            possible_transports=[subtree.bzrdir.root_transport])
871
901
 
872
902
    def test_get_reference_info(self):
873
903
        branch = self.make_branch('branch')
1040
1070
 
1041
1071
class TestBranchControlComponent(per_branch.TestCaseWithBranch):
1042
1072
    """Branch implementations adequately implement ControlComponent."""
1043
 
    
 
1073
 
1044
1074
    def test_urls(self):
1045
1075
        br = self.make_branch('branch')
1046
1076
        self.assertIsInstance(br.user_url, str)