~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_controldir/test_controldir.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for bzrdir implementations - tests a bzrdir format."""
 
17
"""Tests for control directory implementations - tests a controldir format."""
18
18
 
19
 
from cStringIO import StringIO
20
 
import errno
21
19
from itertools import izip
22
 
import os
23
 
from stat import S_ISDIR
24
20
 
25
21
import bzrlib.branch
26
22
from bzrlib import (
30
26
    errors,
31
27
    gpg,
32
28
    osutils,
33
 
    revision as _mod_revision,
34
29
    transport,
35
30
    ui,
36
31
    urlutils,
37
32
    workingtree,
38
33
    )
39
 
from bzrlib.errors import (NoSuchRevision,
40
 
                           NotBranchError,
41
 
                           )
42
34
import bzrlib.revision
43
35
from bzrlib.tests import (
44
 
                          ChrootedTestCase,
45
 
                          TestNotApplicable,
46
 
                          TestSkipped,
47
 
                          )
 
36
    fixtures,
 
37
    ChrootedTestCase,
 
38
    TestNotApplicable,
 
39
    TestSkipped,
 
40
    )
48
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
49
42
from bzrlib.transport.local import LocalTransport
50
43
from bzrlib.ui import (
51
44
    CannedInputUIFactory,
52
45
    )
53
 
from bzrlib.remote import RemoteBzrDir, RemoteRepository
54
 
from bzrlib.repofmt import weaverepo
 
46
from bzrlib.remote import (
 
47
    RemoteBzrDir,
 
48
    RemoteBzrDirFormat,
 
49
    RemoteRepository,
 
50
    )
55
51
 
56
52
 
57
53
class TestControlDir(TestCaseWithControlDir):
58
 
    # Many of these tests test for disk equality rather than checking
59
 
    # for semantic equivalence. This works well for some tests but
60
 
    # is not good at handling changes in representation or the addition
61
 
    # or removal of control data. It would be nice to for instance:
62
 
    # sprout a new branch, check that the nickname has been reset by hand
63
 
    # and then set the nickname to match the source branch, at which point
64
 
    # a semantic equivalence should pass
65
 
 
66
 
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
67
 
        """Assert that the content of source and target are identical.
68
 
 
69
 
        paths in ignore list will be completely ignored.
70
 
 
71
 
        We ignore paths that represent data which is allowed to change during
72
 
        a clone or sprout: for instance, inventory.knit contains gzip fragements
73
 
        which have timestamps in them, and as we have read the inventory from
74
 
        the source knit, the already-read data is recompressed rather than
75
 
        reading it again, which leads to changed timestamps. This is ok though,
76
 
        because the inventory.kndx file is not ignored, and the integrity of
77
 
        knit joins is tested by test_knit and test_versionedfile.
78
 
 
79
 
        :seealso: Additionally, assertRepositoryHasSameItems provides value
80
 
            rather than representation checking of repositories for
81
 
            equivalence.
82
 
        """
83
 
        files = []
84
 
        directories = ['.']
85
 
        while directories:
86
 
            dir = directories.pop()
87
 
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
88
 
                path = dir + '/' + path
89
 
                if path in ignore_list:
90
 
                    continue
91
 
                try:
92
 
                    stat = source.stat(path)
93
 
                except errors.NoSuchFile:
94
 
                    self.fail('%s not in source' % path)
95
 
                if S_ISDIR(stat.st_mode):
96
 
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
97
 
                    directories.append(path)
98
 
                else:
99
 
                    self.assertEqualDiff(source.get(path).read(),
100
 
                                         target.get(path).read(),
101
 
                                         "text for file %r differs:\n" % path)
102
 
 
103
 
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
104
 
        """require left_repo and right_repo to contain the same data."""
105
 
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
106
 
        # local repositories to remote ones...  but this is an as-yet unsolved
107
 
        # aspect of format management and the Remote protocols...
108
 
        # self.assertEqual(left_repo._format.__class__,
109
 
        #     right_repo._format.__class__)
110
 
        left_repo.lock_read()
111
 
        try:
112
 
            right_repo.lock_read()
113
 
            try:
114
 
                # revs
115
 
                all_revs = left_repo.all_revision_ids()
116
 
                self.assertEqual(left_repo.all_revision_ids(),
117
 
                    right_repo.all_revision_ids())
118
 
                for rev_id in left_repo.all_revision_ids():
119
 
                    self.assertEqual(left_repo.get_revision(rev_id),
120
 
                        right_repo.get_revision(rev_id))
121
 
                # Assert the revision trees (and thus the inventories) are equal
122
 
                sort_key = lambda rev_tree: rev_tree.get_revision_id()
123
 
                rev_trees_a = sorted(
124
 
                    left_repo.revision_trees(all_revs), key=sort_key)
125
 
                rev_trees_b = sorted(
126
 
                    right_repo.revision_trees(all_revs), key=sort_key)
127
 
                for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
128
 
                    self.assertEqual([], list(tree_a.iter_changes(tree_b)))
129
 
                # texts
130
 
                text_index = left_repo._generate_text_key_index()
131
 
                self.assertEqual(text_index,
132
 
                    right_repo._generate_text_key_index())
133
 
                desired_files = []
134
 
                for file_id, revision_id in text_index.iterkeys():
135
 
                    desired_files.append(
136
 
                        (file_id, revision_id, (file_id, revision_id)))
137
 
                left_texts = list(left_repo.iter_files_bytes(desired_files))
138
 
                right_texts = list(right_repo.iter_files_bytes(desired_files))
139
 
                left_texts.sort()
140
 
                right_texts.sort()
141
 
                self.assertEqual(left_texts, right_texts)
142
 
                # signatures
143
 
                for rev_id in all_revs:
144
 
                    try:
145
 
                        left_text = left_repo.get_signature_text(rev_id)
146
 
                    except NoSuchRevision:
147
 
                        continue
148
 
                    right_text = right_repo.get_signature_text(rev_id)
149
 
                    self.assertEqual(left_text, right_text)
150
 
            finally:
151
 
                right_repo.unlock()
152
 
        finally:
153
 
            left_repo.unlock()
154
54
 
155
55
    def skipIfNoWorkingTree(self, a_bzrdir):
156
56
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
179
79
        """
180
80
        try:
181
81
            return a_bzrdir.create_workingtree()
182
 
        except errors.NotLocalUrl:
 
