16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from bzrlib.errors import BzrCommandError
19
from bzrlib.commands import Command, register_command
19
from bzrlib.commands import register_command
20
20
from bzrlib.branch import Branch, BranchFormat
21
21
from bzrlib.bzrdir import BzrDir, BzrDirFormat
22
22
from bzrlib.transport import get_transport
24
24
from bzrlib.trace import note
25
25
from bzrlib.workingtree import WorkingTree
27
class cmd_switch(Command):
28
"""Set the branch of a lightweight checkout and update. <BZRTOOLS>"""
27
from command import BzrToolsCommand
29
class cmd_switch(BzrToolsCommand):
30
"""Set the branch of a lightweight checkout and update."""
30
32
takes_args = ['to_location']
32
34
def run(self, to_location):
33
35
to_branch = Branch.open(to_location)
35
wt = WorkingTree.open_containing(url)[0]
37
self._switch(tree_location, to_branch)
38
# need to re-open tree to get the new branch
39
tree = WorkingTree.open_containing(tree_location)[0]
42
def _switch(self, tree_location, to_branch):
43
tree = WorkingTree.open_containing(tree_location)[0]
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
self._check_switch_branch_format(tree_location)
47
self.set_branch_location(tree.bzrdir, to_branch.base)
45
48
note('Switched to branch: %s' % (to_branch.base,))
52
def _update(self, tree):
55
if tree.last_revision() == tree.branch.last_revision():
56
assert tree.branch.get_master_branch() is None, (
57
"switch tried to update a fat checkout")
58
note("Tree is up to date.")
47
61
note('Updated to revision %d' %
48
(wt.branch.revision_id_to_revno(wt.last_revision()),))
62
(tree.branch.revision_id_to_revno(tree.last_revision()),))
50
for unlockable in unlockables:
53
66
def _check_switch_branch_format(self, url):
54
67
transport = get_transport(url)
83
96
branch_format = BranchFormat.find_format(control)
84
97
transport = control.get_branch_transport(None)
85
98
branch = branch_format.open(control)
86
location = transport.put('location', location)
99
location = transport.put_bytes('location', location)