4355
4355
class cmd_switch(Command):
4356
"""Set the branch of a lightweight checkout and update."""
4356
"""Set the branch of a checkout and update.
4358
For lightweight checkouts, this changes the branch being referenced.
4359
For heavyweight checkouts, this checks that there are no local commits
4360
versus the current bound branch, then it makes the local branch a mirror
4361
of the new location and binds to it.
4363
In both cases, the working tree is updated and uncommitted changes
4364
are merged. The user can commit or revert these as they desire.
4366
Pending merges need to be committed or reverted before using switch.
4358
4369
takes_args = ['to_location']
4370
takes_options = [Option('force',
4371
help='Switch even if local commits will be lost.')
4360
def run(self, to_location):
4374
def run(self, to_location, force=False):
4361
4375
from bzrlib import switch
4362
4376
to_branch = Branch.open(to_location)
4363
4377
tree_location = '.'
4364
4378
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
4365
switch.switch(control_dir, to_branch)
4379
switch.switch(control_dir, to_branch, force)
4366
4380
note('Switched to branch: %s',
4367
4381
urlutils.unescape_for_display(to_branch.base, 'utf-8'))