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()
137
139
# Not a branch, ignore
139
141
pb.update(gettext("creating branches"), i, len(refs))
140
if getattr(target_controldir._format, "colocated_branches", False) and colocated:
142
if (getattr(target_controldir._format, "colocated_branches",
143
False) and colocated):
141
144
if name == "HEAD":
142
145
branch_name = None
143
head_branch = self._get_colocated_branch(target_controldir, branch_name)
146
head_branch = self._get_colocated_branch(
147
target_controldir, branch_name)
145
head_branch = self._get_nested_branch(dest_transport, dest_format, branch_name)
149
head_branch = self._get_nested_branch(
150
dest_transport, dest_format, branch_name)
146
151
revid = mapping.revision_id_foreign_to_bzr(sha)
147
source_branch = LocalGitBranch(source_repo.controldir, source_repo,
152
source_branch = LocalGitBranch(
153
source_repo.controldir, source_repo, sha)
149
154
if head_branch.last_revision() != revid:
150
155
head_branch.generate_revision_history(revid)
151
156
source_branch.tags.merge_to(head_branch.tags)
152
157
if not head_branch.get_parent():
153
158
url = urlutils.join_segment_parameters(
154
source_branch.base, {"branch": urlutils.escape(branch_name)})
160
{"branch": urlutils.escape(branch_name)})
155
161
head_branch.set_parent(url)
172
178
aliases = ["git-objects", "git-cat"]
173
179
takes_args = ["sha1?"]
174
180
takes_options = [Option('directory',
176
help='Location of repository.', type=text_type),
177
Option('pretty', help='Pretty-print objects.')]
182
help='Location of repository.', type=text_type),
183
Option('pretty', help='Pretty-print objects.')]
178
184
encoding_type = 'exact'
188
194
from .object_store import (
189
195
get_object_store,
191
from . import gettext
197
from ..i18n import gettext
192
198
controldir, _ = ControlDir.open_containing(directory)
193
199
repo = controldir.find_repository()
194
200
object_store = get_object_store(repo)
195
201
with object_store.lock_read():
196
202
if sha1 is not None:
198
obj = object_store[str(sha1)]
204
obj = object_store[sha1.encode('ascii')]
200
raise BzrCommandError(gettext("Object not found: %s") % sha1)
206
raise BzrCommandError(
207
gettext("Object not found: %s") % sha1)
202
209
text = obj.as_pretty_string()
234
241
with object_store.lock_read():
235
242
refs = get_refs_container(controldir, object_store)
236
243
for k, v in sorted(viewitems(refs.as_dict())):
237
self.outf.write("%s -> %s\n" % (k.decode('utf-8'), v.decode('utf-8')))
244
self.outf.write("%s -> %s\n" %
245
(k.decode('utf-8'), v.decode('utf-8')))
240
248
class cmd_git_apply(Command):
241
249
"""Apply a series of git-am style patches.
243
This command will in the future probably be integrated into
251
This command will in the future probably be integrated into "bzr pull".
247
254
takes_options = [
248
255
Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
250
help='Apply patches even if tree has uncommitted changes.')
257
help='Apply patches even if tree has uncommitted changes.')
252
259
takes_args = ["patches*"]
258
265
:param f: Patch file to read.
259
266
:param signoff: Add Signed-Off-By flag.
261
from . import gettext
268
from ..i18n import gettext
262
269
from ..errors import BzrCommandError
263
270
from dulwich.patch import git_am_patch_split
264
271
import subprocess
266
273
# FIXME: Cope with git-specific bits in patch
267
274
# FIXME: Add new files to working tree
268
275
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
270
277
p.communicate(diff)
271
278
exitcode = p.wait()
272
279
if exitcode != 0:
273
280
raise BzrCommandError(gettext("error running patch"))
281
message = c.message.decode('utf-8')
276
283
signed_off_by = wt.branch.get_config().username()
277
message += "Signed-off-by: %s\n" % signed_off_by.encode('utf-8')
278
wt.commit(authors=[c.author], message=message)
284
message += "Signed-off-by: %s\n" % (signed_off_by, )
285
wt.commit(authors=[c.author.decode('utf-8')], message=message)
280
287
def run(self, patches_list=None, signoff=False, force=False):
281
288
from ..errors import UncommittedChanges
296
303
"""Push pristine tar deltas to a git repository."""
298
305
takes_options = [Option('directory',
300
help='Location of repository.', type=text_type)]
307
help='Location of repository.', type=text_type)]
301
308
takes_args = ['target', 'package']
303
310
def run(self, target, package, directory='.'):
333
340
gitid = git_store._lookup_revision_sha1(revid)
334
if not (name.startswith('upstream/') or name.startswith('upstream-')):
335
warning("Unexpected pristine tar revision tagged %s. Ignoring.",
341
if (not (name.startswith('upstream/') or
342
name.startswith('upstream-'))):
344
"Unexpected pristine tar revision tagged %s. "
338
347
upstream_version = name[len("upstream/"):]
339
filename = '%s_%s.orig.tar.%s' % (package, upstream_version, kind)
340
if not gitid in target:
341
warning("base git id %s for %s missing in target repository",
348
filename = '%s_%s.orig.tar.%s' % (
349
package, upstream_version, kind)
350
if gitid not in target:
352
"base git id %s for %s missing in target repository",
343
354
store_git_pristine_tar_data(target, filename.encode('utf-8'),