~ubuntu-branches/debian/lenny/bzr/lenny

« back to all changes in this revision

Viewing changes to bzrlib/tests/bzrdir_implementations/test_bzrdir.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-08-22 20:06:37 UTC
  • mfrom: (3.1.63 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080822200637-kxobfsnjlzojhqra
Tags: 1.5-1.1
* Non-maintainer upload.
* Apply patch from upstream VCS to fix FTBFS in tools/rst2html.py
  with older docutils. Thanks to Olivier Tétard for digging it
  up.
  Closes: #494246.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
17
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import errno
 
21
from itertools import izip
20
22
import os
21
23
from stat import S_ISDIR
22
24
import sys
23
25
 
24
26
import bzrlib.branch
25
 
import bzrlib.bzrdir as bzrdir
 
27
from bzrlib import (
 
28
    bzrdir,
 
29
    errors,
 
30
    lockdir,
 
31
    repository,
 
32
    revision as _mod_revision,
 
33
    transactions,
 
34
    transport,
 
35
    ui,
 
36
    workingtree,
 
37
    )
26
38
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
27
39
from bzrlib.check import check
28
 
import bzrlib.errors as errors
29
40
from bzrlib.errors import (FileExists,
30
41
                           NoSuchRevision,
31
42
                           NoSuchFile,
32
43
                           UninitializableFormat,
33
44
                           NotBranchError,
34
45
                           )
35
 
import bzrlib.repository as repository
36
46
import bzrlib.revision
37
47
from bzrlib.tests import (
38
48
                          ChrootedTestCase,
39
49
                          TestCase,
40
50
                          TestCaseWithTransport,
 
51
                          TestNotApplicable,
41
52
                          TestSkipped,
42
53
                          )
 
54
from bzrlib.tests.bzrdir_implementations import TestCaseWithBzrDir
43
55
from bzrlib.trace import mutter
44
 
import bzrlib.transactions as transactions
45
 
import bzrlib.transport as transport
46
56
from bzrlib.transport import get_transport
47
 
import bzrlib.ui as ui
 
57
from bzrlib.transport.local import LocalTransport
48
58
from bzrlib.upgrade import upgrade
49
 
import bzrlib.workingtree as workingtree
50
 
 
51
 
 
52
 
class TestCaseWithBzrDir(TestCaseWithTransport):
53
 
 
54
 
    def setUp(self):
55
 
        super(TestCaseWithBzrDir, self).setUp()
56
 
        self.bzrdir = None
57
 
 
58
 
    def get_bzrdir(self):
59
 
        if self.bzrdir is None:
60
 
            self.bzrdir = self.make_bzrdir(None)
61
 
        return self.bzrdir
62
 
 
63
 
    def make_bzrdir(self, relpath, format=None):
64
 
        return super(TestCaseWithBzrDir, self).make_bzrdir(
65
 
            relpath, format=self.bzrdir_format)
66
 
 
 
59
from bzrlib.remote import RemoteBzrDir
 
60
from bzrlib.repofmt import weaverepo
67
61
 
68
62
 
69
63
class TestBzrDir(TestCaseWithBzrDir):
87
81
        reading it again, which leads to changed timestamps. This is ok though,
88
82
        because the inventory.kndx file is not ignored, and the integrity of
89
83
        knit joins is tested by test_knit and test_versionedfile.
 
84
 
 
85
        :seealso: Additionally, assertRepositoryHasSameItems provides value
 
86
            rather than representation checking of repositories for
 
87
            equivalence.
90
88
        """
91
89
        files = []
92
90
        directories = ['.']
93
91
        while directories:
94
92
            dir = directories.pop()
95
 
            for path in source.list_dir(dir):
 
93
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
96
94
                path = dir + '/' + path
97
95
                if path in ignore_list:
98
96
                    continue
99
 
                stat = source.stat(path)
 
97
                try:
 
98
                    stat = source.stat(path)
 
99
                except errors.NoSuchFile:
 
100
                    self.fail('%s not in source' % path)
100
101
                if S_ISDIR(stat.st_mode):
101
102
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
102
103
                    directories.append(path)
105
106
                                         target.get(path).read(),
106
107
                                         "text for file %r differs:\n" % path)
107
108
 
 
109
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
 
110
        """require left_repo and right_repo to contain the same data."""
 
111
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
 
112
        # local repositories to remote ones...  but this is an as-yet unsolved
 
113
        # aspect of format management and the Remote protocols...
 
114
        # self.assertEqual(left_repo._format.__class__,
 
115
        #     right_repo._format.__class__)
 
116
        left_repo.lock_read()
 
117
        try:
 
118
            right_repo.lock_read()
 
119
            try:
 
120
                # revs
 
121
                all_revs = left_repo.all_revision_ids()
 
122
                self.assertEqual(left_repo.all_revision_ids(),
 
123
                    right_repo.all_revision_ids())
 
124
                for rev_id in left_repo.all_revision_ids():
 
125
                    self.assertEqual(left_repo.get_revision(rev_id),
 
126
                        right_repo.get_revision(rev_id))
 
127
                # inventories
 
128
                left_inv_weave = left_repo.get_inventory_weave()
 
129
                right_inv_weave = right_repo.get_inventory_weave()
 
130
                self.assertEqual(set(left_inv_weave.versions()),
 
131
                    set(right_inv_weave.versions()))
 
132
                # XXX: currently this does not handle indirectly referenced
 
133
                # inventories (e.g. where the inventory is a delta basis for
 
134
                # one that is fully present but that the revid for that
 
135
                # inventory is not yet present.)
 
136
                self.assertEqual(set(left_inv_weave.versions()), set(all_revs))
 
137
                left_trees = left_repo.revision_trees(all_revs)
 
138
                right_trees = right_repo.revision_trees(all_revs)
 
139
                for left_tree, right_tree in izip(left_trees, right_trees):
 
140
                    self.assertEqual(left_tree.inventory, right_tree.inventory)
 
141
                # texts
 
142
                text_index = left_repo._generate_text_key_index()
 
143
                self.assertEqual(text_index,
 
144
                    right_repo._generate_text_key_index())
 
145
                for file_id, revision_id in text_index.iterkeys():
 
146
                    left_weave = left_repo.weave_store.get_weave(
 
147
                        file_id, left_repo.get_transaction())
 
148
                    right_weave = right_repo.weave_store.get_weave(
 
149
                        file_id, right_repo.get_transaction())
 
150
                    self.assertEqual(
 
151
                        left_weave.get_text(revision_id),
 
152
                        right_weave.get_text(revision_id))
 
153
                # signatures
 
154
                for rev_id in all_revs:
 
155
                    try:
 
156
                        left_text = left_repo.get_signature_text(rev_id)
 
157
                    except NoSuchRevision:
 
158
                        continue
 
159
                    right_text = right_repo.get_signature_text(rev_id)
 
160
                    self.assertEqual(left_text, right_text)
 
161
            finally:
 
162
                right_repo.unlock()
 
163
        finally:
 
164
            left_repo.unlock()
 
165
 
108
166
    def skipIfNoWorkingTree(self, a_bzrdir):
109
167
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
110
168
        
128
186
            raise TestSkipped("cannot make working tree with transport %r"
129
187
                              % a_bzrdir.transport)
130
188
 
131
 
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
132
 
                     force_new_repo=False):
 
189
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
 
190
                     force_new_repo=False, accelerator_tree=None):
133
191
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
134
192
        
135
193
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
136
194
        TestSkipped.  Returns the newly sprouted bzrdir.
137
195
        """
138
 
        try:
139
 
            target = from_bzrdir.sprout(to_url, revision_id=revision_id,
140
 
                                        basis=basis,
141
 
                                        force_new_repo=force_new_repo)
142
 
        except errors.NotLocalUrl:
 
196
        to_transport = get_transport(to_url)
 
197
        if not isinstance(to_transport, LocalTransport):
143
198
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
 
199
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
 
200
                                    force_new_repo=force_new_repo,
 
201
                                    possible_transports=[to_transport],
 
202
                                    accelerator_tree=accelerator_tree)
