1393
1393
_see_also = ['pull', 'working-trees', 'status-flags']
1394
1394
takes_args = ['dir?']
1395
takes_options = ['revision']
1395
1396
aliases = ['up']
1397
def run(self, dir='.'):
1398
def run(self, dir='.', revision=None):
1399
if revision is not None and len(revision) != 1:
1400
raise errors.BzrCommandError(
1401
"bzr update --revision takes exactly one revision")
1398
1402
tree = WorkingTree.open_containing(dir)[0]
1403
branch = tree.branch
1399
1404
possible_transports = []
1400
master = tree.branch.get_master_branch(
1405
master = branch.get_master_branch(
1401
1406
possible_transports=possible_transports)
1402
1407
if master is not None:
1403
1408
tree.lock_write()
1410
1415
self.outf.encoding)
1412
1417
existing_pending_merges = tree.get_parent_ids()[1:]
1413
last_rev = _mod_revision.ensure_null(tree.last_revision())
1414
if last_rev == _mod_revision.ensure_null(
1415
tree.branch.last_revision()):
1416
# may be up to date, check master too.
1417
if master is None or last_rev == _mod_revision.ensure_null(
1418
master.last_revision()):
1419
revno = tree.branch.revision_id_to_revno(last_rev)
1420
note('Tree is up to date at revision %d of branch %s'
1421
% (revno, branch_location))
1418
# potentially get new revisions from the master branch.
1419
# needed for the case where -r N is given, with N not yet
1420
# in the local branch for a heavyweight checkout.
1421
if revision is not None:
1423
rev = revision[0].in_history(branch).rev_id
1424
# no need to run branch.update()
1426
except (errors.NoSuchRevision, errors.InvalidRevisionSpec):
1427
# revision was not there, but is maybe in the master.
1428
old_tip = branch.update(possible_transports)
1429
rev = revision[0].in_history(branch).rev_id
1434
old_tip = branch.update(possible_transports)
1435
rev = branch.last_revision()
1436
if rev == _mod_revision.ensure_null(tree.last_revision()):
1437
revno = branch.revision_id_to_revno(rev)
1438
# XXX: Should say which branch it's up to date with
1439
note("Tree is up to date at revision %d." %
1423
1442
view_info = _get_view_info_for_change_reporter(tree)
1424
conflicts = tree.update(
1425
delta._ChangeReporter(unversioned_filter=tree.is_ignored,
1426
view_info=view_info), possible_transports=possible_transports)
1427
revno = tree.branch.revision_id_to_revno(
1428
_mod_revision.ensure_null(tree.last_revision()))
1429
note('Updated to revision %d of branch %s' %
1430
(revno, branch_location))
1444
conflicts = tree.update(
1445
delta._ChangeReporter(unversioned_filter=tree.is_ignored),
1446
possible_transports=possible_transports,
1449
view_info=view_info)
1450
except errors.NoSuchRevision, e:
1451
raise errors.BzrCommandError(
1452
"branch has no revision %s\n"
1453
"bzr update --revision only works"
1454
" for a revision in the branch history"
1456
revno = branch.revision_id_to_revno(
1457
_mod_revision.ensure_null(rev))
1458
note('Updated to revision %d.' % (revno,))
1431
1459
if tree.get_parent_ids()[1:] != existing_pending_merges:
1432
1460
note('Your local commits will now show as pending merges with '
1433
1461
"'bzr status', and can be committed with 'bzr commit'.")