1388
1389
If you want to discard your local changes, you can just do a
1389
1390
'bzr revert' instead of 'bzr commit' after the update.
1392
If the tree's branch is bound to a master branch, it will also update
1393
the branch from the master.
1392
1396
_see_also = ['pull', 'working-trees', 'status-flags']
1393
1397
takes_args = ['dir?']
1398
takes_options = ['revision']
1394
1399
aliases = ['up']
1396
def run(self, dir='.'):
1401
def run(self, dir='.', revision=None):
1402
if revision is not None and len(revision) != 1:
1403
raise errors.BzrCommandError(
1404
"bzr update --revision takes exactly one revision")
1397
1405
tree = WorkingTree.open_containing(dir)[0]
1406
branch = tree.branch
1398
1407
possible_transports = []
1399
master = tree.branch.get_master_branch(
1408
master = branch.get_master_branch(
1400
1409
possible_transports=possible_transports)
1401
1410
if master is not None:
1402
1411
tree.lock_write()
1409
1418
self.outf.encoding)
1411
1420
existing_pending_merges = tree.get_parent_ids()[1:]
1412
last_rev = _mod_revision.ensure_null(tree.last_revision())
1413
if last_rev == _mod_revision.ensure_null(
1414
tree.branch.last_revision()):
1415
# may be up to date, check master too.
1416
if master is None or last_rev == _mod_revision.ensure_null(
1417
master.last_revision()):
1418
revno = tree.branch.revision_id_to_revno(last_rev)
1419
note('Tree is up to date at revision %d of branch %s'
1420
% (revno, branch_location))
1424
# may need to fetch data into a heavyweight checkout
1425
# XXX: this may take some time, maybe we should display a
1427
old_tip = branch.update(possible_transports)
1428
if revision is not None:
1429
revision_id = revision[0].as_revision_id(branch)
1431
revision_id = branch.last_revision()
1432
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1433
revno = branch.revision_id_to_revno(revision_id)
1434
note("Tree is up to date at revision %d of branch %s" %
1435
(revno, branch_location))
1422
1437
view_info = _get_view_info_for_change_reporter(tree)
1423
conflicts = tree.update(
1424
delta._ChangeReporter(unversioned_filter=tree.is_ignored,
1425
view_info=view_info), possible_transports=possible_transports)
1438
change_reporter = delta._ChangeReporter(
1439
unversioned_filter=tree.is_ignored,
1440
view_info=view_info)
1442
conflicts = tree.update(
1444
possible_transports=possible_transports,
1445
revision=revision_id,
1447
except errors.NoSuchRevision, e:
1448
raise errors.BzrCommandError(
1449
"branch has no revision %s\n"
1450
"bzr update --revision only works"
1451
" for a revision in the branch history"
1426
1453
revno = tree.branch.revision_id_to_revno(
1427
1454
_mod_revision.ensure_null(tree.last_revision()))
1428
1455
note('Updated to revision %d of branch %s' %
5488
5515
if branch is None:
5489
5516
raise errors.BzrCommandError('cannot create branch without'
5490
5517
' source branch')
5518
to_location = directory_service.directories.dereference(
5491
5520
if '/' not in to_location and '\\' not in to_location:
5492
5521
# This path is meant to be relative to the existing branch
5493
5522
this_url = self._get_branch_location(control_dir)