1
# Copyright (C) 2008-2012 Canonical Ltd
1
# Copyright (C) 2008-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
"""Foreign branch utilities."""
19
from __future__ import absolute_import
22
21
from bzrlib.branch import (
283
282
def run(self, location=None, remember=False, directory=None,
284
283
no_rebase=False, strict=None):
285
284
from bzrlib import urlutils
286
from bzrlib.controldir import ControlDir
285
from bzrlib.bzrdir import BzrDir
287
286
from bzrlib.errors import BzrCommandError, NoWorkingTree
288
287
from bzrlib.workingtree import WorkingTree
303
302
stored_loc = source_branch.get_push_location()
304
303
if location is None:
305
304
if stored_loc is None:
306
raise BzrCommandError(gettext("No push location known or specified."))
305
raise BzrCommandError("No push location known or specified.")
308
307
display_url = urlutils.unescape_for_display(stored_loc,
309
308
self.outf.encoding)
311
gettext("Using saved location: %s\n") % display_url)
309
self.outf.write("Using saved location: %s\n" % display_url)
312
310
location = stored_loc
314
controldir = ControlDir.open(location)
315
target_branch = controldir.open_branch()
312
bzrdir = BzrDir.open(location)
313
target_branch = bzrdir.open_branch()
316
314
target_branch.lock_write()
319
317
push_result = source_branch.push(target_branch, lossy=True)
320
318
except errors.LossyPushToSameVCS:
321
raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy "
322
"push not necessary. Please use regular push.").format(
323
source_branch, target_branch))
319
raise BzrCommandError("%r and %r are in the same VCS, lossy "
320
"push not necessary. Please use regular push." %
321
(source_branch, target_branch))
324
322
# We successfully created the target, remember it
325
323
if source_branch.get_push_location() is None or remember:
326
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
327
324
source_branch.set_push_location(target_branch.base)
328
325
if not no_rebase:
329
326
old_last_revid = source_branch.last_revision()