141
148
raise BzrCommandError(msg)
151
def get_merge_type(typestring):
152
"""Attempt to find the merge class/factory associated with a string."""
153
from merge import merge_types
155
return merge_types[typestring][0]
157
templ = '%s%%7s: %%s' % (' '*12)
158
lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
159
type_list = '\n'.join(lines)
160
msg = "No known merge type %s. Supported types are:\n%s" %\
161
(typestring, type_list)
162
raise BzrCommandError(msg)
145
166
def _get_cmd_dict(plugins_override=True):
445
466
takes_options = ['verbose', 'no-recurse']
447
468
def run(self, file_list, verbose=False, no_recurse=False):
448
from bzrlib.add import smart_add
449
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)
642
665
aliases = ['get', 'clone']
644
667
def run(self, from_location, to_location=None, revision=None):
668
from bzrlib.branch import copy_branch, find_cached_branch
646
from bzrlib.merge import merge
647
from bzrlib.branch import DivergedBranches, \
648
find_cached_branch, Branch
649
671
from shutil import rmtree
650
from meta_store import CachedStore
652
672
cache_root = tempfile.mkdtemp()
656
elif len(revision) > 1:
657
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')
661
680
br_from = find_cached_branch(from_location, cache_root)
662
681
except OSError, e:
683
br_to = Branch(to_location, init=True)
685
br_to.set_root_id(br_from.get_root_id())
688
if revision[0] is None:
689
revno = br_from.revno()
691
revno, rev_id = br_from.get_revision_info(revision[0])
693
br_to.update_revisions(br_from, stop_revision=revno)
694
except bzrlib.errors.NoSuchRevision:
696
msg = "The branch %s has no revision %d." % (from_location,
698
raise BzrCommandError(msg)
700
merge((to_location, -1), (to_location, 0), this_dir=to_location,
701
check_clean=False, ignore_zero=True)
702
from_location = pull_loc(br_from)
703
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)
705
707
rmtree(cache_root)
708
def pull_loc(branch):
709
# TODO: Should perhaps just make attribute be 'base' in
710
# RemoteBranch and Branch?
711
if hasattr(branch, "baseurl"):
712
return branch.baseurl
718
710
class cmd_renames(Command):
719
711
"""Show list of renamed files.
872
867
b = find_branch('.')
874
# TODO: Make show_diff support taking 2 arguments
876
869
if revision is not None:
877
if len(revision) != 1:
878
raise BzrCommandError('bzr diff --revision takes exactly one revision identifier')
879
base_rev = revision[0]
881
show_diff(b, base_rev, specific_files=file_list,
882
external_diff_options=diff_options)
870
if len(revision) == 1:
871
show_diff(b, revision[0], specific_files=file_list,
872
external_diff_options=diff_options)
873
elif len(revision) == 2:
874
show_diff(b, revision[0], specific_files=file_list,
875
external_diff_options=diff_options,
876
revision2=revision[1])
878
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
880
show_diff(b, None, specific_files=file_list,
881
external_diff_options=diff_options)
969
967
takes_args = ['filename?']
970
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision','long', 'message']
968
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
969
'long', 'message', 'short',]
972
971
def run(self, filename=None, timezone='original',
1359
1359
takes_options = ['email']
1361
1361
def run(self, email=False):
1363
b = bzrlib.branch.find_branch('.')
1363
print bzrlib.osutils.user_email()
1368
print bzrlib.osutils.user_email(b)
1365
print bzrlib.osutils.username()
1370
print bzrlib.osutils.username(b)
1368
1373
class cmd_selftest(Command):
1369
1374
"""Run internal test suite"""
1371
takes_options = ['verbose']
1372
def run(self, verbose=False):
1376
takes_options = ['verbose', 'pattern']
1377
def run(self, verbose=False, pattern=".*"):
1373
1379
from bzrlib.selftest import selftest
1374
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
1377
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)
1435
1475
class cmd_merge(Command):
1436
"""Perform a three-way merge of trees.
1438
The SPEC parameters are working tree or revision specifiers. Working trees
1439
are specified using standard paths or urls. No component of a directory
1440
path may begin with '@'.
1442
Working tree examples: '.', '..', 'foo@', but NOT 'foo/@bar'
1444
Revisions are specified using a dirname/@revno pair, where dirname is the
1445
branch directory and revno is the revision within that branch. If no revno
1446
is specified, the latest revision is used.
1448
Revision examples: './@127', 'foo/@', '../@1'
1450
The OTHER_SPEC parameter is required. If the BASE_SPEC parameter is
1451
not supplied, the common ancestor of OTHER_SPEC the current branch is used
1476
"""Perform a three-way merge.
1478
The branch is the branch you will merge from. By default, it will merge
1479
the latest revision. If you specify a revision, that revision will be
1480
merged. If you specify two revisions, the first will be used as a BASE,
1481
and the second one as OTHER. Revision numbers are always relative to the
1486
To merge the latest revision from bzr.dev
1487
bzr merge ../bzr.dev
1489
To merge changes up to and including revision 82 from bzr.dev
1490
bzr merge -r 82 ../bzr.dev
1492
To merge the changes introduced by 82, without previous changes:
1493
bzr merge -r 81..82 ../bzr.dev
1454
1495
merge refuses to run if there are any uncommitted changes, unless
1455
1496
--force is given.
1457
takes_args = ['other_spec', 'base_spec?']
1458
takes_options = ['force', 'merge-type']
1498
takes_args = ['branch?']
1499
takes_options = ['revision', 'force', 'merge-type']
1460
def run(self, other_spec, base_spec=None, force=False, merge_type=None):
1501
def run(self, branch='.', revision=None, force=False,
1461
1503
from bzrlib.merge import merge
1462
1504
from bzrlib.merge_core import ApplyMerge3
1463
1505
if merge_type is None:
1464
1506
merge_type = ApplyMerge3
1465
merge(parse_spec(other_spec), parse_spec(base_spec),
1466
check_clean=(not force), merge_type=merge_type)
1508
if revision is None or len(revision) < 1:
1510
other = (branch, -1)
1512
if len(revision) == 1:
1513
other = (branch, revision[0])
1516
assert len(revision) == 2
1517
if None in revision:
1518
raise BzrCommandError(
1519
"Merge doesn't permit that revision specifier.")
1520
base = (branch, revision[0])
1521
other = (branch, revision[1])
1523
merge(other, base, check_clean=(not force), merge_type=merge_type)
1469
1526
class cmd_revert(Command):
1504
1561
"""Show help on a command or other topic.
1506
1563
For a list of all available commands, say 'bzr help commands'."""
1564
takes_options = ['long']
1507
1565
takes_args = ['topic?']
1508
1566
aliases = ['?']
1510
def run(self, topic=None):
1568
def run(self, topic=None, long=False):
1570
if topic is None and long:
1512
1572
help.help(topic)
1575
class cmd_shell_complete(Command):
1576
"""Show appropriate completions for context.
1578
For a list of all available commands, say 'bzr shell-complete'."""
1579
takes_args = ['context?']
1583
def run(self, context=None):
1584
import shellcomplete
1585
shellcomplete.shellcomplete(context)
1588
class cmd_missing(Command):
1589
"""What is missing in this branch relative to other branch.
1591
takes_args = ['remote?']
1592
aliases = ['mis', 'miss']
1593
# We don't have to add quiet to the list, because
1594
# unknown options are parsed as booleans
1595
takes_options = ['verbose', 'quiet']
1597
def run(self, remote=None, verbose=False, quiet=False):
1598
from bzrlib.branch import find_branch, DivergedBranches
1599
from bzrlib.errors import BzrCommandError
1600
from bzrlib.missing import get_parent, show_missing
1602
if verbose and quiet:
1603
raise BzrCommandError('Cannot pass both quiet and verbose')
1605
b = find_branch('.')
1606
parent = get_parent(b)
1609
raise BzrCommandError("No missing location known or specified.")
1612
print "Using last location: %s" % parent
1614
elif parent is None:
1615
# We only update x-pull if it did not exist, missing should not change the parent
1616
b.controlfile('x-pull', 'wb').write(remote + '\n')
1617
br_remote = find_branch(remote)
1619
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1517
1623
class cmd_plugins(Command):
1822
1931
return cmd_class(cmdopts, cmdargs).status
1825
def _report_exception(summary, quiet=False):
1828
log_error('bzr: ' + summary)
1829
bzrlib.trace.log_exception()
1831
if os.environ.get('BZR_DEBUG'):
1832
traceback.print_exc()
1835
sys.stderr.write('\n')
1836
tb = sys.exc_info()[2]
1837
exinfo = traceback.extract_tb(tb)
1839
sys.stderr.write(' at %s:%d in %s()\n' % exinfo[-1][:3])
1840
sys.stderr.write(' see ~/.bzr.log for debug information\n')
1844
1934
def main(argv):
1846
1937
bzrlib.trace.open_tracefile(argv)
1939
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1851
return run_bzr(argv[1:])
1853
# do this here inside the exception wrappers to catch EPIPE
1856
quiet = isinstance(e, (BzrCommandError))
1857
_report_exception('error: ' + str(e), quiet=quiet)
1860
# some explanation or hints
1863
except AssertionError, e:
1864
msg = 'assertion failed'
1866
msg += ': ' + str(e)
1867
_report_exception(msg)
1869
except KeyboardInterrupt, e:
1870
_report_exception('interrupted', quiet=True)
1872
except Exception, e:
1875
if (isinstance(e, IOError)
1876
and hasattr(e, 'errno')
1877
and e.errno == errno.EPIPE):
1881
msg = str(e).rstrip('\n')
1882
_report_exception(msg, quiet)
1885
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()
1888
1972
if __name__ == '__main__':