~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Shannon Weyrick
  • Date: 2011-11-04 13:40:04 UTC
  • mfrom: (6238 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6256.
  • Revision ID: weyrick@mozek.us-20111104134004-033t2wqhc3ydzm0a
Merge

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)
217
216
    def test_record_initial_ghost(self):
218
217
        """Branches should support having ghosts."""
219
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")
220
222
        wt.set_parent_ids(['non:existent@rev--ision--0--2'],
221
223
            allow_leftmost_as_ghost=True)
222
224
        self.assertEqual(['non:existent@rev--ision--0--2'],
230
232
    def test_record_two_ghosts(self):
231
233
        """Recording with all ghosts works."""
232
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")
233
238
        wt.set_parent_ids([
234
239
                'foo@azkhazan-123123-abcabc',
235
240
                'wibble@fofof--20050401--1928390812',
247
252
                          self.get_branch().repository.get_revision,
248
253
                          None)
249
254
 
250
 
# TODO 20051003 RBC:
251
 
# compare the gpg-to-sign info for a commit with a ghost and
252
 
#     an identical tree without a ghost
253
 
# fetch missing should rewrite the TOC of weaves to list newly available parents.
254
 
 
255
 
    def test_sign_existing_revision(self):
256
 
        wt = self.make_branch_and_tree('.')
257
 
        branch = wt.branch
258
 
        wt.commit("base", allow_pointless=True, rev_id='A')
259
 
        from bzrlib.testament import Testament
260
 
        strategy = gpg.LoopbackGPGStrategy(None)
261
 
        branch.repository.lock_write()
262
 
        branch.repository.start_write_group()
263
 
        branch.repository.sign_revision('A', strategy)
264
 
        branch.repository.commit_write_group()
265
 
        branch.repository.unlock()
266
 
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
267
 
                         Testament.from_revision(branch.repository,
268
 
                         'A').as_short_text() +
269
 
                         '-----END PSEUDO-SIGNED CONTENT-----\n',
270
 
                         branch.repository.get_signature_text('A'))
271
 
 
272
 
    def test_store_signature(self):
273
 
        wt = self.make_branch_and_tree('.')
274
 
        branch = wt.branch
275
 
        branch.lock_write()
276
 
        try:
277
 
            branch.repository.start_write_group()
278
 
            try:
279
 
                branch.repository.store_revision_signature(
280
 
                    gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
281
 
            except:
282
 
                branch.repository.abort_write_group()
283
 
                raise
284
 
            else:
285
 
                branch.repository.commit_write_group()
286
 
        finally:
287
 
            branch.unlock()
288
 
        # A signature without a revision should not be accessible.
289
 
        self.assertRaises(errors.NoSuchRevision,
290
 
                          branch.repository.has_signature_for_revision_id,
291
 
                          'A')
292
 
        wt.commit("base", allow_pointless=True, rev_id='A')
293
 
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
294
 
                         'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
295
 
                         branch.repository.get_signature_text('A'))
296
 
 
297
 
    def test_branch_keeps_signatures(self):
298
 
        wt = self.make_branch_and_tree('source')
299
 
        wt.commit('A', allow_pointless=True, rev_id='A')
300
 
        repo = wt.branch.repository
301
 
        repo.lock_write()
302
 
        repo.start_write_group()
303
 
        repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
304
 
        repo.commit_write_group()
305
 
        repo.unlock()
306
 
        #FIXME: clone should work to urls,
307
 
        # wt.clone should work to disks.
308
 
        self.build_tree(['target/'])
309
 
        d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
310
 
        self.assertEqual(repo.get_signature_text('A'),
311
 
                         d2.open_repository().get_signature_text('A'))
312
 
 
313
255
    def test_nicks_bzr(self):
314
256
        """Test the behaviour of branch nicks specific to bzr branches.
315
257
 
420
362
        try:
421
363
            repo = self.make_repository('.', shared=True)
422
364
        except errors.IncompatibleFormat:
423
 
            return
 
365
            raise tests.TestNotApplicable("requires shared repository support")
424
366
        child_transport = repo.bzrdir.root_transport.clone('child')
425
367
        child_transport.mkdir('.')
426
368
        try:
427
369
            child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
428
370
        except errors.UninitializableFormat:
429
 
            return
 
371
            raise tests.TestNotApplicable("control dir format not initializable")
430
372
        try:
431
373
            child_branch = self.branch_format.initialize(child_dir)
432
374
        except errors.UninitializableFormat:
455
397
        """Create a fake revision history easily."""
456
398
        tree = self.make_branch_and_tree('.')
457
399
        rev1 = tree.commit('foo')
458
 
        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]))
459
406
        rev2 = tree.commit('bar', allow_pointless=True)
460
407
        tree.branch.generate_revision_history(rev1)
461
 
        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])))
462
411
 
463
412
    def test_generate_revision_history_NULL_REVISION(self):
464
413
        tree = self.make_branch_and_tree('.')
465
414
        rev1 = tree.commit('foo')
 
415
        tree.lock_write()
 
416
        self.addCleanup(tree.unlock)
466
417
        tree.branch.generate_revision_history(revision.NULL_REVISION)
467
 
        self.assertEqual([], tree.branch.revision_history())
 
418
        self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
468
419
 
469
420
    def test_create_checkout(self):
470
421
        tree_a = self.make_branch_and_tree('a')
491
442
        tree_a = self.make_branch_and_tree('a')
492
443
        rev_id = tree_a.commit('put some content in the branch')
493
444
        # open the branch via a readonly transport
494
 
        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)
495
450
        # sanity check that the test will be valid
496
451
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
497
452
            source_branch.lock_write)
503
458
        tree_a = self.make_branch_and_tree('a')
504
459
        rev_id = tree_a.commit('put some content in the branch')
505
460
        # open the branch via a readonly transport
506
 
        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)
507
467
        # sanity check that the test will be valid
508
468
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
509
469
            source_branch.lock_write)
591
551
                          _mod_branch.Branch.open_containing,
592
552
                          self.get_readonly_url('g/p/q'))
593
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")
594
557
        branch, relpath = _mod_branch.Branch.open_containing(
595
558
            self.get_readonly_url(''))
596
559
        self.assertEqual('', relpath)
897
860
    def test_fallbacks_not_opened(self):
898
861
        stacked = self.make_branch_with_fallback()
899
862
        self.get_transport('').rename('fallback', 'moved')
900
 
        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)
901
865
        self.assertEqual([], reopened.repository._fallback_repositories)
902
866
 
903
867
    def test_fallbacks_are_opened(self):
904
868
        stacked = self.make_branch_with_fallback()
905
 
        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)
906
871
        self.assertLength(1, reopened.repository._fallback_repositories)
907
872
 
908
873
 
916
881
            tree.add_reference(subtree)
917
882
        except errors.UnsupportedOperation:
918
883
            raise tests.TestNotApplicable('Tree cannot hold references.')
919
 
        reference_parent = tree.branch.reference_parent('subtree-id',
920
 
                                                        'subtree')
 
884
        reference_parent = tree.branch.reference_parent(
 
885
            'subtree-id',
 
886
            urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url))
921
887
        self.assertEqual(subtree.branch.base, reference_parent.base)
922
888
 
923
889
    def test_reference_parent_accepts_possible_transports(self):
929
895
        except errors.UnsupportedOperation:
930
896
            raise tests.TestNotApplicable('Tree cannot hold references.')
931
897
        reference_parent = tree.branch.reference_parent('subtree-id',
932
 
            '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])
933
901
 
934
902
    def test_get_reference_info(self):
935
903
        branch = self.make_branch('branch')