77
78
# have been pushed to the current bound branch then
78
79
# synchronise the local branch with the new remote branch
80
if not force and _any_local_commits(b, bound_branch):
81
possible_transports = []
82
if not force and _any_local_commits(b, possible_transports):
81
83
raise errors.BzrCommandError(
82
84
'Cannot switch as local commits found in the checkout. '
83
85
'Commit these to the bound branch or use --force to '
84
86
'throw them away.')
85
87
b.set_bound_location(None)
86
b.pull(to_branch, overwrite=True)
88
b.pull(to_branch, overwrite=True,
89
possible_transports=possible_transports)
87
90
b.set_bound_location(to_branch.base)
89
92
raise errors.BzrCommandError('Cannot switch a branch, '
90
93
'only a checkout.')
93
def _any_local_commits(this_branch, other_branch_url):
94
"""Does this branch have any commits not in the other branch?"""
96
def _any_local_commits(this_branch, possible_transports):
97
"""Does this branch have any commits not in the master branch?"""
95
98
last_rev = revision.ensure_null(this_branch.last_revision())
96
99
if last_rev != revision.NULL_REVISION:
97
a_bzrdir, relpath = BzrDir.open_containing(other_branch_url)
98
other_branch = a_bzrdir.open_branch()
100
other_branch = this_branch.get_master_branch(possible_transports)
101
this_branch.lock_read()
99
102
other_branch.lock_read()
101
104
other_last_rev = other_branch.last_revision()
102
remote_graph = other_branch.repository.get_revision_graph(
104
if last_rev not in remote_graph:
105
graph = this_branch.repository.get_graph(
106
other_branch.repository)
107
if not graph.is_ancestor(last_rev, other_last_rev):
107
110
other_branch.unlock()