82
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
183
83
            raise TestSkipped("cannot make working tree with transport %r"
184
84
                              % a_bzrdir.transport)
185
85
 
207
107
        dir.create_branch()
208
108
        try:
209
109
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
210
 
        except errors.NotLocalUrl:
 
110
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
211
111
            raise TestSkipped("cannot make working tree with transport %r"
212
112
                              % dir.transport)
213
113
        self.assertEqual([], wt.get_parent_ids())
222
122
            bzrdir.destroy_workingtree()
223
123
        except errors.UnsupportedOperation:
224
124
            raise TestSkipped('Format does not support destroying tree')
225
 
        self.failIfExists('tree/file')
 
125
        self.assertPathDoesNotExist('tree/file')
226
126
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
227
127
        bzrdir.create_workingtree()
228
 
        self.failUnlessExists('tree/file')
 
128
        self.assertPathExists('tree/file')
229
129
        bzrdir.destroy_workingtree_metadata()
230
 
        self.failUnlessExists('tree/file')
 
130
        self.assertPathExists('tree/file')
231
131
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
232
132
 
233
133
    def test_destroy_branch(self):
265
165
            return
266
166
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
267
167
 
268
 
    def test_clone_on_transport(self):
269
 
        a_dir = self.make_bzrdir('source')
270
 
        target_transport = a_dir.root_transport.clone('..').clone('target')
271
 
        target = a_dir.clone_on_transport(target_transport)
272
 
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
273
 
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
274
 
                                    ['./.bzr/merge-hashes'])
275
 
 
276
 
    def test_clone_bzrdir_empty(self):
277
 
        dir = self.make_bzrdir('source')
278
 
        target = dir.clone(self.get_url('target'))
279
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
280
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
281
 
                                    ['./.bzr/merge-hashes'])
282
 
 
283
 
    def test_clone_bzrdir_empty_force_new_ignored(self):
284
 
        # the force_new_repo parameter should have no effect on an empty
285
 
        # bzrdir's clone logic
286
 
        dir = self.make_bzrdir('source')
287
 
        target = dir.clone(self.get_url('target'), force_new_repo=True)
288
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
289
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
290
 
                                    ['./.bzr/merge-hashes'])
291
 
 
292
 
    def test_clone_bzrdir_repository(self):
293
 
        tree = self.make_branch_and_tree('commit_tree')
294
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
295
 
        tree.add('foo')
296
 
        tree.commit('revision 1', rev_id='1')
297
 
        dir = self.make_bzrdir('source')
298
 
        repo = dir.create_repository()
299
 
        repo.fetch(tree.branch.repository)
300
 
        self.assertTrue(repo.has_revision('1'))
301
 
        target = dir.clone(self.get_url('target'))
302
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
303
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
304
 
                                    [
305
 
                                     './.bzr/merge-hashes',
306
 
                                     './.bzr/repository',
307
 
                                     ])
308
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
309
 
            target.open_repository())
310
 
 
311
168
    def test_clone_bzrdir_repository_under_shared(self):
312
169
        tree = self.make_branch_and_tree('commit_tree')
313
170
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
337
194
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
338
195
        tree.add('foo')
339
196
        tree.commit('revision 1', rev_id='1')
340
 
        tree.bzrdir.open_branch().set_revision_history([])
 
197
        tree.bzrdir.open_branch().generate_revision_history(
 
198
            bzrlib.revision.NULL_REVISION)
341
199
        tree.set_parent_trees([])
342
200
        tree.commit('revision 2', rev_id='2')
343
201
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
365
223
        self.build_tree(['commit_tree/foo'])
366
224
        tree.add('foo')
367
225
        tree.commit('revision 1', rev_id='1')
368
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
226
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
227
            bzrlib.revision.NULL_REVISION)
369
228
        tree.set_parent_trees([])
370
229
        tree.commit('revision 2', rev_id='2')
371
230
        tree.branch.repository.copy_content_into(shared_repo)
383
242
        self.assertFalse(branch.repository.make_working_trees())
384
243
        self.assertTrue(branch.repository.is_shared())
385
244
 
386
 
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
387
 
        tree = self.make_branch_and_tree('commit_tree')
388
 
        self.build_tree(['commit_tree/foo'])
389
 
        tree.add('foo')
390
 
        tree.commit('revision 1', rev_id='1')
391
 
        dir = self.make_bzrdir('source')
392
 
        repo = dir.create_repository()
393
 
        repo.fetch(tree.branch.repository)
394
 
        self.assertTrue(repo.has_revision('1'))
395
 
        try:
396
 
            self.make_repository('target', shared=True)
397
 
        except errors.IncompatibleFormat:
398
 
            return
399
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
400
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
401
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
402
 
                                    ['./.bzr/repository',
403
 
                                     ])
404
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
405
 
 
406
245
    def test_clone_bzrdir_repository_revision(self):
407
246
        # test for revision limiting, [smoke test, not corner case checks].
408
247
        # make a repository with some revisions,
412
251
        self.build_tree(['commit_tree/foo'])
413
252
        tree.add('foo')
414
253
        tree.commit('revision 1', rev_id='1')
415
 
        tree.branch.bzrdir.open_branch().set_revision_history([])
 
254
        tree.branch.bzrdir.open_branch().generate_revision_history(
 
255
            bzrlib.revision.NULL_REVISION)
416
256
        tree.set_parent_trees([])
417
257
        tree.commit('revision 2', rev_id='2')
418
258
        source = self.make_repository('source')
423
263
 
424
264
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
425
265
        # Bug #430868 is about an email containing '.sig'
426
 
        os.environ['BZR_EMAIL'] = 'murphy@host.sighup.org'
 
266
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
427
267
        tree = self.make_branch_and_tree('commit_tree')
428
268
        self.build_tree(['commit_tree/foo'])
429
269
        tree.add('foo')
442
282
            tree_repo.get_signature_text(rev1),
443
283
            target.repository.get_signature_text(rev1))
444
284
 
445
 
    def test_clone_bzrdir_branch_and_repo(self):
446
 
        tree = self.make_branch_and_tree('commit_tree')
447
 
        self.build_tree(['commit_tree/foo'])
448
 
        tree.add('foo')
449
 
        tree.commit('revision 1')
450
 
        source = self.make_branch('source')
451
 
        tree.branch.repository.copy_content_into(source.repository)
452
 
        tree.branch.copy_content_into(source)