144
203
        return target
145
204
 
146
205
    def test_create_null_workingtree(self):
147
206
        dir = self.make_bzrdir('dir1')
148
207
        dir.create_repository()
149
208
        dir.create_branch()
150
 
        wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
209
        try:
 
210
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
211
        except errors.NotLocalUrl:
 
212
            raise TestSkipped("cannot make working tree with transport %r"
 
213
                              % dir.transport)
151
214
        self.assertEqual([], wt.get_parent_ids())
152
215
 
 
216
    def test_destroy_workingtree(self):
 
217
        tree = self.make_branch_and_tree('tree')
 
218
        self.build_tree(['tree/file'])
 
219
        tree.add('file')
 
220
        tree.commit('first commit')
 
221
        bzrdir = tree.bzrdir
 
222
        try:
 
223
            bzrdir.destroy_workingtree()
 
224
        except errors.UnsupportedOperation:
 
225
            raise TestSkipped('Format does not support destroying tree')
 
226
        self.failIfExists('tree/file')
 
227
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
228
        bzrdir.create_workingtree()
 
229
        self.failUnlessExists('tree/file')
 
230
        bzrdir.destroy_workingtree_metadata()
 
231
        self.failUnlessExists('tree/file')
 
232
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
233
 
 
234
    def test_destroy_branch(self):
 
235
        branch = self.make_branch('branch')
 
236
        bzrdir = branch.bzrdir
 
237
        try:
 
238
            bzrdir.destroy_branch()
 
239
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
 
240
            raise TestNotApplicable('Format does not support destroying tree')
 
241
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
 
242
        bzrdir.create_branch()
 
243
        bzrdir.open_branch()
 
244
 
 
245
    def test_destroy_repository(self):
 
246
        repo = self.make_repository('repository')
 
247
        bzrdir = repo.bzrdir
 
248
        try:
 
249
            bzrdir.destroy_repository()
 
250
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
 
251
            raise TestNotApplicable('Format does not support destroying'
 
252
                                    ' repository')
 
253
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
 
254
        bzrdir.create_repository()
 
255
        bzrdir.open_repository()
 
256
 
 
257
    def test_open_workingtree_raises_no_working_tree(self):
 
258
        """BzrDir.open_workingtree() should raise NoWorkingTree (rather than
 
259
        e.g. NotLocalUrl) if there is no working tree.
 
260
        """
 
261
        dir = self.make_bzrdir('source')
 
262
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
 
263
        if vfs_dir.has_workingtree():
 
264
            # This BzrDir format doesn't support BzrDirs without working trees,
 
265
            # so this test is irrelevant.
 
266
            return
 
267
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
 
268
 
 
269
    def test_clone_on_transport(self):
 
270
        a_dir = self.make_bzrdir('source')
 
271
        target_transport = a_dir.root_transport.clone('..').clone('target')
 
272
        target = a_dir.clone_on_transport(target_transport)
 
273
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
 
274
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
 
275
                                    ['./.bzr/merge-hashes'])
 
276
 
153
277
    def test_clone_bzrdir_empty(self):
154
278
        dir = self.make_bzrdir('source')
155
279
        target = dir.clone(self.get_url('target'))
156
280
        self.assertNotEqual(dir.transport.base, target.transport.base)
157
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
281
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
 
282
                                    ['./.bzr/merge-hashes'])
158
283
    
159
284
    def test_clone_bzrdir_empty_force_new_ignored(self):
160
285
        # the force_new_repo parameter should have no effect on an empty
162
287
        dir = self.make_bzrdir('source')
163
288
        target = dir.clone(self.get_url('target'), force_new_repo=True)
164
289
        self.assertNotEqual(dir.transport.base, target.transport.base)
165
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
290
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
 
291
                                    ['./.bzr/merge-hashes'])
166
292
    
167
293
    def test_clone_bzrdir_repository(self):
168
294
        tree = self.make_branch_and_tree('commit_tree')
176
302
        target = dir.clone(self.get_url('target'))
177
303
        self.assertNotEqual(dir.transport.base, target.transport.base)
178
304
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
179
 
                                    ['./.bzr/repository/inventory.knit',
 
305
                                    [
 
306
                                     './.bzr/merge-hashes',
 
307
                                     './.bzr/repository',
180
308
                                     ])
181
 
 
 
309
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
182
310
 
183
311
    def test_clone_bzrdir_repository_under_shared(self):
184
312
        tree = self.make_branch_and_tree('commit_tree')
198
326
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
199
327
 
200
328
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
 
329
        # Create a shared repository
201
330
        try:
202
331
            shared_repo = self.make_repository('shared', shared=True)
203
332
        except errors.IncompatibleFormat:
204
333
            return
 
334
        # Make a branch, 'commit_tree', and working tree outside of the shared
 
335
        # repository, and commit some revisions to it.
205
336
        tree = self.make_branch_and_tree('commit_tree')
206
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
337
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
207
338
        tree.add('foo')
