58
66
class GitDir(bzrdir.BzrDir):
59
67
"""An adapter to the '.git' dir used by git."""
61
_gitrepository_class = git_repository.GitRepository
69
_gitrepository_class = repository.GitRepository
63
def __init__(self, transport, lockfiles, format):
71
def __init__(self, transport, lockfiles, gitrepo, format):
64
72
self._format = format
65
73
self.root_transport = transport
66
self.transport = transport.clone('.git')
76
self.transport = transport
78
self.transport = transport.clone('.git')
67
79
self._lockfiles = lockfiles
69
81
def get_branch_transport(self, branch_format):
82
94
def open_branch(self, ignored=None):
83
"""'crate' a branch for this dir."""
84
return git_branch.GitBranch(self, self._lockfiles)
95
"""'create' a branch for this dir."""
96
repo = self.open_repository()
97
if repo._git.heads == []:
100
head = repo._git.heads[0].commit.id
101
return branch.GitBranch(self, repo, head,
102
self.root_transport.base, self._lockfiles)
86
104
def open_repository(self, shared=False):
87
105
"""'open' a repository for this dir."""
88
106
return self._gitrepository_class(self, self._lockfiles)
90
108
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()
110
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
111
raise errors.bzr_errors.NoWorkingTree(loc)
113
return workingtree.GitWorkingTree(self, self.open_repository(),
116
def cloning_metadir(self, stacked=False):
118
return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
120
return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
122
def create_repository(self, shared=False):
123
return self.open_repository()
98
126
class GitBzrDirFormat(bzrdir.BzrDirFormat):
99
127
"""The .git directory control format."""
101
129
_gitdir_class = GitDir
130
_lock_class = TransportLock
104
133
def _known_formats(self):
105
134
return set([GitBzrDirFormat()])
107
def open(self, transport, _create=False, _found=None):
136
def open(self, transport, _found=None):
108
137
"""Open this directory.
110
:param _create: create the git dir on the fly. private to GitDirFormat.
112
140
# we dont grok readonly - git isn't integrated with transport.
113
141
url = transport.base
114
142
if url.startswith('readonly+'):
115
143
url = url[len('readonly+'):]
116
if not transport.has('.git'):
146
gitrepo = git.repo.Repo(transport.local_abspath("."))
147
except errors.bzr_errors.NotLocalUrl:
117
148
raise errors.bzr_errors.NotBranchError(path=transport.base)
118
149
lockfiles = GitLockableFiles(GitLock())
119
return self._gitdir_class(transport, lockfiles, self)
150
return self._gitdir_class(transport, lockfiles, gitrepo, self)
122
153
def probe_transport(klass, transport):
134
165
raise errors.bzr_errors.NotBranchError(path=transport.base)
135
166
raise errors.bzr_errors.NotBranchError(path=transport.base)
168
def get_format_description(self):
169
return "Local Git Repository"
171
def get_format_string(self):
172
return "Local Git Repository"
174
def initialize_on_transport(self, transport):
175
from bzrlib.transport.local import LocalTransport
177
if not isinstance(transport, LocalTransport):
178
raise NotImplementedError(self.initialize,
179
"Can't create Git Repositories/branches on "
180
"non-local transports")
182
git.repo.Repo.create(transport.local_abspath("."))
183
return self.open(transport)
138
186
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)