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.
42
27
from bzrlib.trace import mutter, note, log_error, warning
43
28
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
44
29
from bzrlib.branch import find_branch
474
459
takes_options = ['verbose', 'no-recurse']
476
461
def run(self, file_list, verbose=False, no_recurse=False):
477
from bzrlib.add import smart_add, _PrintAddCallback
478
smart_add(file_list, verbose, not no_recurse,
479
callback=_PrintAddCallback)
462
from bzrlib.add import smart_add
463
smart_add(file_list, verbose, not no_recurse)
673
656
aliases = ['get', 'clone']
675
658
def run(self, from_location, to_location=None, revision=None):
676
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
679
663
from shutil import rmtree
664
from meta_store import CachedStore
680
666
cache_root = tempfile.mkdtemp()
670
elif len(revision) > 1:
671
raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
684
elif len(revision) > 1:
685
raise BzrCommandError(
686
'bzr branch --revision takes exactly 1 revision value')
688
675
br_from = find_cached_branch(from_location, cache_root)
689
676
except OSError, e:
709
copy_branch(br_from, to_location, revision[0])
710
except bzrlib.errors.NoSuchRevision:
712
msg = "The branch %s has no revision %d." % (from_location, revision[0])
713
raise BzrCommandError(msg)
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
719
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
718
732
class cmd_renames(Command):
719
733
"""Show list of renamed files.
1381
1395
class cmd_selftest(Command):
1382
1396
"""Run internal test suite"""
1384
takes_options = ['verbose', 'pattern']
1385
def run(self, verbose=False, pattern=".*"):
1398
takes_options = ['verbose']
1399
def run(self, verbose=False):
1387
1400
from bzrlib.selftest import selftest
1388
# we don't want progress meters from the tests to go to the
1389
# real output; and we don't want log messages cluttering up
1391
save_ui = bzrlib.ui.ui_factory
1392
bzrlib.trace.info('running tests...')
1393
bzrlib.trace.disable_default_logging()
1395
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1396
result = selftest(verbose=verbose, pattern=pattern)
1398
bzrlib.trace.info('tests passed')
1400
bzrlib.trace.info('tests failed')
1401
return int(not result)
1403
bzrlib.trace.enable_default_logging()
1404
bzrlib.ui.ui_factory = save_ui
1401
return int(not selftest(verbose=verbose))
1407
1404
class cmd_version(Command):
1465
class cmd_find_merge_base(Command):
1466
"""Find and print a base revision for merging two branches.
1468
TODO: Options to specify revisions on either side, as if
1469
merging only part of the history.
1471
takes_args = ['branch', 'other']
1474
def run(self, branch, other):
1475
branch1 = find_branch(branch)
1476
branch2 = find_branch(other)
1478
base_revno, base_revid = branch1.common_ancestor(branch2)
1480
if base_revno is None:
1481
raise bzrlib.errors.UnrelatedBranches()
1483
print 'merge base is revision %s' % base_revid
1484
print ' r%-6d in %s' % (base_revno, branch)
1486
other_revno = branch2.revision_id_to_revno(base_revid)
1488
print ' r%-6d in %s' % (other_revno, other)
1492
1462
class cmd_merge(Command):
1493
1463
"""Perform a three-way merge.
1554
1524
def run(self, revision=None, no_backup=False, file_list=None):
1555
1525
from bzrlib.merge import merge
1556
from bzrlib.branch import Branch
1557
1526
if file_list is not None:
1558
1527
if len(file_list) == 0:
1559
1528
raise BzrCommandError("No files specified")
1581
1548
"""Show help on a command or other topic.
1583
1550
For a list of all available commands, say 'bzr help commands'."""
1584
takes_options = ['long']
1585
1551
takes_args = ['topic?']
1586
1552
aliases = ['?']
1588
def run(self, topic=None, long=False):
1554
def run(self, topic=None):
1590
if topic is None and long:
1592
1556
help.help(topic)
1595
class cmd_shell_complete(Command):
1596
"""Show appropriate completions for context.
1598
For a list of all available commands, say 'bzr shell-complete'."""
1599
takes_args = ['context?']
1603
def run(self, context=None):
1604
import shellcomplete
1605
shellcomplete.shellcomplete(context)
1608
1561
class cmd_missing(Command):
1951
1901
return cmd_class(cmdopts, cmdargs).status
1904
def _report_exception(summary, quiet=False):
1907
log_error('bzr: ' + summary)
1908
bzrlib.trace.log_exception()
1910
if os.environ.get('BZR_DEBUG'):
1911
traceback.print_exc()
1914
sys.stderr.write('\n')
1915
tb = sys.exc_info()[2]
1916
exinfo = traceback.extract_tb(tb)
1918
sys.stderr.write(' at %s:%d in %s()\n' % exinfo[-1][:3])
1919
sys.stderr.write(' see ~/.bzr.log for debug information\n')
1954
1923
def main(argv):
1956
bzrlib.trace.log_startup(argv)
1957
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1925
bzrlib.trace.open_tracefile(argv)
1961
return run_bzr(argv[1:])
1963
# do this here inside the exception wrappers to catch EPIPE
1965
except BzrCommandError, e:
1966
# command line syntax error, etc
1970
bzrlib.trace.log_exception()
1972
except AssertionError, e:
1973
bzrlib.trace.log_exception('assertion failed: ' + str(e))
1975
except KeyboardInterrupt, e:
1976
bzrlib.trace.note('interrupted')
1978
except Exception, e:
1980
if (isinstance(e, IOError)
1981
and hasattr(e, 'errno')
1982
and e.errno == errno.EPIPE):
1983
bzrlib.trace.note('broken pipe')
1986
bzrlib.trace.log_exception()
1930
return run_bzr(argv[1:])
1932
# do this here inside the exception wrappers to catch EPIPE
1935
quiet = isinstance(e, (BzrCommandError))
1936
_report_exception('error: ' + str(e), quiet=quiet)
1939
# some explanation or hints
1942
except AssertionError, e:
1943
msg = 'assertion failed'
1945
msg += ': ' + str(e)
1946
_report_exception(msg)
1948
except KeyboardInterrupt, e:
1949
_report_exception('interrupted', quiet=True)
1951
except Exception, e:
1954
if (isinstance(e, IOError)
1955
and hasattr(e, 'errno')
1956
and e.errno == errno.EPIPE):
1960
msg = str(e).rstrip('\n')
1961
_report_exception(msg, quiet)
1964
bzrlib.trace.close_trace()
1990
1967
if __name__ == '__main__':