70
68
# Get stored location
71
69
self.notbranch = False
73
loc = info.get_push_location(self.comm.get_path())
71
from bzrlib.branch import Branch
73
branch = Branch.open_containing(self.comm.get_path())[0]
75
self.entry_stored.set_text(branch.get_push_location())
74
76
except errors.NotBranchError:
75
77
self.notbranch = True
79
self.entry_stored.set_text(loc)
82
81
""" Display the Push dialog. """
118
117
self.comm.set_busy(self.window)
119
118
if self.radio_stored.get_active():
121
revs = commit.push(self.comm.get_path(),
120
revs = do_push(self.comm.get_path(),
122
121
overwrite=self.check_overwrite.get_active())
123
122
except errors.NotBranchError:
124
123
self.dialog.error_dialog(_('Directory is not a branch'),
149
revs = commit.push(self.comm.get_path(), location,
148
revs = do_push(self.comm.get_path(), location,
150
149
self.check_remember.get_active(),
151
150
self.check_overwrite.get_active(),
152
151
self.check_create.get_active())
209
208
def close(self, widget=None):
210
209
self.window.destroy()
211
def do_push(branch, location=None, remember=False, overwrite=False,
212
create_prefix=False):
213
""" Update a mirror of a branch.
215
:param branch: the source branch
217
:param location: the location of the branch that you'd like to update
219
:param remember: if set, the location will be stored
221
:param overwrite: overwrite target location if it diverged
223
:param create_prefix: create the path leading up to the branch if it doesn't exist
225
:return: number of revisions pushed
227
from bzrlib.branch import Branch
228
from bzrlib.transport import get_transport
230
br_from = Branch.open_containing(branch)[0]
232
stored_loc = br_from.get_push_location()
234
if stored_loc is None:
235
raise NoLocationKnown
237
location = stored_loc
239
transport = get_transport(location)
240
location_url = transport.base
242
if br_from.get_push_location() is None or remember:
243
br_from.set_push_location(location_url)
248
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
249
br_to = dir_to.open_branch()
250
except NotBranchError:
252
transport = transport.clone('..')
253
if not create_prefix:
255
relurl = transport.relpath(location_url)
256
transport.mkdir(relurl)
258
raise NonExistingParent(location)
260
current = transport.base
261
needed = [(transport, transport.relpath(location_url))]
264
transport, relpath = needed[-1]
265
transport.mkdir(relpath)
268
new_transport = transport.clone('..')
269
needed.append((new_transport,
270
new_transport.relpath(transport.base)))
271
if new_transport.base == transport.base:
272
raise PathPrefixNotCreated
273
dir_to = br_from.bzrdir.clone(location_url,
274
revision_id=br_from.last_revision())
275
br_to = dir_to.open_branch()
276
count = len(br_to.revision_history())
278
old_rh = br_to.revision_history()
281
tree_to = dir_to.open_workingtree()
283
# FIXME - what to do here? how should we warn the user?
284
#warning('This transport does not update the working '
285
# 'tree of: %s' % (br_to.base,))
286
count = br_to.pull(br_from, overwrite)
287
except NoWorkingTree:
288
count = br_to.pull(br_from, overwrite)
290
count = tree_to.pull(br_from, overwrite)
291
except DivergedBranches:
292
raise DivergedBranchesError