30
30
BareLocalGitControlDirFormat,
31
31
LocalGitControlDirFormat,
34
from bzrlib.controldir import (
40
from bzrlib.bzrdir import (
34
from bzrlib.controldir import (
47
40
class GitLock(object):
48
41
"""A lock that thunks through to Git."""
44
self.lock_name = "git lock"
50
46
def lock_write(self, token=None):
121
117
def get_config(self):
122
118
return GitDirConfig()
120
def clone_on_transport(self, transport, revision_id=None,
121
force_new_repo=False, preserve_stacking=False, stacked_on=None,
122
create_prefix=False, use_existing_dir=True, no_tree=False):
123
from dulwich.protocol import ZERO_SHA
124
"""See ControlDir.clone_on_transport."""
126
format = BareLocalGitControlDirFormat()
128
format = LocalGitControlDirFormat()
129
(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)
130
target_git_repo = target_repo._git
131
source_repo = self.open_repository()
132
source_git_repo = source_repo._git
133
if revision_id is not None:
134
git_sha, mapping = source_repo.lookup_bzr_revision_id(revision_id)
135
if git_sha == ZERO_SHA:
139
determine_wants = lambda heads: wants
141
determine_wants = target_git_repo.object_store.determine_wants_all
142
refs = source_git_repo.fetch(target_git_repo, determine_wants)
143
for name, val in refs.iteritems():
144
target_git_repo.refs[name] = val
145
lockfiles = GitLockableFiles(transport, GitLock())
146
return self.__class__(transport, lockfiles, target_git_repo, format)
125
149
class LocalGitDir(GitDir):
126
150
"""An adapter to the '.git' dir used by git."""
164
188
def is_control_filename(self, filename):
165
return filename == '.git' or filename.startswith('.git/')
189
return (filename == '.git' or filename.startswith('.git/'))
167
191
def get_branch_transport(self, branch_format, name=None):
168
192
if branch_format is None:
215
239
ret.append(self.open_branch(name=name))
218
def open_repository(self, shared=False):
242
def open_repository(self):
219
243
"""'open' a repository for this dir."""
220
244
return self._gitrepository_class(self, self._lockfiles)
239
263
raise bzr_errors.NoWorkingTree(loc)
241
265
def create_repository(self, shared=False):
266
from bzrlib.plugins.git.repository import GitRepositoryFormat
268
raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
242
269
return self.open_repository()
244
def create_branch(self, name=None):
271
def create_branch(self, name=None, repository=None):
245
272
refname = self._branch_name_to_ref(name)
246
273
from dulwich.protocol import ZERO_SHA
247
274
self._git.refs[refname or "HEAD"] = ZERO_SHA
258
285
def create_workingtree(self, revision_id=None, from_branch=None,
259
286
accelerator_tree=None, hardlink=False):
260
287
if self._git.bare:
261
raise bzr_errors.BzrError("Can't create working tree in a bare repo")
288
raise bzr_errors.UnsupportedOperation(self.create_workingtree, self)
262
289
from dulwich.index import write_index
263
290
from dulwich.pack import SHA1Writer
264
291
f = open(self.transport.local_abspath("index"), 'w+')
279
306
return self.open_repository()
308
def _find_or_create_repository(self, force_new_repo=None):
309
return self.create_repository(shared=False)
281
311
def _find_creation_modes(self):
282
312
"""Determine the appropriate modes for files and directories.