/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-18 01:57:45 UTC
  • mto: This revision was merged to the branch mainline in revision 7493.
  • Revision ID: jelmer@jelmer.uk-20200218015745-q2ss9tsk74h4nh61
drop use of future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
260
260
    if revisions is None:
261
261
        return None
262
262
    if len(revisions) != 1:
263
 
        raise errors.CommandError(gettext(
 
263
        raise errors.BzrCommandError(gettext(
264
264
            'brz %s --revision takes exactly one revision identifier') % (
265
265
                command_name,))
266
266
    return revisions[0]
396
396
        from .status import show_tree_status
397
397
 
398
398
        if revision and len(revision) > 2:
399
 
            raise errors.CommandError(
 
399
            raise errors.BzrCommandError(
400
400
                gettext('brz status --revision takes exactly'
401
401
                        ' one or two revision specifiers'))
402
402
 
441
441
    @display_command
442
442
    def run(self, revision_id=None, revision=None, directory=u'.'):
443
443
        if revision_id is not None and revision is not None:
444
 
            raise errors.CommandError(gettext('You can only supply one of'
 
444
            raise errors.BzrCommandError(gettext('You can only supply one of'
445
445
                                                 ' revision_id or --revision'))
446
446
        if revision_id is None and revision is None:
447
 
            raise errors.CommandError(
 
447
            raise errors.BzrCommandError(
448
448
                gettext('You must supply either --revision or a revision_id'))
449
449
 
450
450
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
451
451
 
452
452
        revisions = getattr(b.repository, "revisions", None)
453
453
        if revisions is None:
454
 
            raise errors.CommandError(
 
454
            raise errors.BzrCommandError(
455
455
                gettext('Repository %r does not support '
456
456
                        'access to raw revision texts') % b.repository)
457
457
 
465
465
                    msg = gettext(
466
466
                        "The repository {0} contains no revision {1}.").format(
467
467
                            b.repository.base, revision_id.decode('utf-8'))
468
 
                    raise errors.CommandError(msg)
 
468
                    raise errors.BzrCommandError(msg)
469
469
            elif revision is not None:
470
470
                for rev in revision:
471
471
                    if rev is None:
472
 
                        raise errors.CommandError(
 
472
                        raise errors.BzrCommandError(
473
473
                            gettext('You cannot specify a NULL revision.'))
474
474
                    rev_id = rev.as_revision_id(b)
475
475
                    self.print_revision(revisions, rev_id)
501
501
            try:
502
502
                working = d.open_workingtree()
503
503
            except errors.NoWorkingTree:
504
 
                raise errors.CommandError(
 
504
                raise errors.BzrCommandError(
505
505
                    gettext("No working tree to remove"))
506
506
            except errors.NotLocalUrl:
507
 
                raise errors.CommandError(
 
507
                raise errors.BzrCommandError(
508
508
                    gettext("You cannot remove the working tree"
509
509
                            " of a remote path"))
510
510
            if not force:
514
514
                    raise errors.ShelvedChanges(working)
515
515
 
516
516
            if working.user_url != working.branch.user_url:
517
 
                raise errors.CommandError(
 
517
                raise errors.BzrCommandError(
518
518
                    gettext("You cannot remove the working tree"
519
519
                            " from a lightweight checkout"))
520
520
 
555
555
                pass  # There seems to be a real error here, so we'll reset
556
556
            else:
557
557
                # Refuse
558
 
                raise errors.CommandError(gettext(
 
558
                raise errors.BzrCommandError(gettext(
559
559
                    'The tree does not appear to be corrupt. You probably'
560
560
                    ' want "brz revert" instead. Use "--force" if you are'
561
561
                    ' sure you want to reset the working tree.'))
571
571
                                '-r -1 to set the state to the last commit')
572
572
            else:
573
573
                extra = ''
574
 
            raise errors.CommandError(
 
574
            raise errors.BzrCommandError(
575
575
                gettext('failed to reset the tree state{0}').format(extra))
576
576
 
577
577
 
591
591
    @display_command
592
592
    def run(self, tree=False, location=u'.', revision=None):
593
593
        if revision is not None and tree:
594
 
            raise errors.CommandError(
 
594
            raise errors.BzrCommandError(
595
595
                gettext("--tree and --revision can not be used together"))
596
596
 
597
597
        if tree:
607
607
            self.enter_context(b.lock_read())
608
608
            if revision:
609
609
                if len(revision) != 1:
610
 
                    raise errors.CommandError(gettext(
 
610
                    raise errors.BzrCommandError(gettext(
611
611
                        "Revision numbers only make sense for single "
612
612
                        "revisions, not ranges"))
613
613
                revid = revision[0].as_revision_id(b)
871
871
    def run(self, revision=None, show_ids=False, kind=None, include_root=False,
872
872
            file_list=None):
873
873
        if kind and kind not in ['file', 'directory', 'symlink']:
874
 
            raise errors.CommandError(
 
874
            raise errors.BzrCommandError(
875
875
                gettext('invalid kind %r specified') % (kind,))
876
876
 
877
877
        revision = _get_one_revision('inventory', revision)
934
934
        if names_list is None:
935
935
            names_list = []
936
936
        if len(names_list) < 2:
937
 
            raise errors.CommandError(gettext("missing file argument"))
 
937
            raise errors.BzrCommandError(gettext("missing file argument"))
938
938
        tree, rel_names = WorkingTree.open_containing_paths(
939
939
            names_list, canonicalize=False)
940
940
        for file_name in rel_names[0:-1]:
941
941
            if file_name == '':
942
 
                raise errors.CommandError(
 
942
                raise errors.BzrCommandError(
943
943
                    gettext("can not copy root of branch"))
944
944
        self.enter_context(tree.lock_tree_write())
945
945
        into_existing = osutils.isdir(names_list[-1])
947
947
            try:
948
948
                (src, dst) = rel_names
949
949
            except IndexError:
950
 
                raise errors.CommandError(
 
950
                raise errors.BzrCommandError(
951
951
                    gettext('to copy multiple files the'
952
952
                            ' destination must be a versioned'
953
953
                            ' directory'))
961
961
            try:
962
962
                src_kind = tree.stored_kind(src)
963
963
            except errors.NoSuchFile:
964
 
                raise errors.CommandError(
 
964
                raise errors.BzrCommandError(
965
965
                    gettext('Could not copy %s => %s: %s is not versioned.')
966
966
                    % (src, dst, src))
967
967
            if src_kind is None:
968
 
                raise errors.CommandError(
 
968
                raise errors.BzrCommandError(
969
969
                    gettext('Could not copy %s => %s . %s is not versioned\\.'
970
970
                            % (src, dst, src)))
971
971
            if src_kind == 'directory':
972
 
                raise errors.CommandError(
 
972
                raise errors.BzrCommandError(
973
973
                    gettext('Could not copy %s => %s . %s is a directory.'
974
974
                            % (src, dst, src)))
975
975
            dst_parent = osutils.split(dst)[0]
977
977
                try:
978
978
                    dst_parent_kind = tree.stored_kind(dst_parent)
979
979
                except errors.NoSuchFile:
980
 
                    raise errors.CommandError(
 
980
                    raise errors.BzrCommandError(
981
981
                        gettext('Could not copy %s => %s: %s is not versioned.')
982
982
                        % (src, dst, dst_parent))
983
983
                if dst_parent_kind != 'directory':
984
 
                    raise errors.CommandError(
 
984
                    raise errors.BzrCommandError(
985
985
                        gettext('Could not copy to %s: %s is not a directory.')
986
986
                        % (dst_parent, dst_parent))
987
987
 
1023
1023
        if auto:
1024
1024
            return self.run_auto(names_list, after, dry_run)
1025
1025
        elif dry_run:
1026
 
            raise errors.CommandError(gettext('--dry-run requires --auto.'))
 
1026
            raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
1027
1027
        if names_list is None:
1028
1028
            names_list = []
1029
1029
        if len(names_list) < 2:
1030
 
            raise errors.CommandError(gettext("missing file argument"))
 
1030
            raise errors.BzrCommandError(gettext("missing file argument"))
1031
1031
        tree, rel_names = WorkingTree.open_containing_paths(
1032
1032
            names_list, canonicalize=False)
1033
1033
        for file_name in rel_names[0:-1]:
1034
1034
            if file_name == '':
1035
 
                raise errors.CommandError(
 
1035
                raise errors.BzrCommandError(
1036
1036
                    gettext("can not move root of branch"))
1037
1037
        self.enter_context(tree.lock_tree_write())
1038
1038
        self._run(tree, names_list, rel_names, after)
1039
1039
 
1040
1040
    def run_auto(self, names_list, after, dry_run):
1041
1041
        if names_list is not None and len(names_list) > 1:
1042
 
            raise errors.CommandError(
 
1042
            raise errors.BzrCommandError(
1043
1043
                gettext('Only one path may be specified to --auto.'))
1044
1044
        if after:
1045
 
            raise errors.CommandError(
 
1045
            raise errors.BzrCommandError(
1046
1046
                gettext('--after cannot be specified with --auto.'))
1047
1047
        work_tree, file_list = WorkingTree.open_containing_paths(
1048
1048
            names_list, default_directory='.')
1079
1079
                    self.outf.write("%s => %s\n" % (src, dest))
1080
1080
        else:
1081
1081
            if len(names_list) != 2:
1082
 
                raise errors.CommandError(gettext('to mv multiple files the'
 
1082
                raise errors.BzrCommandError(gettext('to mv multiple files the'
1083
1083
                                                     ' destination must be a versioned'
1084
1084
                                                     ' directory'))
1085
1085
 
1222
1222
        stored_loc = branch_to.get_parent()
1223
1223
        if location is None:
1224
1224
            if stored_loc is None:
1225
 
                raise errors.CommandError(gettext("No pull location known or"
 
1225
                raise errors.BzrCommandError(gettext("No pull location known or"
1226
1226
                                                     " specified."))
1227
1227
            else:
1228
1228
                display_url = urlutils.unescape_for_display(stored_loc,
1235
1235
        revision = _get_one_revision('pull', revision)
1236
1236
        if mergeable is not None:
1237
1237
            if revision is not None:
1238
 
                raise errors.CommandError(gettext(
 
1238
                raise errors.BzrCommandError(gettext(
1239
1239
                    'Cannot use -r with merge directives or bundles'))
1240
1240
            mergeable.install_revisions(branch_to.repository)
1241
1241
            base_revision_id, revision_id, verified = \
1390
1390
                    # error by the feedback given to them. RBC 20080227.
1391
1391
                    stacked_on = parent_url
1392
1392
            if not stacked_on:
1393
 
                raise errors.CommandError(gettext(
 
1393
                raise errors.BzrCommandError(gettext(
1394
1394
                    "Could not determine branch to refer to."))
1395
1395
 
1396
1396
        # Get the destination location
1399
1399
            if stored_loc is None:
1400
1400
                parent_loc = br_from.get_parent()
1401
1401
                if parent_loc:
1402
 
                    raise errors.CommandError(gettext(
 
1402
                    raise errors.BzrCommandError(gettext(
1403
1403
                        "No push location known or specified. To push to the "
1404
1404
                        "parent branch (at %s), use 'brz push :parent'." %
1405
1405
                        urlutils.unescape_for_display(parent_loc,
1406
1406
                                                      self.outf.encoding)))
1407
1407
                else:
1408
 
                    raise errors.CommandError(gettext(
 
1408
                    raise errors.BzrCommandError(gettext(
1409
1409
                        "No push location known or specified."))
1410
1410
            else:
1411
1411
                display_url = urlutils.unescape_for_display(stored_loc,
1434
1434
    parameter, as in "branch foo/bar -r 5".
1435
1435
    """
1436
1436
 
1437
 
    aliase = ['sprout']
1438
1437
    _see_also = ['checkout']
1439
1438
    takes_args = ['from_location', 'to_location?']
1440
1439
    takes_options = ['revision',
1462
1461
                            help="Bind new branch to from location."),
1463
1462
                     Option('no-recurse-nested',
1464
1463
                            help='Do not recursively check out nested trees.'),
1465
 
                     Option('colocated-branch', short_name='b',
1466
 
                            type=str, help='Name of colocated branch to sprout.'),
1467
1464
                     ]
1468
1465
 
1469
1466
    def run(self, from_location, to_location=None, revision=None,
1470
1467
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1471
1468
            use_existing_dir=False, switch=False, bind=False,
1472
 
            files_from=None, no_recurse_nested=False, colocated_branch=None):
 
1469
            files_from=None, no_recurse_nested=False):
1473
1470
        from breezy import switch as _mod_switch
1474
1471
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1475
 
            from_location, name=colocated_branch)
 
1472
            from_location)
1476
1473
        if no_recurse_nested:
1477
1474
            recurse = 'none'
1478
1475
        else:
1504
1501
                    to_transport)
1505
1502
            except errors.NotBranchError:
1506
1503
                if not use_existing_dir:
1507
 
                    raise errors.CommandError(gettext('Target directory "%s" '
 
1504
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
1508
1505
                                                         'already exists.') % to_location)
1509
1506
                else:
1510
1507
                    to_dir = None
1516
1513
                else:
1517
1514
                    raise errors.AlreadyBranchError(to_location)
1518
1515
        except errors.NoSuchFile:
1519
 
            raise errors.CommandError(gettext('Parent of "%s" does not exist.')
 
1516
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1520
1517
                                         % to_location)
1521
1518
        else:
1522
1519
            to_dir = None
1537
1534
                to_transport.delete_tree('.')
1538
1535
                msg = gettext("The branch {0} has no revision {1}.").format(
1539
1536
                    from_location, revision)
1540
 
                raise errors.CommandError(msg)
 
1537
                raise errors.BzrCommandError(msg)
1541
1538
        else:
1542
1539
            try:
1543
1540
                to_repo = to_dir.open_repository()
1593
1590
        if recursive:
1594
1591
            t = transport.get_transport(location, purpose='read')
1595
1592
            if not t.listable():
1596
 
                raise errors.CommandError(
 
1593
                raise errors.BzrCommandError(
1597
1594
                    "Can't scan this type of location.")
1598
1595
            for b in controldir.ControlDir.find_branches(t):
1599
1596
                self.outf.write("%s\n" % urlutils.unescape_for_display(
1698
1695
                               accelerator_tree, hardlink)
1699
1696
 
1700
1697
 
1701
 
class cmd_clone(Command):
1702
 
    __doc__ = """Clone a control directory.
1703
 
    """
1704
 
 
1705
 
    takes_args = ['from_location', 'to_location?']
1706
 
    takes_options = ['revision',
1707
 
                     Option('no-recurse-nested',
1708
 
                            help='Do not recursively check out nested trees.'),
1709
 
                     ]
1710
 
 
1711
 
    def run(self, from_location, to_location=None, revision=None, no_recurse_nested=False):
1712
 
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1713
 
            from_location)
1714
 
        if no_recurse_nested:
1715
 
            recurse = 'none'
1716
 
        else:
1717
 
            recurse = 'down'
1718
 
        revision = _get_one_revision('branch', revision)
1719
 
        self.enter_context(br_from.lock_read())
1720
 
        if revision is not None:
1721
 
            revision_id = revision.as_revision_id(br_from)
1722
 
        else:
1723
 
            # FIXME - wt.last_revision, fallback to branch, fall back to
1724
 
            # None or perhaps NULL_REVISION to mean copy nothing
1725
 
            # RBC 20060209
1726
 
            revision_id = br_from.last_revision()
1727
 
        if to_location is None:
1728
 
            to_location = urlutils.derive_to_location(from_location)
1729
 
        target_controldir = br_from.controldir.clone(to_location, revision_id=revision_id)
1730
 
        note(gettext('Created new control directory.'))
1731
 
 
1732
 
 
1733
1698
class cmd_renames(Command):
1734
1699
    __doc__ = """Show list of renamed files.
1735
1700
    """
1798
1763
 
1799
1764
    def run(self, dir=None, revision=None, show_base=None):
1800
1765
        if revision is not None and len(revision) != 1:
1801
 
            raise errors.CommandError(gettext(
 
1766
            raise errors.BzrCommandError(gettext(
1802
1767
                "brz update --revision takes exactly one revision"))
1803
1768
        if dir is None:
1804
1769
            tree = WorkingTree.open_containing('.')[0]
1806
1771
            tree, relpath = WorkingTree.open_containing(dir)
1807
1772
            if relpath:
1808
1773
                # See bug 557886.
1809
 
                raise errors.CommandError(gettext(
 
1774
                raise errors.BzrCommandError(gettext(
1810
1775
                    "brz update can only update a whole tree, "
1811
1776
                    "not a file or subdirectory"))
1812
1777
        branch = tree.branch
1852
1817
                old_tip=old_tip,
1853
1818
                show_base=show_base)
1854
1819
        except errors.NoSuchRevision as e:
1855
 
            raise errors.CommandError(gettext(
 
1820
            raise errors.BzrCommandError(gettext(
1856
1821
                "branch has no revision %s\n"
1857
1822
                "brz update --revision only works"
1858
1823
                " for a revision in the branch history")
1954
1919
                                      specific_files=file_list).added
1955
1920
            file_list = sorted([f.path[1] for f in added], reverse=True)
1956
1921
            if len(file_list) == 0:
1957
 
                raise errors.CommandError(gettext('No matching files.'))
 
1922
                raise errors.BzrCommandError(gettext('No matching files.'))
1958
1923
        elif file_list is None:
1959
1924
            # missing files show up in iter_changes(basis) as
1960
1925
            # versioned-with-no-kind.
2116
2081
            to_transport.ensure_base()
2117
2082
        except errors.NoSuchFile:
2118
2083
            if not create_prefix:
2119
 
                raise errors.CommandError(gettext("Parent directory of %s"
 
2084
                raise errors.BzrCommandError(gettext("Parent directory of %s"
2120
2085
                                                     " does not exist."
2121
2086
                                                     "\nYou may supply --create-prefix to create all"
2122
2087
                                                     " leading parent directories.")
2151
2116
            try:
2152
2117
                branch.set_append_revisions_only(True)
2153
2118
            except errors.UpgradeRequired:
2154
 
                raise errors.CommandError(gettext('This branch format cannot be set'
 
2119
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
2155
2120
                                                     ' to append-revisions-only.  Try --default.'))
2156
2121
        if not is_quiet():
2157
2122
            from .info import describe_layout, describe_format
2395
2360
        elif u':' in prefix:
2396
2361
            old_label, new_label = prefix.split(u":")
2397
2362
        else:
2398
 
            raise errors.CommandError(gettext(
 
2363
            raise errors.BzrCommandError(gettext(
2399
2364
                '--prefix expects two values separated by a colon'
2400
2365
                ' (eg "old/:new/")'))
2401
2366
 
2402
2367
        if revision and len(revision) > 2:
2403
 
            raise errors.CommandError(gettext('brz diff --revision takes exactly'
 
2368
            raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
2404
2369
                                                 ' one or two revision specifiers'))
2405
2370
 
2406
2371
        if using is not None and format is not None:
2407
 
            raise errors.CommandError(gettext(
 
2372
            raise errors.BzrCommandError(gettext(
2408
2373
                '{0} and {1} are mutually exclusive').format(
2409
2374
                '--using', '--format'))
2410
2375
 
2529
2494
        return int(limitstring)
2530
2495
    except ValueError:
2531
2496
        msg = gettext("The limit argument must be an integer.")
2532
 
        raise errors.CommandError(msg)
 
2497
        raise errors.BzrCommandError(msg)
2533
2498
 
2534
2499
 
2535
2500
def _parse_levels(s):
2537
2502
        return int(s)
2538
2503
    except ValueError:
2539
2504
        msg = gettext("The levels argument must be an integer.")
2540
 
        raise errors.CommandError(msg)
 
2505
        raise errors.BzrCommandError(msg)
2541
2506
 
2542
2507
 
2543
2508
class cmd_log(Command):
2804
2769
            include_merged = False
2805
2770
        if (exclude_common_ancestry
2806
2771
                and (revision is None or len(revision) != 2)):
2807
 
            raise errors.CommandError(gettext(
 
2772
            raise errors.BzrCommandError(gettext(
2808
2773
                '--exclude-common-ancestry requires -r with two revisions'))
2809
2774
        if include_merged:
2810
2775
            if levels is None:
2811
2776
                levels = 0
2812
2777
            else:
2813
 
                raise errors.CommandError(gettext(
 
2778
                raise errors.BzrCommandError(gettext(
2814
2779
                    '{0} and {1} are mutually exclusive').format(
2815
2780
                    '--levels', '--include-merged'))
2816
2781
 
2818
2783
            if len(change) > 1:
2819
2784
                raise errors.RangeInChangeOption()
2820
2785
            if revision is not None:
2821
 
                raise errors.CommandError(gettext(
 
2786
                raise errors.BzrCommandError(gettext(
2822
2787
                    '{0} and {1} are mutually exclusive').format(
2823
2788
                    '--revision', '--change'))
2824
2789
            else:
2825
2790
                revision = change
2826
2791
 
2827
 
        files = []
 
2792
        file_ids = []
2828
2793
        filter_by_dir = False
2829
2794
        if file_list:
2830
2795
            # find the file ids to log and check for directory filtering
2831
2796
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2832
2797
                revision, file_list, self._exit_stack)
2833
 
            for relpath, kind in file_info_list:
2834
 
                if not kind:
2835
 
                    raise errors.CommandError(gettext(
 
2798
            for relpath, file_id, kind in file_info_list:
 
2799
                if file_id is None:
 
2800
                    raise errors.BzrCommandError(gettext(
2836
2801
                        "Path unknown at end or start of revision range: %s") %
2837
2802
                        relpath)
2838
2803
                # If the relpath is the top of the tree, we log everything
2839
2804
                if relpath == '':
2840
 
                    files = []
 
2805
                    file_ids = []
2841
2806
                    break
2842
2807
                else:
2843
 
                    files.append(relpath)
 
2808
                    file_ids.append(file_id)
2844
2809
                filter_by_dir = filter_by_dir or (
2845
2810
                    kind in ['directory', 'tree-reference'])
2846
2811
        else:
2871
2836
            delta_type = 'full'
2872
2837
        if not show_diff:
2873
2838
            diff_type = None
2874
 
        elif files:
 
2839
        elif file_ids:
2875
2840
            diff_type = 'partial'
2876
2841
        else:
2877
2842
            diff_type = 'full'
2903
2868
        # original algorithm - per-file-graph - for the "single
2904
2869
        # file that isn't a directory without showing a delta" case.
2905
2870
        partial_history = revision and b.repository._format.supports_chks
2906
 
        match_using_deltas = (len(files) != 1 or filter_by_dir
 
2871
        match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2907
2872
                              or delta_type or partial_history)
2908
2873
 
2909
2874
        match_dict = {}
2919
2884
            match_dict['bugs'] = match_bugs
2920
2885
 
2921
2886
        # Build the LogRequest and execute it
2922
 
        if len(files) == 0:
2923
 
            files = None
 
2887
        if len(file_ids) == 0:
 
2888
            file_ids = None
2924
2889
        rqst = make_log_request_dict(
2925
 
            direction=direction, specific_files=files,
 
2890
            direction=direction, specific_fileids=file_ids,
2926
2891
            start_revision=rev1, end_revision=rev2, limit=limit,
2927
2892
            message_search=message, delta_type=delta_type,
2928
2893
            diff_type=diff_type, _match_using_deltas=match_using_deltas,
2950
2915
            # b is taken from revision[0].get_branch(), and
2951
2916
            # show_log will use its revision_history. Having
2952
2917
            # different branches will lead to weird behaviors.
2953
 
            raise errors.CommandError(gettext(
 
2918
            raise errors.BzrCommandError(gettext(
2954
2919
                "brz %s doesn't accept two revisions in different"
2955
2920
                " branches.") % command_name)
2956
2921
        if start_spec.spec is None:
2966
2931
        else:
2967
2932
            rev2 = end_spec.in_history(branch)
2968
2933
    else:
2969
 
        raise errors.CommandError(gettext(
 
2934
        raise errors.BzrCommandError(gettext(
2970
2935
            'brz %s --revision takes one or two values.') % command_name)
2971
2936
    return rev1, rev2
2972
2937
 
3046
3011
            null=False, kind=None, show_ids=False, path=None, directory=None):
3047
3012
 
3048
3013
        if kind and kind not in ('file', 'directory', 'symlink', 'tree-reference'):
3049
 
            raise errors.CommandError(gettext('invalid kind specified'))
 
3014
            raise errors.BzrCommandError(gettext('invalid kind specified'))
3050
3015
 
3051
3016
        if verbose and null:
3052
 
            raise errors.CommandError(
 
3017
            raise errors.BzrCommandError(
3053
3018
                gettext('Cannot set both --verbose and --null'))
3054
3019
        all = not (unknown or versioned or ignored)
3055
3020
 
3059
3024
            fs_path = '.'
3060
3025
        else:
3061
3026
            if from_root:
3062
 
                raise errors.CommandError(gettext('cannot specify both --from-root'
 
3027
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
3063
3028
                                                     ' and PATH'))
3064
3029
            fs_path = path
3065
3030
        tree, branch, relpath = \
3236
3201
                self.outf.write("%s\n" % pattern)
3237
3202
            return
3238
3203
        if not name_pattern_list:
3239
 
            raise errors.CommandError(gettext("ignore requires at least one "
 
3204
            raise errors.BzrCommandError(gettext("ignore requires at least one "
3240
3205
                                                 "NAME_PATTERN or --default-rules."))
3241
3206
        name_pattern_list = [globbing.normalize_pattern(p)
3242
3207
                             for p in name_pattern_list]
3255
3220
        for name_pattern in name_pattern_list:
3256
3221
            if (name_pattern[0] == '/' or
3257
3222
                    (len(name_pattern) > 1 and name_pattern[1] == ':')):
3258
 
                raise errors.CommandError(gettext(
 
3223
                raise errors.BzrCommandError(gettext(
3259
3224
                    "NAME_PATTERN should not be an absolute path"))
3260
3225
        tree, relpath = WorkingTree.open_containing(directory)
3261
3226
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3316
3281
        try:
3317
3282
            revno = int(revno)
3318
3283
        except ValueError:
3319
 
            raise errors.CommandError(gettext("not a valid revision-number: %r")
 
3284
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
3320
3285
                                         % revno)
3321
3286
        revid = WorkingTree.open_containing(
3322
3287
            directory)[0].branch.get_rev_id(revno)
3387
3352
 
3388
3353
        if uncommitted:
3389
3354
            if tree is None:
3390
 
                raise errors.CommandError(
 
3355
                raise errors.BzrCommandError(
3391
3356
                    gettext("--uncommitted requires a working tree"))
3392
3357
            export_tree = tree
3393
3358
        else:
3415
3380
            export(export_tree, dest, format, root, subdir,
3416
3381
                   per_file_timestamps=per_file_timestamps)
3417
3382
        except errors.NoSuchExportFormat as e:
3418
 
            raise errors.CommandError(
 
3383
            raise errors.BzrCommandError(
3419
3384
                gettext('Unsupported export format: %s') % e.format)
3420
3385
 
3421
3386
 
3443
3408
    def run(self, filename, revision=None, name_from_revision=False,
3444
3409
            filters=False, directory=None):
3445
3410
        if revision is not None and len(revision) != 1:
3446
 
            raise errors.CommandError(gettext("brz cat --revision takes exactly"
 
3411
            raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
3447
3412
                                                 " one revision specifier"))
3448
3413
        tree, branch, relpath = \
3449
3414
            _open_directory_or_containing_tree_or_branch(filename, directory)
3462
3427
        if name_from_revision:
3463
3428
            # Try in revision if requested
3464
3429
            if not rev_tree.is_versioned(relpath):
3465
 
                raise errors.CommandError(gettext(
 
3430
                raise errors.BzrCommandError(gettext(
3466
3431
                    "{0!r} is not present in revision {1}").format(
3467
3432
                        filename, rev_tree.get_revision_id()))
3468
3433
            rev_tree_path = relpath
3476
3441
            if rev_tree_path is None:
3477
3442
                # Path didn't exist in working tree
3478
3443
                if not rev_tree.is_versioned(relpath):
3479
 
                    raise errors.CommandError(gettext(
 
3444
                    raise errors.BzrCommandError(gettext(
3480
3445
                        "{0!r} is not present in revision {1}").format(
3481
3446
                            filename, rev_tree.get_revision_id()))
3482
3447
                else:
3619
3584
                    default_bugtracker = branch_config.get(
3620
3585
                        "bugtracker")
3621
3586
                if default_bugtracker is None:
3622
 
                    raise errors.CommandError(gettext(
 
3587
                    raise errors.BzrCommandError(gettext(
3623
3588
                        "No tracker specified for bug %s. Use the form "
3624
3589
                        "'tracker:id' or specify a default bug tracker "
3625
3590
                        "using the `bugtracker` option.\nSee "
3628
3593
                tag = default_bugtracker
3629
3594
                bug_id = tokens[0]
3630
3595
            elif len(tokens) != 2:
3631
 
                raise errors.CommandError(gettext(
 
3596
                raise errors.BzrCommandError(gettext(
3632
3597
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3633
3598
                    "See \"brz help bugs\" for more information on this "
3634
3599
                    "feature.\nCommit refused.") % bug)
3637
3602
            try:
3638
3603
                yield bugtracker.get_bug_url(tag, branch, bug_id), status
3639
3604
            except bugtracker.UnknownBugTrackerAbbreviation:
3640
 
                raise errors.CommandError(gettext(
 
3605
                raise errors.BzrCommandError(gettext(
3641
3606
                    'Unrecognized bug %s. Commit refused.') % bug)
3642
3607
            except bugtracker.MalformedBugIdentifier as e:
3643
 
                raise errors.CommandError(gettext(
 
3608
                raise errors.BzrCommandError(gettext(
3644
3609
                    u"%s\nCommit refused.") % (e,))
3645
3610
 
3646
3611
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3667
3632
            try:
3668
3633
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3669
3634
            except ValueError as e:
3670
 
                raise errors.CommandError(gettext(
 
3635
                raise errors.BzrCommandError(gettext(
3671
3636
                    "Could not parse --commit-time: " + str(e)))
3672
3637
 
3673
3638
        properties = {}
3711
3676
                message = message.replace('\r\n', '\n')
3712
3677
                message = message.replace('\r', '\n')
3713
3678
            if file:
3714
 
                raise errors.CommandError(gettext(
 
3679
                raise errors.BzrCommandError(gettext(
3715
3680
                    "please specify either --message or --file"))
3716
3681
 
3717
3682
        def get_message(commit_obj):
3742
3707
                    my_message = edit_commit_message_encoded(text,
3743
3708
                                                             start_message=start_message)
3744
3709
                if my_message is None:
3745
 
                    raise errors.CommandError(gettext("please specify a commit"
 
3710
                    raise errors.BzrCommandError(gettext("please specify a commit"
3746
3711
                                                         " message with either --message or --file"))
3747
3712
                if my_message == "":
3748
 
                    raise errors.CommandError(gettext("Empty commit message specified."
 
3713
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
3749
3714
                                                         " Please specify a commit message with either"
3750
3715
                                                         " --message or --file or leave a blank message"
3751
3716
                                                         " with --message \"\"."))
3765
3730
                        exclude=tree.safe_relpath_files(exclude),
3766
3731
                        lossy=lossy)
3767
3732
        except PointlessCommit:
3768
 
            raise errors.CommandError(gettext("No changes to commit."
 
3733
            raise errors.BzrCommandError(gettext("No changes to commit."
3769
3734
                                                 " Please 'brz add' the files you want to commit, or use"
3770
3735
                                                 " --unchanged to force an empty commit."))
3771
3736
        except ConflictsInTree:
3772
 
            raise errors.CommandError(gettext('Conflicts detected in working '
 
3737
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
3773
3738
                                                 'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
3774
3739
                                                 ' resolve.'))
3775
3740
        except StrictCommitFailed:
3776
 
            raise errors.CommandError(gettext("Commit refused because there are"
 
3741
            raise errors.BzrCommandError(gettext("Commit refused because there are"
3777
3742
                                                 " unknown files in the working tree."))
3778
3743
        except errors.BoundBranchOutOfDate as e:
3779
3744
            e.extra_help = (gettext("\n"
3955
3920
            return
3956
3921
 
3957
3922
        if email:
3958
 
            raise errors.CommandError(gettext("--email can only be used to display existing "
 
3923
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
3959
3924
                                                 "identity"))
3960
3925
 
3961
3926
        # display a warning if an email address isn't included in the given name.
4045
4010
 
4046
4011
    def remove_alias(self, alias_name):
4047
4012
        if alias_name is None:
4048
 
            raise errors.CommandError(gettext(
 
4013
            raise errors.BzrCommandError(gettext(
4049
4014
                'brz alias --remove expects an alias to remove.'))
4050
4015
        # If alias is not found, print something like:
4051
4016
        # unalias: foo: not found
4140
4105
            return test_server.FakeNFSServer
4141
4106
        msg = "No known transport type %s. Supported types are: sftp\n" %\
4142
4107
            (typestring)
4143
 
        raise errors.CommandError(msg)
 
4108
        raise errors.BzrCommandError(msg)
4144
4109
 
4145
4110
    hidden = True
4146
4111
    takes_args = ['testspecs*']
4224
4189
 
4225
4190
        try:
4226
4191
            from . import tests
4227
 
        except ImportError as e:
4228
 
            raise errors.CommandError("tests not available. Install the "
 
4192
        except ImportError:
 
4193
            raise errors.BzrCommandError("tests not available. Install the "
4229
4194
                                         "breezy tests to run the breezy testsuite.")
4230
4195
 
4231
4196
        if testspecs_list is not None:
4236
4201
            try:
4237
4202
                from .tests import SubUnitBzrRunnerv1
4238
4203
            except ImportError:
4239
 
                raise errors.CommandError(gettext(
 
4204
                raise errors.BzrCommandError(gettext(
4240
4205
                    "subunit not available. subunit needs to be installed "
4241
4206
                    "to use --subunit."))
4242
4207
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv1
4253
4218
            try:
4254
4219
                from .tests import SubUnitBzrRunnerv2
4255
4220
            except ImportError:
4256
 
                raise errors.CommandError(gettext(
 
4221
                raise errors.BzrCommandError(gettext(
4257
4222
                    "subunit not available. subunit "
4258
4223
                    "needs to be installed to use --subunit2."))
4259
4224
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv2
4262
4227
            self.additional_selftest_args.setdefault(
4263
4228
                'suite_decorators', []).append(parallel)
4264
4229
        if benchmark:
4265
 
            raise errors.CommandError(gettext(
 
4230
            raise errors.BzrCommandError(gettext(
4266
4231
                "--benchmark is no longer supported from brz 2.2; "
4267
4232
                "use bzr-usertest instead"))
4268
4233
        test_suite_factory = None
4490
4455
 
4491
4456
        tree = WorkingTree.open_containing(directory)[0]
4492
4457
        if tree.branch.last_revision() == _mod_revision.NULL_REVISION:
4493
 
            raise errors.CommandError(gettext('Merging into empty branches not currently supported, '
 
4458
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
4494
4459
                                                 'https://bugs.launchpad.net/bzr/+bug/308562'))
4495
4460
 
4496
4461
        # die as quickly as possible if there are uncommitted changes
4512
4477
                mergeable = None
4513
4478
            else:
4514
4479
                if uncommitted:
4515
 
                    raise errors.CommandError(gettext('Cannot use --uncommitted'
 
4480
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4516
4481
                                                         ' with bundles or merge directives.'))
4517
4482
 
4518
4483
                if revision is not None:
4519
 
                    raise errors.CommandError(gettext(
 
4484
                    raise errors.BzrCommandError(gettext(
4520
4485
                        'Cannot use -r with merge directives or bundles'))
4521
4486
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4522
4487
                                                                    mergeable)
4523
4488
 
4524
4489
        if merger is None and uncommitted:
4525
4490
            if revision is not None and len(revision) > 0:
4526
 
                raise errors.CommandError(gettext('Cannot use --uncommitted and'
 
4491
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4527
4492
                                                     ' --revision at the same time.'))
4528
4493
            merger = self.get_merger_from_uncommitted(tree, location, None)
4529
4494
            allow_pending = False
4549
4514
            return 0
4550
4515
        if pull and not preview:
4551
4516
            if merger.interesting_files is not None:
4552
 
                raise errors.CommandError(
 
4517
                raise errors.BzrCommandError(
4553
4518
                    gettext('Cannot pull individual files'))
4554
4519
            if (merger.base_rev_id == tree.last_revision()):
4555
4520
                result = tree.pull(merger.other_branch, False,
4557
4522
                result.report(self.outf)
4558
4523
                return 0
4559
4524
        if merger.this_basis is None:
4560
 
            raise errors.CommandError(gettext(
 
4525
            raise errors.BzrCommandError(gettext(
4561
4526
                "This branch has no commits."
4562
4527
                " (perhaps you would prefer 'brz pull')"))
4563
4528
        if preview:
4616
4581
    def sanity_check_merger(self, merger):
4617
4582
        if (merger.show_base and
4618
4583
                merger.merge_type is not _mod_merge.Merge3Merger):
4619
 
            raise errors.CommandError(gettext("Show-base is not supported for this"
 
4584
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
4620
4585
                                                 " merge type. %s") % merger.merge_type)
4621
4586
        if merger.reprocess is None:
4622
4587
            if merger.show_base:
4625
4590
                # Use reprocess if the merger supports it
4626
4591
                merger.reprocess = merger.merge_type.supports_reprocess
4627
4592
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4628
 
            raise errors.CommandError(gettext("Conflict reduction is not supported"
 
4593
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
4629
4594
                                                 " for merge type %s.") %
4630
4595
                                         merger.merge_type)
4631
4596
        if merger.reprocess and merger.show_base:
4632
 
            raise errors.CommandError(gettext("Cannot do conflict reduction and"
 
4597
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
4633
4598
                                                 " show base."))
4634
4599
 
4635
4600
        if (merger.merge_type.requires_file_merge_plan and
4637
4602
             not getattr(merger.other_tree, 'plan_file_merge', None) or
4638
4603
             (merger.base_tree is not None and
4639
4604
                 not getattr(merger.base_tree, 'plan_file_merge', None)))):
4640
 
            raise errors.CommandError(
 
4605
            raise errors.BzrCommandError(
4641
4606
                gettext('Plan file merge unsupported: '
4642
4607
                        'Merge type incompatible with tree formats.'))
4643
4608
 
4748
4713
            stored_location_type = "parent"
4749
4714
        mutter("%s", stored_location)
4750
4715
        if stored_location is None:
4751
 
            raise errors.CommandError(
 
4716
            raise errors.BzrCommandError(
4752
4717
                gettext("No location specified or remembered"))
4753
4718
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4754
4719
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
4795
4760
        self.enter_context(tree.lock_write())
4796
4761
        parents = tree.get_parent_ids()
4797
4762
        if len(parents) != 2:
4798
 
            raise errors.CommandError(
 
4763
            raise errors.BzrCommandError(
4799
4764
                gettext("Sorry, remerge only works after normal"
4800
4765
                        " merges.  Not cherrypicking or multi-merges."))
4801
4766
        interesting_files = None
5070
5035
        if other_branch is None:
5071
5036
            other_branch = parent
5072
5037
            if other_branch is None:
5073
 
                raise errors.CommandError(gettext("No peer location known"
 
5038
                raise errors.BzrCommandError(gettext("No peer location known"
5074
5039
                                                     " or specified."))
5075
5040
            display_url = urlutils.unescape_for_display(parent,
5076
5041
                                                        self.outf.encoding)
5318
5283
 
5319
5284
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
5320
5285
        if revision_id_list is not None and revision is not None:
5321
 
            raise errors.CommandError(
 
5286
            raise errors.BzrCommandError(
5322
5287
                gettext('You can only supply one of revision_id or --revision'))
5323
5288
        if revision_id_list is None and revision is None:
5324
 
            raise errors.CommandError(
 
5289
            raise errors.BzrCommandError(
5325
5290
                gettext('You must supply either --revision or a revision_id'))
5326
5291
        b = WorkingTree.open_containing(directory)[0].branch
5327
5292
        self.enter_context(b.lock_write())
5349
5314
                if to_revid is None:
5350
5315
                    to_revno = b.revno()
5351
5316
                if from_revno is None or to_revno is None:
5352
 
                    raise errors.CommandError(
 
5317
                    raise errors.BzrCommandError(
5353
5318
                        gettext('Cannot sign a range of non-revision-history revisions'))
5354
5319
                with WriteGroup(b.repository):
5355
5320
                    for revno in range(from_revno, to_revno + 1):
5356
5321
                        b.repository.sign_revision(b.get_rev_id(revno),
5357
5322
                                                   gpg_strategy)
5358
5323
            else:
5359
 
                raise errors.CommandError(
 
5324
                raise errors.BzrCommandError(
5360
5325
                    gettext('Please supply either one revision, or a range.'))
5361
5326
 
5362
5327
 
5382
5347
            try:
5383
5348
                location = b.get_old_bound_location()
5384
5349
            except errors.UpgradeRequired:
5385
 
                raise errors.CommandError(
 
5350
                raise errors.BzrCommandError(
5386
5351
                    gettext('No location supplied.  '
5387
5352
                            'This format does not remember old locations.'))
5388
5353
            else:
5389
5354
                if location is None:
5390
5355
                    if b.get_bound_location() is not None:
5391
 
                        raise errors.CommandError(
 
5356
                        raise errors.BzrCommandError(
5392
5357
                            gettext('Branch is already bound'))
5393
5358
                    else:
5394
 
                        raise errors.CommandError(
 
5359
                        raise errors.BzrCommandError(
5395
5360
                            gettext('No location supplied'
5396
5361
                                    ' and no previous location known'))
5397
5362
        b_other = Branch.open(location)
5398
5363
        try:
5399
5364
            b.bind(b_other)
5400
5365
        except errors.DivergedBranches:
5401
 
            raise errors.CommandError(
 
5366
            raise errors.BzrCommandError(
5402
5367
                gettext('These branches have diverged.'
5403
5368
                        ' Try merging, and then bind again.'))
5404
5369
        if b.get_config().has_explicit_nickname():
5419
5384
    def run(self, directory=u'.'):
5420
5385
        b, relpath = Branch.open_containing(directory)
5421
5386
        if not b.unbind():
5422
 
            raise errors.CommandError(gettext('Local branch is not bound'))
 
5387
            raise errors.BzrCommandError(gettext('Local branch is not bound'))
5423
5388
 
5424
5389
 
5425
5390
class cmd_uncommit(Command):
5678
5643
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5679
5644
        repo = containing_tree.branch.repository
5680
5645
        if not repo.supports_rich_root():
5681
 
            raise errors.CommandError(gettext(
 
5646
            raise errors.BzrCommandError(gettext(
5682
5647
                "Can't join trees because %s doesn't support rich root data.\n"
5683
5648
                "You can use brz upgrade on the repository.")
5684
5649
                % (repo,))
5688
5653
            except BadReferenceTarget as e:
5689
5654
                # XXX: Would be better to just raise a nicely printable
5690
5655
                # exception from the real origin.  Also below.  mbp 20070306
5691
 
                raise errors.CommandError(
 
5656
                raise errors.BzrCommandError(
5692
5657
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5693
5658
        else:
5694
5659
            try:
5695
5660
                containing_tree.subsume(sub_tree)
5696
5661
            except errors.BadSubsumeSource as e:
5697
 
                raise errors.CommandError(
 
5662
                raise errors.BzrCommandError(
5698
5663
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5699
5664
 
5700
5665
 
5786
5751
        if submit_branch is None:
5787
5752
            submit_branch = branch.get_parent()
5788
5753
        if submit_branch is None:
5789
 
            raise errors.CommandError(
 
5754
            raise errors.BzrCommandError(
5790
5755
                gettext('No submit branch specified or known'))
5791
5756
 
5792
5757
        stored_public_branch = branch.get_public_branch()
5796
5761
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-03
5797
5762
            branch.set_public_branch(public_branch)
5798
5763
        if not include_bundle and public_branch is None:
5799
 
            raise errors.CommandError(
 
5764
            raise errors.BzrCommandError(
5800
5765
                gettext('No public branch specified or known'))
5801
5766
        base_revision_id = None
5802
5767
        if revision is not None:
5803
5768
            if len(revision) > 2:
5804
 
                raise errors.CommandError(
 
5769
                raise errors.BzrCommandError(
5805
5770
                    gettext('brz merge-directive takes '
5806
5771
                            'at most two one revision identifiers'))
5807
5772
            revision_id = revision[-1].as_revision_id(branch)
5811
5776
            revision_id = branch.last_revision()
5812
5777
        revision_id = ensure_null(revision_id)
5813
5778
        if revision_id == NULL_REVISION:
5814
 
            raise errors.CommandError(gettext('No revisions to bundle.'))
 
5779
            raise errors.BzrCommandError(gettext('No revisions to bundle.'))
5815
5780
        directive = merge_directive.MergeDirective2.from_objects(
5816
5781
            branch.repository, revision_id, time.time(),
5817
5782
            osutils.local_time_offset(), submit_branch,
6058
6023
        self.enter_context(branch.lock_write())
6059
6024
        if delete:
6060
6025
            if tag_name is None:
6061
 
                raise errors.CommandError(
 
6026
                raise errors.BzrCommandError(
6062
6027
                    gettext("No tag specified to delete."))
6063
6028
            branch.tags.delete_tag(tag_name)
6064
6029
            note(gettext('Deleted tag %s.') % tag_name)
6065
6030
        else:
6066
6031
            if revision:
6067
6032
                if len(revision) != 1:
6068
 
                    raise errors.CommandError(gettext(
 
6033
                    raise errors.BzrCommandError(gettext(
6069
6034
                        "Tags can only be placed on a single revision, "
6070
6035
                        "not on a range"))
6071
6036
                revision_id = revision[0].as_revision_id(branch)
6074
6039
            if tag_name is None:
6075
6040
                tag_name = branch.automatic_tag_name(revision_id)
6076
6041
                if tag_name is None:
6077
 
                    raise errors.CommandError(gettext(
 
6042
                    raise errors.BzrCommandError(gettext(
6078
6043
                        "Please specify a tag name."))
6079
6044
            try:
6080
6045
                existing_target = branch.tags.lookup_tag(tag_name)
6238
6203
            stacked_on=None, unstacked=None):
6239
6204
        directory = controldir.ControlDir.open(location)
6240
6205
        if stacked_on and unstacked:
6241
 
            raise errors.CommandError(
 
6206
            raise errors.BzrCommandError(
6242
6207
                gettext("Can't use both --stacked-on and --unstacked"))
6243
6208
        elif stacked_on is not None:
6244
6209
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
6253
6218
            if stacked_on or unstacked:
6254
6219
                return
6255
6220
            else:
6256
 
                raise errors.CommandError(gettext('No target configuration '
 
6221
                raise errors.BzrCommandError(gettext('No target configuration '
6257
6222
                                                     'specified'))
6258
6223
        reconfiguration = None
6259
6224
        if tree_type == 'branch':
6332
6297
        possible_transports = [control_dir.root_transport]
6333
6298
        if to_location is None:
6334
6299
            if revision is None:
6335
 
                raise errors.CommandError(gettext('You must supply either a'
 
6300
                raise errors.BzrCommandError(gettext('You must supply either a'
6336
6301
                                                     ' revision or a location'))
6337
6302
            to_location = tree_location
6338
6303
        try:
6346
6311
            possible_transports.append(branch.user_transport)
6347
6312
        if create_branch:
6348
6313
            if branch is None:
6349
 
                raise errors.CommandError(
 
6314
                raise errors.BzrCommandError(
6350
6315
                    gettext('cannot create branch without source branch'))
6351
6316
            to_location = lookup_new_sibling_branch(
6352
6317
                control_dir, to_location,
6374
6339
                          store_uncommitted=store,
6375
6340
                          possible_transports=possible_transports)
6376
6341
        except controldir.BranchReferenceLoop:
6377
 
            raise errors.CommandError(
 
6342
            raise errors.BzrCommandError(
6378
6343
                gettext('switching would create a branch reference loop. '
6379
6344
                        'Use the "bzr up" command to switch to a '
6380
6345
                        'different revision.'))
6486
6451
            name = current_view
6487
6452
        if delete:
6488
6453
            if file_list:
6489
 
                raise errors.CommandError(gettext(
 
6454
                raise errors.BzrCommandError(gettext(
6490
6455
                    "Both --delete and a file list specified"))
6491
6456
            elif switch:
6492
 
                raise errors.CommandError(gettext(
 
6457
                raise errors.BzrCommandError(gettext(
6493
6458
                    "Both --delete and --switch specified"))
6494
6459
            elif all:
6495
6460
                tree.views.set_view_info(None, {})
6496
6461
                self.outf.write(gettext("Deleted all views.\n"))
6497
6462
            elif name is None:
6498
 
                raise errors.CommandError(
 
6463
                raise errors.BzrCommandError(
6499
6464
                    gettext("No current view to delete"))
6500
6465
            else:
6501
6466
                tree.views.delete_view(name)
6502
6467
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
6503
6468
        elif switch:
6504
6469
            if file_list:
6505
 
                raise errors.CommandError(gettext(
 
6470
                raise errors.BzrCommandError(gettext(
6506
6471
                    "Both --switch and a file list specified"))
6507
6472
            elif all:
6508
 
                raise errors.CommandError(gettext(
 
6473
                raise errors.BzrCommandError(gettext(
6509
6474
                    "Both --switch and --all specified"))
6510
6475
            elif switch == 'off':
6511
6476
                if current_view is None:
6512
 
                    raise errors.CommandError(
 
6477
                    raise errors.BzrCommandError(
6513
6478
                        gettext("No current view to disable"))
6514
6479
                tree.views.set_view_info(None, view_dict)
6515
6480
                self.outf.write(gettext("Disabled '%s' view.\n") %
6536
6501
                # No name given and no current view set
6537
6502
                name = 'my'
6538
6503
            elif name == 'off':
6539
 
                raise errors.CommandError(gettext(
 
6504
                raise errors.BzrCommandError(gettext(
6540
6505
                    "Cannot change the 'off' pseudo view"))
6541
6506
            tree.views.set_view(name, sorted(file_list))
6542
6507
            view_str = views.view_display_str(tree.views.lookup_view())
6603
6568
                active_branch = None
6604
6569
            if (active_branch is not None and
6605
6570
                    br.control_url == active_branch.control_url):
6606
 
                raise errors.CommandError(
 
6571
                raise errors.BzrCommandError(
6607
6572
                    gettext("Branch is active. Use --force to remove it."))
6608
6573
        br.controldir.destroy_branch(br.name)
6609
6574
 
6972
6937
            path_list = ['.']
6973
6938
        else:
6974
6939
            if from_root:
6975
 
                raise errors.CommandError(
 
6940
                raise errors.BzrCommandError(
6976
6941
                    'cannot specify both --from-root and PATH.')
6977
6942
 
6978
6943
        if files_with_matches and files_without_match:
6979
 
            raise errors.CommandError(
 
6944
            raise errors.BzrCommandError(
6980
6945
                'cannot specify both '
6981
6946
                '-l/--files-with-matches and -L/--files-without-matches.')
6982
6947
 
6989
6954
            color = 'never'
6990
6955
 
6991
6956
        if color not in ['always', 'never', 'auto']:
6992
 
            raise errors.CommandError('Valid values for --color are '
 
6957
            raise errors.BzrCommandError('Valid values for --color are '
6993
6958
                                         '"always", "never" or "auto".')
6994
6959
 
6995
6960
        if levels is None: