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
459
474
takes_options = ['verbose', 'no-recurse']
461
476
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)
477
from bzrlib.add import smart_add, _PrintAddCallback
478
smart_add(file_list, verbose, not no_recurse,
479
callback=_PrintAddCallback)
656
673
aliases = ['get', 'clone']
658
675
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
663
679
from shutil import rmtree
664
from meta_store import CachedStore
666
680
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')
675
688
br_from = find_cached_branch(from_location, cache_root)
676
689
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")
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)
719
715
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
718
class cmd_renames(Command):
733
719
"""Show list of renamed files.
1381
1367
takes_options = ['email']
1383
1369
def run(self, email=False):
1371
b = bzrlib.branch.find_branch('.')
1385
print bzrlib.osutils.user_email()
1376
print bzrlib.osutils.user_email(b)
1387
print bzrlib.osutils.username()
1378
print bzrlib.osutils.username(b)
1390
1381
class cmd_selftest(Command):
1391
1382
"""Run internal test suite"""
1393
takes_options = ['verbose']
1394
def run(self, verbose=False):
1384
takes_options = ['verbose', 'pattern']
1385
def run(self, verbose=False, pattern=".*"):
1395
1387
from bzrlib.selftest import selftest
1396
return int(not selftest(verbose=verbose))
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
1399
1407
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)
1457
1492
class cmd_merge(Command):
1458
1493
"""Perform a three-way merge.
1546
1581
"""Show help on a command or other topic.
1548
1583
For a list of all available commands, say 'bzr help commands'."""
1584
takes_options = ['long']
1549
1585
takes_args = ['topic?']
1550
1586
aliases = ['?']
1552
def run(self, topic=None):
1588
def run(self, topic=None, long=False):
1590
if topic is None and long:
1554
1592
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)
1559
1608
class cmd_missing(Command):
1899
1951
return cmd_class(cmdopts, cmdargs).status
1902
def _report_exception(summary, quiet=False):
1905
log_error('bzr: ' + summary)
1906
bzrlib.trace.log_exception()
1908
if os.environ.get('BZR_DEBUG'):
1909
traceback.print_exc()
1912
sys.stderr.write('\n')
1913
tb = sys.exc_info()[2]
1914
exinfo = traceback.extract_tb(tb)
1916
sys.stderr.write(' at %s:%d in %s()\n' % exinfo[-1][:3])
1917
sys.stderr.write(' see ~/.bzr.log for debug information\n')
1921
1954
def main(argv):
1923
bzrlib.trace.open_tracefile(argv)
1956
bzrlib.trace.log_startup(argv)
1957
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1928
return run_bzr(argv[1:])
1930
# do this here inside the exception wrappers to catch EPIPE
1933
quiet = isinstance(e, (BzrCommandError))
1934
_report_exception('error: ' + str(e), quiet=quiet)
1937
# some explanation or hints
1940
except AssertionError, e:
1941
msg = 'assertion failed'
1943
msg += ': ' + str(e)
1944
_report_exception(msg)
1946
except KeyboardInterrupt, e:
1947
_report_exception('interrupted', quiet=True)
1949
except Exception, e:
1952
if (isinstance(e, IOError)
1953
and hasattr(e, 'errno')
1954
and e.errno == errno.EPIPE):
1958
msg = str(e).rstrip('\n')
1959
_report_exception(msg, quiet)
1962
bzrlib.trace.close_trace()
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()
1965
1990
if __name__ == '__main__':