453
 
        dir = source.bzrdir
454
 
        target = dir.clone(self.get_url('target'))
455
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
456
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
457
 
                                    [
458
 
                                     './.bzr/basis-inventory-cache',
459
 
                                     './.bzr/checkout/stat-cache',
460
 
                                     './.bzr/merge-hashes',
461
 
                                     './.bzr/repository',
462
 
                                     './.bzr/stat-cache',
463
 
                                    ])
464
 
        self.assertRepositoryHasSameItems(
465
 
            tree.branch.repository, target.open_repository())
466
 
 
467
285
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
468
286
        # by default cloning into a shared repo uses the shared repo.
469
287
        tree = self.make_branch_and_tree('commit_tree')
484
302
        self.assertEqual(source.revision_history(),
485
303
                         target.open_branch().revision_history())
486
304
 
487
 
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
488
 
        # by default cloning into a shared repo uses the shared repo.
489
 
        tree = self.make_branch_and_tree('commit_tree')
490
 
        self.build_tree(['commit_tree/foo'])
491
 
        tree.add('foo')
492
 
        tree.commit('revision 1')
493
 
        source = self.make_branch('source')
494
 
        tree.branch.repository.copy_content_into(source.repository)
495
 
        tree.branch.copy_content_into(source)
496
 
        try:
497
 
            self.make_repository('target', shared=True)
498
 
        except errors.IncompatibleFormat:
499
 
            return
500
 
        dir = source.bzrdir
501
 
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
502
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
503
 
        repo = target.open_repository()
504
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
505
 
                                    ['./.bzr/repository',
506
 
                                     ])
507
 
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
508
 
 
509
 
    def test_clone_bzrdir_branch_reference(self):
510
 
        # cloning should preserve the reference status of the branch in a bzrdir
511
 
        referenced_branch = self.make_branch('referencced')
512
 
        dir = self.make_bzrdir('source')
513
 
        try:
514
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
515
 
                target_branch=referenced_branch)
516
 
        except errors.IncompatibleFormat:
517
 
            # this is ok too, not all formats have to support references.
518
 
            return
519
 
        target = dir.clone(self.get_url('target'))
520
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
521
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
522
 
 
523
305
    def test_clone_bzrdir_branch_revision(self):
524
306
        # test for revision limiting, [smoke test, not corner case checks].
525
307
        # make a branch with some revisions,
537
319
        target = dir.clone(self.get_url('target'), revision_id='1')
538
320
        self.assertEqual('1', target.open_branch().last_revision())
539
321
 
540
 
    def test_clone_bzrdir_tree_branch_repo(self):
541
 
        tree = self.make_branch_and_tree('source')
542
 
        self.build_tree(['source/foo'])
543
 
        tree.add('foo')
544
 
        tree.commit('revision 1')
545
 
        dir = tree.bzrdir
546
 
        target = dir.clone(self.get_url('target'))
547
 
        self.skipIfNoWorkingTree(target)
548
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
549
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
550
 
                                    ['./.bzr/stat-cache',
551
 
                                     './.bzr/checkout/dirstate',
552
 
                                     './.bzr/checkout/stat-cache',
553
 
                                     './.bzr/checkout/merge-hashes',
554
 
                                     './.bzr/merge-hashes',
555
 
                                     './.bzr/repository',
556
 
                                     ])
557
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
558
 
            target.open_repository())
559
 
        target.open_workingtree().revert()
560
 
 
561
322
    def test_clone_on_transport_preserves_repo_format(self):
562
323
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
563
324
            format = 'knit'
577
338
            target_repo = target_repo._real_repository
578
339
        self.assertEqual(target_repo._format, source_branch.repository._format)
579
340
 
580
 
    def test_revert_inventory(self):
581
 
        tree = self.make_branch_and_tree('source')
582
 
        self.build_tree(['source/foo'])
583
 
        tree.add('foo')
584
 
        tree.commit('revision 1')
585
 
        dir = tree.bzrdir
586
 
        target = dir.clone(self.get_url('target'))
587
 
        self.skipIfNoWorkingTree(target)
588
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
589
 
                                    ['./.bzr/stat-cache',
590
 
                                     './.bzr/checkout/dirstate',
591
 
                                     './.bzr/checkout/stat-cache',
592
 
                                     './.bzr/checkout/merge-hashes',
593
 
                                     './.bzr/merge-hashes',
594
 
                                     './.bzr/repository',
595
 
                                     ])
596
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
597
 
            target.open_repository())
598
 
 
599
 
        target.open_workingtree().revert()
600
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
601
 
                                    ['./.bzr/stat-cache',
602
 
                                     './.bzr/checkout/dirstate',
603
 
                                     './.bzr/checkout/stat-cache',
604
 
                                     './.bzr/checkout/merge-hashes',
605
 
                                     './.bzr/merge-hashes',
606
 
                                     './.bzr/repository',
607
 
                                     ])
608
 
        self.assertRepositoryHasSameItems(tree.branch.repository,
609
 
            target.open_repository())
610
 
 
611
 
    def test_clone_bzrdir_tree_branch_reference(self):
612
 
        # a tree with a branch reference (aka a checkout)
613
 
        # should stay a checkout on clone.
614
 
        referenced_branch = self.make_branch('referencced')
615
 
        dir = self.make_bzrdir('source')
616
 
        try:
617
 
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
618
 
                target_branch=referenced_branch)
619
 
        except errors.IncompatibleFormat:
620
 
            # this is ok too, not all formats have to support references.
621
 
            return
622
 
        self.createWorkingTreeOrSkip(dir)
623
 
        target = dir.clone(self.get_url('target'))
624
 
        self.skipIfNoWorkingTree(target)
625
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
626
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
627
 
                                    ['./.bzr/stat-cache',
628
 
                                     './.bzr/checkout/stat-cache',
629
 
                                     './.bzr/checkout/merge-hashes',
630
 
                                     './.bzr/merge-hashes',
631
 
                                     './.bzr/repository/inventory.knit',
632
 
                                     ])
633
 
 
634
341
    def test_clone_bzrdir_tree_revision(self):
635
342
        # test for revision limiting, [smoke test, not corner case checks].
636
343
        # make a tree with a revision with a last-revision
722
429
        try:
723
430
            target.open_workingtree()
724
431
        except errors.NoWorkingTree:
725
 
            # bzrdir's that never have working trees are allowed to pass;
