~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-18 16:55:04 UTC
  • mfrom: (6437.23.10 2.5)
  • mto: This revision was merged to the branch mainline in revision 6469.
  • Revision ID: jelmer@samba.org-20120218165504-c9oe5c5ue805y8wp
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd.
 
1
# Copyright (C) 2007, 2009-2012 Canonical Ltd.
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
# Original author: David Allouche
18
20
 
19
21
from bzrlib import errors, merge, revision
43
45
        source_repository = control_dir.open_branch().repository
44
46
    except errors.NotBranchError:
45
47
        source_repository = to_branch.repository
46
 
    _set_branch_location(control_dir, to_branch, force)
 
48
    to_branch.lock_read()
 
49
    try:
 
50
        _set_branch_location(control_dir, to_branch, force)
 
51
    finally:
 
52
        to_branch.unlock()
47
53
    tree = control_dir.open_workingtree()
48
54
    _update(tree, source_repository, quiet, revision_id)
49
55
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
99
105
                        'Unable to connect to current master branch %(target)s: '
100
106
                        '%(error)s To switch anyway, use --force.') %
101
107
                        e.__dict__)
102
 
            b.set_bound_location(None)
103
 
            b.pull(to_branch, overwrite=True,
104
 
                possible_transports=possible_transports)
105
 
            b.set_bound_location(to_branch.base)
106
 
            b.set_parent(b.get_master_branch().get_parent())
 
108
            b.lock_write()
 
109
            try:
 
110
                b.set_bound_location(None)
 
111
                b.pull(to_branch, overwrite=True,
 
112
                       possible_transports=possible_transports)
 
113
                b.set_bound_location(to_branch.base)
 
114
                b.set_parent(b.get_master_branch().get_parent())
 
115
            finally:
 
116
                b.unlock()
107
117
        else:
108
 
            raise errors.BzrCommandError(gettext('Cannot switch a branch, '
109
 
                'only a checkout.'))
 
118
            # If this is a standalone tree and the new branch
 
119
            # is derived from this one, create a lightweight checkout.
 
120
            b.lock_read()
 
121
            try:
 
122
                graph = b.repository.get_graph(to_branch.repository)
 
123
                if (b.bzrdir._format.colocated_branches and
 
124
                     (force or graph.is_ancestor(b.last_revision(),
 
125
                        to_branch.last_revision()))):
 
126
                    b.bzrdir.destroy_branch()
 
127
                    b.bzrdir.set_branch_reference(to_branch, name="")
 
128
                else:
 
129
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
 
130
                        'only a checkout.'))
 
131
            finally:
 
132
                b.unlock()
110
133
 
111
134
 
112
135
def _any_local_commits(this_branch, possible_transports):