20
20
# TODO: probably should say which arguments are candidates for glob
21
21
# expansion on windows and do that at the command level.
23
# TODO: Help messages for options.
25
# TODO: Define arguments by objects, rather than just using names.
26
# Those objects can specify the expected type of the argument, which
27
# would help with validation and shell completion.
30
# TODO: Help messages for options.
32
# TODO: Define arguments by objects, rather than just using names.
33
# Those objects can specify the expected type of the argument, which
34
# would help with validation and shell completion.
27
42
from bzrlib.trace import mutter, note, log_error, warning
28
43
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
29
44
from bzrlib.branch import find_branch
44
59
if not plugin_cmds.has_key(k_unsquished):
45
60
plugin_cmds[k_unsquished] = cmd
61
mutter('registered plugin command %s', k_unsquished)
47
63
log_error('Two plugins defined the same command: %r' % k)
48
64
log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
459
476
takes_options = ['verbose', 'no-recurse']
461
478
def run(self, file_list, verbose=False, no_recurse=False):
462
from bzrlib.add import smart_add
463
smart_add(file_list, verbose, not no_recurse)
479
from bzrlib.add import smart_add, _PrintAddCallback
480
recurse = not no_recurse
481
smart_add(file_list, verbose, not no_recurse,
482
callback=_PrintAddCallback)
574
594
if os.path.isdir(names_list[-1]):
575
595
# move into existing directory
576
b.move(rel_names[:-1], rel_names[-1])
596
for pair in b.move(rel_names[:-1], rel_names[-1]):
597
print "%s => %s" % pair
578
599
if len(names_list) != 2:
579
600
raise BzrCommandError('to mv multiple files the destination '
580
601
'must be a versioned directory')
581
b.move(rel_names[0], rel_names[1])
602
for pair in b.move(rel_names[0], rel_names[1]):
603
print "%s => %s" % pair
656
679
aliases = ['get', 'clone']
658
681
def run(self, from_location, to_location=None, revision=None):
682
from bzrlib.branch import copy_branch, find_cached_branch
660
from bzrlib.merge import merge
661
from bzrlib.branch import DivergedBranches, \
662
find_cached_branch, Branch
663
685
from shutil import rmtree
664
from meta_store import CachedStore
666
686
cache_root = tempfile.mkdtemp()
670
elif len(revision) > 1:
671
raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
690
elif len(revision) > 1:
691
raise BzrCommandError(
692
'bzr branch --revision takes exactly 1 revision value')
675
694
br_from = find_cached_branch(from_location, cache_root)
676
695
except OSError, e:
697
br_to = Branch(to_location, init=True)
699
br_to.set_root_id(br_from.get_root_id())
702
if revision[0] is None:
703
revno = br_from.revno()
705
revno, rev_id = br_from.get_revision_info(revision[0])
707
br_to.update_revisions(br_from, stop_revision=revno)
708
except bzrlib.errors.NoSuchRevision:
710
msg = "The branch %s has no revision %d." % (from_location,
712
raise BzrCommandError(msg)
714
merge((to_location, -1), (to_location, 0), this_dir=to_location,
715
check_clean=False, ignore_zero=True)
716
from_location = pull_loc(br_from)
717
br_to.controlfile("x-pull", "wb").write(from_location + "\n")
715
copy_branch(br_from, to_location, revision[0])
716
except bzrlib.errors.NoSuchRevision:
718
msg = "The branch %s has no revision %d." % (from_location, revision[0])
719
raise BzrCommandError(msg)
719
721
rmtree(cache_root)
722
def pull_loc(branch):
723
# TODO: Should perhaps just make attribute be 'base' in
724
# RemoteBranch and Branch?
725
if hasattr(branch, "baseurl"):
726
return branch.baseurl
732
724
class cmd_renames(Command):
733
725
"""Show list of renamed files.
1395
1387
class cmd_selftest(Command):
1396
1388
"""Run internal test suite"""
1398
takes_options = ['verbose']
1399
def run(self, verbose=False):
1390
takes_options = ['verbose', 'pattern']
1391
def run(self, verbose=False, pattern=".*"):
1400
1393
from bzrlib.selftest import selftest
1401
return int(not selftest(verbose=verbose))
1394
# we don't want progress meters from the tests to go to the
1395
# real output; and we don't want log messages cluttering up
1397
save_ui = bzrlib.ui.ui_factory
1398
bzrlib.trace.info('running tests...')
1400
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1401
result = selftest(verbose=verbose, pattern=pattern)
1403
bzrlib.trace.info('tests passed')
1405
bzrlib.trace.info('tests failed')
1406
return int(not result)
1408
bzrlib.ui.ui_factory = save_ui
1404
1411
class cmd_version(Command):
1469
class cmd_find_merge_base(Command):
1470
"""Find and print a base revision for merging two branches.
1472
TODO: Options to specify revisions on either side, as if
1473
merging only part of the history.
1475
takes_args = ['branch', 'other']
1478
def run(self, branch, other):
1479
branch1 = find_branch(branch)
1480
branch2 = find_branch(other)
1482
base_revno, base_revid = branch1.common_ancestor(branch2)
1484
if base_revno is None:
1485
raise bzrlib.errors.UnrelatedBranches()
1487
print 'merge base is revision %s' % base_revid
1488
print ' r%-6d in %s' % (base_revno, branch)
1490
other_revno = branch2.revision_id_to_revno(base_revid)
1492
print ' r%-6d in %s' % (other_revno, other)
1462
1496
class cmd_merge(Command):
1463
1497
"""Perform a three-way merge.
1524
1558
def run(self, revision=None, no_backup=False, file_list=None):
1525
1559
from bzrlib.merge import merge
1560
from bzrlib.branch import Branch
1526
1561
if file_list is not None:
1527
1562
if len(file_list) == 0:
1528
1563
raise BzrCommandError("No files specified")
1548
1585
"""Show help on a command or other topic.
1550
1587
For a list of all available commands, say 'bzr help commands'."""
1588
takes_options = ['long']
1551
1589
takes_args = ['topic?']
1552
1590
aliases = ['?']
1554
def run(self, topic=None):
1592
def run(self, topic=None, long=False):
1594
if topic is None and long:
1556
1596
help.help(topic)
1611
1652
from inspect import getdoc
1612
1653
from pprint import pprint
1613
1654
for plugin in bzrlib.plugin.all_plugins:
1614
print plugin.__path__[0]
1655
if hasattr(plugin, '__path__'):
1656
print plugin.__path__[0]
1615
1659
d = getdoc(plugin)
1617
1661
print '\t', d.split('\n')[0]
1912
1958
return cmd_class(cmdopts, cmdargs).status
1915
def _report_exception(summary, quiet=False):
1918
log_error('bzr: ' + summary)
1919
bzrlib.trace.log_exception()
1921
if os.environ.get('BZR_DEBUG'):
1922
traceback.print_exc()
1925
sys.stderr.write('\n')
1926
tb = sys.exc_info()[2]
1927
exinfo = traceback.extract_tb(tb)
1929
sys.stderr.write(' at %s:%d in %s()\n' % exinfo[-1][:3])
1930
sys.stderr.write(' see ~/.bzr.log for debug information\n')
1934
1961
def main(argv):
1936
bzrlib.trace.open_tracefile(argv)
1963
bzrlib.trace.log_startup(argv)
1964
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1941
return run_bzr(argv[1:])
1943
# do this here inside the exception wrappers to catch EPIPE
1946
quiet = isinstance(e, (BzrCommandError))
1947
_report_exception('error: ' + str(e), quiet=quiet)
1950
# some explanation or hints
1953
except AssertionError, e:
1954
msg = 'assertion failed'
1956
msg += ': ' + str(e)
1957
_report_exception(msg)
1959
except KeyboardInterrupt, e:
1960
_report_exception('interrupted', quiet=True)
1962
except Exception, e:
1965
if (isinstance(e, IOError)
1966
and hasattr(e, 'errno')
1967
and e.errno == errno.EPIPE):
1971
msg = str(e).rstrip('\n')
1972
_report_exception(msg, quiet)
1975
bzrlib.trace.close_trace()
1968
return run_bzr(argv[1:])
1970
# do this here inside the exception wrappers to catch EPIPE
1972
except BzrCommandError, e:
1973
# command line syntax error, etc
1977
bzrlib.trace.log_exception()
1979
except AssertionError, e:
1980
bzrlib.trace.log_exception('assertion failed: ' + str(e))
1982
except KeyboardInterrupt, e:
1983
bzrlib.trace.note('interrupted')
1985
except Exception, e:
1987
if (isinstance(e, IOError)
1988
and hasattr(e, 'errno')
1989
and e.errno == errno.EPIPE):
1990
bzrlib.trace.note('broken pipe')
1993
bzrlib.trace.log_exception()
1978
1997
if __name__ == '__main__':