27
27
from bzrlib.foreign import foreign_vcs_registry
28
28
from bzrlib.lockable_files import TransportLock
29
29
from bzrlib.transport import register_lazy_transport
30
from bzrlib.commands import plugin_cmds
30
from bzrlib.commands import Command, register_command
31
from bzrlib.option import Option
31
32
from bzrlib.trace import warning
33
34
MINIMUM_DULWICH_VERSION = (0, 1, 0)
206
207
"Stupid content tracker")
208
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
209
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
210
class cmd_git_serve(Command):
211
"""Provide access to a Bazaar branch using the git protocol.
213
This command is experimental and doesn't do much yet.
217
help='serve contents of directory',
221
def run(self, directory=None):
222
lazy_check_versions()
223
from dulwich.server import TCPGitServer
224
from bzrlib.plugins.git.server import BzrBackend
225
from bzrlib.trace import warning
228
warning("server support in bzr-git is experimental.")
230
if directory is None:
231
directory = os.getcwd()
233
backend = BzrBackend(directory)
235
server = TCPGitServer(backend, 'localhost')
236
server.serve_forever()
238
register_command(cmd_git_serve)
241
class cmd_git_import(Command):
242
"""Import all branches from a git repository.
246
takes_args = ["src_location", "dest_location"]
248
def run(self, src_location, dest_location):
249
from bzrlib.bzrdir import BzrDir, format_registry
250
from bzrlib.errors import NoRepositoryPresent, NotBranchError
251
from bzrlib.repository import Repository
252
source_repo = Repository.open(src_location)
253
format = format_registry.make_bzrdir('rich-root-pack')
255
target_bzrdir = BzrDir.open(dest_location)
256
except NotBranchError:
257
target_bzrdir = BzrDir.create(dest_location, format=format)
259
target_repo = target_bzrdir.open_repository()
260
except NoRepositoryPresent:
261
target_repo = target_bzrdir.create_repository(shared=True)
263
target_repo.fetch(source_repo)
264
for name, ref in source_repo._git.heads().iteritems():
265
head_loc = os.path.join(dest_location, name)
267
head_bzrdir = BzrDir.open(head_loc)
268
except NotBranchError:
269
head_bzrdir = BzrDir.create(head_loc, format=format)
271
head_branch = head_bzrdir.open_branch()
272
except NotBranchError:
273
head_branch = head_bzrdir.create_branch()
274
head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
277
register_command(cmd_git_import)
211
280
def test_suite():
212
281
from bzrlib.plugins.git import tests