~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

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)
111
115
            finally:
112
116
                b.unlock()
113
117
        else:
114
 
            raise errors.BzrCommandError(gettext('Cannot switch a branch, '
115
 
                '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()
116
133
 
117
134
 
118
135
def _any_local_commits(this_branch, possible_transports):