224
235
def __init__(self, mapping):
225
236
self.mapping = mapping
226
237
super(ForeignBranch, self).__init__()
240
def update_workingtree_fileids(wt, target_tree):
241
"""Update the file ids in a working tree based on another tree.
243
:param wt: Working tree in which to update file ids
244
:param target_tree: Tree to retrieve new file ids from, based on path
246
tt = transform.TreeTransform(wt)
248
for f, p, c, v, d, n, k, e in target_tree.iter_changes(wt):
249
if v == (True, False):
250
trans_id = tt.trans_id_tree_path(p[0])
251
tt.unversion_file(trans_id)
252
elif v == (False, True):
253
trans_id = tt.trans_id_tree_path(p[1])
254
tt.version_file(f, trans_id)
258
if len(wt.get_parent_ids()) == 1:
259
wt.set_parent_trees([(target_tree.get_revision_id(), target_tree)])
261
wt.set_last_revision(target_tree.get_revision_id())
264
class cmd_dpush(Command):
265
__doc__ = """Push into a different VCS without any custom bzr metadata.
267
This will afterwards rebase the local branch on the remote
268
branch unless the --no-rebase option is used, in which case
269
the two branches will be out of sync after the push.
271
takes_args = ['location?']
275
help='Branch to push from, '
276
'rather than the one containing the working directory.',
280
Option('no-rebase', help="Do not rebase after push."),
282
help='Refuse to push if there are uncommitted changes in'
283
' the working tree, --no-strict disables the check.'),
286
def run(self, location=None, remember=False, directory=None,
287
no_rebase=False, strict=None):
288
from breezy import urlutils
289
from breezy.controldir import ControlDir
290
from breezy.errors import BzrCommandError, NoWorkingTree
291
from breezy.workingtree import WorkingTree
293
if directory is None:
296
source_wt = WorkingTree.open_containing(directory)[0]
297
source_branch = source_wt.branch
298
except NoWorkingTree:
299
source_branch = Branch.open(directory)
301
if source_wt is not None:
302
source_wt.check_changed_or_out_of_date(
303
strict, 'dpush_strict',
304
more_error='Use --no-strict to force the push.',
305
more_warning='Uncommitted changes will not be pushed.')
306
stored_loc = source_branch.get_push_location()
308
if stored_loc is None:
309
raise BzrCommandError(gettext("No push location known or specified."))
311
display_url = urlutils.unescape_for_display(stored_loc,
314
gettext("Using saved location: %s\n") % display_url)
315
location = stored_loc
317
controldir = ControlDir.open(location)
318
target_branch = controldir.open_branch()
319
target_branch.lock_write()
322
push_result = source_branch.push(target_branch, lossy=True)
323
except errors.LossyPushToSameVCS:
324
raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy "
325
"push not necessary. Please use regular push.").format(
326
source_branch, target_branch))
327
# We successfully created the target, remember it
328
if source_branch.get_push_location() is None or remember:
329
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
330
source_branch.set_push_location(target_branch.base)
332
old_last_revid = source_branch.last_revision()
333
source_branch.pull(target_branch, overwrite=True)
334
new_last_revid = source_branch.last_revision()
335
if source_wt is not None and old_last_revid != new_last_revid:
336
source_wt.lock_write()
338
target = source_wt.branch.repository.revision_tree(
340
update_workingtree_fileids(source_wt, target)
343
push_result.report(self.outf)
345
target_branch.unlock()