133
133
except NotBranchError:
134
134
remote_branch = BzrDir.create_branch_and_repo(
135
135
target_url, format=required_format)
138
if remote_branch.bzrdir.needs_format_conversion(
140
# For upgrades, push to a new branch in
141
# the new format. When done pushing,
142
# retire the old .bzr directory and rename
143
# the new one in place.
144
old_branch = remote_branch
145
upgrade_url = urljoin(target_url, "backup.bzr")
147
remote_branch.bzrdir.root_transport.delete_tree(
151
remote_branch = BzrDir.create_branch_and_repo(
152
upgrade_url, format=required_format)
136
155
pull_result = remote_branch.pull(bzr_branch, overwrite=True)
137
156
# Because of the way we do incremental imports, there may be revisions
138
157
# in the branch's repo that are not in the ancestry of the branch tip.
139
158
# We need to transfer them too.
140
159
remote_branch.repository.fetch(bzr_branch.repository)
160
if old_branch is not None:
161
# The format has changed; move the new format
163
base_transport = old_branch.bzrdir.root_transport
164
base_transport.delete_tree('.bzr')
165
base_transport.rename("backup.bzr/.bzr", ".bzr")
166
base_transport.rmdir("backup.bzr")
141
167
return pull_result.old_revid != pull_result.new_revid