~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-01 19:18:09 UTC
  • mfrom: (6459 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6460.
  • Revision ID: jelmer@samba.org-20120201191809-xn340a5i5v4fqsfu
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        source_repository = control_dir.open_branch().repository
46
46
    except errors.NotBranchError:
47
47
        source_repository = to_branch.repository
48
 
    _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()
49
53
    tree = control_dir.open_workingtree()
50
54
    _update(tree, source_repository, quiet, revision_id)
51
55
    _run_post_switch_hooks(control_dir, to_branch, force, revision_id)
109
113
        else:
110
114
            # If this is a standalone tree and the new branch
111
115
            # is derived from this one, create a lightweight checkout.
112
 
            graph = b.repository.get_graph(to_branch.repository)
113
 
            if (b.bzrdir._format.colocated_branches and
114
 
                 (force or graph.is_ancestor(b.last_revision(),
115
 
                    to_branch.last_revision()))):
116
 
                b.bzrdir.destroy_branch()
117
 
                b.bzrdir.set_branch_reference(to_branch, name="")
118
 
            else:
119
 
                raise errors.BzrCommandError(gettext('Cannot switch a branch, '
120
 
                    'only a checkout.'))
 
116
            b.lock_read()
 
117
            try:
 
118
                graph = b.repository.get_graph(to_branch.repository)
 
119
                if (b.bzrdir._format.colocated_branches and
 
120
                     (force or graph.is_ancestor(b.last_revision(),
 
121
                        to_branch.last_revision()))):
 
122
                    b.bzrdir.destroy_branch()
 
123
                    b.bzrdir.set_branch_reference(to_branch, name="")
 
124
                else:
 
125
                    raise errors.BzrCommandError(gettext('Cannot switch a branch, '
 
126
                        'only a checkout.'))
 
127
            finally:
 
128
                b.unlock()
121
129
 
122
130
 
123
131
def _any_local_commits(this_branch, possible_transports):