30
31
from bzrlib.plugins.git import (
31
32
get_rich_root_format,
34
class cmd_git_serve(Command):
35
"""Provide access to a Bazaar branch using the git protocol.
37
This command is experimental and doesn't do much yet.
41
help='serve contents of directory',
45
def run(self, directory=None):
47
from dulwich.server import TCPGitServer
48
from bzrlib.plugins.git.server import BzrBackend
49
from bzrlib.trace import warning
52
warning("server support in bzr-git is experimental.")
55
directory = os.getcwd()
57
backend = BzrBackend(directory)
59
server = TCPGitServer(backend, 'localhost')
60
server.serve_forever()
63
36
class cmd_git_import(Command):
64
37
"""Import all branches from a git repository.
128
101
head_branch = head_bzrdir.create_branch()
129
102
revid = mapping.revision_id_foreign_to_bzr(ref)
130
103
source_branch = GitBranch(source_repo.bzrdir, source_repo,
105
source_branch.head = ref
132
106
head_branch.generate_revision_history(revid)
133
107
source_branch.tags.merge_to(head_branch.tags)
112
class cmd_git_object(Command):
113
"""List or display Git objects by SHA.
115
Cat a particular object's Git representation if a SHA is specified.
116
List all available SHAs otherwise.
121
aliases = ["git-objects", "git-cat"]
122
takes_args = ["sha1?"]
123
takes_options = [Option('directory',
125
help='Location of repository.', type=unicode),
126
Option('pretty', help='Pretty-print objects.')]
127
encoding_type = 'exact'
130
def run(self, sha1=None, directory=".", pretty=False):
131
from bzrlib.errors import (
134
from bzrlib.bzrdir import (
137
bzrdir, _ = BzrDir.open_containing(directory)
138
repo = bzrdir.find_repository()
139
from bzrlib.plugins.git.object_store import (
142
object_store = get_object_store(repo)
147
obj = object_store[str(sha1)]
149
raise BzrCommandError("Object not found: %s" % sha1)
151
text = obj.as_pretty_string()
153
text = obj.as_raw_string()
154
self.outf.write(text)
156
for sha1 in object_store:
157
self.outf.write("%s\n" % sha1)