1
# Copyright (C) 2007, 2009-2012 Canonical Ltd.
1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd.
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
17
from __future__ import absolute_import
19
17
# Original author: David Allouche
21
19
from bzrlib import errors, merge, revision
45
43
source_repository = control_dir.open_branch().repository
46
44
except errors.NotBranchError:
47
45
source_repository = to_branch.repository
50
_set_branch_location(control_dir, to_branch, force)
46
_set_branch_location(control_dir, to_branch, force)
53
47
tree = control_dir.open_workingtree()
54
48
_update(tree, source_repository, quiet, revision_id)
55
49
_run_post_switch_hooks(control_dir, to_branch, force, revision_id)
105
99
'Unable to connect to current master branch %(target)s: '
106
100
'%(error)s To switch anyway, use --force.') %
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())
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())
118
# If this is a standalone tree and the new branch
119
# is derived from this one, create a lightweight checkout.
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="")
129
raise errors.BzrCommandError(gettext('Cannot switch a branch, '
108
raise errors.BzrCommandError(gettext('Cannot switch a branch, '
135
112
def _any_local_commits(this_branch, possible_transports):