726
 
            # whitelist them for now.
727
 
            self.assertIsInstance(target, RemoteBzrDir)
 
432
            # Some bzrdirs can never have working trees.
 
433
            self.assertFalse(target._format.supports_workingtrees)
728
434
 
729
435
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
730
436
        # the force_new_repo parameter should force use of a new repo in an empty
739
445
        target.open_branch()
740
446
        self.openWorkingTreeIfLocal(target)
741
447
 
742
 
    def test_sprout_bzrdir_repository(self):
743
 
        tree = self.make_branch_and_tree('commit_tree')
744
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
745
 
        tree.add('foo')
746
 
        tree.commit('revision 1', rev_id='1')
747
 
        dir = self.make_bzrdir('source')
748
 
        repo = dir.create_repository()
749
 
        repo.fetch(tree.branch.repository)
750
 
        self.assertTrue(repo.has_revision('1'))
751
 
        try:
752
 
            self.assertTrue(
753
 
                _mod_revision.is_null(_mod_revision.ensure_null(
754
 
                dir.open_branch().last_revision())))
755
 
        except errors.NotBranchError:
756
 
            pass
757
 
        target = dir.sprout(self.get_url('target'))
758
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
759
 
        # testing inventory isn't reasonable for repositories
760
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
761
 
                                    [
762
 
                                     './.bzr/branch',
763
 
                                     './.bzr/checkout',
764
 
                                     './.bzr/inventory',
765
 
                                     './.bzr/parent',
766
 
                                     './.bzr/repository/inventory.knit',
767
 
                                     ])
768
 
        try:
769
 
            local_inventory = dir.transport.local_abspath('inventory')
770
 
        except errors.NotLocalUrl:
771
 
            return
772
 
        try:
773
 
            # If we happen to have a tree, we'll guarantee everything
774
 
            # except for the tree root is the same.
775
 
            inventory_f = file(local_inventory, 'rb')
776
 
            self.addCleanup(inventory_f.close)
777
 
            self.assertContainsRe(inventory_f.read(),
778
 
                                  '<inventory format="5">\n</inventory>\n')
779
 
        except IOError, e:
780
 
            if e.errno != errno.ENOENT:
781
 
                raise
782
 
 
783
448
    def test_sprout_bzrdir_with_repository_to_shared(self):
784
449
        tree = self.make_branch_and_tree('commit_tree')
785
450
        self.build_tree(['commit_tree/foo'])
786
451
        tree.add('foo')
787
452
        tree.commit('revision 1', rev_id='1')
788
 
        tree.bzrdir.open_branch().set_revision_history([])
 
453
        tree.bzrdir.open_branch().generate_revision_history(
 
454
            bzrlib.revision.NULL_REVISION)
789
455
        tree.set_parent_trees([])
790
456
        tree.commit('revision 2', rev_id='2')
791
457
        source = self.make_repository('source')
808
474
        self.build_tree(['commit_tree/foo'])
809
475
        tree.add('foo')
810
476
        tree.commit('revision 1', rev_id='1')
811
 
        tree.bzrdir.open_branch().set_revision_history([])
 
477
        tree.bzrdir.open_branch().generate_revision_history(
 
478
            bzrlib.revision.NULL_REVISION)
812
479
        tree.set_parent_trees([])
813
480
        tree.commit('revision 2', rev_id='2')
814
481
        tree.branch.repository.copy_content_into(shared_repo)
828
495
        self.build_tree(['commit_tree/foo'])
829
496
        tree.add('foo')
830
497
        tree.commit('revision 1', rev_id='1')
831
 
        tree.bzrdir.open_branch().set_revision_history([])
 
498
        tree.bzrdir.open_branch().generate_revision_history(
 
499
            bzrlib.revision.NULL_REVISION)
832
500
        tree.set_parent_trees([])
833
501
        tree.commit('revision 2', rev_id='2')
834
502
        tree.branch.repository.copy_content_into(shared_repo)
842
510
        self.assertNotEqual(dir.transport.base, target.transport.base)
843
511
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
844
512
        branch = target.open_branch()
845
 
        self.assertTrue(branch.repository.has_revision('1'))
846
 
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
513
        # The sprouted bzrdir has a branch, so only revisions referenced by
 
514
        # that branch are copied, rather than the whole repository.  It's an
 
515
        # empty branch, so none are copied.
 
516
        self.assertEqual([], branch.repository.all_revision_ids())
 
517
        if branch.bzrdir._format.supports_workingtrees:
847
518
            self.assertTrue(branch.repository.make_working_trees())
848
519
        self.assertFalse(branch.repository.is_shared())
849
520
 
852
523
        self.build_tree(['commit_tree/foo'])
853
524
        tree.add('foo')
854
525
        tree.commit('revision 1', rev_id='1')
855
 
        tree.bzrdir.open_branch().set_revision_history([])
 
526
        tree.bzrdir.open_branch().generate_revision_history(
 
527
            bzrlib.revision.NULL_REVISION)
856
528
        tree.set_parent_trees([])
857
529
        tree.commit('revision 2', rev_id='2')
858
530
        source = self.make_repository('source')
875
547
        self.build_tree(['commit_tree/foo'])
876
548
        tree.add('foo')
877
549
        tree.commit('revision 1', rev_id='1')
878
 
        tree.bzrdir.open_branch().set_revision_history([])
 
550
        br = tree.bzrdir.open_branch()
 
551
        br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
879
552
        tree.set_parent_trees([])
880
553
        tree.commit('revision 2', rev_id='2')
881
554
        source = self.make_repository('source')
884
557
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
885
558
        raise TestSkipped('revision limiting not strict yet')
886
559
 
887
 
    def test_sprout_bzrdir_branch_and_repo(self):
888
 
        tree = self.make_branch_and_tree('commit_tree')
889
 
        self.build_tree(['commit_tree/foo'])
890
 
        tree.add('foo')
891
 
        tree.commit('revision 1')
892
 
        source = self.make_branch('source')
893
 
        tree.branch.repository.copy_content_into(source.repository)
894
 
        tree.bzrdir.open_branch().copy_content_into(source)
895
 
        dir = source.bzrdir
896
 
        target = dir.sprout(self.get_url('target'))
897
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
898
 
        target_repo = target.open_repository()
899
 
        self.assertRepositoryHasSameItems(source.repository, target_repo)
