125
def get_merge_type(typestring):
126
"""Attempt to find the merge class/factory associated with a string."""
127
from merge import merge_types
129
return merge_types[typestring][0]
131
templ = '%s%%7s: %%s' % (' '*12)
132
lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
133
type_list = '\n'.join(lines)
134
msg = "No known merge type %s. Supported types are:\n%s" %\
135
(typestring, type_list)
136
raise BzrCommandError(msg)
140
126
def _get_cmd_dict(plugins_override=True):
214
200
assert isinstance(arguments, dict)
215
201
cmdargs = options.copy()
216
202
cmdargs.update(arguments)
217
if self.__doc__ == Command.__doc__:
218
from warnings import warn
219
warn("No help message set for %r" % self)
203
assert self.__doc__ != Command.__doc__, \
204
("No help message set for %r" % self)
220
205
self.status = self.run(**cmdargs)
221
if self.status is None:
426
409
whether already versioned or not, are searched for files or
427
410
subdirectories that are neither versioned or ignored, and these
428
411
are added. This search proceeds recursively into versioned
429
directories. If no names are given '.' is assumed.
431
Therefore simply saying 'bzr add' will version all files that
414
Therefore simply saying 'bzr add .' will version all files that
432
415
are currently unknown.
434
417
TODO: Perhaps adding a file whose directly is not versioned should
435
418
recursively add that parent, rather than giving an error?
437
takes_args = ['file*']
420
takes_args = ['file+']
438
421
takes_options = ['verbose', 'no-recurse']
440
423
def run(self, file_list, verbose=False, no_recurse=False):
1274
class cmd_scan_cache(Command):
1257
class cmd_update_hashes(Command):
1277
1260
from bzrlib.hashcache import HashCache
1280
1262
c = HashCache('.')
1264
for name in c._cache:
1284
print '%6d stats' % c.stat_count
1285
print '%6d in hashcache' % len(c._cache)
1286
print '%6d files removed from cache' % c.removed_count
1287
print '%6d hashes updated' % c.update_count
1288
print '%6d files changed too recently to cache' % c.danger_count
1295
1271
class cmd_upgrade(Command):
1320
1296
class cmd_selftest(Command):
1321
1297
"""Run internal test suite"""
1323
takes_options = ['verbose']
1324
def run(self, verbose=False):
1325
1300
from bzrlib.selftest import selftest
1326
return int(not selftest(verbose=verbose))
1301
return int(not selftest())
1329
1304
class cmd_version(Command):
1407
1382
--force is given.
1409
1384
takes_args = ['other_spec', 'base_spec?']
1410
takes_options = ['force', 'merge-type']
1385
takes_options = ['force']
1412
def run(self, other_spec, base_spec=None, force=False, merge_type=None):
1387
def run(self, other_spec, base_spec=None, force=False):
1413
1388
from bzrlib.merge import merge
1414
from bzrlib.merge_core import ApplyMerge3
1415
if merge_type is None:
1416
merge_type = ApplyMerge3
1417
1389
merge(parse_spec(other_spec), parse_spec(base_spec),
1418
check_clean=(not force), merge_type=merge_type)
1390
check_clean=(not force))
1421
1394
class cmd_revert(Command):
1395
"""Restore selected files from a previous revision.
1397
takes_args = ['file+']
1398
def run(self, file_list):
1399
from bzrlib.branch import find_branch
1404
b = find_branch(file_list[0])
1406
b.revert([b.relpath(f) for f in file_list])
1409
class cmd_merge_revert(Command):
1422
1410
"""Reverse all changes since the last commit.
1424
Only versioned files are affected. Specify filenames to revert only
1425
those files. By default, any files that are changed will be backed up
1426
first. Backup files have a '~' appended to their name.
1412
Only versioned files are affected.
1414
TODO: Store backups of any files that will be reverted, so
1415
that the revert can be undone.
1428
takes_options = ['revision', 'no-backup']
1429
takes_args = ['file*']
1430
aliases = ['merge-revert']
1417
takes_options = ['revision']
1432
def run(self, revision=None, no_backup=False, file_list=None):
1419
def run(self, revision=None):
1433
1420
from bzrlib.merge import merge
1434
if file_list is not None:
1435
if len(file_list) == 0:
1436
raise BzrCommandError("No files specified")
1437
1421
if revision is None:
1438
1422
revision = [-1]
1439
1423
elif len(revision) != 1:
1440
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1424
raise BzrCommandError('bzr merge-revert --revision takes exactly 1 argument')
1441
1425
merge(('.', revision[0]), parse_spec('.'),
1442
1426
check_clean=False,
1444
backup_files=not no_backup,
1445
file_list=file_list)
1448
1430
class cmd_assert_fail(Command):
1684
1664
This is also a non-master option.
1685
1665
--help Run help and exit, also a non-master option (I think that should stay, though)
1687
>>> argv, opts = _parse_master_args(['--test'])
1667
>>> argv, opts = _parse_master_args(['bzr', '--test'])
1688
1668
Traceback (most recent call last):
1690
1670
BzrCommandError: Invalid master option: 'test'
1691
>>> argv, opts = _parse_master_args(['--version', 'command'])
1671
>>> argv, opts = _parse_master_args(['bzr', '--version', 'command'])
1694
1674
>>> print opts['version']
1696
>>> argv, opts = _parse_master_args(['--profile', 'command', '--more-options'])
1676
>>> argv, opts = _parse_master_args(['bzr', '--profile', 'command', '--more-options'])
1698
1678
['command', '--more-options']
1699
1679
>>> print opts['profile']
1701
>>> argv, opts = _parse_master_args(['--no-plugins', 'command'])
1681
>>> argv, opts = _parse_master_args(['bzr', '--no-plugins', 'command'])
1704
1684
>>> print opts['no-plugins']
1706
1686
>>> print opts['profile']
1708
>>> argv, opts = _parse_master_args(['command', '--profile'])
1688
>>> argv, opts = _parse_master_args(['bzr', 'command', '--profile'])
1710
1690
['command', '--profile']
1711
1691
>>> print opts['profile']
1738
1722
This is similar to main(), but without all the trappings for
1739
1723
logging and error handling.
1742
The command-line arguments, without the program name.
1744
Returns a command status or raises an exception.
1746
1725
argv = [a.decode(bzrlib.user_encoding) for a in argv]
1748
# some options like --builtin and --no-plugins have special effects
1749
argv, master_opts = _parse_master_args(argv)
1750
if not master_opts['no-plugins']:
1751
from bzrlib.plugin import load_plugins
1754
args, opts = parse_args(argv)
1756
if master_opts.get('help') or 'help' in opts:
1757
from bzrlib.help import help
1764
if 'version' in opts:
1768
if args and args[0] == 'builtin':
1769
include_plugins=False
1728
# some options like --builtin and --no-plugins have special effects
1729
argv, master_opts = _parse_master_args(argv)
1730
if not master_opts['no-plugins']:
1731
from bzrlib.plugin import load_plugins
1734
args, opts = parse_args(argv)
1736
if master_opts['help']:
1737
from bzrlib.help import help
1745
from bzrlib.help import help
1751
elif 'version' in opts:
1754
elif args and args[0] == 'builtin':
1755
include_plugins=False
1773
1757
cmd = str(args.pop(0))
1774
1758
except IndexError:
1775
print >>sys.stderr, "please try 'bzr help' for help"
1778
1764
plugins_override = not (master_opts['builtin'])
1779
1765
canonical_cmd, cmd_class = get_cmd_class(cmd, plugins_override=plugins_override)