208
339
        tree.commit('revision 1', rev_id='1')
209
340
        tree.bzrdir.open_branch().set_revision_history([])
210
341
        tree.set_parent_trees([])
211
342
        tree.commit('revision 2', rev_id='2')
212
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
343
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
 
344
        # repository into the shared repository.
 
345
        tree.branch.repository.copy_content_into(shared_repo)
 
346
        # Make a branch 'source' inside the shared repository.
213
347
        dir = self.make_bzrdir('shared/source')
214
348
        dir.create_branch()
 
349
        # Clone 'source' to 'target', also inside the shared repository.
215
350
        target = dir.clone(self.get_url('shared/target'))
 
351
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
216
352
        self.assertNotEqual(dir.transport.base, target.transport.base)
217
353
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
354
        # The shared repository will contain revisions from the 'commit_tree'
 
355
        # repository, even revisions that are not part of the history of the
 
356
        # 'commit_tree' branch.
218
357
        self.assertTrue(shared_repo.has_revision('1'))
219
358
 
220
359
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
223
362
        except errors.IncompatibleFormat:
224
363
            return
225
364
        tree = self.make_branch_and_tree('commit_tree')
226
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
365
        self.build_tree(['commit_tree/foo'])
227
366
        tree.add('foo')
228
367
        tree.commit('revision 1', rev_id='1')
229
 
        tree.bzrdir.open_branch().set_revision_history([])
 
368
        tree.branch.bzrdir.open_branch().set_revision_history([])
230
369
        tree.set_parent_trees([])
231
370
        tree.commit('revision 2', rev_id='2')
232
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
233
 
        shared_repo.set_make_working_trees(False)
234
 
        self.assertFalse(shared_repo.make_working_trees())
 
371
        tree.branch.repository.copy_content_into(shared_repo)
 
372
        if shared_repo.make_working_trees():
 
373
            shared_repo.set_make_working_trees(False)
 
374
            self.assertFalse(shared_repo.make_working_trees())
235
375
        self.assertTrue(shared_repo.has_revision('1'))
236
376
        dir = self.make_bzrdir('shared/source')
237
377
        dir.create_branch()
245
385
        
246
386
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
247
387
        tree = self.make_branch_and_tree('commit_tree')
248
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
388
        self.build_tree(['commit_tree/foo'])
249
389
        tree.add('foo')
250
390
        tree.commit('revision 1', rev_id='1')
251
391
        dir = self.make_bzrdir('source')
259
399
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
260
400
        self.assertNotEqual(dir.transport.base, target.transport.base)
261
401
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
262
 
                                    ['./.bzr/repository/inventory.knit',
 
402
                                    ['./.bzr/repository',
263
403
                                     ])
 
404
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
264
405
 
265
406
    def test_clone_bzrdir_repository_revision(self):
266
407
        # test for revision limiting, [smoke test, not corner case checks].
268
409
        # and clone it with a revision limit.
269
410
        # 
270
411
        tree = self.make_branch_and_tree('commit_tree')
271
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
412
        self.build_tree(['commit_tree/foo'])
272
413
        tree.add('foo')
273
414
        tree.commit('revision 1', rev_id='1')
274
 
        tree.bzrdir.open_branch().set_revision_history([])
 
415
        tree.branch.bzrdir.open_branch().set_revision_history([])
275
416
        tree.set_parent_trees([])
276
417
        tree.commit('revision 2', rev_id='2')
277
418
        source = self.make_repository('source')
278
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
419
        tree.branch.repository.copy_content_into(source)
279
420
        dir = source.bzrdir
280
421
        target = dir.clone(self.get_url('target'), revision_id='2')
281
422
        raise TestSkipped('revision limiting not strict yet')
282
423
 
283
424
    def test_clone_bzrdir_branch_and_repo(self):
284
425
        tree = self.make_branch_and_tree('commit_tree')
285
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
426
        self.build_tree(['commit_tree/foo'])
286
427
        tree.add('foo')
287
428
        tree.commit('revision 1')
288
429
        source = self.make_branch('source')
289
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
290
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
430
        tree.branch.repository.copy_content_into(source.repository)
 
431
        tree.branch.copy_content_into(source)
291
432
        dir = source.bzrdir
292
433
        target = dir.clone(self.get_url('target'))
293
434
        self.assertNotEqual(dir.transport.base, target.transport.base)
294
435
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
295
 
                                    ['./.bzr/stat-cache',
 
436
                                    [
 
437
                                     './.bzr/basis-inventory-cache',
296
438
                                     './.bzr/checkout/stat-cache',
297
 
                                     './.bzr/repository/inventory.knit',
298
 
                                     ])
 
439
                                     './.bzr/merge-hashes',
 
440
                                     './.bzr/repository',
 
441
                                     './.bzr/stat-cache',
 
442
                                    ])
 
443
        self.assertRepositoryHasSameItems(
 
444
            tree.branch.repository, target.open_repository())
299
445
 
300
446
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
301
447
        # by default cloning into a shared repo uses the shared repo.
302
448
        tree = self.make_branch_and_tree('commit_tree')
303
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
449
        self.build_tree(['commit_tree/foo'])
304
450
        tree.add('foo')
305
451
        tree.commit('revision 1')
306
452
        source = self.make_branch('source')
307
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
308
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
453
        tree.branch.repository.copy_content_into(source.repository)
 
454
        tree.branch.copy_content_into(source)
309
455
        try:
310
456
            self.make_repository('target', shared=True)
311
457
        except errors.IncompatibleFormat:
320
466
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
321
467
        # by default cloning into a shared repo uses the shared repo.
322
468
        tree = self.make_branch_and_tree('commit_tree')
323
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
469
        self.build_tree(['commit_tree/foo'])
324
470
        tree.add('foo')
325
471
        tree.commit('revision 1')
326
472
        source = self.make_branch('source')
327
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
328
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
473
        tree.branch.repository.copy_content_into(source.repository)
 
474
        tree.branch.copy_content_into(source)
329
475
        try:
330
476
            self.make_repository('target', shared=True)
331
477
        except errors.IncompatibleFormat:
333
479
        dir = source.bzrdir
334
480
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
335
481
        self.assertNotEqual(dir.transport.base, target.transport.base)
336
 
        target.open_repository()
 
482
        repo = target.open_repository()
337
483
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
338
 
                                    ['./.bzr/repository/inventory.knit',
 
484
                                    ['./.bzr/repository',
339
485
                                     ])
 
486
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
340
487
 
341
488
    def test_clone_bzrdir_branch_reference(self):