900
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
901
 
                                    [
902
 
                                     './.bzr/basis-inventory-cache',
903
 
                                     './.bzr/branch/branch.conf',
904
 
                                     './.bzr/branch/parent',
905
 
                                     './.bzr/checkout',
906
 
                                     './.bzr/checkout/inventory',
907
 
                                     './.bzr/checkout/stat-cache',
908
 
                                     './.bzr/inventory',
909
 
                                     './.bzr/parent',
910
 
                                     './.bzr/repository',
911
 
                                     './.bzr/stat-cache',
912
 
                                     './foo',
913
 
                                     ])
914
 
 
915
560
    def test_sprout_bzrdir_branch_and_repo_shared(self):
916
561
        # sprouting a branch with a repo into a shared repo uses the shared
917
562
        # repo
1036
681
        target = dir.sprout(self.get_url('target'), revision_id='1')
1037
682
        self.assertEqual('1', target.open_branch().last_revision())
1038
683
 
1039
 
    def test_sprout_bzrdir_tree_branch_repo(self):
1040
 
        tree = self.make_branch_and_tree('source')
1041
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1042
 
        tree.add('foo')
1043
 
        tree.commit('revision 1')
1044
 
        dir = tree.bzrdir
1045
 
        target = self.sproutOrSkip(dir, self.get_url('target'))
1046
 
        self.assertNotEqual(dir.transport.base, target.transport.base)
1047
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1048
 
                                    [
1049
 
                                     './.bzr/branch/branch.conf',
1050
 
                                     './.bzr/branch/parent',
1051
 
                                     './.bzr/checkout/dirstate',
1052
 
                                     './.bzr/checkout/stat-cache',
1053
 
                                     './.bzr/checkout/inventory',
1054
 
                                     './.bzr/inventory',
1055
 
                                     './.bzr/parent',
1056
 
                                     './.bzr/repository',
1057
 
                                     './.bzr/stat-cache',
1058
 
                                     ])
1059
 
        self.assertRepositoryHasSameItems(
1060
 
            tree.branch.repository, target.open_repository())
 
684
    def test_sprout_bzrdir_branch_with_tags(self):
 
685
        # when sprouting a branch all revisions named in the tags are copied
 
686
        # too.
 
687
        builder = self.make_branch_builder('source')
 
688
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
689
        try:
 
690
            source.tags.set_tag('tag-a', 'rev-2')
 
691
        except errors.TagsNotSupported:
 
692
            raise TestNotApplicable('Branch format does not support tags.')
 
693
        # Now source has a tag not in its ancestry.  Sprout its controldir.
 
694
        dir = source.bzrdir
 
695
        target = dir.sprout(self.get_url('target'))
 
696
        # The tag is present, and so is its revision.
 
697
        new_branch = target.open_branch()
 
698
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
699
        new_branch.repository.get_revision('rev-2')
 
700
 
 
701
    def test_sprout_bzrdir_branch_with_absent_tag(self):
 
702
        # tags referencing absent revisions are copied (and those absent
 
703
        # revisions do not prevent the sprout.)
 
704
        builder = self.make_branch_builder('source')
 
705
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
706
        source = builder.get_branch()
 
707
        try:
 
708
            source.tags.set_tag('tag-a', 'missing-rev')
 
709
        except errors.TagsNotSupported:
 
710
            raise TestNotApplicable('Branch format does not support tags.')
 
711
        # Now source has a tag pointing to an absent revision.  Sprout its
 
712
        # controldir.
 
713
        dir = source.bzrdir
 
714
        target = dir.sprout(self.get_url('target'))
 
715
        # The tag is present in the target
 
716
        new_branch = target.open_branch()
 
717
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
718
 
 
719
    def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
 
720
        # tags referencing absent revisions are copied (and those absent
 
721
        # revisions do not prevent the sprout.)
 
722
        builder = self.make_branch_builder('source')
 
723
        builder.build_commit(message="Rev 1", rev_id='rev-1')
 
724
        source = builder.get_branch()
 
725
        try:
 
726
            source.tags.set_tag('tag-a', 'missing-rev')
 
727
        except errors.TagsNotSupported:
 
728
            raise TestNotApplicable('Branch format does not support tags.')
 
729
        # Now source has a tag pointing to an absent revision.  Sprout its
 
730
        # controldir.
 
731
        dir = source.bzrdir
 
732
        target = dir.sprout(self.get_url('target'), source_branch=source)
 
733
        # The tag is present in the target
 
734
        new_branch = target.open_branch()
 
735
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
 
736
 
 
737
    def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
 
738
        # dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
 
739
        # the branch at that bzrdir, the ancestry of all of those, but no other
 
740
        # revs (not even the tip of the source branch).
 
741
        builder = self.make_branch_builder('source')
 
742
        builder.build_commit(message="Base", rev_id='base-rev')
 
743
        # Make three parallel lines of ancestry off this base.
 
744
        source = builder.get_branch()
 
745
        builder.build_commit(message="Rev A1", rev_id='rev-a1')
 
746
        builder.build_commit(message="Rev A2", rev_id='rev-a2')
 
747
        builder.build_commit(message="Rev A3", rev_id='rev-a3')
 
748
        source.set_last_revision_info(1, 'base-rev')
 
749
        builder.build_commit(message="Rev B1", rev_id='rev-b1')
 
750
        builder.build_commit(message="Rev B2", rev_id='rev-b2')
 
751
        builder.build_commit(message="Rev B3", rev_id='rev-b3')
 
752
        source.set_last_revision_info(1, 'base-rev')
 
753
        builder.build_commit(message="Rev C1", rev_id='rev-c1')
 
754
        builder.build_commit(message="Rev C2", rev_id='rev-c2')
 
755
        builder.build_commit(message="Rev C3", rev_id='rev-c3')
 
756
        # Set the branch tip to A2
 
757
        source.set_last_revision_info(3, 'rev-a2')
 
758
        try:
 
759
            # Create a tag for B2, and for an absent rev
 
760
            source.tags.set_tag('tag-non-ancestry', 'rev-b2')
 
761
            source.tags.set_tag('tag-absent', 'absent-rev')
 
762
        except errors.TagsNotSupported:
 
763
            raise TestNotApplicable('Branch format does not support tags.')
 
764
        # And ask sprout for C2
 
765
        dir = source.bzrdir
 
766
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
 
767
        # The tags are present
 
768
        new_branch = target.open_branch()
 
