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
102
103
dest_format = controldir.ControlDirFormat.get_default_format()
103
104
if dest_format is None:
104
raise errors.BzrError('no default format')
105
raise BzrError('no default format')
106
107
if dest_location is None:
107
108
dest_location = os.path.basename(src_location.rstrip("/\\"))
111
112
source_repo = Repository.open(src_location)
112
113
if not isinstance(source_repo, GitRepository):
113
raise BzrCommandError(gettext("%r is not a git repository") % src_location)
114
raise BzrCommandError(
115
gettext("%r is not a git repository") % src_location)
115
117
target_controldir = ControlDir.open_from_transport(dest_transport)
116
118
except NotBranchError:
122
124
target_repo = target_controldir.create_repository(shared=True)
124
126
if not target_repo.supports_rich_root():
125
raise BzrCommandError(gettext("Target repository doesn't support rich roots"))
127
raise BzrCommandError(
128
gettext("Target repository doesn't support rich roots"))
127
130
interrepo = InterRepository.get(source_repo, target_repo)
128
131
mapping = source_repo.get_mapping()
136
139
# Not a branch, ignore
138
141
pb.update(gettext("creating branches"), i, len(refs))
139
if getattr(target_controldir._format, "colocated_branches", False) and colocated:
142
if (getattr(target_controldir._format, "colocated_branches",
143
False) and colocated):
140
144
if name == "HEAD":
141
145
branch_name = None
142
head_branch = self._get_colocated_branch(target_controldir, branch_name)
146
head_branch = self._get_colocated_branch(
147
target_controldir, branch_name)
144
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)
145
151
revid = mapping.revision_id_foreign_to_bzr(sha)
146
source_branch = LocalGitBranch(source_repo.controldir, source_repo,
152
source_branch = LocalGitBranch(
153
source_repo.controldir, source_repo, sha)
148
154
if head_branch.last_revision() != revid:
149
155
head_branch.generate_revision_history(revid)
150
156
source_branch.tags.merge_to(head_branch.tags)
151
157
if not head_branch.get_parent():
152
158
url = urlutils.join_segment_parameters(
153
source_branch.base, {"branch": urlutils.escape(branch_name)})
160
{"branch": urlutils.escape(branch_name)})
154
161
head_branch.set_parent(url)
171
178
aliases = ["git-objects", "git-cat"]
172
179
takes_args = ["sha1?"]
173
180
takes_options = [Option('directory',
175
help='Location of repository.', type=text_type),
176
Option('pretty', help='Pretty-print objects.')]
182
help='Location of repository.', type=text_type),
183
Option('pretty', help='Pretty-print objects.')]
177
184
encoding_type = 'exact'
233
241
with object_store.lock_read():
234
242
refs = get_refs_container(controldir, object_store)
235
243
for k, v in sorted(viewitems(refs.as_dict())):
236
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')))
239
248
class cmd_git_apply(Command):
240
249
"""Apply a series of git-am style patches.
242
This command will in the future probably be integrated into
251
This command will in the future probably be integrated into "bzr pull".
246
254
takes_options = [
247
255
Option('signoff', short_name='s', help='Add a Signed-off-by line.'),
249
help='Apply patches even if tree has uncommitted changes.')
257
help='Apply patches even if tree has uncommitted changes.')
251
259
takes_args = ["patches*"]
265
273
# FIXME: Cope with git-specific bits in patch
266
274
# FIXME: Add new files to working tree
267
275
p = subprocess.Popen(["patch", "-p1"], stdin=subprocess.PIPE,
269
277
p.communicate(diff)
270
278
exitcode = p.wait()
271
279
if exitcode != 0:
295
303
"""Push pristine tar deltas to a git repository."""
297
305
takes_options = [Option('directory',
299
help='Location of repository.', type=text_type)]
307
help='Location of repository.', type=text_type)]
300
308
takes_args = ['target', 'package']
302
310
def run(self, target, package, directory='.'):
332
340
gitid = git_store._lookup_revision_sha1(revid)
333
if not (name.startswith('upstream/') or name.startswith('upstream-')):
334
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. "
337
347
upstream_version = name[len("upstream/"):]
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",
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",
342
354
store_git_pristine_tar_data(target, filename.encode('utf-8'),