45
45
takes_args = ["src_location", "dest_location?"]
48
Option('colocated', help='Create colocated branches.'),
48
Option('colocated', help='Create colocated branches.'),
51
51
def _get_colocated_branch(self, target_controldir, name):
52
52
from ..errors import NotBranchError
103
103
dest_format = controldir.ControlDirFormat.get_default_format()
104
104
if dest_format is None:
105
raise errors.BzrError('no default format')
105
raise BzrError('no default format')
107
107
if dest_location is None:
108
108
dest_location = os.path.basename(src_location.rstrip("/\\"))
112
112
source_repo = Repository.open(src_location)
113
113
if not isinstance(source_repo, GitRepository):
114
raise BzrCommandError(gettext("%r is not a git repository") % src_location)
114
raise BzrCommandError(
115
gettext("%r is not a git repository") % src_location)
116
117
target_controldir = ControlDir.open_from_transport(dest_transport)
117
118
except NotBranchError:
123
124
target_repo = target_controldir.create_repository(shared=True)
125
126
if not target_repo.supports_rich_root():
126
raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
127
raise BzrCommandError(
128
gettext("Target repository doesn't support rich roots"))
128
130
interrepo = InterRepository.get(source_repo, target_repo)
129
131
mapping = source_repo.get_mapping()
136
138
# Not a branch, ignore
138
140
pb.update(gettext("creating branches"), i, len(refs))
139
if getattr(target_controldir._format, "colocated_branches", False) and colocated:
141
if (getattr(target_controldir._format, "colocated_branches",
142
False) and colocated):
140
143
if name == "HEAD":
141
144
branch_name = None
142
head_branch = self._get_colocated_branch(target_controldir, branch_name)
145
head_branch = self._get_colocated_branch(
146
target_controldir, branch_name)
144
head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
148
head_branch = self._get_nested_branch(
149
dest_transport, dest_format, branch_name)
145
150
revid = mapping.revision_id_foreign_to_bzr(sha)
146
source_branch = LocalGitBranch(source_repo.controldir, source_repo,
151
source_branch = LocalGitBranch(
152
source_repo.controldir, source_repo, sha)
148
153
if head_branch.last_revision() != revid:
149
154
head_branch.generate_revision_history(revid)
150
155
source_branch.tags.merge_to(head_branch.tags)
151
156
if not head_branch.get_parent():
152
157
url = urlutils.join_segment_parameters(
153
source_branch.base, {"branch": urlutils.escape(branch_name)})
159
{"branch": urlutils.escape(branch_name)})
154
160
head_branch.set_parent(url)
155
161
trace.note(gettext(
156
162
"Use 'bzr checkout' to create a working tree in "
169
175
aliases = ["git-objects", "git-cat"]
170
176
takes_args = ["sha1?"]
171
177
takes_options = [Option('directory',
173
help='Location of repository.', type=text_type),
174
Option('pretty', help='Pretty-print objects.')]
179
help='Location of repository.', type=text_type),
180
Option('pretty', help='Pretty-print objects.')]
175
181
encoding_type = 'exact'
185
191
from .object_store import (
186
192
get_object_store,
188
from . import gettext
194
from ..i18n import gettext
189
195
controldir, _ = ControlDir.open_containing(directory)
190
196
repo = controldir.find_repository()
191
197
object_store = get_object_store(repo)
192
198
with object_store.lock_read():
193
199
if sha1 is not None:
195
obj = object_store[str(sha1)]
201
obj = object_store[sha1.encode('ascii')]
197
raise BzrCommandError(gettext("Object not found: %s") % sha1)
203
raise BzrCommandError(
204
gettext("Object not found: %s") % sha1)
199
206
text = obj.as_pretty_string()
231
238
with object_store.lock_read():
232
239
refs = get_refs_container(controldir, object_store)
233
240
for k, v in sorted(viewitems(refs.as_dict())):
234
self.outf.write("%s -> %s\n" % (k.decode('utf-8'), v.decode('utf-8')))
241
self.outf.write("%s -> %s\n" %
242
(k.decode('utf-8'), v.decode('utf-8')))
237
245
class cmd_git_apply(Command):
238
246
"""Apply a series of git-am style patches.
240
This command will in the future probably be integrated into
248
This command will in the future probably be integrated into "bzr pull".
244
251
takes_options = [
245
252
Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
247
help='Apply patches even if tree has uncommitted changes.')
254
help='Apply patches even if tree has uncommitted changes.')
249
256
takes_args = ["patches*"]
255
262
:param f: Patch file to read.
256
263
:param signoff: Add Signed-Off-By flag.
258
from . import gettext
265
from ..i18n import gettext
259
266
from ..errors import BzrCommandError
260
267
from dulwich.patch import git_am_patch_split
261
268
import subprocess
263
270
# FIXME: Cope with git-specific bits in patch
264
271
# FIXME: Add new files to working tree
265
272
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
267
274
p.communicate(diff)
268
275
exitcode = p.wait()
269
276
if exitcode != 0:
270
277
raise BzrCommandError(gettext("error running patch"))
278
message = c.message.decode('utf-8')
273
280
signed_off_by = wt.branch.get_config().username()
274
message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
275
wt.commit(authors=[c.author], message=message)
281
message += "Signed-off-by: %s\n" % (signed_off_by, )
282
wt.commit(authors=[c.author.decode('utf-8')], message=message)
277
284
def run(self, patches_list=None, signoff=False, force=False):
278
285
from ..errors import UncommittedChanges
293
300
"""Push pristine tar deltas to a git repository."""
295
302
takes_options = [Option('directory',
297
help='Location of repository.', type=text_type)]
304
help='Location of repository.', type=text_type)]
298
305
takes_args = ['target', 'package']
300
307
def run(self, target, package, directory='.'):
330
337
gitid = git_store._lookup_revision_sha1(revid)
331
if not (name.startswith('upstream/') or name.startswith('upstream-')):
332
warning("Unexpected pristine tar revision tagged %s. Ignoring.",
338
if (not (name.startswith('upstream/') or
339
name.startswith('upstream-'))):
341
"Unexpected pristine tar revision tagged %s. "
335
344
upstream_version = name[len("upstream/"):]
336
filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
337
if not gitid in target:
338
warning("base git id %s for %s missing in target repository",
345
filename = '%s_%s.orig.tar.%s' % (
346
package, upstream_version, kind)
347
if gitid not in target:
349
"base git id %s for %s missing in target repository",
340
351
store_git_pristine_tar_data(target, filename.encode('utf-8'),