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.
27
35
from bzrlib.trace import mutter, note, log_error, warning
28
36
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
29
37
from bzrlib.branch import find_branch
1393
1406
takes_options = ['verbose']
1394
1407
def run(self, verbose=False):
1395
1409
from bzrlib.selftest import selftest
1396
return int(not selftest(verbose=verbose))
1411
# we don't want progress meters from the tests to go to the
1412
# real output; and we don't want log messages cluttering up
1415
save_ui = bzrlib.ui.ui_factory
1416
bzrlib.trace.info('running tests...')
1417
bzrlib.trace.disable_default_logging()
1419
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1420
result = selftest(verbose=verbose)
1422
bzrlib.trace.info('tests passed')
1424
bzrlib.trace.info('tests failed')
1425
return int(not result)
1427
bzrlib.trace.enable_default_logging()
1428
bzrlib.ui.ui_factory = save_ui
1399
1431
class cmd_version(Command):
1489
class cmd_find_merge_base(Command):
1490
"""Find and print a base revision for merging two branches.
1492
TODO: Options to specify revisions on either side, as if
1493
merging only part of the history.
1495
takes_args = ['branch', 'other']
1498
def run(self, branch, other):
1499
branch1 = find_branch(branch)
1500
branch2 = find_branch(other)
1502
base_revno, base_revid = branch1.common_ancestor(branch2)
1504
if base_revno is None:
1505
raise bzrlib.errors.UnrelatedBranches()
1507
print 'merge base is revision %s' % base_revid
1508
print ' r%-6d in %s' % (base_revno, branch)
1510
other_revno = branch2.revision_id_to_revno(base_revid)
1512
print ' r%-6d in %s' % (other_revno, other)
1457
1516
class cmd_merge(Command):
1458
"""Perform a three-way merge of trees.
1460
The SPEC parameters are working tree or revision specifiers. Working trees
1461
are specified using standard paths or urls. No component of a directory
1462
path may begin with '@'.
1464
Working tree examples: '.', '..', 'foo@', but NOT 'foo/@bar'
1466
Revisions are specified using a dirname/@revno pair, where dirname is the
1467
branch directory and revno is the revision within that branch. If no revno
1468
is specified, the latest revision is used.
1470
Revision examples: './@127', 'foo/@', '../@1'
1472
The OTHER_SPEC parameter is required. If the BASE_SPEC parameter is
1473
not supplied, the common ancestor of OTHER_SPEC the current branch is used
1517
"""Perform a three-way merge.
1519
The branch is the branch you will merge from. By default, it will merge
1520
the latest revision. If you specify a revision, that revision will be
1521
merged. If you specify two revisions, the first will be used as a BASE,
1522
and the second one as OTHER. Revision numbers are always relative to the
1527
To merge the latest revision from bzr.dev
1528
bzr merge ../bzr.dev
1530
To merge changes up to and including revision 82 from bzr.dev
1531
bzr merge -r 82 ../bzr.dev
1533
To merge the changes introduced by 82, without previous changes:
1534
bzr merge -r 81..82 ../bzr.dev
1476
1536
merge refuses to run if there are any uncommitted changes, unless
1477
1537
--force is given.
1479
takes_args = ['other_spec', 'base_spec?']
1480
takes_options = ['force', 'merge-type']
1539
takes_args = ['branch?']
1540
takes_options = ['revision', 'force', 'merge-type']
1482
def run(self, other_spec, base_spec=None, force=False, merge_type=None):
1542
def run(self, branch='.', revision=None, force=False,
1483
1544
from bzrlib.merge import merge
1484
1545
from bzrlib.merge_core import ApplyMerge3
1485
1546
if merge_type is None:
1486
1547
merge_type = ApplyMerge3
1487
merge(parse_spec(other_spec), parse_spec(base_spec),
1488
check_clean=(not force), merge_type=merge_type)
1549
if revision is None or len(revision) < 1:
1551
other = (branch, -1)
1553
if len(revision) == 1:
1554
other = (branch, revision[0])
1557
assert len(revision) == 2
1558
if None in revision:
1559
raise BzrCommandError(
1560
"Merge doesn't permit that revision specifier.")
1561
base = (branch, revision[0])
1562
other = (branch, revision[1])
1564
merge(other, base, check_clean=(not force), merge_type=merge_type)
1491
1567
class cmd_revert(Command):
1526
1602
"""Show help on a command or other topic.
1528
1604
For a list of all available commands, say 'bzr help commands'."""
1605
takes_options = ['long']
1529
1606
takes_args = ['topic?']
1530
1607
aliases = ['?']
1532
def run(self, topic=None):
1609
def run(self, topic=None, long=False):
1611
if topic is None and long:
1534
1613
help.help(topic)
1616
class cmd_shell_complete(Command):
1617
"""Show appropriate completions for context.
1619
For a list of all available commands, say 'bzr shell-complete'."""
1620
takes_args = ['context?']
1624
def run(self, context=None):
1625
import shellcomplete
1626
shellcomplete.shellcomplete(context)
1539
1629
class cmd_missing(Command):
1879
1971
return cmd_class(cmdopts, cmdargs).status
1882
def _report_exception(summary, quiet=False):
1885
log_error('bzr: ' + summary)
1886
bzrlib.trace.log_exception()
1888
if os.environ.get('BZR_DEBUG'):
1889
traceback.print_exc()
1892
sys.stderr.write('\n')
1893
tb = sys.exc_info()[2]
1894
exinfo = traceback.extract_tb(tb)
1896
sys.stderr.write(' at %s:%d in %s()\n' % exinfo[-1][:3])
1897
sys.stderr.write(' see ~/.bzr.log for debug information\n')
1901
1974
def main(argv):
1903
bzrlib.trace.open_tracefile(argv)
1977
bzrlib.trace.log_startup(argv)
1979
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1908
return run_bzr(argv[1:])
1910
# do this here inside the exception wrappers to catch EPIPE
1913
quiet = isinstance(e, (BzrCommandError))
1914
_report_exception('error: ' + str(e), quiet=quiet)
1917
# some explanation or hints
1920
except AssertionError, e:
1921
msg = 'assertion failed'
1923
msg += ': ' + str(e)
1924
_report_exception(msg)
1926
except KeyboardInterrupt, e:
1927
_report_exception('interrupted', quiet=True)
1929
except Exception, e:
1932
if (isinstance(e, IOError)
1933
and hasattr(e, 'errno')
1934
and e.errno == errno.EPIPE):
1938
msg = str(e).rstrip('\n')
1939
_report_exception(msg, quiet)
1942
bzrlib.trace.close_trace()
1983
return run_bzr(argv[1:])
1985
# do this here inside the exception wrappers to catch EPIPE
1987
except BzrCommandError, e:
1988
# command line syntax error, etc
1992
bzrlib.trace.log_exception()
1994
except AssertionError, e:
1995
bzrlib.trace.log_exception('assertion failed: ' + str(e))
1997
except KeyboardInterrupt, e:
1998
bzrlib.trace.note('interrupted')
2000
except Exception, e:
2002
if (isinstance(e, IOError)
2003
and hasattr(e, 'errno')
2004
and e.errno == errno.EPIPE):
2005
bzrlib.trace.note('broken pipe')
2008
bzrlib.trace.log_exception()
1945
2012
if __name__ == '__main__':