~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to switch.py

  • Committer: Aaron Bentley
  • Date: 2006-04-12 01:27:15 UTC
  • mto: This revision was merged to the branch mainline in revision 362.
  • Revision ID: aaron.bentley@utoronto.ca-20060412012715-b8e33bae91b660a0
Tweak switch command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Limited.
 
2
# Authors: David Allouche <david@allouche.net>
 
3
#          Aaron Bentley <aaron.bentley@utoronto.ca>
 
4
#
 
5
#    This program is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    This program is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this program; if not, write to the Free Software
 
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1
18
from bzrlib.errors import BzrCommandError
2
19
from bzrlib.commands import Command, register_command
3
20
from bzrlib.branch import Branch, BranchFormat
5
22
from bzrlib.transport import get_transport
6
23
from bzrlib.builtins import cmd_update
7
24
from bzrlib.trace import note
 
25
from bzrlib.workingtree import WorkingTree
8
26
 
9
27
class cmd_switch(Command):
10
28
    """Set the branch of a lightweight checkout and update."""
14
32
    def run(self, to_location):
15
33
        to_branch = Branch.open(to_location)
16
34
        url = '.'
17
 
        branch = Branch.open_containing(url)[0]
18
 
        branch.lock_write()
 
35
        wt = WorkingTree.open_containing(url)[0]
 
36
        branch = wt.branch
 
37
        unlockables = []
19
38
        try:
20
 
            control = BzrDir.open_containing(url)[0]
 
39
            wt.lock_write()
 
40
            unlockables.append(wt)
 
41
            branch.lock_write()
 
42
            unlockables.append(branch)
21
43
            self._check_switch_branch_format(url)
22
 
            self.set_branch_location(control, to_branch.base)
 
44
            self.set_branch_location(wt.bzrdir, to_branch.base)
 
45
            note('Switched to branch: %s' % (to_branch.base,))
 
46
            wt.update()
 
47
            note('Updated to revision %d' %
 
48
                 (wt.branch.revision_id_to_revno(wt.last_revision()),))
23
49
        finally:
24
 
            branch.unlock()
25
 
        note('Switched to branch: %s' % (to_branch.base,))
26
 
        cmd_update().run(url)
 
50
            for unlockable in unlockables:
 
51
                unlockable.unlock()
27
52
 
28
53
    def _check_switch_branch_format(self, url):
29
54
        transport = get_transport(url)