617
617
to_location, force_new_tree=False, format=format)
618
618
checkout = checkout_branch.bzrdir
619
619
checkout_branch.bind(self)
620
if revision_id is not None:
621
rh = checkout_branch.revision_history()
622
new_rh = rh[:rh.index(revision_id) + 1]
623
checkout_branch.set_revision_history(new_rh)
620
# pull up to the specified revision_id to set the initial
621
# branch tip correctly, and seed it with history.
622
checkout_branch.pull(self, stop_revision=revision_id)
624
623
return checkout.create_workingtree(revision_id)
1328
1327
@needs_write_lock
1329
1328
def bind(self, other):
1330
"""Bind the local branch the other branch.
1329
"""Bind this branch to the branch other.
1331
This does not push or pull data between the branches, though it does
1332
check for divergence to raise an error when the branches are not
1333
either the same, or one a prefix of the other. That behaviour may not
1334
be useful, so that check may be removed in future.
1332
1336
:param other: The branch to bind to
1333
1337
:type other: Branch
1339
1343
# but binding itself may not be.
1340
1344
# Since we *have* to check at commit time, we don't
1341
1345
# *need* to check here
1344
# we are now equal to or a suffix of other.
1346
# Since we have 'pulled' from the remote location,
1347
# now we should try to pull in the opposite direction
1348
# in case the local tree has more revisions than the
1350
# There may be a different check you could do here
1351
# rather than actually trying to install revisions remotely.
1352
# TODO: capture an exception which indicates the remote branch
1354
# If it is up-to-date, this probably should not be a failure
1356
# lock other for write so the revision-history syncing cannot race
1360
# if this does not error, other now has the same last rev we do
1361
# it can only error if the pull from other was concurrent with
1362
# a commit to other from someone else.
1364
# until we ditch revision-history, we need to sync them up:
1365
self.set_revision_history(other.revision_history())
1366
# now other and self are up to date with each other and have the
1367
# same revision-history.
1347
# we want to raise diverged if:
1348
# last_rev is not in the other_last_rev history, AND
1349
# other_last_rev is not in our history, and do it without pulling
1351
last_rev = self.last_revision()
1352
if last_rev is not None:
1355
other_last_rev = other.last_revision()
1356
if other_last_rev is not None:
1357
# neither branch is new, we have to do some work to
1358
# ascertain diversion.
1359
remote_graph = other.repository.get_revision_graph(
1361
local_graph = self.repository.get_revision_graph(last_rev)
1362
if (last_rev not in remote_graph and
1363
other_last_rev not in local_graph):
1364
raise errors.DivergedBranches(self, other)
1371
1367
self.set_bound_location(other.base)
1373
1369
@needs_write_lock