55
55
if not allow_unsupported and not format.is_supported():
56
56
raise errors.UnsupportedFormatError(format)
58
def clone(self, url, revision_id=None, basis=None):
58
def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
59
59
"""Clone this bzrdir and its contents to url verbatim.
61
61
If urls last component does not exist, it will be created.
63
63
if revision_id is not None, then the clone operation may tune
64
64
itself to download less data.
65
:param force_new_repo: Do not use a shared repository for the target
66
even if one is available.
66
68
self._make_tail(url)
69
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
67
70
result = self._format.initialize(url)
68
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
70
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
72
local_repo = self.find_repository()
71
73
except errors.NoRepositoryPresent:
76
# may need to copy content in
78
local_repo.clone(result, revision_id=revision_id, basis=basis_repo)
81
result_repo = result.find_repository()
82
# fetch content this dir needs.
84
# XXX FIXME RBC 20060214 need tests for this when the basis
86
result_repo.fetch(basis_repo, revision_id=revision_id)
87
result_repo.fetch(local_repo, revision_id=revision_id)
88
except errors.NoRepositoryPresent:
89
# needed to make one anyway.
90
local_repo.clone(result, revision_id=revision_id, basis=basis_repo)
91
# 1 if there is a branch present
92
# make sure its content is available in the target repository
74
95
self.open_branch().clone(result, revision_id=revision_id)
75
96
except errors.NotBranchError:
140
161
raise NotImplementedError(self.create_branch)
143
def create_branch_and_repo(base):
164
def create_branch_and_repo(base, force_new_repo=False):
144
165
"""Create a new BzrDir, Branch and Repository at the url 'base'.
146
167
This will use the current default BzrDirFormat, and use whatever
147
168
repository format that that uses via bzrdir.create_branch and
169
create_repository. If a shared repository is available that is used
150
172
The created Branch object is returned.
174
:param base: The URL to create the branch at.
175
:param force_new_repo: If True a new repository is always created.
152
177
bzrdir = BzrDir.create(base)
153
bzrdir.create_repository()
179
bzrdir.create_repository()
181
repo = bzrdir.find_repository()
182
except errors.NoRepositoryPresent:
183
bzrdir.create_repository()
154
184
return bzrdir.create_branch()
193
223
"""Create a working tree at this BzrDir"""
194
224
raise NotImplementedError(self.create_workingtree)
226
def find_repository(self):
227
"""Find the repository that should be used for a_bzrdir.
229
This does not require a branch as we use it to find the repo for
230
new branches as well as to hook existing branches up to their
234
return self.open_repository()
235
except errors.NoRepositoryPresent:
237
next_transport = self.root_transport.clone('..')
240
found_bzrdir = BzrDir.open_containing_transport(
242
except errors.NotBranchError:
243
raise errors.NoRepositoryPresent(self)
245
repository = found_bzrdir.open_repository()
246
except errors.NoRepositoryPresent:
247
next_transport = found_bzrdir.root_transport.clone('..')
249
if ((found_bzrdir.root_transport.base ==
250
self.root_transport.base) or repository.is_shared()):
253
raise errors.NoRepositoryPresent(self)
254
raise errors.NoRepositoryPresent(self)
196
256
def get_branch_transport(self, branch_format):
197
257
"""Get the transport for use by branch format in this BzrDir.