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.
459
466
takes_options = ['verbose', 'no-recurse']
461
468
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)
469
from bzrlib.add import smart_add, _PrintAddCallback
470
smart_add(file_list, verbose, not no_recurse,
471
callback=_PrintAddCallback)
656
665
aliases = ['get', 'clone']
658
667
def run(self, from_location, to_location=None, revision=None):
668
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
671
from shutil import rmtree
664
from meta_store import CachedStore
666
672
cache_root = tempfile.mkdtemp()
670
elif len(revision) > 1:
671
raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
676
elif len(revision) > 1:
677
raise BzrCommandError(
678
'bzr branch --revision takes exactly 1 revision value')
675
680
br_from = find_cached_branch(from_location, cache_root)
676
681
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")
701
copy_branch(br_from, to_location, revision[0])
702
except bzrlib.errors.NoSuchRevision:
704
msg = "The branch %s has no revision %d." % (from_location, revision[0])
705
raise BzrCommandError(msg)
719
707
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
710
class cmd_renames(Command):
733
711
"""Show list of renamed files.
1395
1373
class cmd_selftest(Command):
1396
1374
"""Run internal test suite"""
1398
takes_options = ['verbose']
1399
def run(self, verbose=False):
1376
takes_options = ['verbose', 'pattern']
1377
def run(self, verbose=False, pattern=".*"):
1400
1379
from bzrlib.selftest import selftest
1401
return int(not selftest(verbose=verbose))
1380
# we don't want progress meters from the tests to go to the
1382
save_ui = bzrlib.ui.ui_factory
1384
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1385
return int(not selftest(verbose=verbose, pattern=pattern))
1387
bzrlib.ui.ui_factory = save_ui
1404
1390
class cmd_version(Command):
1448
class cmd_find_merge_base(Command):
1449
"""Find and print a base revision for merging two branches.
1451
TODO: Options to specify revisions on either side, as if
1452
merging only part of the history.
1454
takes_args = ['branch', 'other']
1457
def run(self, branch, other):
1458
branch1 = find_branch(branch)
1459
branch2 = find_branch(other)
1461
base_revno, base_revid = branch1.common_ancestor(branch2)
1463
if base_revno is None:
1464
raise bzrlib.errors.UnrelatedBranches()
1466
print 'merge base is revision %s' % base_revid
1467
print ' r%-6d in %s' % (base_revno, branch)
1469
other_revno = branch2.revision_id_to_revno(base_revid)
1471
print ' r%-6d in %s' % (other_revno, other)
1462
1475
class cmd_merge(Command):
1463
1476
"""Perform a three-way merge.
1548
1561
"""Show help on a command or other topic.
1550
1563
For a list of all available commands, say 'bzr help commands'."""
1564
takes_options = ['long']
1551
1565
takes_args = ['topic?']
1552
1566
aliases = ['?']
1554
def run(self, topic=None):
1568
def run(self, topic=None, long=False):
1570
if topic is None and long:
1556
1572
help.help(topic)
1912
1931
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
1934
def main(argv):
1936
1937
bzrlib.trace.open_tracefile(argv)
1939
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()
1943
return run_bzr(argv[1:])
1945
# do this here inside the exception wrappers to catch EPIPE
1947
except BzrCommandError, e:
1948
# command line syntax error, etc
1952
bzrlib.trace.log_exception()
1954
except AssertionError, e:
1955
bzrlib.trace.log_exception('assertion failed: ' + str(e))
1957
except KeyboardInterrupt, e:
1958
bzrlib.trace.note('interrupted')
1960
except Exception, e:
1962
if (isinstance(e, IOError)
1963
and hasattr(e, 'errno')
1964
and e.errno == errno.EPIPE):
1965
bzrlib.trace.note('broken pipe')
1968
bzrlib.trace.log_exception()
1978
1972
if __name__ == '__main__':