58
67
class GitDir(bzrdir.BzrDir):
59
68
"""An adapter to the '.git' dir used by git."""
61
_gitrepository_class = git_repository.GitRepository
70
_gitrepository_class = repository.GitRepository
63
def __init__(self, transport, lockfiles, format):
72
def __init__(self, transport, lockfiles, gitrepo, format):
64
73
self._format = format
65
74
self.root_transport = transport
66
self.transport = transport.clone('.git')
77
self.transport = transport
79
self.transport = transport.clone('.git')
67
80
self._lockfiles = lockfiles
69
82
def get_branch_transport(self, branch_format):
82
95
def open_branch(self, ignored=None):
83
"""'crate' a branch for this dir."""
84
return git_branch.GitBranch(self, self._lockfiles)
96
"""'create' a branch for this dir."""
97
repo = self.open_repository()
98
if repo._git.heads == []:
101
head = repo._git.head()
102
return branch.GitBranch(self, repo, head,
103
self.root_transport.base, self._lockfiles)
86
105
def open_repository(self, shared=False):
87
106
"""'open' a repository for this dir."""
88
107
return self._gitrepository_class(self, self._lockfiles)
90
109
def open_workingtree(self, recommend_upgrade=True):
91
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
92
raise errors.bzr_errors.NoWorkingTree(loc)
94
def cloning_metadir(self):
95
return bzrdir.BzrDirFormat.get_default_format()
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()
98
127
class GitBzrDirFormat(bzrdir.BzrDirFormat):
99
128
"""The .git directory control format."""
101
130
_gitdir_class = GitDir
131
_lock_class = TransportLock
104
134
def _known_formats(self):
105
135
return set([GitBzrDirFormat()])
107
def open(self, transport, _create=False, _found=None):
137
def open(self, transport, _found=None):
108
138
"""Open this directory.
110
:param _create: create the git dir on the fly. private to GitDirFormat.
141
from bzrlib.plugins.git import git
112
142
# we dont grok readonly - git isn't integrated with transport.
113
143
url = transport.base
114
144
if url.startswith('readonly+'):
115
145
url = url[len('readonly+'):]
116
if not transport.has('.git'):
148
gitrepo = git.repo.Repo(transport.local_abspath("."))
149
except errors.bzr_errors.NotLocalUrl:
117
150
raise errors.bzr_errors.NotBranchError(path=transport.base)
118
151
lockfiles = GitLockableFiles(GitLock())
119
return self._gitdir_class(transport, lockfiles, self)
152
return self._gitdir_class(transport, lockfiles, gitrepo, self)
122
155
def probe_transport(klass, transport):
134
167
raise errors.bzr_errors.NotBranchError(path=transport.base)
135
168
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)
138
189
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)