30
# versions ending in 'exp' mean experimental mappings
31
# versions ending in 'dev' mean development version
32
# versions ending in 'final' mean release (well tested, etc)
33
version_info = (0, 3, 3, 'dev', 0)
31
bzr_compatible_versions,
32
bzr_plugin_version as version_info,
33
dulwich_minimum_version,
35
36
if version_info[3] == 'final':
36
37
version_string = '%d.%d.%d' % version_info[:3]
38
39
version_string = '%d.%d.%d%s%d' % version_info
39
40
__version__ = version_string
41
MINIMUM_DULWICH_VERSION = (0, 3, 1)
42
COMPATIBLE_BZR_VERSIONS = [(1, 14, 0), (1, 15, 0)]
44
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
42
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
47
45
from bzrlib import (
62
60
from bzrlib.commands import (
65
from bzrlib.trace import (
68
63
from bzrlib.version_info_formats.format_rio import (
69
64
RioVersionInfoBuilder,
66
from bzrlib.send import (
67
format_registry as send_format_registry,
73
71
if getattr(sys, "frozen", None):
84
82
from dulwich import __version__ as dulwich_version
85
83
except ImportError:
86
raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
84
raise bzr_errors.DependencyNotPresent("dulwich",
85
"bzr-git: Please install dulwich, https://launchpad.net/dulwich")
88
if dulwich_version < MINIMUM_DULWICH_VERSION:
89
raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
87
if dulwich_version < dulwich_minimum_version:
88
raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
91
bzrdir.format_registry.register_lazy('git',
90
bzrdir.format_registry.register_lazy('git',
92
91
"bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
93
92
help='GIT repository.', native=False, experimental=True,
96
95
from bzrlib.revisionspec import revspec_registry
97
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
96
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
97
"RevisionSpec_git")
100
from bzrlib.revisionspec import dwim_revspecs
104
from bzrlib.plugins.git.revspec import RevisionSpec_git
105
dwim_revspecs.append(RevisionSpec_git)
101
108
class GitBzrDirFormat(bzrdir.BzrDirFormat):
102
110
_lock_class = TransportLock
104
112
def is_supported(self):
119
127
"""Open this directory.
122
import dulwich as git
130
lazy_check_versions()
123
131
# we dont grok readonly - git isn't integrated with transport.
125
if url.startswith('readonly+'):
126
url = url[len('readonly+'):]
129
gitrepo = git.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
130
except bzr_errors.NotLocalUrl:
131
raise bzr_errors.NotBranchError(path=transport.base)
132
from bzrlib.transport.local import LocalTransport
133
if isinstance(transport, LocalTransport):
135
gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
137
from bzrlib.plugins.git.transportgit import TransportRepo
138
gitrepo = TransportRepo(transport)
132
139
from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
140
lockfiles = GitLockableFiles(transport, GitLock())
134
141
return LocalGitDir(transport, lockfiles, gitrepo, self)
137
144
def probe_transport(klass, transport):
138
"""Our format is present if the transport ends in '.not/'."""
139
from bzrlib.transport.local import LocalTransport
141
if not isinstance(transport, LocalTransport):
142
raise bzr_errors.NotBranchError(path=transport.base)
144
# This should quickly filter out most things that are not
145
# git repositories, saving us the trouble from loading dulwich.
146
if not transport.has(".git") and not transport.has("objects"):
147
raise bzr_errors.NotBranchError(path=transport.base)
149
import dulwich as git
146
if not (transport.has('info/refs') or
147
transport.has('.git/branches') or
148
transport.has('branches')):
149
raise bzr_errors.NotBranchError(path=transport.base)
150
except bzr_errors.NoSuchFile:
151
raise bzr_errors.NotBranchError(path=transport.base)
152
from bzrlib import urlutils
153
if urlutils.split(transport.base)[1] == ".git":
154
raise bzr_errors.NotBranchError(path=transport.base)
155
lazy_check_versions()
152
159
format.open(transport)
154
except git.errors.NotGitRepository, e:
161
except dulwich.errors.NotGitRepository, e:
155
162
raise bzr_errors.NotBranchError(path=transport.base)
156
163
raise bzr_errors.NotBranchError(path=transport.base)
165
172
from bzrlib.transport.local import LocalTransport
167
174
if not isinstance(transport, LocalTransport):
168
raise NotImplementedError(self.initialize,
175
raise NotImplementedError(self.initialize,
169
176
"Can't create Git Repositories/branches on "
170
177
"non-local transports")
178
lazy_check_versions()
172
179
from dulwich.repo import Repo
173
Repo.create(transport.local_abspath(".").encode(osutils._fs_enc))
180
Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
174
181
return self.open(transport)
176
183
def is_supported(self):
192
199
url = transport.base
193
200
if url.startswith('readonly+'):
194
201
url = url[len('readonly+'):]
195
if (not url.startswith("git://") and
196
not url.startswith("git+")):
202
if (not url.startswith("git://") and not url.startswith("git+")):
197
203
raise bzr_errors.NotBranchError(transport.base)
198
204
from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
199
205
if not isinstance(transport, GitSmartTransport):
208
214
url = transport.base
209
215
if url.startswith('readonly+'):
210
216
url = url[len('readonly+'):]
211
if (not url.startswith("git://") and
212
not url.startswith("git+")):
217
if (not url.startswith("git://") and not url.startswith("git+")):
213
218
raise bzr_errors.NotBranchError(transport.base)
214
219
# little ugly, but works
231
236
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
237
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
234
register_transport_proto('git://',
239
register_transport_proto('git://',
235
240
help="Access using the Git smart server protocol.")
236
register_transport_proto('git+ssh://',
241
register_transport_proto('git+ssh://',
237
242
help="Access using the Git smart server protocol over SSH.")
239
244
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
246
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
247
'SSHGitSmartTransport')
244
foreign_vcs_registry.register_lazy("git",
249
foreign_vcs_registry.register_lazy("git",
245
250
"bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
247
252
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
253
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
254
"bzrlib.plugins.git.commands")
251
256
def update_stanza(rev, stanza):
259
264
rio_hooks.install_named_hook('revision', update_stanza, None)
263
from bzrlib.transport import transport_server_registry
267
transport_server_registry.register_lazy('git',
268
'bzrlib.plugins.git.server',
270
'Git Smart server protocol over TCP. (default port: 9418)')
267
from bzrlib.transport import transport_server_registry
268
transport_server_registry.register_lazy('git',
269
'bzrlib.plugins.git.server',
271
'Git Smart server protocol over TCP. (default port: 9418)')
273
274
from bzrlib.repository import network_format_registry as repository_network_format_registry
274
repository_network_format_registry.register_lazy('git',
275
repository_network_format_registry.register_lazy('git',
275
276
'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
277
278
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
285
286
return bzrdir.format_registry.make_bzrdir("default-rich-root")
288
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
289
'send_git', 'Git am-style diff format')
287
291
def test_suite():
288
292
from bzrlib.plugins.git import tests
289
293
return tests.test_suite()