342
489
        # cloning should preserve the reference status of the branch in a bzrdir
350
497
            return
351
498
        target = dir.clone(self.get_url('target'))
352
499
        self.assertNotEqual(dir.transport.base, target.transport.base)
353
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
354
 
                                    ['./.bzr/repository/inventory.knit',
355
 
                                     ])
 
500
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
356
501
 
357
502
    def test_clone_bzrdir_branch_revision(self):
358
503
        # test for revision limiting, [smoke test, not corner case checks].
360
505
        # and clone it with a revision limit.
361
506
        # 
362
507
        tree = self.make_branch_and_tree('commit_tree')
363
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
508
        self.build_tree(['commit_tree/foo'])
364
509
        tree.add('foo')
365
510
        tree.commit('revision 1', rev_id='1')
366
511
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
367
512
        source = self.make_branch('source')
368
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
369
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
513
        tree.branch.repository.copy_content_into(source.repository)
 
514
        tree.branch.copy_content_into(source)
370
515
        dir = source.bzrdir
371
516
        target = dir.clone(self.get_url('target'), revision_id='1')
372
517
        self.assertEqual('1', target.open_branch().last_revision())
373
518
        
374
519
    def test_clone_bzrdir_tree_branch_repo(self):
375
 
        tree = self.make_branch_and_tree('sourcce')
376
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
520
        tree = self.make_branch_and_tree('source')
 
521
        self.build_tree(['source/foo'])
377
522
        tree.add('foo')
378
523
        tree.commit('revision 1')
379
524
        dir = tree.bzrdir
382
527
        self.assertNotEqual(dir.transport.base, target.transport.base)
383
528
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
384
529
                                    ['./.bzr/stat-cache',
 
530
                                     './.bzr/checkout/dirstate',
385
531
                                     './.bzr/checkout/stat-cache',
386
 
                                     './.bzr/repository/inventory.knit',
 
532
                                     './.bzr/checkout/merge-hashes',
 
533
                                     './.bzr/merge-hashes',
 
534
                                     './.bzr/repository',
387
535
                                     ])
 
536
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
537
            target.open_repository())
 
538
        target.open_workingtree().revert()
388
539
 
389
 
        target.open_workingtree().revert([])
 
540
    def test_clone_on_transport_preserves_repo_format(self):
 
541
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
 
542
            format = 'knit'
 
543
        else:
 
544
            format = None
 
545
        source_branch = self.make_branch('source', format=format)
 
546
        # Ensure no format data is cached
 
547
        a_dir = bzrlib.branch.Branch.open_from_transport(
 
548
            self.get_transport('source')).bzrdir
 
549
        target_transport = a_dir.root_transport.clone('..').clone('target')
 
550
        target_bzrdir = a_dir.clone_on_transport(target_transport)
 
551
        target_repo = target_bzrdir.open_repository()
 
552
        self.assertEqual(target_repo._format, source_branch.repository._format)
390
553
 
391
554
    def test_revert_inventory(self):
392
 
        tree = self.make_branch_and_tree('sourcce')
393
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
555
        tree = self.make_branch_and_tree('source')
 
556
        self.build_tree(['source/foo'])
394
557
        tree.add('foo')
395
558
        tree.commit('revision 1')
396
559
        dir = tree.bzrdir
398
561
        self.skipIfNoWorkingTree(target)
399
562
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
400
563
                                    ['./.bzr/stat-cache',
 
564
                                     './.bzr/checkout/dirstate',
401
565
                                     './.bzr/checkout/stat-cache',
402
 
                                     './.bzr/repository/inventory.knit',
 
566
                                     './.bzr/checkout/merge-hashes',
 
567
                                     './.bzr/merge-hashes',
 
568
                                     './.bzr/repository',
403
569
                                     ])
 
570
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
571
            target.open_repository())
404
572
 
405
 
        target.open_workingtree().revert([])
 
573
        target.open_workingtree().revert()
406
574
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
407
575
                                    ['./.bzr/stat-cache',
 
576
                                     './.bzr/checkout/dirstate',
408
577
                                     './.bzr/checkout/stat-cache',
409
 
                                     './.bzr/repository/inventory.knit',
 
578
                                     './.bzr/checkout/merge-hashes',
 
579
                                     './.bzr/merge-hashes',
 
580
                                     './.bzr/repository',
410
581
                                     ])
411
 
 
 
582
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
583
            target.open_repository())
412
584
 
413
585
    def test_clone_bzrdir_tree_branch_reference(self):
414
586
        # a tree with a branch reference (aka a checkout) 
428
600
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
429
601
                                    ['./.bzr/stat-cache',
430
602
                                     './.bzr/checkout/stat-cache',
 
603
                                     './.bzr/checkout/merge-hashes',
 
604
                                     './.bzr/merge-hashes',
431
605
                                     './.bzr/repository/inventory.knit',
432
606
                                     ])
433
607
 
438
612
        # This smoke test just checks the revision-id is right. Tree specific
439
613
        # tests will check corner cases.
440
614
        tree = self.make_branch_and_tree('source')
441
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
615
        self.build_tree(['source/foo'])
442
616
        tree.add('foo')
443
617
        tree.commit('revision 1', rev_id='1')
444
618
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
447
621
        self.skipIfNoWorkingTree(target)
448
622
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
449
623
 
450
 
    def test_clone_bzrdir_incomplete_source_with_basis(self):
451
 
        # ensure that basis really does grab from the basis by having incomplete source
452
 
        tree = self.make_branch_and_tree('commit_tree')
453
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
624
    def test_clone_bzrdir_into_notrees_repo(self):
 
625
        """Cloning into a no-trees repo should not create a working tree"""
 
626
        tree = self.make_branch_and_tree('source')
 
627
        self.build_tree(['source/foo'])
454
628
        tree.add('foo')
455
 
        tree.commit('revision 1', rev_id='1')
456
 
        source = self.make_branch_and_tree('source')
457
 
        # this gives us an incomplete repository
458
 
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
459
 
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
460
 
        tree.bzrdir.open_branch().copy_content_into(source.branch)
461
 
        tree.copy_content_into(source)
462
 
        self.assertFalse(source.branch.repository.has_revision('2'))
463
 
        dir = source.bzrdir
464
 
        target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
465
 
        self.assertEqual('2', target.open_branch().last_revision())
466
 
        try:
467
 
            self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
468
 
        except errors.NoWorkingTree:
469
 
            # It should have a working tree if it's able to have one, so if
470
 
            # we're here make sure it really can't have one.
471
 
            self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
