74
75
except NotBranchError:
75
76
target_bzrdir = BzrDir.create(dest_location, format=format)
77
target_repo = target_bzrdir.open_repository()
78
target_repo = target_bzrdir.find_repository()
78
79
except NoRepositoryPresent:
79
80
target_repo = target_bzrdir.create_repository(shared=True)
82
if not target_repo.supports_rich_root():
83
raise BzrCommandError("Target repository doesn't support rich roots")
81
85
interrepo = InterRepository.get(source_repo, target_repo)
82
86
mapping = source_repo.get_mapping()
83
87
refs = interrepo.fetch_refs()
89
for k, v in extract_tags(refs).iteritems():
90
tags[k] = mapping.revision_id_foreign_to_bzr(v)
84
91
pb = ui.ui_factory.nested_progress_bar()
86
93
for i, (name, ref) in enumerate(refs.iteritems()):
100
107
except NotBranchError:
101
108
head_branch = head_bzrdir.create_branch()
102
109
revid = mapping.revision_id_foreign_to_bzr(ref)
103
source_branch = GitBranch(source_repo.bzrdir, source_repo,
110
source_branch = GitBranch(source_repo.bzrdir, source_repo,
105
112
source_branch.head = ref
106
head_branch.generate_revision_history(revid)
113
if head_branch.last_revision() != revid:
114
head_branch.generate_revision_history(revid)
107
115
source_branch.tags.merge_to(head_branch.tags)
121
129
aliases = ["git-objects", "git-cat"]
122
130
takes_args = ["sha1?"]
123
takes_options = [Option('directory',
131
takes_options = [Option('directory',
125
133
help='Location of repository.', type=unicode),
126
134
Option('pretty', help='Pretty-print objects.')]
157
165
self.outf.write("%s\n" % sha1)
170
class cmd_git_refs(Command):
171
"""Output all of the virtual refs for a repository.
177
takes_options = [Option('directory',
179
help='Location of repository.', type=unicode)]
182
def run(self, directory="."):
183
from bzrlib.bzrdir import (
186
from bzrlib.plugins.git.refs import (
189
from bzrlib.plugins.git.object_store import (
192
bzrdir, _ = BzrDir.open_containing(directory)
193
repo = bzrdir.find_repository()
196
object_store = get_object_store(repo)
197
refs = BazaarRefsContainer(bzrdir, object_store)
198
for k, v in refs.as_dict().iteritems():
199
self.outf.write("%s -> %s\n" % (k, v))
204
class cmd_git_apply(Command):
205
"""Apply a series of git-am style patches.
207
This command will in the future probably be integrated into
211
takes_args = ["patches*"]
213
def _apply_patch(self, wt, f):
214
from dulwich.patch import git_am_patch_split
215
(c, diff, version) = git_am_patch_split(f)
216
# FIXME: Process diff
217
wt.commit(committer=c.committer,
220
def run(self, patches_list=None):
221
from bzrlib.workingtree import WorkingTree
222
if patches_list is None:
225
tree, _ = WorkingTree.open_containing(".")
228
for patch in patches_list:
231
self._apply_patch(tree, f)