1362
1363
If you want to discard your local changes, you can just do a
1363
1364
'bzr revert' instead of 'bzr commit' after the update.
1366
If the tree's branch is bound to a master branch, it will also update
1367
the branch from the master.
1366
1370
_see_also = ['pull', 'working-trees', 'status-flags']
1367
1371
takes_args = ['dir?']
1372
takes_options = ['revision']
1368
1373
aliases = ['up']
1370
def run(self, dir='.'):
1375
def run(self, dir='.', revision=None):
1376
if revision is not None and len(revision) != 1:
1377
raise errors.BzrCommandError(
1378
"bzr update --revision takes exactly one revision")
1371
1379
tree = WorkingTree.open_containing(dir)[0]
1380
branch = tree.branch
1372
1381
possible_transports = []
1373
master = tree.branch.get_master_branch(
1382
master = branch.get_master_branch(
1374
1383
possible_transports=possible_transports)
1375
1384
if master is not None:
1376
1385
tree.lock_write()
1383
1392
branch_location = urlutils.unescape_for_display(branch_location[:-1],
1384
1393
self.outf.encoding)
1385
1394
existing_pending_merges = tree.get_parent_ids()[1:]
1386
last_rev = _mod_revision.ensure_null(tree.last_revision())
1387
if last_rev == _mod_revision.ensure_null(
1388
tree.branch.last_revision()):
1389
# may be up to date, check master too.
1390
if master is None or last_rev == _mod_revision.ensure_null(
1391
master.last_revision()):
1392
revno = tree.branch.revision_id_to_revno(last_rev)
1393
note('Tree is up to date at revision %d of branch %s'
1394
% (revno, branch_location))
1398
# may need to fetch data into a heavyweight checkout
1399
# XXX: this may take some time, maybe we should display a
1401
old_tip = branch.update(possible_transports)
1402
if revision is not None:
1403
revision_id = revision[0].as_revision_id(branch)
1405
revision_id = branch.last_revision()
1406
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1407
revno = branch.revision_id_to_revno(revision_id)
1408
note("Tree is up to date at revision %d of branch %s" %
1409
(revno, branch_location))
1396
1411
view_info = _get_view_info_for_change_reporter(tree)
1397
conflicts = tree.update(
1398
delta._ChangeReporter(unversioned_filter=tree.is_ignored,
1399
view_info=view_info), possible_transports=possible_transports)
1412
change_reporter = delta._ChangeReporter(
1413
unversioned_filter=tree.is_ignored,
1414
view_info=view_info)
1416
conflicts = tree.update(
1418
possible_transports=possible_transports,
1419
revision=revision_id,
1421
except errors.NoSuchRevision, e:
1422
raise errors.BzrCommandError(
1423
"branch has no revision %s\n"
1424
"bzr update --revision only works"
1425
" for a revision in the branch history"
1400
1427
revno = tree.branch.revision_id_to_revno(
1401
1428
_mod_revision.ensure_null(tree.last_revision()))
1402
1429
note('Updated to revision %d of branch %s' %
5401
5428
if branch is None:
5402
5429
raise errors.BzrCommandError('cannot create branch without'
5403
5430
' source branch')
5431
to_location = directory_service.directories.dereference(
5404
5433
if '/' not in to_location and '\\' not in to_location:
5405
5434
# This path is meant to be relative to the existing branch
5406
5435
this_url = self._get_branch_location(control_dir)