108
120
def _branch_name_to_ref(self, name):
109
121
raise NotImplementedError(self._branch_name_to_ref)
111
if bzrlib_version >= (2, 2):
112
def open_branch(self, name=None, unsupported=False,
113
ignore_fallbacks=None):
114
return self._open_branch(name=name,
115
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
117
def open_branch(self, ignore_fallbacks=None, unsupported=False):
118
return self._open_branch(name=None,
119
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
121
123
def get_config(self):
122
124
return GitDirConfig()
126
def sprout(self, url, revision_id=None, force_new_repo=False,
127
recurse='down', possible_transports=None,
128
accelerator_tree=None, hardlink=False, stacked=False,
129
source_branch=None, create_tree_if_local=True):
130
from bzrlib.repository import InterRepository
131
from bzrlib.transport.local import LocalTransport
132
from bzrlib.transport import get_transport
133
target_transport = get_transport(url, possible_transports)
134
target_transport.ensure_base()
135
cloning_format = self.cloning_metadir()
136
# Create/update the result branch
137
result = cloning_format.initialize_on_transport(target_transport)
138
source_branch = self.open_branch()
139
source_repository = self.find_repository()
141
result_repo = result.find_repository()
142
except bzr_errors.NoRepositoryPresent:
143
result_repo = result.create_repository()
144
target_is_empty = True
146
target_is_empty = None # Unknown
148
raise bzr_errors.IncompatibleRepositories(source_repository, result_repo)
149
interrepo = InterRepository.get(source_repository, result_repo)
151
if revision_id is not None:
152
determine_wants = interrepo.get_determine_wants_revids(
153
[revision_id], include_tags=True)
155
determine_wants = interrepo.determine_wants_all
156
interrepo.fetch_objects(determine_wants=determine_wants,
157
mapping=source_branch.mapping)
158
result_branch = source_branch.sprout(result,
159
revision_id=revision_id, repository=result_repo)
160
if (create_tree_if_local and isinstance(target_transport, LocalTransport)
161
and (result_repo is None or result_repo.make_working_trees())):
162
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
163
hardlink=hardlink, from_branch=result_branch)
166
if wt.path2id('') is None:
168
wt.set_root_id(self.open_workingtree.get_root_id())
169
except bzr_errors.NoWorkingTree:
175
def clone_on_transport(self, transport, revision_id=None,
176
force_new_repo=False, preserve_stacking=False, stacked_on=None,
177
create_prefix=False, use_existing_dir=True, no_tree=False):
178
from dulwich.protocol import ZERO_SHA
179
"""See ControlDir.clone_on_transport."""
181
format = BareLocalGitControlDirFormat()
183
format = LocalGitControlDirFormat()
184
(target_repo, target_controldir, stacking, repo_policy) = format.initialize_on_transport_ex(transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo)
185
target_git_repo = target_repo._git
186
source_repo = self.open_repository()
187
source_git_repo = source_repo._git
188
if revision_id is not None:
189
determine_wants = source_repo.determine_wants_revid_and_tags(revision_id)
191
determine_wants = target_git_repo.object_store.determine_wants_all
192
refs = source_git_repo.fetch(target_git_repo, determine_wants)
193
for name, val in refs.iteritems():
194
target_git_repo.refs[name] = val
195
lockfiles = GitLockableFiles(transport, GitLock())
196
return self.__class__(transport, lockfiles, target_git_repo, format)
198
def find_repository(self):
199
"""Find the repository that should be used.
201
This does not require a branch as we use it to find the repo for
202
new branches as well as to hook existing branches up to their
205
return self.open_repository()
208
class LocalGitControlDirFormat(GitControlDirFormat):
209
"""The .git directory control format."""
214
def _known_formats(self):
215
return set([LocalGitControlDirFormat()])
218
def repository_format(self):
219
from bzrlib.plugins.git.repository import GitRepositoryFormat
220
return GitRepositoryFormat()
222
def get_branch_format(self):
223
from bzrlib.plugins.git.branch import GitBranchFormat
224
return GitBranchFormat()
226
def open(self, transport, _found=None):
227
"""Open this directory.
230
from bzrlib.plugins.git.transportgit import TransportRepo
231
gitrepo = TransportRepo(transport)
232
lockfiles = GitLockableFiles(transport, GitLock())
233
return LocalGitDir(transport, lockfiles, gitrepo, self)
235
def get_format_description(self):
236
return "Local Git Repository"
238
def initialize_on_transport(self, transport):
239
from bzrlib.plugins.git.transportgit import TransportRepo
240
TransportRepo.init(transport, bare=self.bare)
241
return self.open(transport)
243
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
244
create_prefix=False, force_new_repo=False, stacked_on=None,
245
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
246
shared_repo=False, vfs_only=False):
247
def make_directory(transport):
250
def redirected(transport, e, redirection_notice):
251
trace.note(redirection_notice)
252
return transport._redirected_to(e.source, e.target)
254
transport = do_catching_redirections(make_directory, transport,
256
except bzr_errors.FileExists:
257
if not use_existing_dir:
259
except bzr_errors.NoSuchFile:
260
if not create_prefix:
262
transport.create_prefix()
263
controldir = self.initialize_on_transport(transport)
264
repository = controldir.open_repository()
265
repository.lock_write()
266
return (repository, controldir, False, CreateRepository(controldir))
268
def is_supported(self):
272
class BareLocalGitControlDirFormat(LocalGitControlDirFormat):
275
supports_workingtrees = False
277
def get_format_description(self):
278
return "Local Git Repository (bare)"
125
281
class LocalGitDir(GitDir):
126
282
"""An adapter to the '.git' dir used by git."""