5325
5325
takes_args = ['to_location']
5326
5326
takes_options = [Option('force',
5327
help='Switch even if local commits will be lost.')
5327
help='Switch even if local commits will be lost.'),
5328
Option('create-branch', short_name='b',
5329
help='Create the target branch from this one before'
5330
' switching to it.'),
5330
def run(self, to_location, force=False):
5333
def run(self, to_location, force=False, create_branch=False):
5331
5334
from bzrlib import switch
5332
5335
tree_location = '.'
5333
5336
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5335
5338
branch = control_dir.open_branch()
5336
5339
had_explicit_nick = branch.get_config().has_explicit_nickname()
5337
5340
except errors.NotBranchError:
5338
5342
had_explicit_nick = False
5340
to_branch = Branch.open(to_location)
5341
except errors.NotBranchError:
5342
this_url = self._get_branch_location(control_dir)
5343
to_branch = Branch.open(
5344
urlutils.join(this_url, '..', to_location))
5345
raise errors.BzrCommandError('cannot create branch without'
5347
if '/' not in to_location and '\\' not in to_location:
5348
# This path is meant to be relative to the existing branch
5349
this_url = self._get_branch_location(control_dir)
5350
to_location = urlutils.join(this_url, '..', to_location)
5351
to_branch = branch.bzrdir.sprout(to_location,
5352
possible_transports=[branch.bzrdir.root_transport],
5353
source_branch=branch).open_branch()
5355
# from_branch = control_dir.open_branch()
5356
# except errors.NotBranchError:
5357
# raise BzrCommandError('Cannot create a branch from this'
5358
# ' location when we cannot open this branch')
5359
# from_branch.bzrdir.sprout(
5363
to_branch = Branch.open(to_location)
5364
except errors.NotBranchError:
5365
this_url = self._get_branch_location(control_dir)
5366
to_branch = Branch.open(
5367
urlutils.join(this_url, '..', to_location))
5345
5368
switch.switch(control_dir, to_branch, force)
5346
5369
if had_explicit_nick:
5347
5370
branch = control_dir.open_branch() #get the new branch!