41
44
takes_args = ["src_location", "dest_location?"]
44
Option('colocated', help='Create colocated branches.'),
45
RegistryOption('dest-format',
46
help='Specify a format for this branch. '
47
'See "help formats" for a full list.',
48
lazy_registry=('breezy.controldir', 'format_registry'),
49
converter=lambda name: controldir.format_registry.make_controldir(
52
title="Branch format",
47
Option('colocated', help='Create colocated branches.'),
56
50
def _get_colocated_branch(self, target_controldir, name):
57
51
from ..errors import NotBranchError
106
100
from .repository import GitRepository
102
dest_format = controldir.ControlDirFormat.get_default_format()
108
103
if dest_format is None:
109
dest_format = controldir.format_registry.make_controldir('default')
104
raise errors.BzrError('no default format')
111
106
if dest_location is None:
112
107
dest_location = os.path.basename(src_location.rstrip("/\\"))
128
122
target_repo = target_controldir.create_repository(shared=True)
130
124
if not target_repo.supports_rich_root():
132
gettext("Target repository doesn't support rich roots"))
125
raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
134
127
interrepo = InterRepository.get(source_repo, target_repo)
135
128
mapping = source_repo.get_mapping()
136
result = interrepo.fetch()
137
with ui.ui_factory.nested_progress_bar() as pb:
138
for i, (name, sha) in enumerate(result.refs.items()):
129
refs = interrepo.fetch()
130
pb = ui.ui_factory.nested_progress_bar()
132
for i, (name, sha) in enumerate(refs.iteritems()):
140
134
branch_name = ref_to_branch_name(name)
141
135
except ValueError:
142
136
# Not a branch, ignore
144
pb.update(gettext("creating branches"), i, len(result.refs))
145
if (getattr(target_controldir._format, "colocated_branches",
146
False) and colocated):
138
pb.update(gettext("creating branches"), i, len(refs))
139
if getattr(target_controldir._format, "colocated_branches", False) and colocated:
147
140
if name == "HEAD":
148
141
branch_name = None
149
head_branch = self._get_colocated_branch(
150
target_controldir, branch_name)
142
head_branch = self._get_colocated_branch(target_controldir, branch_name)
152
head_branch = self._get_nested_branch(
153
dest_transport, dest_format, branch_name)
144
head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
154
145
revid = mapping.revision_id_foreign_to_bzr(sha)
155
source_branch = LocalGitBranch(
156
source_repo.controldir, source_repo, sha)
146
source_branch = LocalGitBranch(source_repo.controldir, source_repo,
157
148
if head_branch.last_revision() != revid:
158
149
head_branch.generate_revision_history(revid)
159
150
source_branch.tags.merge_to(head_branch.tags)
160
151
if not head_branch.get_parent():
161
152
url = urlutils.join_segment_parameters(
163
{"branch": urlutils.escape(branch_name)})
153
source_branch.base, {"branch": urllib.quote(branch_name.encode('utf-8'), '')})
164
154
head_branch.set_parent(url)
165
157
trace.note(gettext(
166
158
"Use 'bzr checkout' to create a working tree in "
167
159
"the newly created branches."))
179
171
aliases = ["git-objects", "git-cat"]
180
172
takes_args = ["sha1?"]
181
173
takes_options = [Option('directory',
183
help='Location of repository.', type=str),
184
Option('pretty', help='Pretty-print objects.')]
175
help='Location of repository.', type=text_type),
176
Option('pretty', help='Pretty-print objects.')]
185
177
encoding_type = 'exact'
188
180
def run(self, sha1=None, directory=".", pretty=False):
189
181
from ..errors import (
192
184
from ..controldir import (
195
187
from .object_store import (
196
188
get_object_store,
198
from ..i18n import gettext
190
from . import gettext
199
191
controldir, _ = ControlDir.open_containing(directory)
200
192
repo = controldir.find_repository()
201
193
object_store = get_object_store(repo)
202
194
with object_store.lock_read():
203
195
if sha1 is not None:
205
obj = object_store[sha1.encode('ascii')]
197
obj = object_store[str(sha1)]
208
gettext("Object not found: %s") % sha1)
199
raise BzrCommandError(gettext("Object not found: %s") % sha1)
210
201
text = obj.as_pretty_string()
241
232
object_store = get_object_store(repo)
242
233
with object_store.lock_read():
243
234
refs = get_refs_container(controldir, object_store)
244
for k, v in sorted(refs.as_dict().items()):
245
self.outf.write("%s -> %s\n" %
246
(k.decode('utf-8'), v.decode('utf-8')))
235
for k, v in refs.as_dict().iteritems():
236
self.outf.write("%s -> %s\n" % (k, v))
249
239
class cmd_git_apply(Command):
250
240
"""Apply a series of git-am style patches.
252
This command will in the future probably be integrated into "bzr pull".
242
This command will in the future probably be integrated into
255
246
takes_options = [
256
247
Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
258
help='Apply patches even if tree has uncommitted changes.')
249
help='Apply patches even if tree has uncommitted changes.')
260
251
takes_args = ["patches*"]
266
257
:param f: Patch file to read.
267
258
:param signoff: Add Signed-Off-By flag.
260
from . import gettext
261
from ..errors import BzrCommandError
269
262
from dulwich.patch import git_am_patch_split
270
from breezy.patch import patch_tree
271
264
(c, diff, version) = git_am_patch_split(f)
272
265
# FIXME: Cope with git-specific bits in patch
273
266
# FIXME: Add new files to working tree
274
patch_tree(wt, [diff], strip=1, out=self.outf)
275
message = c.message.decode('utf-8')
267
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
272
raise BzrCommandError(gettext("error running patch"))
277
275
signed_off_by = wt.branch.get_config().username()
278
message += "Signed-off-by: %s\n" % (signed_off_by, )
279
wt.commit(authors=[c.author.decode('utf-8')], message=message)
276
message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
277
wt.commit(authors=[c.author], message=message)
281
279
def run(self, patches_list=None, signoff=False, force=False):
282
280
from ..errors import UncommittedChanges
297
295
"""Push pristine tar deltas to a git repository."""
299
297
takes_options = [Option('directory',
301
help='Location of repository.', type=str)]
299
help='Location of repository.', type=text_type)]
302
300
takes_args = ['target', 'package']
304
302
def run(self, target, package, directory='.'):
305
303
from ..branch import Branch
306
304
from ..errors import (
310
308
from ..trace import warning
311
309
from ..repository import Repository
312
from .mapping import encode_git_path
313
310
from .object_store import get_object_store
314
311
from .pristine_tar import (
315
312
revision_pristine_tar_data,
319
316
target_bzr = Repository.open(target)
320
317
target = getattr(target_bzr, '_git', None)
321
318
if target is None:
322
raise CommandError("Target not a git repository")
319
raise BzrCommandError("Target not a git repository")
323
320
git_store = get_object_store(source.repository)
324
321
with git_store.lock_read():
325
322
tag_dict = source.tags.get_tag_dict()
335
332
gitid = git_store._lookup_revision_sha1(revid)
336
if (not (name.startswith('upstream/') or
337
name.startswith('upstream-'))):
339
"Unexpected pristine tar revision tagged %s. "
333
if not (name.startswith('upstream/') or name.startswith('upstream-')):
334
warning("Unexpected pristine tar revision tagged %s. Ignoring.",
342
337
upstream_version = name[len("upstream/"):]
343
filename = '%s_%s.orig.tar.%s' % (
344
package, upstream_version, kind)
345
if gitid not in target:
347
"base git id %s for %s missing in target repository",
349
store_git_pristine_tar_data(target, encode_git_path(filename),
338
filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
339
if not gitid in target:
340
warning("base git id %s for %s missing in target repository",
342
store_git_pristine_tar_data(target, filename.encode('utf-8'),