29
26
lazy_import(globals(), """
30
from bzrlib.lockable_files import TransportLock
31
27
from bzrlib.plugins.git import (
41
35
class GitLock(object):
42
36
"""A lock that thunks through to Git."""
44
def lock_write(self, token=None):
47
41
def lock_read(self):
67
58
class GitDir(bzrdir.BzrDir):
68
59
"""An adapter to the '.git' dir used by git."""
70
_gitrepository_class = repository.GitRepository
61
_gitrepository_class = git_repository.GitRepository
72
def __init__(self, transport, lockfiles, gitrepo, format):
63
def __init__(self, transport, lockfiles, format):
73
64
self._format = format
74
65
self.root_transport = transport
77
self.transport = transport
79
self.transport = transport.clone('.git')
66
self.transport = transport.clone('.git')
80
67
self._lockfiles = lockfiles
82
69
def get_branch_transport(self, branch_format):
98
85
if repo._git.heads == []:
101
head = repo._git.head()
102
return branch.GitBranch(self, repo, head,
88
head = repo._git.heads[0].commit.id
89
return git_branch.GitBranch(self, repo, head,
103
90
self.root_transport.base, self._lockfiles)
105
92
def open_repository(self, shared=False):
107
94
return self._gitrepository_class(self, self._lockfiles)
109
96
def open_workingtree(self, recommend_upgrade=True):
111
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
112
raise errors.bzr_errors.NoWorkingTree(loc)
114
return workingtree.GitWorkingTree(self, self.open_repository(),
117
def cloning_metadir(self, stacked=False):
119
return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
121
return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
123
def create_repository(self, shared=False):
124
return self.open_repository()
97
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
98
raise errors.bzr_errors.NoWorkingTree(loc)
100
def cloning_metadir(self):
101
return bzrdir.BzrDirFormat.get_default_format()
127
104
class GitBzrDirFormat(bzrdir.BzrDirFormat):
128
105
"""The .git directory control format."""
130
107
_gitdir_class = GitDir
131
_lock_class = TransportLock
134
110
def _known_formats(self):
135
111
return set([GitBzrDirFormat()])
137
def open(self, transport, _found=None):
113
def open(self, transport, _create=False, _found=None):
138
114
"""Open this directory.
116
:param _create: create the git dir on the fly. private to GitDirFormat.
141
from bzrlib.plugins.git import git
142
118
# we dont grok readonly - git isn't integrated with transport.
143
119
url = transport.base
144
120
if url.startswith('readonly+'):
145
121
url = url[len('readonly+'):]
148
gitrepo = git.repo.Repo(transport.local_abspath("."))
149
except errors.bzr_errors.NotLocalUrl:
122
if not transport.has('.git'):
150
123
raise errors.bzr_errors.NotBranchError(path=transport.base)
151
124
lockfiles = GitLockableFiles(GitLock())
152
return self._gitdir_class(transport, lockfiles, gitrepo, self)
125
return self._gitdir_class(transport, lockfiles, self)
155
128
def probe_transport(klass, transport):
167
140
raise errors.bzr_errors.NotBranchError(path=transport.base)
168
141
raise errors.bzr_errors.NotBranchError(path=transport.base)
170
def get_format_description(self):
171
return "Local Git Repository"
173
def get_format_string(self):
174
return "Local Git Repository"
176
def initialize_on_transport(self, transport):
177
from bzrlib.transport.local import LocalTransport
178
from bzrlib.plugins.git import git
180
if not isinstance(transport, LocalTransport):
181
raise NotImplementedError(self.initialize,
182
"Can't create Git Repositories/branches on "
183
"non-local transports")
185
git.repo.Repo.create(transport.local_abspath("."))
186
return self.open(transport)
189
144
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)