472
 
        self.assertTrue(target.open_branch().repository.has_revision('2'))
 
629
        tree.commit('revision 1')
 
630
 
 
631
        try:
 
632
            repo = self.make_repository('repo', shared=True)
 
633
        except errors.IncompatibleFormat:
 
634
            raise TestNotApplicable('must support shared repositories')
 
635
        if repo.make_working_trees():
 
636
            repo.set_make_working_trees(False)
 
637
            self.assertFalse(repo.make_working_trees())
 
638
 
 
639
        dir = tree.bzrdir
 
640
        a_dir = dir.clone(self.get_url('repo/a'))
 
641
        a_dir.open_branch()
 
642
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
 
643
 
 
644
    def test_get_branch_reference_on_reference(self):
 
645
        """get_branch_reference should return the right url."""
 
646
        referenced_branch = self.make_branch('referenced')
 
647
        dir = self.make_bzrdir('source')
 
648
        try:
 
649
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
650
                referenced_branch)
 
651
        except errors.IncompatibleFormat:
 
652
            # this is ok too, not all formats have to support references.
 
653
            return
 
654
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
655
            dir.get_branch_reference())
 
656
 
 
657
    def test_get_branch_reference_on_non_reference(self):
 
658
        """get_branch_reference should return None for non-reference branches."""
 
659
        branch = self.make_branch('referenced')
 
660
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
 
661
 
 
662
    def test_get_branch_reference_no_branch(self):
 
663
        """get_branch_reference should not mask NotBranchErrors."""
 
664
        dir = self.make_bzrdir('source')
 
665
        if dir.has_branch():
 
666
            # this format does not support branchless bzrdirs.
 
667
            return
 
668
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
473
669
 
474
670
    def test_sprout_bzrdir_empty(self):
475
671
        dir = self.make_bzrdir('source')
490
686
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
491
687
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
492
688
        target.open_branch()
493
 
        target.open_workingtree()
 
689
        try:
 
690
            target.open_workingtree()
 
691
        except errors.NoWorkingTree:
 
692
            # bzrdir's that never have working trees are allowed to pass;
 
693
            # whitelist them for now.
 
694
            self.assertIsInstance(target, RemoteBzrDir)
494
695
 
495
696
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
496
697
        # the force_new_repo parameter should force use of a new repo in an empty
515
716
        repo = dir.create_repository()
516
717
        repo.fetch(tree.branch.repository)
517
718
        self.assertTrue(repo.has_revision('1'))
 
719
        try:
 
720
            self.assertTrue(
 
721
                _mod_revision.is_null(_mod_revision.ensure_null(
 
722
                dir.open_branch().last_revision())))
 
723
        except errors.NotBranchError:
 
724
            pass
518
725
        target = self.sproutOrSkip(dir, self.get_url('target'))
519
726
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
727
        # testing inventory isn't reasonable for repositories
520
728
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
521
 
                                    ['./.bzr/repository/inventory.knit',
 
729
                                    [
 
730
                                     './.bzr/branch',
 
731
                                     './.bzr/checkout',
 
732
                                     './.bzr/inventory',
 
733
                                     './.bzr/parent',
 
734
                                     './.bzr/repository/inventory.knit',
522
735
                                     ])
 
736
        try:
 
737
            # If we happen to have a tree, we'll guarantee everything
 
738
            # except for the tree root is the same.
 
739
            inventory_f = file(dir.transport.base+'inventory', 'rb')
 
740
            self.assertContainsRe(inventory_f.read(), 
 
741
                                  '<inventory file_id="TREE_ROOT[^"]*"'
 
742
                                  ' format="5">\n</inventory>\n')
 
743
            inventory_f.close()
 
744
        except IOError, e:
 
745
            if e.errno != errno.ENOENT:
 
746
                raise
523
747
 
524
748
    def test_sprout_bzrdir_with_repository_to_shared(self):
525
749
        tree = self.make_branch_and_tree('commit_tree')
526
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
750
        self.build_tree(['commit_tree/foo'])
527
751
        tree.add('foo')
528
752
        tree.commit('revision 1', rev_id='1')
529
753
        tree.bzrdir.open_branch().set_revision_history([])
530
754
        tree.set_parent_trees([])
531
755
        tree.commit('revision 2', rev_id='2')
532
756
        source = self.make_repository('source')
533
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
757
        tree.branch.repository.copy_content_into(source)
534
758
        dir = source.bzrdir
535
759
        try:
536
760
            shared_repo = self.make_repository('target', shared=True)
546
770
        except errors.IncompatibleFormat:
547
771
            return
548
772
        tree = self.make_branch_and_tree('commit_tree')
549
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
773
        self.build_tree(['commit_tree/foo'])
550
774
        tree.add('foo')
551
775
        tree.commit('revision 1', rev_id='1')
552
776
        tree.bzrdir.open_branch().set_revision_history([])
553
777
        tree.set_parent_trees([])
554
778
        tree.commit('revision 2', rev_id='2')
555
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
779
        tree.branch.repository.copy_content_into(shared_repo)
556
780
        dir = self.make_bzrdir('shared/source')
557
781
        dir.create_branch()
558
782
        target = self.sproutOrSkip(dir, self.get_url('shared/target'))
566
790
        except errors.IncompatibleFormat:
567
791
            return
568
792
        tree = self.make_branch_and_tree('commit_tree')
569
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
793
        self.build_tree(['commit_tree/foo'])
570
794
        tree.add('foo')
571
795
        tree.commit('revision 1', rev_id='1')
572
796
        tree.bzrdir.open_branch().set_revision_history([])
573
797
        tree.set_parent_trees([])
574
798
        tree.commit('revision 2', rev_id='2')
575
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
576
 
        shared_repo.set_make_working_trees(False)
577
 
        self.assertFalse(shared_repo.make_working_trees())
 
799
        tree.branch.repository.copy_content_into(shared_repo)
 
800
        if shared_repo.make_working_trees():
 
801
            shared_repo.set_make_working_trees(False)
 
802
            self.assertFalse(shared_repo.make_working_trees())
578
803
        self.assertTrue(shared_repo.has_revision('1'))
579
804
        dir = self.make_bzrdir('shared/source')
580
805
        dir.create_branch()
583
808
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
584
809
        branch = target.open_branch()
585
810
        self.assertTrue(branch.repository.has_revision('1'))
586
 
        self.assertTrue(branch.repository.make_working_trees())
 
811
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
812
            self.assertTrue(branch.repository.make_working_trees())
587
813
        self.assertFalse(branch.repository.is_shared())
