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):
872
896
b = find_branch('.')
874
# TODO: Make show_diff support taking 2 arguments
876
898
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)
899
if len(revision) == 1:
900
show_diff(b, revision[0], specific_files=file_list,
901
external_diff_options=diff_options)
902
elif len(revision) == 2:
903
show_diff(b, revision[0], specific_files=file_list,
904
external_diff_options=diff_options,
905
revision2=revision[1])
907
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
909
show_diff(b, None, specific_files=file_list,
910
external_diff_options=diff_options)
969
996
takes_args = ['filename?']
970
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision','long', 'message']
997
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
998
'long', 'message', 'short',]
972
1000
def run(self, filename=None, timezone='original',
1359
1388
takes_options = ['email']
1361
1390
def run(self, email=False):
1392
b = bzrlib.branch.find_branch('.')
1363
print bzrlib.osutils.user_email()
1397
print bzrlib.osutils.user_email(b)
1365
print bzrlib.osutils.username()
1399
print bzrlib.osutils.username(b)
1368
1402
class cmd_selftest(Command):
1369
1403
"""Run internal test suite"""
1371
takes_options = ['verbose']
1372
def run(self, verbose=False):
1405
takes_options = ['verbose', 'pattern']
1406
def run(self, verbose=False, pattern=".*"):
1373
1407
from bzrlib.selftest import selftest
1374
return int(not selftest(verbose=verbose))
1408
return int(not selftest(verbose=verbose, pattern=pattern))
1377
1411
class cmd_version(Command):
1435
1469
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
1470
"""Perform a three-way merge.
1472
The branch is the branch you will merge from. By default, it will merge
1473
the latest revision. If you specify a revision, that revision will be
1474
merged. If you specify two revisions, the first will be used as a BASE,
1475
and the second one as OTHER. Revision numbers are always relative to the
1480
To merge the latest revision from bzr.dev
1481
bzr merge ../bzr.dev
1483
To merge changes up to and including revision 82 from bzr.dev
1484
bzr merge -r 82 ../bzr.dev
1486
To merge the changes introduced by 82, without previous changes:
1487
bzr merge -r 81..82 ../bzr.dev
1454
1489
merge refuses to run if there are any uncommitted changes, unless
1455
1490
--force is given.
1457
takes_args = ['other_spec', 'base_spec?']
1458
takes_options = ['force', 'merge-type']
1492
takes_args = ['branch?']
1493
takes_options = ['revision', 'force', 'merge-type']
1460
def run(self, other_spec, base_spec=None, force=False, merge_type=None):
1495
def run(self, branch='.', revision=None, force=False,
1461
1497
from bzrlib.merge import merge
1462
1498
from bzrlib.merge_core import ApplyMerge3
1463
1499
if merge_type is None:
1464
1500
merge_type = ApplyMerge3
1465
merge(parse_spec(other_spec), parse_spec(base_spec),
1466
check_clean=(not force), merge_type=merge_type)
1502
if revision is None or len(revision) < 1:
1504
other = (branch, -1)
1506
if len(revision) == 1:
1507
other = (branch, revision[0])
1510
assert len(revision) == 2
1511
if None in revision:
1512
raise BzrCommandError(
1513
"Merge doesn't permit that revision specifier.")
1514
base = (branch, revision[0])
1515
other = (branch, revision[1])
1517
merge(other, base, check_clean=(not force), merge_type=merge_type)
1469
1520
class cmd_revert(Command):
1512
1563
help.help(topic)
1566
class cmd_shell_complete(Command):
1567
"""Show appropriate completions for context.
1569
For a list of all available commands, say 'bzr shell-complete'."""
1570
takes_args = ['context?']
1574
def run(self, context=None):
1575
import shellcomplete
1576
shellcomplete.shellcomplete(context)
1579
class cmd_missing(Command):
1580
"""What is missing in this branch relative to other branch.
1582
takes_args = ['remote?']
1583
aliases = ['mis', 'miss']
1584
# We don't have to add quiet to the list, because
1585
# unknown options are parsed as booleans
1586
takes_options = ['verbose', 'quiet']
1588
def run(self, remote=None, verbose=False, quiet=False):
1589
from bzrlib.branch import find_branch, DivergedBranches
1590
from bzrlib.errors import BzrCommandError
1591
from bzrlib.missing import get_parent, show_missing
1593
if verbose and quiet:
1594
raise BzrCommandError('Cannot pass both quiet and verbose')
1596
b = find_branch('.')
1597
parent = get_parent(b)
1600
raise BzrCommandError("No missing location known or specified.")
1603
print "Using last location: %s" % parent
1605
elif parent is None:
1606
# We only update x-pull if it did not exist, missing should not change the parent
1607
b.controlfile('x-pull', 'wb').write(remote + '\n')
1608
br_remote = find_branch(remote)
1610
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1517
1614
class cmd_plugins(Command):
1844
1940
def main(argv):
1846
1941
bzrlib.trace.open_tracefile(argv)
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()
1945
return run_bzr(argv[1:])
1947
# do this here inside the exception wrappers to catch EPIPE
1949
except BzrCommandError, e:
1950
# command line syntax error, etc
1954
bzrlib.trace.log_exception()
1956
except AssertionError, e:
1957
bzrlib.trace.log_exception('assertion failed: ' + str(e))
1959
except KeyboardInterrupt, e:
1960
bzrlib.trace.note('interrupted')
1962
except Exception, e:
1964
if (isinstance(e, IOError)
1965
and hasattr(e, 'errno')
1966
and e.errno == errno.EPIPE):
1967
bzrlib.trace.note('broken pipe')
1970
bzrlib.trace.log_exception('terminated by exception')
1888
1974
if __name__ == '__main__':