288
275
def run(self, show_ids=False, file_list=None, revision=None, short=False,
289
versioned=False, no_pending=False, verbose=False,
276
versioned=False, no_pending=False, verbose=False):
291
277
from bzrlib.status import show_tree_status
293
279
if revision and len(revision) > 2:
294
raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
295
' one or two revision specifiers'))
280
raise errors.BzrCommandError('bzr status --revision takes exactly'
281
' one or two revision specifiers')
297
283
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
298
284
# Avoid asking for specific files when that is not needed.
336
321
def run(self, revision_id=None, revision=None, directory=u'.'):
337
322
if revision_id is not None and revision is not None:
338
raise errors.BzrCommandError(gettext('You can only supply one of'
339
' revision_id or --revision'))
323
raise errors.BzrCommandError('You can only supply one of'
324
' revision_id or --revision')
340
325
if revision_id is None and revision is None:
341
raise errors.BzrCommandError(gettext('You must supply either'
342
' --revision or a revision_id'))
344
b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
326
raise errors.BzrCommandError('You must supply either'
327
' --revision or a revision_id')
328
b = WorkingTree.open_containing(directory)[0].branch
346
330
revisions = b.repository.revisions
347
331
if revisions is None:
348
raise errors.BzrCommandError(gettext('Repository %r does not support '
349
'access to raw revision texts'))
332
raise errors.BzrCommandError('Repository %r does not support '
333
'access to raw revision texts')
351
335
b.repository.lock_read()
491
472
raise errors.ShelvedChanges(working)
493
474
if working.user_url != working.branch.user_url:
494
raise errors.BzrCommandError(gettext("You cannot remove the working tree"
495
" from a lightweight checkout"))
475
raise errors.BzrCommandError("You cannot remove the working tree"
476
" from a lightweight checkout")
497
478
d.destroy_workingtree()
500
class cmd_repair_workingtree(Command):
501
__doc__ = """Reset the working tree state file.
503
This is not meant to be used normally, but more as a way to recover from
504
filesystem corruption, etc. This rebuilds the working inventory back to a
505
'known good' state. Any new modifications (adding a file, renaming, etc)
506
will be lost, though modified files will still be detected as such.
508
Most users will want something more like "bzr revert" or "bzr update"
509
unless the state file has become corrupted.
511
By default this attempts to recover the current state by looking at the
512
headers of the state file. If the state file is too corrupted to even do
513
that, you can supply --revision to force the state of the tree.
516
takes_options = ['revision', 'directory',
518
help='Reset the tree even if it doesn\'t appear to be'
523
def run(self, revision=None, directory='.', force=False):
524
tree, _ = WorkingTree.open_containing(directory)
525
self.add_cleanup(tree.lock_tree_write().unlock)
529
except errors.BzrError:
530
pass # There seems to be a real error here, so we'll reset
533
raise errors.BzrCommandError(gettext(
534
'The tree does not appear to be corrupt. You probably'
535
' want "bzr revert" instead. Use "--force" if you are'
536
' sure you want to reset the working tree.'))
540
revision_ids = [r.as_revision_id(tree.branch) for r in revision]
542
tree.reset_state(revision_ids)
543
except errors.BzrError, e:
544
if revision_ids is None:
545
extra = (gettext(', the header appears corrupt, try passing -r -1'
546
' to set the state to the last commit'))
549
raise errors.BzrCommandError(gettext('failed to reset the tree state{0}').format(extra))
552
481
class cmd_revno(Command):
553
482
__doc__ = """Show current revision number.
559
488
takes_args = ['location?']
560
489
takes_options = [
561
490
Option('tree', help='Show revno of working tree'),
566
def run(self, tree=False, location=u'.', revision=None):
567
if revision is not None and tree:
568
raise errors.BzrCommandError(gettext("--tree and --revision can "
569
"not be used together"))
494
def run(self, tree=False, location=u'.'):
573
497
wt = WorkingTree.open_containing(location)[0]
574
498
self.add_cleanup(wt.lock_read().unlock)
575
499
except (errors.NoWorkingTree, errors.NotLocalUrl):
576
500
raise errors.NoWorkingTree(location)
578
501
revid = wt.last_revision()
503
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
504
except errors.NoSuchRevision:
506
revno = ".".join(str(n) for n in revno_t)
580
508
b = Branch.open_containing(location)[0]
581
509
self.add_cleanup(b.lock_read().unlock)
583
if len(revision) != 1:
584
raise errors.BzrCommandError(gettext(
585
"Tags can only be placed on a single revision, "
587
revid = revision[0].as_revision_id(b)
589
revid = b.last_revision()
591
revno_t = b.revision_id_to_dotted_revno(revid)
592
except errors.NoSuchRevision:
594
revno = ".".join(str(n) for n in revno_t)
595
511
self.cleanup_now()
596
self.outf.write(revno + '\n')
512
self.outf.write(str(revno) + '\n')
599
515
class cmd_revision_info(Command):
879
785
return self.run_auto(names_list, after, dry_run)
881
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
787
raise errors.BzrCommandError('--dry-run requires --auto.')
882
788
if names_list is None:
884
790
if len(names_list) < 2:
885
raise errors.BzrCommandError(gettext("missing file argument"))
791
raise errors.BzrCommandError("missing file argument")
886
792
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
887
793
self.add_cleanup(tree.lock_tree_write().unlock)
888
794
self._run(tree, names_list, rel_names, after)
890
796
def run_auto(self, names_list, after, dry_run):
891
797
if names_list is not None and len(names_list) > 1:
892
raise errors.BzrCommandError(gettext('Only one path may be specified to'
798
raise errors.BzrCommandError('Only one path may be specified to'
895
raise errors.BzrCommandError(gettext('--after cannot be specified with'
801
raise errors.BzrCommandError('--after cannot be specified with'
897
803
work_tree, file_list = WorkingTree.open_containing_paths(
898
804
names_list, default_directory='.')
899
805
self.add_cleanup(work_tree.lock_tree_write().unlock)
996
902
match the remote one, use pull --overwrite. This will work even if the two
997
903
branches have diverged.
999
If there is no default location set, the first pull will set it (use
1000
--no-remember to avoid setting it). After that, you can omit the
1001
location to use the default. To change the default, use --remember. The
1002
value will only be saved if the remote location can be accessed.
1004
The --verbose option will display the revisions pulled using the log_format
1005
configuration option. You can use a different format by overriding it with
1006
-Olog_format=<other_format>.
905
If there is no default location set, the first pull will set it. After
906
that, you can omit the location to use the default. To change the
907
default, use --remember. The value will only be saved if the remote
908
location can be accessed.
1008
910
Note: The location can be specified either in the form of a branch,
1009
911
or in the form of a path to a file containing a merge directive generated
1063
959
stored_loc = branch_to.get_parent()
1064
960
if location is None:
1065
961
if stored_loc is None:
1066
raise errors.BzrCommandError(gettext("No pull location known or"
962
raise errors.BzrCommandError("No pull location known or"
1069
965
display_url = urlutils.unescape_for_display(stored_loc,
1070
966
self.outf.encoding)
1071
967
if not is_quiet():
1072
self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
968
self.outf.write("Using saved parent location: %s\n" % display_url)
1073
969
location = stored_loc
1075
971
revision = _get_one_revision('pull', revision)
1076
972
if mergeable is not None:
1077
973
if revision is not None:
1078
raise errors.BzrCommandError(gettext(
1079
'Cannot use -r with merge directives or bundles'))
974
raise errors.BzrCommandError(
975
'Cannot use -r with merge directives or bundles')
1080
976
mergeable.install_revisions(branch_to.repository)
1081
977
base_revision_id, revision_id, verified = \
1082
978
mergeable.get_merge_request(branch_to.repository)
1136
1027
do a merge (see bzr help merge) from the other branch, and commit that.
1137
1028
After that you will be able to do a push without '--overwrite'.
1139
If there is no default push location set, the first push will set it (use
1140
--no-remember to avoid setting it). After that, you can omit the
1141
location to use the default. To change the default, use --remember. The
1142
value will only be saved if the remote location can be accessed.
1144
The --verbose option will display the revisions pushed using the log_format
1145
configuration option. You can use a different format by overriding it with
1146
-Olog_format=<other_format>.
1030
If there is no default push location set, the first push will set it.
1031
After that, you can omit the location to use the default. To change the
1032
default, use --remember. The value will only be saved if the remote
1033
location can be accessed.
1149
1036
_see_also = ['pull', 'update', 'working-trees']
1170
1057
Option('strict',
1171
1058
help='Refuse to push if there are uncommitted changes in'
1172
1059
' the working tree, --no-strict disables the check.'),
1174
help="Don't populate the working tree, even for protocols"
1175
" that support it."),
1177
1061
takes_args = ['location?']
1178
1062
encoding_type = 'replace'
1180
def run(self, location=None, remember=None, overwrite=False,
1064
def run(self, location=None, remember=False, overwrite=False,
1181
1065
create_prefix=False, verbose=False, revision=None,
1182
1066
use_existing_dir=False, directory=None, stacked_on=None,
1183
stacked=False, strict=None, no_tree=False):
1067
stacked=False, strict=None):
1184
1068
from bzrlib.push import _show_push_branch
1186
1070
if directory is None:
1187
1071
directory = '.'
1188
1072
# Get the source branch
1189
1073
(tree, br_from,
1190
_unused) = controldir.ControlDir.open_containing_tree_or_branch(directory)
1074
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1191
1075
# Get the tip's revision_id
1192
1076
revision = _get_one_revision('push', revision)
1193
1077
if revision is not None:
1214
1098
# error by the feedback given to them. RBC 20080227.
1215
1099
stacked_on = parent_url
1216
1100
if not stacked_on:
1217
raise errors.BzrCommandError(gettext(
1218
"Could not determine branch to refer to."))
1101
raise errors.BzrCommandError(
1102
"Could not determine branch to refer to.")
1220
1104
# Get the destination location
1221
1105
if location is None:
1222
1106
stored_loc = br_from.get_push_location()
1223
1107
if stored_loc is None:
1224
raise errors.BzrCommandError(gettext(
1225
"No push location known or specified."))
1108
raise errors.BzrCommandError(
1109
"No push location known or specified.")
1227
1111
display_url = urlutils.unescape_for_display(stored_loc,
1228
1112
self.outf.encoding)
1229
note(gettext("Using saved push location: %s") % display_url)
1113
self.outf.write("Using saved push location: %s\n" % display_url)
1230
1114
location = stored_loc
1232
1116
_show_push_branch(br_from, revision_id, location, self.outf,
1233
1117
verbose=verbose, overwrite=overwrite, remember=remember,
1234
1118
stacked_on=stacked_on, create_prefix=create_prefix,
1235
use_existing_dir=use_existing_dir, no_tree=no_tree)
1119
use_existing_dir=use_existing_dir)
1238
1122
class cmd_branch(Command):
1315
1191
to_transport.mkdir('.')
1316
1192
except errors.FileExists:
1317
1193
if not use_existing_dir:
1318
raise errors.BzrCommandError(gettext('Target directory "%s" '
1319
'already exists.') % to_location)
1194
raise errors.BzrCommandError('Target directory "%s" '
1195
'already exists.' % to_location)
1322
to_dir = controldir.ControlDir.open_from_transport(
1198
bzrdir.BzrDir.open_from_transport(to_transport)
1324
1199
except errors.NotBranchError:
1328
to_dir.open_branch()
1329
except errors.NotBranchError:
1332
raise errors.AlreadyBranchError(to_location)
1202
raise errors.AlreadyBranchError(to_location)
1333
1203
except errors.NoSuchFile:
1334
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1204
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1340
# preserve whatever source format we have.
1341
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1342
possible_transports=[to_transport],
1343
accelerator_tree=accelerator_tree,
1344
hardlink=hardlink, stacked=stacked,
1345
force_new_repo=standalone,
1346
create_tree_if_local=not no_tree,
1347
source_branch=br_from)
1348
branch = to_dir.open_branch()
1349
except errors.NoSuchRevision:
1350
to_transport.delete_tree('.')
1351
msg = gettext("The branch {0} has no revision {1}.").format(
1352
from_location, revision)
1353
raise errors.BzrCommandError(msg)
1355
branch = br_from.sprout(to_dir, revision_id=revision_id)
1207
# preserve whatever source format we have.
1208
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1209
possible_transports=[to_transport],
1210
accelerator_tree=accelerator_tree,
1211
hardlink=hardlink, stacked=stacked,
1212
force_new_repo=standalone,
1213
create_tree_if_local=not no_tree,
1214
source_branch=br_from)
1215
branch = dir.open_branch()
1216
except errors.NoSuchRevision:
1217
to_transport.delete_tree('.')
1218
msg = "The branch %s has no revision %s." % (from_location,
1220
raise errors.BzrCommandError(msg)
1356
1221
_merge_tags_if_possible(br_from, branch)
1357
1222
# If the source branch is stacked, the new branch may
1358
1223
# be stacked whether we asked for that explicitly or not.
1359
1224
# We therefore need a try/except here and not just 'if stacked:'
1361
note(gettext('Created new stacked branch referring to %s.') %
1226
note('Created new stacked branch referring to %s.' %
1362
1227
branch.get_stacked_on_url())
1363
1228
except (errors.NotStacked, errors.UnstackableBranchFormat,
1364
1229
errors.UnstackableRepositoryFormat), e:
1365
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1230
note('Branched %d revision(s).' % branch.revno())
1367
1232
# Bind to the parent
1368
1233
parent_branch = Branch.open(from_location)
1369
1234
branch.bind(parent_branch)
1370
note(gettext('New branch bound to %s') % from_location)
1235
note('New branch bound to %s' % from_location)
1372
1237
# Switch to the new branch
1373
1238
wt, _ = WorkingTree.open_containing('.')
1374
1239
_mod_switch.switch(wt.bzrdir, branch)
1375
note(gettext('Switched to branch: %s'),
1240
note('Switched to branch: %s',
1376
1241
urlutils.unescape_for_display(branch.base, 'utf-8'))
1379
class cmd_branches(Command):
1380
__doc__ = """List the branches available at the current location.
1382
This command will print the names of all the branches at the current
1386
takes_args = ['location?']
1388
Option('recursive', short_name='R',
1389
help='Recursively scan for branches rather than '
1390
'just looking in the specified location.')]
1392
def run(self, location=".", recursive=False):
1394
t = transport.get_transport(location)
1395
if not t.listable():
1396
raise errors.BzrCommandError(
1397
"Can't scan this type of location.")
1398
for b in controldir.ControlDir.find_branches(t):
1399
self.outf.write("%s\n" % urlutils.unescape_for_display(
1400
urlutils.relative_url(t.base, b.base),
1401
self.outf.encoding).rstrip("/"))
1403
dir = controldir.ControlDir.open_containing(location)[0]
1404
for branch in dir.list_branches():
1405
if branch.name is None:
1406
self.outf.write(gettext(" (default)\n"))
1408
self.outf.write(" %s\n" % branch.name.encode(
1409
self.outf.encoding))
1412
1244
class cmd_checkout(Command):
1413
1245
__doc__ = """Create a new checkout of an existing branch.
1516
1348
class cmd_update(Command):
1517
__doc__ = """Update a working tree to a new revision.
1519
This will perform a merge of the destination revision (the tip of the
1520
branch, or the specified revision) into the working tree, and then make
1521
that revision the basis revision for the working tree.
1523
You can use this to visit an older revision, or to update a working tree
1524
that is out of date from its branch.
1526
If there are any uncommitted changes in the tree, they will be carried
1527
across and remain as uncommitted changes after the update. To discard
1528
these changes, use 'bzr revert'. The uncommitted changes may conflict
1529
with the changes brought in by the change in basis revision.
1531
If the tree's branch is bound to a master branch, bzr will also update
1349
__doc__ = """Update a tree to have the latest code committed to its branch.
1351
This will perform a merge into the working tree, and may generate
1352
conflicts. If you have any local changes, you will still
1353
need to commit them after the update for the update to be complete.
1355
If you want to discard your local changes, you can just do a
1356
'bzr revert' instead of 'bzr commit' after the update.
1358
If the tree's branch is bound to a master branch, it will also update
1532
1359
the branch from the master.
1534
You cannot update just a single file or directory, because each Bazaar
1535
working tree has just a single basis revision. If you want to restore a
1536
file that has been removed locally, use 'bzr revert' instead of 'bzr
1537
update'. If you want to restore a file to its state in a previous
1538
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1539
out the old content of that file to a new location.
1541
The 'dir' argument, if given, must be the location of the root of a
1542
working tree to update. By default, the working tree that contains the
1543
current working directory is used.
1546
1362
_see_also = ['pull', 'working-trees', 'status-flags']
1547
1363
takes_args = ['dir?']
1548
takes_options = ['revision',
1550
help="Show base revision text in conflicts."),
1364
takes_options = ['revision']
1552
1365
aliases = ['up']
1554
def run(self, dir=None, revision=None, show_base=None):
1367
def run(self, dir='.', revision=None):
1555
1368
if revision is not None and len(revision) != 1:
1556
raise errors.BzrCommandError(gettext(
1557
"bzr update --revision takes exactly one revision"))
1559
tree = WorkingTree.open_containing('.')[0]
1561
tree, relpath = WorkingTree.open_containing(dir)
1564
raise errors.BzrCommandError(gettext(
1565
"bzr update can only update a whole tree, "
1566
"not a file or subdirectory"))
1369
raise errors.BzrCommandError(
1370
"bzr update --revision takes exactly one revision")
1371
tree = WorkingTree.open_containing(dir)[0]
1567
1372
branch = tree.branch
1568
1373
possible_transports = []
1569
1374
master = branch.get_master_branch(
1605
1410
change_reporter,
1606
1411
possible_transports=possible_transports,
1607
1412
revision=revision_id,
1609
show_base=show_base)
1610
1414
except errors.NoSuchRevision, e:
1611
raise errors.BzrCommandError(gettext(
1415
raise errors.BzrCommandError(
1612
1416
"branch has no revision %s\n"
1613
1417
"bzr update --revision only works"
1614
" for a revision in the branch history")
1418
" for a revision in the branch history"
1615
1419
% (e.revision))
1616
1420
revno = tree.branch.revision_id_to_dotted_revno(
1617
1421
_mod_revision.ensure_null(tree.last_revision()))
1618
note(gettext('Updated to revision {0} of branch {1}').format(
1619
'.'.join(map(str, revno)), branch_location))
1422
note('Updated to revision %s of branch %s' %
1423
('.'.join(map(str, revno)), branch_location))
1620
1424
parent_ids = tree.get_parent_ids()
1621
1425
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1622
note(gettext('Your local commits will now show as pending merges with '
1623
"'bzr status', and can be committed with 'bzr commit'."))
1426
note('Your local commits will now show as pending merges with '
1427
"'bzr status', and can be committed with 'bzr commit'.")
1624
1428
if conflicts != 0:
1668
1472
noise_level = 0
1669
1473
from bzrlib.info import show_bzrdir_info
1670
show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
1474
show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1671
1475
verbose=noise_level, outfile=self.outf)
1674
1478
class cmd_remove(Command):
1675
1479
__doc__ = """Remove files or directories.
1677
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1678
delete them if they can easily be recovered using revert otherwise they
1679
will be backed up (adding an extention of the form .~#~). If no options or
1680
parameters are given Bazaar will scan for files that are being tracked by
1681
Bazaar but missing in your tree and stop tracking them for you.
1481
This makes bzr stop tracking changes to the specified files. bzr will delete
1482
them if they can easily be recovered using revert. If no options or
1483
parameters are given bzr will scan for files that are being tracked by bzr
1484
but missing in your tree and stop tracking them for you.
1683
1486
takes_args = ['file*']
1684
1487
takes_options = ['verbose',
1686
1489
RegistryOption.from_kwargs('file-deletion-strategy',
1687
1490
'The file deletion mode to be used.',
1688
1491
title='Deletion Strategy', value_switches=True, enum_switch=False,
1689
safe='Backup changed files (default).',
1492
safe='Only delete files if they can be'
1493
' safely recovered (default).',
1690
1494
keep='Delete from bzr but leave the working copy.',
1691
no_backup='Don\'t backup changed files.',
1692
1495
force='Delete all the specified files, even if they can not be '
1693
'recovered and even if they are non-empty directories. '
1694
'(deprecated, use no-backup)')]
1496
'recovered and even if they are non-empty directories.')]
1695
1497
aliases = ['rm', 'del']
1696
1498
encoding_type = 'replace'
1698
1500
def run(self, file_list, verbose=False, new=False,
1699
1501
file_deletion_strategy='safe'):
1700
if file_deletion_strategy == 'force':
1701
note(gettext("(The --force option is deprecated, rather use --no-backup "
1703
file_deletion_strategy = 'no-backup'
1705
1502
tree, file_list = WorkingTree.open_containing_paths(file_list)
1707
1504
if file_list is not None:
1891
1674
help='Specify a format for this branch. '
1892
1675
'See "help formats".',
1893
1676
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1894
converter=lambda name: controldir.format_registry.make_bzrdir(name),
1677
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1895
1678
value_switches=True,
1896
1679
title="Branch format",
1898
1681
Option('append-revisions-only',
1899
1682
help='Never change revnos or the existing log.'
1900
' Append revisions to it only.'),
1902
'Create a branch without a working tree.')
1683
' Append revisions to it only.')
1904
1685
def run(self, location=None, format=None, append_revisions_only=False,
1905
create_prefix=False, no_tree=False):
1686
create_prefix=False):
1906
1687
if format is None:
1907
format = controldir.format_registry.make_bzrdir('default')
1688
format = bzrdir.format_registry.make_bzrdir('default')
1908
1689
if location is None:
1909
1690
location = u'.'
1919
1700
to_transport.ensure_base()
1920
1701
except errors.NoSuchFile:
1921
1702
if not create_prefix:
1922
raise errors.BzrCommandError(gettext("Parent directory of %s"
1703
raise errors.BzrCommandError("Parent directory of %s"
1923
1704
" does not exist."
1924
1705
"\nYou may supply --create-prefix to create all"
1925
" leading parent directories.")
1706
" leading parent directories."
1927
1708
to_transport.create_prefix()
1930
a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
1711
a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1931
1712
except errors.NotBranchError:
1932
1713
# really a NotBzrDir error...
1933
create_branch = controldir.ControlDir.create_branch_convenience
1935
force_new_tree = False
1937
force_new_tree = None
1714
create_branch = bzrdir.BzrDir.create_branch_convenience
1938
1715
branch = create_branch(to_transport.base, format=format,
1939
possible_transports=[to_transport],
1940
force_new_tree=force_new_tree)
1716
possible_transports=[to_transport])
1941
1717
a_bzrdir = branch.bzrdir
1943
1719
from bzrlib.transport.local import LocalTransport
2170
1927
elif ':' in prefix:
2171
1928
old_label, new_label = prefix.split(":")
2173
raise errors.BzrCommandError(gettext(
1930
raise errors.BzrCommandError(
2174
1931
'--prefix expects two values separated by a colon'
2175
' (eg "old/:new/")'))
1932
' (eg "old/:new/")')
1934
if using is not None and diff_options is not None:
1935
raise errors.BzrCommandError(
1936
'--diff-options and --using are mutually exclusive.')
2177
1938
if revision and len(revision) > 2:
2178
raise errors.BzrCommandError(gettext('bzr diff --revision takes exactly'
2179
' one or two revision specifiers'))
1939
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1940
' one or two revision specifiers')
2181
1942
if using is not None and format is not None:
2182
raise errors.BzrCommandError(gettext(
2183
'{0} and {1} are mutually exclusive').format(
2184
'--using', '--format'))
1943
raise errors.BzrCommandError('--using and --format are mutually '
2186
1946
(old_tree, new_tree,
2187
1947
old_branch, new_branch,
2501
2256
Option('show-diff',
2502
2257
short_name='p',
2503
2258
help='Show changes made in each revision as a patch.'),
2504
Option('include-merged',
2259
Option('include-merges',
2505
2260
help='Show merged revisions like --levels 0 does.'),
2506
Option('include-merges', hidden=True,
2507
help='Historical alias for --include-merged.'),
2508
Option('omit-merges',
2509
help='Do not report commits with more than one parent.'),
2510
2261
Option('exclude-common-ancestry',
2511
2262
help='Display only the revisions that are not part'
2512
2263
' of both ancestries (require -rX..Y)'
2514
Option('signatures',
2515
help='Show digital signature validity'),
2518
help='Show revisions whose properties match this '
2521
ListOption('match-message',
2522
help='Show revisions whose message matches this '
2525
ListOption('match-committer',
2526
help='Show revisions whose committer matches this '
2529
ListOption('match-author',
2530
help='Show revisions whose authors match this '
2533
ListOption('match-bugs',
2534
help='Show revisions whose bugs match this '
2538
2266
encoding_type = 'replace'
2567
2287
_get_info_for_log_files,
2569
2289
direction = (forward and 'forward') or 'reverse'
2570
if symbol_versioning.deprecated_passed(include_merges):
2571
ui.ui_factory.show_user_warning(
2572
'deprecated_command_option',
2573
deprecated_name='--include-merges',
2574
recommended_name='--include-merged',
2575
deprecated_in_version='2.5',
2576
command=self.invoked_as)
2577
if include_merged is None:
2578
include_merged = include_merges
2580
raise errors.BzrCommandError(gettext(
2581
'{0} and {1} are mutually exclusive').format(
2582
'--include-merges', '--include-merged'))
2583
if include_merged is None:
2584
include_merged = False
2585
2290
if (exclude_common_ancestry
2586
2291
and (revision is None or len(revision) != 2)):
2587
raise errors.BzrCommandError(gettext(
2588
'--exclude-common-ancestry requires -r with two revisions'))
2292
raise errors.BzrCommandError(
2293
'--exclude-common-ancestry requires -r with two revisions')
2590
2295
if levels is None:
2593
raise errors.BzrCommandError(gettext(
2594
'{0} and {1} are mutually exclusive').format(
2595
'--levels', '--include-merged'))
2298
raise errors.BzrCommandError(
2299
'--levels and --include-merges are mutually exclusive')
2597
2301
if change is not None:
2598
2302
if len(change) > 1:
2599
2303
raise errors.RangeInChangeOption()
2600
2304
if revision is not None:
2601
raise errors.BzrCommandError(gettext(
2602
'{0} and {1} are mutually exclusive').format(
2603
'--revision', '--change'))
2305
raise errors.BzrCommandError(
2306
'--revision and --change are mutually exclusive')
2605
2308
revision = change
3011
2685
self.outf.write("%s\n" % pattern)
3013
2687
if not name_pattern_list:
3014
raise errors.BzrCommandError(gettext("ignore requires at least one "
3015
"NAME_PATTERN or --default-rules."))
2688
raise errors.BzrCommandError("ignore requires at least one "
2689
"NAME_PATTERN or --default-rules.")
3016
2690
name_pattern_list = [globbing.normalize_pattern(p)
3017
2691
for p in name_pattern_list]
3019
bad_patterns_count = 0
3020
for p in name_pattern_list:
3021
if not globbing.Globster.is_pattern_valid(p):
3022
bad_patterns_count += 1
3023
bad_patterns += ('\n %s' % p)
3025
msg = (ngettext('Invalid ignore pattern found. %s',
3026
'Invalid ignore patterns found. %s',
3027
bad_patterns_count) % bad_patterns)
3028
ui.ui_factory.show_error(msg)
3029
raise errors.InvalidPattern('')
3030
2692
for name_pattern in name_pattern_list:
3031
2693
if (name_pattern[0] == '/' or
3032
2694
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3033
raise errors.BzrCommandError(gettext(
3034
"NAME_PATTERN should not be an absolute path"))
2695
raise errors.BzrCommandError(
2696
"NAME_PATTERN should not be an absolute path")
3035
2697
tree, relpath = WorkingTree.open_containing(directory)
3036
2698
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3037
2699
ignored = globbing.Globster(name_pattern_list)
3203
2864
old_file_id = rev_tree.path2id(relpath)
3205
# TODO: Split out this code to something that generically finds the
3206
# best id for a path across one or more trees; it's like
3207
# find_ids_across_trees but restricted to find just one. -- mbp
3209
2866
if name_from_revision:
3210
2867
# Try in revision if requested
3211
2868
if old_file_id is None:
3212
raise errors.BzrCommandError(gettext(
3213
"{0!r} is not present in revision {1}").format(
2869
raise errors.BzrCommandError(
2870
"%r is not present in revision %s" % (
3214
2871
filename, rev_tree.get_revision_id()))
3216
actual_file_id = old_file_id
2873
content = rev_tree.get_file_text(old_file_id)
3218
2875
cur_file_id = tree.path2id(relpath)
3219
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3220
actual_file_id = cur_file_id
3221
elif old_file_id is not None:
3222
actual_file_id = old_file_id
3224
raise errors.BzrCommandError(gettext(
3225
"{0!r} is not present in revision {1}").format(
2877
if cur_file_id is not None:
2878
# Then try with the actual file id
2880
content = rev_tree.get_file_text(cur_file_id)
2882
except errors.NoSuchId:
2883
# The actual file id didn't exist at that time
2885
if not found and old_file_id is not None:
2886
# Finally try with the old file id
2887
content = rev_tree.get_file_text(old_file_id)
2890
# Can't be found anywhere
2891
raise errors.BzrCommandError(
2892
"%r is not present in revision %s" % (
3226
2893
filename, rev_tree.get_revision_id()))
3228
from bzrlib.filter_tree import ContentFilterTree
3229
filter_tree = ContentFilterTree(rev_tree,
3230
rev_tree._content_filter_stack)
3231
content = filter_tree.get_file_text(actual_file_id)
2895
from bzrlib.filters import (
2896
ContentFilterContext,
2897
filtered_output_bytes,
2899
filters = rev_tree._content_filter_stack(relpath)
2900
chunks = content.splitlines(True)
2901
content = filtered_output_bytes(chunks, filters,
2902
ContentFilterContext(relpath, rev_tree))
2904
self.outf.writelines(content)
3233
content = rev_tree.get_file_text(actual_file_id)
3235
self.outf.write(content)
2907
self.outf.write(content)
3238
2910
class cmd_local_time_offset(Command):
3299
2971
to trigger updates to external systems like bug trackers. The --fixes
3300
2972
option can be used to record the association between a revision and
3301
2973
one or more bugs. See ``bzr help bugs`` for details.
2975
A selective commit may fail in some cases where the committed
2976
tree would be invalid. Consider::
2981
bzr commit foo -m "committing foo"
2982
bzr mv foo/bar foo/baz
2985
bzr commit foo/bar -m "committing bar but not baz"
2987
In the example above, the last commit will fail by design. This gives
2988
the user the opportunity to decide whether they want to commit the
2989
rename at the same time, separately first, or not at all. (As a general
2990
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
2992
# TODO: Run hooks on tree to-be-committed, and after commit.
2994
# TODO: Strict commit that fails if there are deleted files.
2995
# (what does "deleted files" mean ??)
2997
# TODO: Give better message for -s, --summary, used by tla people
2999
# XXX: verbose currently does nothing
3304
3001
_see_also = ['add', 'bugs', 'hooks', 'uncommit']
3305
3002
takes_args = ['selected*']
3337
3034
Option('show-diff', short_name='p',
3338
3035
help='When no message is supplied, show the diff along'
3339
3036
' with the status summary in the message editor.'),
3341
help='When committing to a foreign version control '
3342
'system do not push data that can not be natively '
3345
3038
aliases = ['ci', 'checkin']
3347
3040
def _iter_bug_fix_urls(self, fixes, branch):
3348
default_bugtracker = None
3349
3041
# Configure the properties for bug fixing attributes.
3350
3042
for fixed_bug in fixes:
3351
3043
tokens = fixed_bug.split(':')
3352
if len(tokens) == 1:
3353
if default_bugtracker is None:
3354
branch_config = branch.get_config()
3355
default_bugtracker = branch_config.get_user_option(
3357
if default_bugtracker is None:
3358
raise errors.BzrCommandError(gettext(
3359
"No tracker specified for bug %s. Use the form "
3360
"'tracker:id' or specify a default bug tracker "
3361
"using the `bugtracker` option.\nSee "
3362
"\"bzr help bugs\" for more information on this "
3363
"feature. Commit refused.") % fixed_bug)
3364
tag = default_bugtracker
3366
elif len(tokens) != 2:
3367
raise errors.BzrCommandError(gettext(
3044
if len(tokens) != 2:
3045
raise errors.BzrCommandError(
3368
3046
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3369
3047
"See \"bzr help bugs\" for more information on this "
3370
"feature.\nCommit refused.") % fixed_bug)
3372
tag, bug_id = tokens
3048
"feature.\nCommit refused." % fixed_bug)
3049
tag, bug_id = tokens
3374
3051
yield bugtracker.get_bug_url(tag, branch, bug_id)
3375
3052
except errors.UnknownBugTrackerAbbreviation:
3376
raise errors.BzrCommandError(gettext(
3377
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3053
raise errors.BzrCommandError(
3054
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3378
3055
except errors.MalformedBugIdentifier, e:
3379
raise errors.BzrCommandError(gettext(
3380
"%s\nCommit refused.") % (str(e),))
3056
raise errors.BzrCommandError(
3057
"%s\nCommit refused." % (str(e),))
3382
3059
def run(self, message=None, file=None, verbose=False, selected_list=None,
3383
3060
unchanged=False, strict=False, local=False, fixes=None,
3384
author=None, show_diff=False, exclude=None, commit_time=None,
3061
author=None, show_diff=False, exclude=None, commit_time=None):
3386
3062
from bzrlib.errors import (
3387
3063
PointlessCommit,
3388
3064
ConflictsInTree,
3464
3145
# make_commit_message_template_encoded returns user encoding.
3465
3146
# We probably want to be using edit_commit_message instead to
3467
my_message = set_commit_message(commit_obj)
3468
if my_message is None:
3469
start_message = generate_commit_message_template(commit_obj)
3470
my_message = edit_commit_message_encoded(text,
3471
start_message=start_message)
3472
if my_message is None:
3473
raise errors.BzrCommandError(gettext("please specify a commit"
3474
" message with either --message or --file"))
3475
if my_message == "":
3476
raise errors.BzrCommandError(gettext("Empty commit message specified."
3477
" Please specify a commit message with either"
3478
" --message or --file or leave a blank message"
3479
" with --message \"\"."))
3148
start_message = generate_commit_message_template(commit_obj)
3149
my_message = edit_commit_message_encoded(text,
3150
start_message=start_message)
3151
if my_message is None:
3152
raise errors.BzrCommandError("please specify a commit"
3153
" message with either --message or --file")
3154
if my_message == "":
3155
raise errors.BzrCommandError("empty commit message specified")
3480
3156
return my_message
3482
3158
# The API permits a commit with a filter of [] to mean 'select nothing'
3490
3166
reporter=None, verbose=verbose, revprops=properties,
3491
3167
authors=author, timestamp=commit_stamp,
3492
3168
timezone=offset,
3493
exclude=tree.safe_relpath_files(exclude),
3169
exclude=tree.safe_relpath_files(exclude))
3495
3170
except PointlessCommit:
3496
raise errors.BzrCommandError(gettext("No changes to commit."
3497
" Please 'bzr add' the files you want to commit, or use"
3498
" --unchanged to force an empty commit."))
3171
raise errors.BzrCommandError("No changes to commit."
3172
" Use --unchanged to commit anyhow.")
3499
3173
except ConflictsInTree:
3500
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3174
raise errors.BzrCommandError('Conflicts detected in working '
3501
3175
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3503
3177
except StrictCommitFailed:
3504
raise errors.BzrCommandError(gettext("Commit refused because there are"
3505
" unknown files in the working tree."))
3178
raise errors.BzrCommandError("Commit refused because there are"
3179
" unknown files in the working tree.")
3506
3180
except errors.BoundBranchOutOfDate, e:
3507
e.extra_help = (gettext("\n"
3181
e.extra_help = ("\n"
3508
3182
'To commit to master branch, run update and then commit.\n'
3509
3183
'You can also pass --local to commit to continue working '
3584
3258
class cmd_upgrade(Command):
3585
__doc__ = """Upgrade a repository, branch or working tree to a newer format.
3587
When the default format has changed after a major new release of
3588
Bazaar, you may be informed during certain operations that you
3589
should upgrade. Upgrading to a newer format may improve performance
3590
or make new features available. It may however limit interoperability
3591
with older repositories or with older versions of Bazaar.
3593
If you wish to upgrade to a particular format rather than the
3594
current default, that can be specified using the --format option.
3595
As a consequence, you can use the upgrade command this way to
3596
"downgrade" to an earlier format, though some conversions are
3597
a one way process (e.g. changing from the 1.x default to the
3598
2.x default) so downgrading is not always possible.
3600
A backup.bzr.~#~ directory is created at the start of the conversion
3601
process (where # is a number). By default, this is left there on
3602
completion. If the conversion fails, delete the new .bzr directory
3603
and rename this one back in its place. Use the --clean option to ask
3604
for the backup.bzr directory to be removed on successful conversion.
3605
Alternatively, you can delete it by hand if everything looks good
3608
If the location given is a shared repository, dependent branches
3609
are also converted provided the repository converts successfully.
3610
If the conversion of a branch fails, remaining branches are still
3613
For more information on upgrades, see the Bazaar Upgrade Guide,
3614
http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3259
__doc__ = """Upgrade branch storage to current format.
3261
The check command or bzr developers may sometimes advise you to run
3262
this command. When the default format has changed you may also be warned
3263
during other operations to upgrade.
3617
_see_also = ['check', 'reconcile', 'formats']
3266
_see_also = ['check']
3618
3267
takes_args = ['url?']
3619
3268
takes_options = [
3620
RegistryOption('format',
3621
help='Upgrade to a specific format. See "bzr help'
3622
' formats" for details.',
3623
lazy_registry=('bzrlib.controldir', 'format_registry'),
3624
converter=lambda name: controldir.format_registry.make_bzrdir(name),
3625
value_switches=True, title='Branch format'),
3627
help='Remove the backup.bzr directory if successful.'),
3629
help="Show what would be done, but don't actually do anything."),
3269
RegistryOption('format',
3270
help='Upgrade to a specific format. See "bzr help'
3271
' formats" for details.',
3272
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3273
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3274
value_switches=True, title='Branch format'),
3632
def run(self, url='.', format=None, clean=False, dry_run=False):
3277
def run(self, url='.', format=None):
3633
3278
from bzrlib.upgrade import upgrade
3634
exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
3636
if len(exceptions) == 1:
3637
# Compatibility with historical behavior
3279
upgrade(url, format)
3643
3282
class cmd_whoami(Command):
3767
3402
def remove_alias(self, alias_name):
3768
3403
if alias_name is None:
3769
raise errors.BzrCommandError(gettext(
3770
'bzr alias --remove expects an alias to remove.'))
3404
raise errors.BzrCommandError(
3405
'bzr alias --remove expects an alias to remove.')
3771
3406
# If alias is not found, print something like:
3772
3407
# unalias: foo: not found
3773
c = _mod_config.GlobalConfig()
3408
c = config.GlobalConfig()
3774
3409
c.unset_alias(alias_name)
3776
3411
@display_command
3777
3412
def print_aliases(self):
3778
3413
"""Print out the defined aliases in a similar format to bash."""
3779
aliases = _mod_config.GlobalConfig().get_aliases()
3414
aliases = config.GlobalConfig().get_aliases()
3780
3415
for key, value in sorted(aliases.iteritems()):
3781
3416
self.outf.write('bzr alias %s="%s"\n' % (key, value))
3924
3555
def run(self, testspecs_list=None, verbose=False, one=False,
3925
3556
transport=None, benchmark=None,
3557
lsprof_timed=None, cache_dir=None,
3927
3558
first=False, list_only=False,
3928
3559
randomize=None, exclude=None, strict=False,
3929
3560
load_list=None, debugflag=None, starting_with=None, subunit=False,
3930
parallel=None, lsprof_tests=False,
3932
from bzrlib import tests
3561
parallel=None, lsprof_tests=False):
3562
from bzrlib.tests import selftest
3563
import bzrlib.benchmarks as benchmarks
3564
from bzrlib.benchmarks import tree_creator
3566
# Make deprecation warnings visible, unless -Werror is set
3567
symbol_versioning.activate_deprecation_warnings(override=False)
3569
if cache_dir is not None:
3570
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3934
3571
if testspecs_list is not None:
3935
3572
pattern = '|'.join(testspecs_list)
3955
3592
self.additional_selftest_args.setdefault(
3956
3593
'suite_decorators', []).append(parallel)
3958
raise errors.BzrCommandError(gettext(
3959
"--benchmark is no longer supported from bzr 2.2; "
3960
"use bzr-usertest instead"))
3961
test_suite_factory = None
3963
exclude_pattern = None
3595
test_suite_factory = benchmarks.test_suite
3596
# Unless user explicitly asks for quiet, be verbose in benchmarks
3597
verbose = not is_quiet()
3598
# TODO: should possibly lock the history file...
3599
benchfile = open(".perf_history", "at", buffering=1)
3600
self.add_cleanup(benchfile.close)
3965
exclude_pattern = '(' + '|'.join(exclude) + ')'
3967
self._disable_fsync()
3602
test_suite_factory = None
3968
3604
selftest_kwargs = {"verbose": verbose,
3969
3605
"pattern": pattern,
3970
3606
"stop_on_failure": one,
3972
3608
"test_suite_factory": test_suite_factory,
3973
3609
"lsprof_timed": lsprof_timed,
3974
3610
"lsprof_tests": lsprof_tests,
3611
"bench_history": benchfile,
3975
3612
"matching_tests_first": first,
3976
3613
"list_only": list_only,
3977
3614
"random_seed": randomize,
3978
"exclude_pattern": exclude_pattern,
3615
"exclude_pattern": exclude,
3979
3616
"strict": strict,
3980
3617
"load_list": load_list,
3981
3618
"debug_flags": debugflag,
3982
3619
"starting_with": starting_with
3984
3621
selftest_kwargs.update(self.additional_selftest_args)
3986
# Make deprecation warnings visible, unless -Werror is set
3987
cleanup = symbol_versioning.activate_deprecation_warnings(
3990
result = tests.selftest(**selftest_kwargs)
3622
result = selftest(**selftest_kwargs)
3993
3623
return int(not result)
3995
def _disable_fsync(self):
3996
"""Change the 'os' functionality to not synchronize."""
3997
self._orig_fsync = getattr(os, 'fsync', None)
3998
if self._orig_fsync is not None:
3999
os.fsync = lambda filedes: None
4000
self._orig_fdatasync = getattr(os, 'fdatasync', None)
4001
if self._orig_fdatasync is not None:
4002
os.fdatasync = lambda filedes: None
4005
3626
class cmd_version(Command):
4006
3627
__doc__ = """Show version of bzr."""
4059
3680
The source of the merge can be specified either in the form of a branch,
4060
3681
or in the form of a path to a file containing a merge directive generated
4061
3682
with bzr send. If neither is specified, the default is the upstream branch
4062
or the branch most recently merged using --remember. The source of the
4063
merge may also be specified in the form of a path to a file in another
4064
branch: in this case, only the modifications to that file are merged into
4065
the current working tree.
4067
When merging from a branch, by default bzr will try to merge in all new
4068
work from the other branch, automatically determining an appropriate base
4069
revision. If this fails, you may need to give an explicit base.
4071
To pick a different ending revision, pass "--revision OTHER". bzr will
4072
try to merge in all new work up to and including revision OTHER.
4074
If you specify two values, "--revision BASE..OTHER", only revisions BASE
4075
through OTHER, excluding BASE but including OTHER, will be merged. If this
4076
causes some revisions to be skipped, i.e. if the destination branch does
4077
not already contain revision BASE, such a merge is commonly referred to as
4078
a "cherrypick". Unlike a normal merge, Bazaar does not currently track
4079
cherrypicks. The changes look like a normal commit, and the history of the
4080
changes from the other branch is not stored in the commit.
4082
Revision numbers are always relative to the source branch.
3683
or the branch most recently merged using --remember.
3685
When merging a branch, by default the tip will be merged. To pick a different
3686
revision, pass --revision. If you specify two values, the first will be used as
3687
BASE and the second one as OTHER. Merging individual revisions, or a subset of
3688
available revisions, like this is commonly referred to as "cherrypicking".
3690
Revision numbers are always relative to the branch being merged.
3692
By default, bzr will try to merge in all new work from the other
3693
branch, automatically determining an appropriate base. If this
3694
fails, you may need to give an explicit base.
4084
3696
Merge will do its best to combine the changes in two branches, but there
4085
3697
are some kinds of problems only a human can fix. When it encounters those,
4089
3701
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
4091
If there is no default branch set, the first merge will set it (use
4092
--no-remember to avoid setting it). After that, you can omit the branch
4093
to use the default. To change the default, use --remember. The value will
4094
only be saved if the remote location can be accessed.
3703
If there is no default branch set, the first merge will set it. After
3704
that, you can omit the branch to use the default. To change the
3705
default, use --remember. The value will only be saved if the remote
3706
location can be accessed.
4096
3708
The results of the merge are placed into the destination working
4097
3709
directory, where they can be reviewed (with bzr diff), tested, and then
4098
3710
committed to record the result of the merge.
4100
3712
merge refuses to run if there are any uncommitted changes, unless
4101
--force is given. If --force is given, then the changes from the source
4102
will be merged with the current working tree, including any uncommitted
4103
changes in the tree. The --force option can also be used to create a
3713
--force is given. The --force option can also be used to create a
4104
3714
merge revision which has more than two parents.
4106
3716
If one would like to merge changes from the working tree of the other
4208
3814
mergeable = None
4210
3816
if uncommitted:
4211
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4212
' with bundles or merge directives.'))
3817
raise errors.BzrCommandError('Cannot use --uncommitted'
3818
' with bundles or merge directives.')
4214
3820
if revision is not None:
4215
raise errors.BzrCommandError(gettext(
4216
'Cannot use -r with merge directives or bundles'))
3821
raise errors.BzrCommandError(
3822
'Cannot use -r with merge directives or bundles')
4217
3823
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4218
3824
mergeable, None)
4220
3826
if merger is None and uncommitted:
4221
3827
if revision is not None and len(revision) > 0:
4222
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4223
' --revision at the same time.'))
3828
raise errors.BzrCommandError('Cannot use --uncommitted and'
3829
' --revision at the same time.')
4224
3830
merger = self.get_merger_from_uncommitted(tree, location, None)
4225
3831
allow_pending = False
4234
3840
self.sanity_check_merger(merger)
4235
3841
if (merger.base_rev_id == merger.other_rev_id and
4236
3842
merger.other_rev_id is not None):
4237
# check if location is a nonexistent file (and not a branch) to
4238
# disambiguate the 'Nothing to do'
4239
if merger.interesting_files:
4240
if not merger.other_tree.has_filename(
4241
merger.interesting_files[0]):
4242
note(gettext("merger: ") + str(merger))
4243
raise errors.PathsDoNotExist([location])
4244
note(gettext('Nothing to do.'))
3843
note('Nothing to do.')
4246
if pull and not preview:
4247
3846
if merger.interesting_files is not None:
4248
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
3847
raise errors.BzrCommandError('Cannot pull individual files')
4249
3848
if (merger.base_rev_id == tree.last_revision()):
4250
3849
result = tree.pull(merger.other_branch, False,
4251
3850
merger.other_rev_id)
4252
3851
result.report(self.outf)
4254
3853
if merger.this_basis is None:
4255
raise errors.BzrCommandError(gettext(
3854
raise errors.BzrCommandError(
4256
3855
"This branch has no commits."
4257
" (perhaps you would prefer 'bzr pull')"))
3856
" (perhaps you would prefer 'bzr pull')")
4259
3858
return self._do_preview(merger)
4260
3859
elif interactive:
4358
3957
if other_revision_id is None:
4359
3958
other_revision_id = _mod_revision.ensure_null(
4360
3959
other_branch.last_revision())
4361
# Remember where we merge from. We need to remember if:
4362
# - user specify a location (and we don't merge from the parent
4364
# - user ask to remember or there is no previous location set to merge
4365
# from and user didn't ask to *not* remember
4366
if (user_location is not None
4368
or (remember is None
4369
and tree.branch.get_submit_branch() is None)))):
3960
# Remember where we merge from
3961
if ((remember or tree.branch.get_submit_branch() is None) and
3962
user_location is not None):
4370
3963
tree.branch.set_submit_branch(other_branch.base)
4371
# Merge tags (but don't set them in the master branch yet, the user
4372
# might revert this merge). Commit will propagate them.
4373
_merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3964
_merge_tags_if_possible(other_branch, tree.branch)
4374
3965
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
4375
3966
other_revision_id, base_revision_id, other_branch, base_branch)
4376
3967
if other_path != '':
4720
4308
theirs_only=False,
4721
4309
log_format=None, long=False, short=False, line=False,
4722
4310
show_ids=False, verbose=False, this=False, other=False,
4723
include_merged=None, revision=None, my_revision=None,
4725
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4311
include_merges=False, revision=None, my_revision=None,
4726
4313
from bzrlib.missing import find_unmerged, iter_log_revisions
4727
4314
def message(s):
4728
4315
if not is_quiet():
4729
4316
self.outf.write(s)
4731
if symbol_versioning.deprecated_passed(include_merges):
4732
ui.ui_factory.show_user_warning(
4733
'deprecated_command_option',
4734
deprecated_name='--include-merges',
4735
recommended_name='--include-merged',
4736
deprecated_in_version='2.5',
4737
command=self.invoked_as)
4738
if include_merged is None:
4739
include_merged = include_merges
4741
raise errors.BzrCommandError(gettext(
4742
'{0} and {1} are mutually exclusive').format(
4743
'--include-merges', '--include-merged'))
4744
if include_merged is None:
4745
include_merged = False
4747
4319
mine_only = this
4905
4473
@display_command
4906
4474
def run(self, verbose=False):
4907
from bzrlib import plugin
4908
# Don't give writelines a generator as some codecs don't like that
4909
self.outf.writelines(
4910
list(plugin.describe_plugins(show_paths=verbose)))
4475
import bzrlib.plugin
4476
from inspect import getdoc
4478
for name, plugin in bzrlib.plugin.plugins().items():
4479
version = plugin.__version__
4480
if version == 'unknown':
4482
name_ver = '%s %s' % (name, version)
4483
d = getdoc(plugin.module)
4485
doc = d.split('\n')[0]
4487
doc = '(no description)'
4488
result.append((name_ver, doc, plugin.path()))
4489
for name_ver, doc, path in sorted(result):
4490
self.outf.write("%s\n" % name_ver)
4491
self.outf.write(" %s\n" % doc)
4493
self.outf.write(" %s\n" % path)
4494
self.outf.write("\n")
4913
4497
class cmd_testament(Command):
4977
4559
self.add_cleanup(branch.lock_read().unlock)
4978
4560
tree = _get_one_revision_tree('annotate', revision, branch=branch)
4979
4561
self.add_cleanup(tree.lock_read().unlock)
4980
if wt is not None and revision is None:
4981
4563
file_id = wt.path2id(relpath)
4983
4565
file_id = tree.path2id(relpath)
4984
4566
if file_id is None:
4985
4567
raise errors.NotVersionedError(filename)
4568
file_version = tree.inventory[file_id].revision
4986
4569
if wt is not None and revision is None:
4987
4570
# If there is a tree and we're not annotating historical
4988
4571
# versions, annotate the working tree's content.
4989
4572
annotate_file_tree(wt, file_id, self.outf, long, all,
4990
4573
show_ids=show_ids)
4992
annotate_file_tree(tree, file_id, self.outf, long, all,
4993
show_ids=show_ids, branch=branch)
4575
annotate_file(branch, file_version, file_id, long, all, self.outf,
4996
4579
class cmd_re_sign(Command):
5081
4664
location = b.get_old_bound_location()
5082
4665
except errors.UpgradeRequired:
5083
raise errors.BzrCommandError(gettext('No location supplied. '
5084
'This format does not remember old locations.'))
4666
raise errors.BzrCommandError('No location supplied. '
4667
'This format does not remember old locations.')
5086
4669
if location is None:
5087
4670
if b.get_bound_location() is not None:
5088
raise errors.BzrCommandError(gettext('Branch is already bound'))
4671
raise errors.BzrCommandError('Branch is already bound')
5090
raise errors.BzrCommandError(gettext('No location supplied '
5091
'and no previous location known'))
4673
raise errors.BzrCommandError('No location supplied '
4674
'and no previous location known')
5092
4675
b_other = Branch.open(location)
5094
4677
b.bind(b_other)
5095
4678
except errors.DivergedBranches:
5096
raise errors.BzrCommandError(gettext('These branches have diverged.'
5097
' Try merging, and then bind again.'))
4679
raise errors.BzrCommandError('These branches have diverged.'
4680
' Try merging, and then bind again.')
5098
4681
if b.get_config().has_explicit_nickname():
5099
4682
b.nick = b_other.nick
5167
4749
self.add_cleanup(tree.lock_write().unlock)
5169
4751
self.add_cleanup(b.lock_write().unlock)
5170
return self._run(b, tree, dry_run, verbose, revision, force,
4752
return self._run(b, tree, dry_run, verbose, revision, force, local=local)
5173
def _run(self, b, tree, dry_run, verbose, revision, force, local,
4754
def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5175
4755
from bzrlib.log import log_formatter, show_log
5176
4756
from bzrlib.uncommit import uncommit
5207
4787
end_revision=last_revno)
5210
self.outf.write(gettext('Dry-run, pretending to remove'
5211
' the above revisions.\n'))
4790
self.outf.write('Dry-run, pretending to remove'
4791
' the above revisions.\n')
5213
self.outf.write(gettext('The above revision(s) will be removed.\n'))
4793
self.outf.write('The above revision(s) will be removed.\n')
5216
if not ui.ui_factory.confirm_action(
5217
gettext(u'Uncommit these revisions'),
5218
'bzrlib.builtins.uncommit',
5220
self.outf.write(gettext('Canceled\n'))
4796
if not ui.ui_factory.get_boolean('Are you sure'):
4797
self.outf.write('Canceled')
5223
4800
mutter('Uncommitting from {%s} to {%s}',
5224
4801
last_rev_id, rev_id)
5225
4802
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5226
revno=revno, local=local, keep_tags=keep_tags)
5227
self.outf.write(gettext('You can restore the old tip by running:\n'
5228
' bzr pull . -r revid:%s\n') % last_rev_id)
4803
revno=revno, local=local)
4804
self.outf.write('You can restore the old tip by running:\n'
4805
' bzr pull . -r revid:%s\n' % last_rev_id)
5231
4808
class cmd_break_lock(Command):
5232
__doc__ = """Break a dead lock.
5234
This command breaks a lock on a repository, branch, working directory or
4809
__doc__ = """Break a dead lock on a repository, branch or working directory.
5237
4811
CAUTION: Locks should only be broken when you are sure that the process
5238
4812
holding the lock has been stopped.
5245
4819
bzr break-lock bzr+ssh://example.com/bzr/foo
5246
bzr break-lock --conf ~/.bazaar
5249
4821
takes_args = ['location?']
5252
help='LOCATION is the directory where the config lock is.'),
5254
help='Do not ask for confirmation before breaking the lock.'),
5257
def run(self, location=None, config=False, force=False):
4823
def run(self, location=None, show=False):
5258
4824
if location is None:
5259
4825
location = u'.'
5261
ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
5263
{'bzrlib.lockdir.break': True})
5265
conf = _mod_config.LockableConfig(file_name=location)
5268
control, relpath = controldir.ControlDir.open_containing(location)
5270
control.break_lock()
5271
except NotImplementedError:
4826
control, relpath = bzrdir.BzrDir.open_containing(location)
4828
control.break_lock()
4829
except NotImplementedError:
5275
4833
class cmd_wait_until_signalled(Command):
5350
4906
if not allow_writes:
5351
4907
url = 'readonly+' + url
5352
4908
t = transport.get_transport(url)
5354
protocol(t, host, port, inet, client_timeout)
5355
except TypeError, e:
5356
# We use symbol_versioning.deprecated_in just so that people
5357
# grepping can find it here.
5358
# symbol_versioning.deprecated_in((2, 5, 0))
5359
symbol_versioning.warn(
5360
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5361
'Most likely it needs to be updated to support a'
5362
' "timeout" parameter (added in bzr 2.5.0)'
5363
% (e, protocol.__module__, protocol),
5365
protocol(t, host, port, inet)
4909
protocol(t, host, port, inet)
5368
4912
class cmd_join(Command):
5780
5318
self.add_cleanup(branch.lock_write().unlock)
5782
5320
if tag_name is None:
5783
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5321
raise errors.BzrCommandError("No tag specified to delete.")
5784
5322
branch.tags.delete_tag(tag_name)
5785
note(gettext('Deleted tag %s.') % tag_name)
5323
self.outf.write('Deleted tag %s.\n' % tag_name)
5788
5326
if len(revision) != 1:
5789
raise errors.BzrCommandError(gettext(
5327
raise errors.BzrCommandError(
5790
5328
"Tags can only be placed on a single revision, "
5792
5330
revision_id = revision[0].as_revision_id(branch)
5794
5332
revision_id = branch.last_revision()
5795
5333
if tag_name is None:
5796
5334
tag_name = branch.automatic_tag_name(revision_id)
5797
5335
if tag_name is None:
5798
raise errors.BzrCommandError(gettext(
5799
"Please specify a tag name."))
5801
existing_target = branch.tags.lookup_tag(tag_name)
5802
except errors.NoSuchTag:
5803
existing_target = None
5804
if not force and existing_target not in (None, revision_id):
5336
raise errors.BzrCommandError(
5337
"Please specify a tag name.")
5338
if (not force) and branch.tags.has_tag(tag_name):
5805
5339
raise errors.TagAlreadyExists(tag_name)
5806
if existing_target == revision_id:
5807
note(gettext('Tag %s already exists for that revision.') % tag_name)
5809
branch.tags.set_tag(tag_name, revision_id)
5810
if existing_target is None:
5811
note(gettext('Created tag %s.') % tag_name)
5813
note(gettext('Updated tag %s.') % tag_name)
5340
branch.tags.set_tag(tag_name, revision_id)
5341
self.outf.write('Created tag %s.\n' % tag_name)
5816
5344
class cmd_tags(Command):
5843
5376
self.add_cleanup(branch.lock_read().unlock)
5845
# Restrict to the specified range
5846
tags = self._tags_for_range(branch, revision)
5848
sort = tag_sort_methods.get()
5378
graph = branch.repository.get_graph()
5379
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5380
revid1, revid2 = rev1.rev_id, rev2.rev_id
5381
# only show revisions between revid1 and revid2 (inclusive)
5382
tags = [(tag, revid) for tag, revid in tags if
5383
graph.is_between(revid, revid1, revid2)]
5386
elif sort == 'time':
5388
for tag, revid in tags:
5390
revobj = branch.repository.get_revision(revid)
5391
except errors.NoSuchRevision:
5392
timestamp = sys.maxint # place them at the end
5394
timestamp = revobj.timestamp
5395
timestamps[revid] = timestamp
5396
tags.sort(key=lambda x: timestamps[x[1]])
5850
5397
if not show_ids:
5851
5398
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5852
5399
for index, (tag, revid) in enumerate(tags):
5865
5410
for tag, revspec in tags:
5866
5411
self.outf.write('%-20s %s\n' % (tag, revspec))
5868
def _tags_for_range(self, branch, revision):
5870
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5871
revid1, revid2 = rev1.rev_id, rev2.rev_id
5872
# _get_revision_range will always set revid2 if it's not specified.
5873
# If revid1 is None, it means we want to start from the branch
5874
# origin which is always a valid ancestor. If revid1 == revid2, the
5875
# ancestry check is useless.
5876
if revid1 and revid1 != revid2:
5877
# FIXME: We really want to use the same graph than
5878
# branch.iter_merge_sorted_revisions below, but this is not
5879
# easily available -- vila 2011-09-23
5880
if branch.repository.get_graph().is_ancestor(revid2, revid1):
5881
# We don't want to output anything in this case...
5883
# only show revisions between revid1 and revid2 (inclusive)
5884
tagged_revids = branch.tags.get_reverse_tag_dict()
5886
for r in branch.iter_merge_sorted_revisions(
5887
start_revision_id=revid2, stop_revision_id=revid1,
5888
stop_rule='include'):
5889
revid_tags = tagged_revids.get(r[0], None)
5891
found.extend([(tag, r[0]) for tag in revid_tags])
5895
5414
class cmd_reconfigure(Command):
5896
5415
__doc__ = """Reconfigure the type of a bzr directory.
5910
5429
takes_args = ['location?']
5911
5430
takes_options = [
5912
5431
RegistryOption.from_kwargs(
5915
help='The relation between branch and tree.',
5433
title='Target type',
5434
help='The type to reconfigure the directory to.',
5916
5435
value_switches=True, enum_switch=False,
5917
5436
branch='Reconfigure to be an unbound branch with no working tree.',
5918
5437
tree='Reconfigure to be an unbound branch with a working tree.',
5919
5438
checkout='Reconfigure to be a bound branch with a working tree.',
5920
5439
lightweight_checkout='Reconfigure to be a lightweight'
5921
5440
' checkout (with no local history).',
5923
RegistryOption.from_kwargs(
5925
title='Repository type',
5926
help='Location fo the repository.',
5927
value_switches=True, enum_switch=False,
5928
5441
standalone='Reconfigure to be a standalone branch '
5929
5442
'(i.e. stop using shared repository).',
5930
5443
use_shared='Reconfigure to use a shared repository.',
5932
RegistryOption.from_kwargs(
5934
title='Trees in Repository',
5935
help='Whether new branches in the repository have trees.',
5936
value_switches=True, enum_switch=False,
5937
5444
with_trees='Reconfigure repository to create '
5938
5445
'working trees on branches by default.',
5939
5446
with_no_trees='Reconfigure repository to not create '
5956
def run(self, location=None, bind_to=None, force=False,
5957
tree_type=None, repository_type=None, repository_trees=None,
5958
stacked_on=None, unstacked=None):
5959
directory = controldir.ControlDir.open(location)
5463
def run(self, location=None, target_type=None, bind_to=None, force=False,
5466
directory = bzrdir.BzrDir.open(location)
5960
5467
if stacked_on and unstacked:
5961
raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5468
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5962
5469
elif stacked_on is not None:
5963
5470
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5964
5471
elif unstacked:
5966
5473
# At the moment you can use --stacked-on and a different
5967
5474
# reconfiguration shape at the same time; there seems no good reason
5969
if (tree_type is None and
5970
repository_type is None and
5971
repository_trees is None):
5476
if target_type is None:
5972
5477
if stacked_on or unstacked:
5975
raise errors.BzrCommandError(gettext('No target configuration '
5977
reconfiguration = None
5978
if tree_type == 'branch':
5480
raise errors.BzrCommandError('No target configuration '
5482
elif target_type == 'branch':
5979
5483
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5980
elif tree_type == 'tree':
5484
elif target_type == 'tree':
5981
5485
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5982
elif tree_type == 'checkout':
5486
elif target_type == 'checkout':
5983
5487
reconfiguration = reconfigure.Reconfigure.to_checkout(
5984
5488
directory, bind_to)
5985
elif tree_type == 'lightweight-checkout':
5489
elif target_type == 'lightweight-checkout':
5986
5490
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5987
5491
directory, bind_to)
5989
reconfiguration.apply(force)
5990
reconfiguration = None
5991
if repository_type == 'use-shared':
5492
elif target_type == 'use-shared':
5992
5493
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5993
elif repository_type == 'standalone':
5494
elif target_type == 'standalone':
5994
5495
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5996
reconfiguration.apply(force)
5997
reconfiguration = None
5998
if repository_trees == 'with-trees':
5496
elif target_type == 'with-trees':
5999
5497
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6000
5498
directory, True)
6001
elif repository_trees == 'with-no-trees':
5499
elif target_type == 'with-no-trees':
6002
5500
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6003
5501
directory, False)
6005
reconfiguration.apply(force)
6006
reconfiguration = None
5502
reconfiguration.apply(force)
6009
5505
class cmd_switch(Command):
6197
5693
name = current_view
6200
raise errors.BzrCommandError(gettext(
6201
"Both --delete and a file list specified"))
5696
raise errors.BzrCommandError(
5697
"Both --delete and a file list specified")
6203
raise errors.BzrCommandError(gettext(
6204
"Both --delete and --switch specified"))
5699
raise errors.BzrCommandError(
5700
"Both --delete and --switch specified")
6206
5702
tree.views.set_view_info(None, {})
6207
self.outf.write(gettext("Deleted all views.\n"))
5703
self.outf.write("Deleted all views.\n")
6208
5704
elif name is None:
6209
raise errors.BzrCommandError(gettext("No current view to delete"))
5705
raise errors.BzrCommandError("No current view to delete")
6211
5707
tree.views.delete_view(name)
6212
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5708
self.outf.write("Deleted '%s' view.\n" % name)
6215
raise errors.BzrCommandError(gettext(
6216
"Both --switch and a file list specified"))
5711
raise errors.BzrCommandError(
5712
"Both --switch and a file list specified")
6218
raise errors.BzrCommandError(gettext(
6219
"Both --switch and --all specified"))
5714
raise errors.BzrCommandError(
5715
"Both --switch and --all specified")
6220
5716
elif switch == 'off':
6221
5717
if current_view is None:
6222
raise errors.BzrCommandError(gettext("No current view to disable"))
5718
raise errors.BzrCommandError("No current view to disable")
6223
5719
tree.views.set_view_info(None, view_dict)
6224
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5720
self.outf.write("Disabled '%s' view.\n" % (current_view))
6226
5722
tree.views.set_view_info(switch, view_dict)
6227
5723
view_str = views.view_display_str(tree.views.lookup_view())
6228
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5724
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6231
self.outf.write(gettext('Views defined:\n'))
5727
self.outf.write('Views defined:\n')
6232
5728
for view in sorted(view_dict):
6233
5729
if view == current_view:
6237
5733
view_str = views.view_display_str(view_dict[view])
6238
5734
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
6240
self.outf.write(gettext('No views defined.\n'))
5736
self.outf.write('No views defined.\n')
6241
5737
elif file_list:
6242
5738
if name is None:
6243
5739
# No name given and no current view set
6245
5741
elif name == 'off':
6246
raise errors.BzrCommandError(gettext(
6247
"Cannot change the 'off' pseudo view"))
5742
raise errors.BzrCommandError(
5743
"Cannot change the 'off' pseudo view")
6248
5744
tree.views.set_view(name, sorted(file_list))
6249
5745
view_str = views.view_display_str(tree.views.lookup_view())
6250
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5746
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6252
5748
# list the files
6253
5749
if name is None:
6254
5750
# No name given and no current view set
6255
self.outf.write(gettext('No current view.\n'))
5751
self.outf.write('No current view.\n')
6257
5753
view_str = views.view_display_str(tree.views.lookup_view(name))
6258
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
5754
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6261
5757
class cmd_hooks(Command):
6507
5989
self.outf.write('%s %s\n' % (path, location))
6510
class cmd_export_pot(Command):
6511
__doc__ = """Export command helps and error messages in po format."""
6514
takes_options = [Option('plugin',
6515
help='Export help text from named command '\
6516
'(defaults to all built in commands).',
6519
def run(self, plugin=None):
6520
from bzrlib.export_pot import export_pot
6521
export_pot(self.outf, plugin)
6524
5992
def _register_lazy_builtins():
6525
5993
# register lazy builtins from other modules; called at startup and should
6526
5994
# be only called once.
6527
5995
for (name, aliases, module_name) in [
6528
5996
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6529
('cmd_config', [], 'bzrlib.config'),
6530
5997
('cmd_dpush', [], 'bzrlib.foreign'),
6531
5998
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6532
5999
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6533
6000
('cmd_conflicts', [], 'bzrlib.conflicts'),
6534
('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
6535
('cmd_verify_signatures', [],
6536
'bzrlib.commit_signature_commands'),
6537
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6001
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6539
6003
builtin_command_registry.register_lazy(name, aliases, module_name)