588
814
 
589
815
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
590
816
        tree = self.make_branch_and_tree('commit_tree')
591
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
817
        self.build_tree(['commit_tree/foo'])
592
818
        tree.add('foo')
593
819
        tree.commit('revision 1', rev_id='1')
594
820
        tree.bzrdir.open_branch().set_revision_history([])
595
821
        tree.set_parent_trees([])
596
822
        tree.commit('revision 2', rev_id='2')
597
823
        source = self.make_repository('source')
598
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
824
        tree.branch.repository.copy_content_into(source)
599
825
        dir = source.bzrdir
600
826
        try:
601
827
            shared_repo = self.make_repository('target', shared=True)
612
838
        # and sprout it with a revision limit.
613
839
        # 
614
840
        tree = self.make_branch_and_tree('commit_tree')
615
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
841
        self.build_tree(['commit_tree/foo'])
616
842
        tree.add('foo')
617
843
        tree.commit('revision 1', rev_id='1')
618
844
        tree.bzrdir.open_branch().set_revision_history([])
619
845
        tree.set_parent_trees([])
620
846
        tree.commit('revision 2', rev_id='2')
621
847
        source = self.make_repository('source')
622
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
848
        tree.branch.repository.copy_content_into(source)
623
849
        dir = source.bzrdir
624
850
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
625
851
        raise TestSkipped('revision limiting not strict yet')
626
852
 
627
853
    def test_sprout_bzrdir_branch_and_repo(self):
628
854
        tree = self.make_branch_and_tree('commit_tree')
629
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
855
        self.build_tree(['commit_tree/foo'])
630
856
        tree.add('foo')
631
857
        tree.commit('revision 1')
632
858
        source = self.make_branch('source')
633
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
859
        tree.branch.repository.copy_content_into(source.repository)
634
860
        tree.bzrdir.open_branch().copy_content_into(source)
635
861
        dir = source.bzrdir
636
862
        target = self.sproutOrSkip(dir, self.get_url('target'))
637
863
        self.assertNotEqual(dir.transport.base, target.transport.base)
638
864
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
639
 
                                    ['./.bzr/stat-cache',
 
865
                                    [
 
866
                                     './.bzr/basis-inventory-cache',
 
867
                                     './.bzr/branch/branch.conf',
 
868
                                     './.bzr/branch/parent',
 
869
                                     './.bzr/checkout',
 
870
                                     './.bzr/checkout/inventory',
640
871
                                     './.bzr/checkout/stat-cache',
641
872
                                     './.bzr/inventory',
642
 
                                     './.bzr/checkout/inventory',
 
873
                                     './.bzr/parent',
643
874
                                     './.bzr/repository/inventory.knit',
 
875
                                     './.bzr/stat-cache',
 
876
                                     './foo',
644
877
                                     ])
645
878
 
646
879
    def test_sprout_bzrdir_branch_and_repo_shared(self):
647
880
        # sprouting a branch with a repo into a shared repo uses the shared
648
881
        # repo
649
882
        tree = self.make_branch_and_tree('commit_tree')
650
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
883
        self.build_tree(['commit_tree/foo'])
651
884
        tree.add('foo')
652
885
        tree.commit('revision 1', rev_id='1')
653
886
        source = self.make_branch('source')
654
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
887
        tree.branch.repository.copy_content_into(source.repository)
655
888
        tree.bzrdir.open_branch().copy_content_into(source)
656
889
        dir = source.bzrdir
657
890
        try:
665
898
        # sprouting a branch with a repo into a shared repo uses the shared
666
899
        # repo
667
900
        tree = self.make_branch_and_tree('commit_tree')
668
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
901
        self.build_tree(['commit_tree/foo'])
669
902
        tree.add('foo')
670
903
        tree.commit('revision 1', rev_id='1')
671
904
        source = self.make_branch('source')
672
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
905
        tree.branch.repository.copy_content_into(source.repository)
673
906
        tree.bzrdir.open_branch().copy_content_into(source)
674
907
        dir = source.bzrdir
675
908
        try:
758
991
        # and sprout it with a revision limit.
759
992
        # 
760
993
        tree = self.make_branch_and_tree('commit_tree')
761
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
994
        self.build_tree(['commit_tree/foo'])
762
995
        tree.add('foo')
763
996
        tree.commit('revision 1', rev_id='1')
764
997
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
765
998
        source = self.make_branch('source')
766
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
999
        tree.branch.repository.copy_content_into(source.repository)
767
1000
        tree.bzrdir.open_branch().copy_content_into(source)
768
1001
        dir = source.bzrdir
769
1002
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
770
1003
        self.assertEqual('1', target.open_branch().last_revision())
771
1004
        
772
1005
    def test_sprout_bzrdir_tree_branch_repo(self):
773
 
        tree = self.make_branch_and_tree('sourcce')
 
1006
        tree = self.make_branch_and_tree('source')
774
1007
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
775
1008
        tree.add('foo')
776
1009
        tree.commit('revision 1')
778
1011
        target = self.sproutOrSkip(dir, self.get_url('target'))
779
1012
        self.assertNotEqual(dir.transport.base, target.transport.base)
780
1013
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
781
 
                                    ['./.bzr/stat-cache',
 
1014
                                    [
 
1015
                                     './.bzr/branch/branch.conf',
 
1016
                                     './.bzr/branch/parent',
 
1017
                                     './.bzr/checkout/dirstate',
782
1018
                                     './.bzr/checkout/stat-cache',
 
1019
                                     './.bzr/checkout/inventory',
783
1020
                                     './.bzr/inventory',
784
 
                                     './.bzr/checkout/inventory',
785
 
                                     './.bzr/repository/inventory.knit',
 
1021
                                     './.bzr/parent',
 
1022
                                     './.bzr/repository',
 
1023
                                     './.bzr/stat-cache',
786
1024
                                     ])
 
1025
        self.assertRepositoryHasSameItems(
 
1026
            tree.branch.repository, target.open_repository())
787
1027
 
788
1028
    def test_sprout_bzrdir_tree_branch_reference(self):
789
1029
        # sprouting should create a repository if needed and a sprouted branch.
798
1038
            return
799
1039
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
800
1040
        tree = self.createWorkingTreeOrSkip(dir)
801
 
        tree.bzrdir.root_transport.mkdir('subdir')
 
1041
        self.build_tree(['source/subdir/'])
802
1042
        tree.add('subdir')
803
1043
        target = self.sproutOrSkip(dir, self.get_url('target'))