769
        self.assertEqual(
 
770
            {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
 
771
            new_branch.tags.get_tag_dict())
 
772
        # And the revs for A2, B2 and C2's ancestries are present, but no
 
773
        # others.
 
774
        self.assertEqual(
 
775
            ['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
 
776
            sorted(new_branch.repository.all_revision_ids()))
1061
777
 
1062
778
    def test_sprout_bzrdir_tree_branch_reference(self):
1063
779
        # sprouting should create a repository if needed and a sprouted branch.
1147
863
        tree.commit('revision 1', rev_id='1')
1148
864
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1149
865
        dir = tree.bzrdir
1150
 
        if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
1151
 
            self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
1152
 
                              self.get_url('target'),
1153
 
                              create_tree_if_local=False)
1154
 
            return
1155
 
        target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
1156
 
        self.failIfExists('target/foo')
 
866
        try:
 
867
            target = dir.sprout(self.get_url('target'),
 
868
                create_tree_if_local=False)
 
869
        except errors.MustHaveWorkingTree:
 
870
            raise TestNotApplicable("control dir format requires working tree")
 
871
        self.assertPathDoesNotExist('target/foo')
1157
872
        self.assertEqual(tree.branch.last_revision(),
1158
873
                         target.open_branch().last_revision())
1159
874
 
1195
910
            '_network_name', None),
1196
911
            None)
1197
912
        # supported formats must be able to init and open
1198
 
        t = transport.get_transport(self.get_url())
1199
 
        readonly_t = transport.get_transport(self.get_readonly_url())
 
913
        t = self.get_transport()
 
914
        readonly_t = self.get_readonly_transport()
1200
915
        made_control = self.bzrdir_format.initialize(t.base)
1201
 
        self.failUnless(isinstance(made_control, controldir.ControlDir))
 
916
        self.assertIsInstance(made_control, controldir.ControlDir)
 
917
        if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
 
918
            return
1202
919
        self.assertEqual(self.bzrdir_format,
1203
920
                         controldir.ControlDirFormat.find_format(readonly_t))
1204
921
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1207
924
                         opened_dir._format)
1208
925
        self.assertEqual(direct_opened_dir._format,
1209
926
                         opened_dir._format)
1210
 
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
 
927
        self.assertIsInstance(opened_dir, controldir.ControlDir)
1211
928
 
1212
929
    def test_format_initialize_on_transport_ex(self):
1213
930
        t = self.get_transport('dir')
1265
982
        if control is None:
1266
983
            # uninitialisable format
1267
984
            return
1268
 
        if not isinstance(control._format, (bzrdir.BzrDirFormat5,
1269
 
            bzrdir.BzrDirFormat6,)):
 
985
        if not control._format.fixed_components:
1270
986
            self.assertEqual(repo.bzrdir.root_transport.base,
1271
987
                made_repo.bzrdir.root_transport.base)
1272
988
 
1334
1050
        if control is None:
1335
1051
            # uninitialisable format
1336
1052
            return
1337
 
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
1338
 
            bzrdir.BzrDirFormat6)):
 
1053
        if self.bzrdir_format.fixed_components:
1339
1054
            # must stay with the all-in-one-format.
1340
1055
            repo_name = self.bzrdir_format.network_name()
1341
1056
        self.assertEqual(repo_name, repo._format.network_name())
1360
1075
            # Repositories are open write-locked
1361
1076
            self.assertTrue(repo.is_write_locked())
1362
1077
            self.addCleanup(repo.unlock)
1363
 
        self.assertIsInstance(control, bzrdir.BzrDir)
 
1078
        self.assertIsInstance(control, controldir.ControlDir)
1364
1079
        opened = bzrdir.BzrDir.open(t.base)
1365
1080
        expected_format = self.bzrdir_format
1366
 
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
1367
 
            # Current RemoteBzrDirFormat's do not reliably get network_name
1368
 
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
1369
 
            self.assertIsInstance(control, RemoteBzrDir)
1370
 
        else:
1371
 
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1372
 
                bzrdir.BzrDirFormat6)):
1373
 
                # Pre-metadir formats change when we are making something that
1374
 
                # needs a metaformat, because clone is used for push.
1375
 
                expected_format = bzrdir.BzrDirMetaFormat1()
 
1081
        if need_meta and expected_format.fixed_components:
 
1082
            # Pre-metadir formats change when we are making something that
 
1083
            # needs a metaformat, because clone is used for push.
 
1084
            expected_format = bzrdir.BzrDirMetaFormat1()
 
1085
        if not isinstance(expected_format, RemoteBzrDirFormat):
1376
1086
            self.assertEqual(control._format.network_name(),
1377
1087
                expected_format.network_name())
