25
25
from bzrlib.workingtree import WorkingTree
27
27
class cmd_switch(Command):
28
"""Set the branch of a lightweight checkout and update."""
28
"""Set the branch of a lightweight checkout and update. <BZRTOOLS>"""
30
30
takes_args = ['to_location']
32
32
def run(self, to_location):
33
33
to_branch = Branch.open(to_location)
35
self._switch(tree_location, to_branch)
36
# need to re-open tree to get the new branch
37
tree = WorkingTree.open_containing(tree_location)[0]
40
def _switch(self, tree_location, to_branch):
41
tree = WorkingTree.open_containing(tree_location)[0]
35
wt = WorkingTree.open_containing(url)[0]
44
self._check_switch_branch_format(tree_location)
45
self.set_branch_location(tree.bzrdir, to_branch.base)
40
unlockables.append(wt)
42
unlockables.append(branch)
43
self._check_switch_branch_format(url)
44
self.set_branch_location(wt.bzrdir, to_branch.base)
46
45
note('Switched to branch: %s' % (to_branch.base,))
50
def _update(self, tree):
53
if tree.last_revision() == tree.branch.last_revision():
54
assert tree.branch.get_master_branch() is None, (
55
"switch tried to update a fat checkout")
56
note("Tree is up to date.")
59
47
note('Updated to revision %d' %
60
(tree.branch.revision_id_to_revno(tree.last_revision()),))
48
(wt.branch.revision_id_to_revno(wt.last_revision()),))
50
for unlockable in unlockables:
64
53
def _check_switch_branch_format(self, url):
65
54
transport = get_transport(url)
94
83
branch_format = BranchFormat.find_format(control)
95
84
transport = control.get_branch_transport(None)
96
85
branch = branch_format.open(control)
97
location = transport.put_bytes('location', location)
86
location = transport.put('location', location)