804
1044
        self.assertNotEqual(dir.transport.base, target.transport.base)
824
1064
            return
825
1065
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
826
1066
        tree = self.createWorkingTreeOrSkip(dir)
827
 
        self.build_tree(['foo'], transport=dir.root_transport)
 
1067
        self.build_tree(['source/foo'])
828
1068
        tree.add('foo')
829
1069
        tree.commit('revision 1', rev_id='1')
830
1070
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
847
1087
        # This smoke test just checks the revision-id is right. Tree specific
848
1088
        # tests will check corner cases.
849
1089
        tree = self.make_branch_and_tree('source')
850
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
1090
        self.build_tree(['source/foo'])
851
1091
        tree.add('foo')
852
1092
        tree.commit('revision 1', rev_id='1')
853
1093
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
855
1095
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
856
1096
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
857
1097
 
858
 
    def test_sprout_bzrdir_incomplete_source_with_basis(self):
859
 
        # ensure that basis really does grab from the basis by having incomplete source
860
 
        tree = self.make_branch_and_tree('commit_tree')
861
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
1098
    def test_sprout_takes_accelerator(self):
 
1099
        tree = self.make_branch_and_tree('source')
 
1100
        self.build_tree(['source/foo'])
862
1101
        tree.add('foo')
863
1102
        tree.commit('revision 1', rev_id='1')
864
 
        source = self.make_branch_and_tree('source')
865
 
        # this gives us an incomplete repository
866
 
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
867
1103
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
868
 
        tree.bzrdir.open_branch().copy_content_into(source.branch)
869
 
        tree.copy_content_into(source)
870
 
        self.assertFalse(source.branch.repository.has_revision('2'))
871
 
        dir = source.bzrdir
 
1104
        dir = tree.bzrdir
872
1105
        target = self.sproutOrSkip(dir, self.get_url('target'),
873
 
                                   basis=tree.bzrdir)
874
 
        self.assertEqual('2', target.open_branch().last_revision())
 
1106
                                   accelerator_tree=tree)
875
1107
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
876
 
        self.assertTrue(target.open_branch().repository.has_revision('2'))
877
1108
 
878
1109
    def test_format_initialize_find_open(self):
879
1110
        # loopback test to check the current format initializes to itself.
942
1173
        t = get_transport(self.get_url())
943
1174
        made_control = self.bzrdir_format.initialize(t.base)
944
1175
        made_repo = made_control.create_repository()
945
 
        self.failUnless(isinstance(made_repo, repository.Repository))
 
1176
        # Check that we have a repository object.
 
1177
        made_repo.has_revision('foo')
946
1178
        self.assertEqual(made_control, made_repo.bzrdir)
947
1179
 
948
1180
    def test_create_repository_shared(self):
1010
1242
        source = self.make_branch_and_tree('source')
1011
1243
        source.commit('a', rev_id='a', allow_pointless=True)
1012
1244
        source.commit('b', rev_id='b', allow_pointless=True)
1013
 
        self.build_tree(['new/'])
 
1245
        t.mkdir('new')
1014
1246
        t_new = t.clone('new')
1015
1247
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1016
1248
        source.branch.repository.clone(made_control)
1027
1259
            # because the default open will not open them and
1028
1260
            # they may not be initializable.
1029
1261
            return
1030
 
        # this has to be tested with local access as we still support creating 
 
1262
        # this has to be tested with local access as we still support creating
1031
1263
        # format 6 bzrdirs
1032
 
        t = get_transport('.')
1033
 
        made_control = self.bzrdir_format.initialize(t.base)
1034
 
        made_repo = made_control.create_repository()
1035
 
        made_branch = made_control.create_branch()
1036
 
        made_tree = made_control.create_workingtree()
 
1264
        t = self.get_transport()
 
1265
        try:
 
1266
            made_control = self.bzrdir_format.initialize(t.base)
 
1267
            made_repo = made_control.create_repository()
 
1268
            made_branch = made_control.create_branch()
 
1269
            made_tree = made_control.create_workingtree()
 
1270
        except errors.NotLocalUrl:
 
1271
            raise TestSkipped("Can't initialize %r on transport %r"
 
1272
                              % (self.bzrdir_format, t))
1037
1273
        opened_tree = made_control.open_workingtree()
1038
1274
        self.assertEqual(made_control, opened_tree.bzrdir)
1039
1275
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1067
1303
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1068
1304
                                   transport.Transport))
1069
1305
        # with a given format, either the bzr dir supports identifiable
1070
 
        # repositoryes, or it supports anonymous  repository formats, but not both.
1071
 
        anonymous_format = repository.RepositoryFormat6()
1072
 
        identifiable_format = repository.RepositoryFormat7()
 
1306
        # repositories, or it supports anonymous  repository formats, but not both.
 
1307
        anonymous_format = weaverepo.RepositoryFormat6()
 
1308
        identifiable_format = weaverepo.RepositoryFormat7()
1073
1309
        try:
1074
1310
            found_transport = dir.get_repository_transport(anonymous_format)
1075
1311
            self.assertRaises(errors.IncompatibleFormat,
1222
1458
        dir = self.make_bzrdir('.')
1223
1459
        if dir.can_convert_format():
1224
1460
            # if its default updatable there must be an updater 
1225
 
            # (we change the default to match the lastest known format
1226
 
            # as downgrades may not be available
1227
 
            old_format = bzrdir.BzrDirFormat.get_default_format()
1228
 
            bzrdir.BzrDirFormat.set_default_format(dir._format)
1229
 
            try:
1230
 
                self.assertTrue(isinstance(dir._format.get_converter(),
1231
 
                                           bzrdir.Converter))
1232
 
            finally:
1233
 
                bzrdir.BzrDirFormat.set_default_format(old_format)
 
1461
            # (we force the latest known format as downgrades may not be
 
1462
            # available
 
1463
            self.assertTrue(isinstance(dir._format.get_converter(
 
1464
                format=dir._format), bzrdir.Converter))
1234
1465
        dir.needs_format_conversion(None)
1235
1466
 
1236
1467
    def test_upgrade_new_instance(self):
1242
1473
        self.createWorkingTreeOrSkip(dir)
1243
1474
        if dir.can_convert_format():
1244
1475
            # if its default updatable there must be an updater 
1245
 
            # (we change the default to match the lastest known format
1246
 
            # as downgrades may not be available
1247
 
            old_format = bzrdir.BzrDirFormat.get_default_format()
1248
 
            bzrdir.BzrDirFormat.set_default_format(dir._format)
 
1476
            # (we force the latest known format as downgrades may not be
 
1477
            # available
1249
1478
            pb = ui.ui_factory.nested_progress_bar()
1250
1479
            try:
1251
 
                dir._format.get_converter(None).convert(dir, pb)
 
1480
                dir._format.get_converter(format=dir._format).convert(dir, pb)
1252
1481
            finally:
1253
 
                bzrdir.BzrDirFormat.set_default_format(old_format)
1254
1482
                pb.finished()
1255
1483
            # and it should pass 'check' now.
1256
1484
            check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1260
1488
        text = dir._format.get_format_description()
1261
1489
        self.failUnless(len(text))
1262
1490
 
 
1491
    def test_retire_bzrdir(self):
 
1492
        bd = self.make_bzrdir('.')
 
1493
        transport = bd.root_transport
 
1494
        # must not overwrite existing directories
 
1495
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
 
1496
            transport=transport)
 