1378
1088
            self.assertEqual(control._format.network_name(),
1389
1099
        # key in the registry gives back the same format. For remote obects
1390
1100
        # we check that the network_name of the RemoteBzrDirFormat we have
1391
1101
        # locally matches the actual format present on disk.
1392
 
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
 
1102
        if isinstance(format, RemoteBzrDirFormat):
1393
1103
            dir._ensure_real()
1394
1104
            real_dir = dir._real_bzrdir
1395
1105
            network_name = format.network_name()
1396
1106
            self.assertEqual(real_dir._format.network_name(), network_name)
1397
1107
        else:
1398
 
            registry = bzrdir.network_format_registry
 
1108
            registry = controldir.network_format_registry
1399
1109
            network_name = format.network_name()
1400
1110
            looked_up_format = registry.get(network_name)
1401
 
            self.assertEqual(format.__class__, looked_up_format.__class__)
 
1111
            self.assertTrue(
 
1112
                issubclass(format.__class__, looked_up_format.__class__))
1402
1113
        # The network name must be a byte string.
1403
1114
        self.assertIsInstance(network_name, str)
1404
1115
 
1405
1116
    def test_open_not_bzrdir(self):
1406
1117
        # test the formats specific behaviour for no-content or similar dirs.
1407
 
        self.assertRaises(NotBranchError,
 
1118
        self.assertRaises(errors.NotBranchError,
1408
1119
                          self.bzrdir_format.open,
1409
1120
                          transport.get_transport(self.get_readonly_url()))
1410
1121
 
1415
1126
            # because the default open will not open them and
1416
1127
            # they may not be initializable.
1417
1128
            return
1418
 
        t = transport.get_transport(self.get_url())
 
1129
        t = self.get_transport()
1419
1130
        made_control = self.bzrdir_format.initialize(t.base)
1420
1131
        made_repo = made_control.create_repository()
1421
1132
        made_branch = made_control.create_branch()
1422
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
 
1133
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1423
1134
        self.assertEqual(made_control, made_branch.bzrdir)
1424
1135
 
1425
1136
    def test_open_branch(self):
1428
1139
            # because the default open will not open them and
1429
1140
            # they may not be initializable.
1430
1141
            return
1431
 
        t = transport.get_transport(self.get_url())
 
1142
        t = self.get_transport()
1432
1143
        made_control = self.bzrdir_format.initialize(t.base)
1433
1144
        made_repo = made_control.create_repository()
1434
1145
        made_branch = made_control.create_branch()
1435
1146
        opened_branch = made_control.open_branch()
1436
1147
        self.assertEqual(made_control, opened_branch.bzrdir)
1437
 
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1438
 
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
 
1148
        self.assertIsInstance(opened_branch, made_branch.__class__)
 
1149
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1439
1150
 
1440
1151
    def test_list_branches(self):
1441
1152
        if not self.bzrdir_format.is_supported():
1443
1154
            # because the default open will not open them and
1444
1155
            # they may not be initializable.
1445
1156
            return
1446
 
        t = transport.get_transport(self.get_url())
 
1157
        t = self.get_transport()
1447
1158
        made_control = self.bzrdir_format.initialize(t.base)
1448
1159
        made_repo = made_control.create_repository()
1449
1160
        made_branch = made_control.create_branch()
1464
1175
            # because the default open will not open them and
1465
1176
            # they may not be initializable.
1466
1177
            return
1467
 
        t = transport.get_transport(self.get_url())
 
1178
        t = self.get_transport()
1468
1179
        made_control = self.bzrdir_format.initialize(t.base)
1469
1180
        made_repo = made_control.create_repository()
1470
1181
        # Check that we have a repository object.
1479
1190
            # because the default open will not open them and
1480
1191
            # they may not be initializable.
1481
1192
            return
1482
 
        t = transport.get_transport(self.get_url())
 
1193
        t = self.get_transport()
1483
1194
        made_control = self.bzrdir_format.initialize(t.base)
1484
1195
        try:
1485
1196
            made_repo = made_control.create_repository(shared=True)
1496
1207
            # because the default open will not open them and
1497
1208
            # they may not be initializable.
1498
1209
            return
1499
 
        t = transport.get_transport(self.get_url())
 
1210
        t = self.get_transport()
1500
1211
        made_control = self.bzrdir_format.initialize(t.base)
1501
1212
        made_repo = made_control.create_repository(shared=False)
1502
1213
        self.assertFalse(made_repo.is_shared())
1507
1218
            # because the default open will not open them and
1508
1219
            # they may not be initializable.
1509
1220
            return
1510
 
        t = transport.get_transport(self.get_url())
 
1221
        t = self.get_transport()
1511
1222
        made_control = self.bzrdir_format.initialize(t.base)
1512
1223
        made_repo = made_control.create_repository()
1513
1224
        opened_repo = made_control.open_repository()
1514
1225
        self.assertEqual(made_control, opened_repo.bzrdir)
1515
 
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1516
 
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
 
1226
        self.assertIsInstance(opened_repo, made_repo.__class__)
 
1227
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1517
1228
 
1518
1229
    def test_create_workingtree(self):
1519
1230
        # a bzrdir can construct a working tree for itself.
1527
1238
        made_repo = made_control.create_repository()
1528
1239
        made_branch = made_control.create_branch()
1529
1240
        made_tree = self.createWorkingTreeOrSkip(made_control)
1530
 
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
 
1241
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
1531
1242
        self.assertEqual(made_control, made_tree.bzrdir)
1532
1243
 
1533
1244
    def test_create_workingtree_revision(self):
1543
1254
        source.branch.clone(made_control)
1544
1255
        try:
1545
1256
            made_tree = made_control.create_workingtree(revision_id='a')
1546
 
        except errors.NotLocalUrl:
 
1257
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1547
1258
            raise TestSkipped("Can't make working tree on transport %r" % t)
1548
1259
        self.assertEqual(['a'], made_tree.get_parent_ids())
1549
1260
 
1561
1272
            made_repo = made_control.create_repository()
1562
1273
            made_branch = made_control.create_branch()
1563
1274
            made_tree = made_control.create_workingtree()
1564
 
        except errors.NotLocalUrl:
 
1275
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1565
1276
            raise TestSkipped("Can't initialize %r on transport %r"
1566
1277
                              % (self.bzrdir_format, t))
1567
1278
        opened_tree = made_control.open_workingtree()
1568
1279
        self.assertEqual(made_control, opened_tree.bzrdir)
1569
 
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1570
 
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1571
 
 
1572
 
    def test_get_branch_transport(self):
1573
 
        dir = self.make_bzrdir('.')
1574
 
        # without a format, get_branch_transport gives use a transport
1575
 
        # which -may- point to an existing dir.
1576
 
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1577
 
                                   transport.Transport))
1578
 
        # with a given format, either the bzr dir supports identifiable
1579
 
        # branches, or it supports anonymous  branch formats, but not both.
1580
 
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1581
 
        identifiable_format = bzrlib.branch.BzrBranchFormat5()
1582
 
        try:
1583
 
            found_transport = dir.get_branch_transport(anonymous_format)
1584
 
            self.assertRaises(errors.IncompatibleFormat,
1585
 
                              dir.get_branch_transport,
1586
 
                              identifiable_format)
1587
 
        except errors.IncompatibleFormat:
1588
 
            found_transport = dir.get_branch_transport(identifiable_format)
1589
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1590
 
        # and the dir which has been initialized for us must exist.
1591
 
        found_transport.list_dir('.')
1592
 
 
1593
 
    def test_get_repository_transport(self):
1594
 
        dir = self.make_bzrdir('.')
1595
 
        # without a format, get_repository_transport gives use a transport
1596
 
        # which -may- point to an existing dir.
1597
 
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1598
 
                                   transport.Transport))
1599
 
        # with a given format, either the bzr dir supports identifiable
1600
 
        # repositories, or it supports anonymous  repository formats, but not both.
1601
 
        anonymous_format = weaverepo.RepositoryFormat6()
1602
 
        identifiable_format = weaverepo.RepositoryFormat7()
