5300
5300
takes_args = ['to_location']
5301
5301
takes_options = [Option('force',
5302
help='Switch even if local commits will be lost.')
5302
help='Switch even if local commits will be lost.'),
5303
Option('create-branch', short_name='b',
5304
help='Create the target branch from this one before'
5305
' switching to it.'),
5305
def run(self, to_location, force=False):
5308
def run(self, to_location, force=False, create_branch=False):
5306
5309
from bzrlib import switch
5307
5310
tree_location = '.'
5308
5311
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5310
5313
branch = control_dir.open_branch()
5311
5314
had_explicit_nick = branch.get_config().has_explicit_nickname()
5312
5315
except errors.NotBranchError:
5313
5317
had_explicit_nick = False
5315
to_branch = Branch.open(to_location)
5316
except errors.NotBranchError:
5317
this_url = self._get_branch_location(control_dir)
5318
to_branch = Branch.open(
5319
urlutils.join(this_url, '..', to_location))
5320
raise errors.BzrCommandError('cannot create branch without'
5322
if '/' not in to_location and '\\' not in to_location:
5323
# This path is meant to be relative to the existing branch
5324
this_url = self._get_branch_location(control_dir)
5325
to_location = urlutils.join(this_url, '..', to_location)
5326
to_branch = branch.bzrdir.sprout(to_location,
5327
possible_transports=[branch.bzrdir.root_transport],
5328
source_branch=branch).open_branch()
5330
# from_branch = control_dir.open_branch()
5331
# except errors.NotBranchError:
5332
# raise BzrCommandError('Cannot create a branch from this'
5333
# ' location when we cannot open this branch')
5334
# from_branch.bzrdir.sprout(
5338
to_branch = Branch.open(to_location)
5339
except errors.NotBranchError:
5340
this_url = self._get_branch_location(control_dir)
5341
to_branch = Branch.open(
5342
urlutils.join(this_url, '..', to_location))
5320
5343
switch.switch(control_dir, to_branch, force)
5321
5344
if had_explicit_nick:
5322
5345
branch = control_dir.open_branch() #get the new branch!