1497
        self.failUnless(transport.has('.bzr'))
 
1498
        bd.retire_bzrdir()
 
1499
        self.failIf(transport.has('.bzr'))
 
1500
        self.failUnless(transport.has('.bzr.retired.1'))
 
1501
 
 
1502
    def test_retire_bzrdir_limited(self):
 
1503
        bd = self.make_bzrdir('.')
 
1504
        transport = bd.root_transport
 
1505
        # must not overwrite existing directories
 
1506
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
 
1507
            transport=transport)
 
1508
        self.failUnless(transport.has('.bzr'))
 
1509
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
 
1510
            bd.retire_bzrdir, limit=0) 
 
1511
 
1263
1512
 
1264
1513
class TestBreakLock(TestCaseWithBzrDir):
1265
1514
 
1287
1536
        # break lock with just a repo should unlock the repo.
1288
1537
        repo = self.make_repository('.')
1289
1538
        repo.lock_write()
 
1539
        lock_repo = repo.bzrdir.open_repository()
 
1540
        if not lock_repo.get_physical_lock_status():
 
1541
            # This bzrdir's default repository does not physically lock things
 
1542
            # and thus this interaction cannot be tested at the interface
 
1543
            # level.
 
1544
            repo.unlock()
 
1545
            return
1290
1546
        # only one yes needed here: it should only be unlocking
1291
1547
        # the repo
1292
1548
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1296
1552
            # this bzrdir does not implement break_lock - so we cant test it.
1297
1553
            repo.unlock()
1298
1554
            return
1299
 
        lock_repo = repo.bzrdir.open_repository()
1300
1555
        lock_repo.lock_write()
1301
1556
        lock_repo.unlock()
1302
1557
        self.assertRaises(errors.LockBroken, repo.unlock)
1317
1572
        unused_repo = thisdir.create_repository()
1318
1573
        master.lock_write()
1319
1574
        unused_repo.lock_write()
1320
 
        # two yes's : branch and repository. If the repo in this
1321
 
        # dir is inappropriately accessed, 3 will be needed, and
1322
 
        # we'll see that because the stream will be fully consumed
1323
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1324
 
        master.bzrdir.break_lock()
1325
 
        # only two ys should have been read
1326
 
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1327
 
        # we should be able to lock a newly opened branch now
1328
 
        branch = master.bzrdir.open_branch()
1329
 
        branch.lock_write()
1330
 
        branch.unlock()
1331
 
        # we should not be able to lock the repository in thisdir as its still
1332
 
        # held by the explicit lock we took, and the break lock should not have
1333
 
        # touched it.
1334
 
        repo = thisdir.open_repository()
1335
 
        self.assertRaises(errors.LockContention, repo.lock_write)
1336
 
        unused_repo.unlock()
 
1575
        try:
 
1576
            # two yes's : branch and repository. If the repo in this
 
1577
            # dir is inappropriately accessed, 3 will be needed, and
 
1578
            # we'll see that because the stream will be fully consumed
 
1579
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1580
            # determine if the repository will have been locked;
 
1581
            this_repo_locked = \
 
1582
                thisdir.open_repository().get_physical_lock_status()
 
1583
            master.bzrdir.break_lock()
 
1584
            if this_repo_locked:
 
1585
                # only two ys should have been read
 
1586
                self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1587
            else:
 
1588
                # only one y should have been read
 
1589
                self.assertEqual("y\ny\n", bzrlib.ui.ui_factory.stdin.read())
 
1590
            # we should be able to lock a newly opened branch now
 
1591
            branch = master.bzrdir.open_branch()
 
1592
            branch.lock_write()
 
1593
            branch.unlock()
 
1594
            if this_repo_locked:
 
1595
                # we should not be able to lock the repository in thisdir as
 
1596
                # its still held by the explicit lock we took, and the break
 
1597
                # lock should not have touched it.
 
1598
                repo = thisdir.open_repository()
 
1599
                self.assertRaises(errors.LockContention, repo.lock_write)
 
1600
        finally:
 
1601
            unused_repo.unlock()
1337
1602
        self.assertRaises(errors.LockBroken, master.unlock)
1338
1603
 
1339
1604
    def test_break_lock_tree(self):
1348
1613
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1349
1614
        try:
1350
1615
            tree.bzrdir.break_lock()
1351
 
        except NotImplementedError:
 
1616
        except (NotImplementedError, errors.LockActive):
1352
1617
            # bzrdir does not support break_lock
 
1618
            # or one of the locked objects (currently only tree does this)
 
1619
            # raised a LockActive because we do still have a live locked
 
1620
            # object.
1353
1621
            tree.unlock()
1354
1622
            return
1355
1623
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1370
1638
            # they may not be initializable.
1371
1639
            return
1372
1640
        # supported formats must be able to init and open
1373
 
        url = self.get_url('subdir')
1374
 
        get_transport(self.get_url()).mkdir('subdir')
1375
 
        made_control = self.bzrdir_format.initialize(url)
 
1641
        # - do the vfs initialisation over the basic vfs transport
 
1642
        # XXX: TODO this should become a 'bzrdirlocation' api call.
 
1643
        url = self.get_vfs_only_url('subdir')
 
1644
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1645
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1376
1646
        try:
1377
1647
            repo = made_control.open_repository()
1378
1648
            # if there is a repository, then the format cannot ever hit this 
1380
1650
            return
1381
1651
        except errors.NoRepositoryPresent:
1382
1652
            pass
1383
 
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1653
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1384
1654
        self.assertRaises(errors.NoRepositoryPresent,
1385
 
                          opened_control.find_repository)
 
1655
                          made_control.find_repository)
1386
1656