1603
 
        try:
1604
 
            found_transport = dir.get_repository_transport(anonymous_format)
1605
 
            self.assertRaises(errors.IncompatibleFormat,
1606
 
                              dir.get_repository_transport,
1607
 
                              identifiable_format)
1608
 
        except errors.IncompatibleFormat:
1609
 
            found_transport = dir.get_repository_transport(identifiable_format)
1610
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1611
 
        # and the dir which has been initialized for us must exist.
1612
 
        found_transport.list_dir('.')
1613
 
 
1614
 
    def test_get_workingtree_transport(self):
1615
 
        dir = self.make_bzrdir('.')
1616
 
        # without a format, get_workingtree_transport gives use a transport
1617
 
        # which -may- point to an existing dir.
1618
 
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1619
 
                                   transport.Transport))
1620
 
        # with a given format, either the bzr dir supports identifiable
1621
 
        # trees, or it supports anonymous tree formats, but not both.
1622
 
        anonymous_format = workingtree.WorkingTreeFormat2()
1623
 
        identifiable_format = workingtree.WorkingTreeFormat3()
1624
 
        try:
1625
 
            found_transport = dir.get_workingtree_transport(anonymous_format)
1626
 
            self.assertRaises(errors.IncompatibleFormat,
1627
 
                              dir.get_workingtree_transport,
1628
 
                              identifiable_format)
1629
 
        except errors.IncompatibleFormat:
1630
 
            found_transport = dir.get_workingtree_transport(identifiable_format)
1631
 
        self.assertTrue(isinstance(found_transport, transport.Transport))
1632
 
        # and the dir which has been initialized for us must exist.
1633
 
        found_transport.list_dir('.')
 
1280
        self.assertIsInstance(opened_tree, made_tree.__class__)
 
1281
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1634
1282
 
1635
1283
    def test_root_transport(self):
1636
1284
        dir = self.make_bzrdir('.')
1637
1285
        self.assertEqual(dir.root_transport.base,
1638
 
                         transport.get_transport(self.get_url('.')).base)
 
1286
                         self.get_transport().base)
1639
1287
 
1640
1288
    def test_find_repository_no_repo_under_standalone_branch(self):
1641
1289
        # finding a repo stops at standalone branches even if there is a
1646
1294
            # need a shared repository to test this.
1647
1295
            return
1648
1296
        url = self.get_url('intermediate')
1649
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1650
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1297
        t = self.get_transport()
 
1298
        t.mkdir('intermediate')
 
1299
        t.mkdir('intermediate/child')
1651
1300
        made_control = self.bzrdir_format.initialize(url)
1652
1301
        made_control.create_repository()
1653
1302
        innermost_control = self.bzrdir_format.initialize(
1671
1320
            # need a shared repository to test this.
1672
1321
            return
1673
1322
        url = self.get_url('childbzrdir')
1674
 
        transport.get_transport(self.get_url()).mkdir('childbzrdir')
 
1323
        self.get_transport().mkdir('childbzrdir')
1675
1324
        made_control = self.bzrdir_format.initialize(url)
1676
1325
        try:
1677
1326
            child_repo = made_control.open_repository()
1705
1354
            # need a shared repository to test this.
1706
1355
            return
1707
1356
        url = self.get_url('childrepo')
1708
 
        transport.get_transport(self.get_url()).mkdir('childrepo')
 
1357
        self.get_transport().mkdir('childrepo')
1709
1358
        child_control = self.bzrdir_format.initialize(url)
1710
1359
        child_repo = child_control.create_repository(shared=True)
1711
1360
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1724
1373
            # need a shared repository to test this.
1725
1374
            return
1726
1375
        url = self.get_url('intermediate')
1727
 
        transport.get_transport(self.get_url()).mkdir('intermediate')
1728
 
        transport.get_transport(self.get_url()).mkdir('intermediate/child')
 
1376
        t = self.get_transport()
 
1377
        t.mkdir('intermediate')
 
1378
        t.mkdir('intermediate/child')
1729
1379
        made_control = self.bzrdir_format.initialize(url)
1730
1380
        try:
1731
1381
            child_repo = made_control.open_repository()
1755
1405
            # (we force the latest known format as downgrades may not be
1756
1406
            # available
1757
1407
            self.assertTrue(isinstance(dir._format.get_converter(
1758
 
                format=dir._format), bzrdir.Converter))
 
1408
                format=dir._format), controldir.Converter))
1759
1409
        dir.needs_format_conversion(
1760
1410
            controldir.ControlDirFormat.get_default_format())
1761
1411
 
1767
1417
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1768
1418
        old_path = urlutils.local_path_from_url(old_url)
1769
1419
        new_path = urlutils.local_path_from_url(new_url)
1770
 
        self.failUnlessExists(old_path)
1771
 
        self.failUnlessExists(new_path)
 
1420
        self.assertPathExists(old_path)
 
1421
        self.assertPathExists(new_path)
1772
1422
        for (((dir_relpath1, _), entries1),
1773
1423
             ((dir_relpath2, _), entries2)) in izip(
1774
1424
                osutils.walkdirs(old_path),
1802
1452
    def test_format_description(self):
1803
1453
        dir = self.make_bzrdir('.')
1804
1454
        text = dir._format.get_format_description()
1805
 
        self.failUnless(len(text))
1806
 
 
1807
 
    def test_retire_bzrdir(self):
1808
 
        bd = self.make_bzrdir('.')
1809
 
        transport = bd.root_transport
1810
 
        # must not overwrite existing directories
1811
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1812
 
            transport=transport)
1813
 
        self.failUnless(transport.has('.bzr'))
1814
 
        bd.retire_bzrdir()
1815
 
        self.failIf(transport.has('.bzr'))
1816
 
        self.failUnless(transport.has('.bzr.retired.1'))
1817
 
 
1818
 
    def test_retire_bzrdir_limited(self):
1819
 
        bd = self.make_bzrdir('.')
1820
 
        transport = bd.root_transport
1821
 
        # must not overwrite existing directories
1822
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1823
 
            transport=transport)
1824
 
        self.failUnless(transport.has('.bzr'))
1825
 
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1826
 
            bd.retire_bzrdir, limit=0)
 
1455
        self.assertTrue(len(text))
1827
1456
 
1828
1457
 
1829
1458
class TestBreakLock(TestCaseWithControlDir):