/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

Rename BzrCommandError to CommandError.

Merged from https://code.launchpad.net/~jelmer/brz/command-error/+merge/386136

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
    if revisions is None:
269
269
        return None
270
270
    if len(revisions) != 1:
271
 
        raise errors.BzrCommandError(gettext(
 
271
        raise errors.CommandError(gettext(
272
272
            'brz %s --revision takes exactly one revision identifier') % (
273
273
                command_name,))
274
274
    return revisions[0]
404
404
        from .status import show_tree_status
405
405
 
406
406
        if revision and len(revision) > 2:
407
 
            raise errors.BzrCommandError(
 
407
            raise errors.CommandError(
408
408
                gettext('brz status --revision takes exactly'
409
409
                        ' one or two revision specifiers'))
410
410
 
449
449
    @display_command
450
450
    def run(self, revision_id=None, revision=None, directory=u'.'):
451
451
        if revision_id is not None and revision is not None:
452
 
            raise errors.BzrCommandError(gettext('You can only supply one of'
 
452
            raise errors.CommandError(gettext('You can only supply one of'
453
453
                                                 ' revision_id or --revision'))
454
454
        if revision_id is None and revision is None:
455
 
            raise errors.BzrCommandError(
 
455
            raise errors.CommandError(
456
456
                gettext('You must supply either --revision or a revision_id'))
457
457
 
458
458
        b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
459
459
 
460
460
        revisions = getattr(b.repository, "revisions", None)
461
461
        if revisions is None:
462
 
            raise errors.BzrCommandError(
 
462
            raise errors.CommandError(
463
463
                gettext('Repository %r does not support '
464
464
                        'access to raw revision texts') % b.repository)
465
465
 
473
473
                    msg = gettext(
474
474
                        "The repository {0} contains no revision {1}.").format(
475
475
                            b.repository.base, revision_id.decode('utf-8'))
476
 
                    raise errors.BzrCommandError(msg)
 
476
                    raise errors.CommandError(msg)
477
477
            elif revision is not None:
478
478
                for rev in revision:
479
479
                    if rev is None:
480
 
                        raise errors.BzrCommandError(
 
480
                        raise errors.CommandError(
481
481
                            gettext('You cannot specify a NULL revision.'))
482
482
                    rev_id = rev.as_revision_id(b)
483
483
                    self.print_revision(revisions, rev_id)
509
509
            try:
510
510
                working = d.open_workingtree()
511
511
            except errors.NoWorkingTree:
512
 
                raise errors.BzrCommandError(
 
512
                raise errors.CommandError(
513
513
                    gettext("No working tree to remove"))
514
514
            except errors.NotLocalUrl:
515
 
                raise errors.BzrCommandError(
 
515
                raise errors.CommandError(
516
516
                    gettext("You cannot remove the working tree"
517
517
                            " of a remote path"))
518
518
            if not force:
522
522
                    raise errors.ShelvedChanges(working)
523
523
 
524
524
            if working.user_url != working.branch.user_url:
525
 
                raise errors.BzrCommandError(
 
525
                raise errors.CommandError(
526
526
                    gettext("You cannot remove the working tree"
527
527
                            " from a lightweight checkout"))
528
528
 
563
563
                pass  # There seems to be a real error here, so we'll reset
564
564
            else:
565
565
                # Refuse
566
 
                raise errors.BzrCommandError(gettext(
 
566
                raise errors.CommandError(gettext(
567
567
                    'The tree does not appear to be corrupt. You probably'
568
568
                    ' want "brz revert" instead. Use "--force" if you are'
569
569
                    ' sure you want to reset the working tree.'))
579
579
                                '-r -1 to set the state to the last commit')
580
580
            else:
581
581
                extra = ''
582
 
            raise errors.BzrCommandError(
 
582
            raise errors.CommandError(
583
583
                gettext('failed to reset the tree state{0}').format(extra))
584
584
 
585
585
 
599
599
    @display_command
600
600
    def run(self, tree=False, location=u'.', revision=None):
601
601
        if revision is not None and tree:
602
 
            raise errors.BzrCommandError(
 
602
            raise errors.CommandError(
603
603
                gettext("--tree and --revision can not be used together"))
604
604
 
605
605
        if tree:
615
615
            self.enter_context(b.lock_read())
616
616
            if revision:
617
617
                if len(revision) != 1:
618
 
                    raise errors.BzrCommandError(gettext(
 
618
                    raise errors.CommandError(gettext(
619
619
                        "Revision numbers only make sense for single "
620
620
                        "revisions, not ranges"))
621
621
                revid = revision[0].as_revision_id(b)
879
879
    def run(self, revision=None, show_ids=False, kind=None, include_root=False,
880
880
            file_list=None):
881
881
        if kind and kind not in ['file', 'directory', 'symlink']:
882
 
            raise errors.BzrCommandError(
 
882
            raise errors.CommandError(
883
883
                gettext('invalid kind %r specified') % (kind,))
884
884
 
885
885
        revision = _get_one_revision('inventory', revision)
942
942
        if names_list is None:
943
943
            names_list = []
944
944
        if len(names_list) < 2:
945
 
            raise errors.BzrCommandError(gettext("missing file argument"))
 
945
            raise errors.CommandError(gettext("missing file argument"))
946
946
        tree, rel_names = WorkingTree.open_containing_paths(
947
947
            names_list, canonicalize=False)
948
948
        for file_name in rel_names[0:-1]:
949
949
            if file_name == '':
950
 
                raise errors.BzrCommandError(
 
950
                raise errors.CommandError(
951
951
                    gettext("can not copy root of branch"))
952
952
        self.enter_context(tree.lock_tree_write())
953
953
        into_existing = osutils.isdir(names_list[-1])
955
955
            try:
956
956
                (src, dst) = rel_names
957
957
            except IndexError:
958
 
                raise errors.BzrCommandError(
 
958
                raise errors.CommandError(
959
959
                    gettext('to copy multiple files the'
960
960
                            ' destination must be a versioned'
961
961
                            ' directory'))
969
969
            try:
970
970
                src_kind = tree.stored_kind(src)
971
971
            except errors.NoSuchFile:
972
 
                raise errors.BzrCommandError(
 
972
                raise errors.CommandError(
973
973
                    gettext('Could not copy %s => %s: %s is not versioned.')
974
974
                    % (src, dst, src))
975
975
            if src_kind is None:
976
 
                raise errors.BzrCommandError(
 
976
                raise errors.CommandError(
977
977
                    gettext('Could not copy %s => %s . %s is not versioned\\.'
978
978
                            % (src, dst, src)))
979
979
            if src_kind == 'directory':
980
 
                raise errors.BzrCommandError(
 
980
                raise errors.CommandError(
981
981
                    gettext('Could not copy %s => %s . %s is a directory.'
982
982
                            % (src, dst, src)))
983
983
            dst_parent = osutils.split(dst)[0]
985
985
                try:
986
986
                    dst_parent_kind = tree.stored_kind(dst_parent)
987
987
                except errors.NoSuchFile:
988
 
                    raise errors.BzrCommandError(
 
988
                    raise errors.CommandError(
989
989
                        gettext('Could not copy %s => %s: %s is not versioned.')
990
990
                        % (src, dst, dst_parent))
991
991
                if dst_parent_kind != 'directory':
992
 
                    raise errors.BzrCommandError(
 
992
                    raise errors.CommandError(
993
993
                        gettext('Could not copy to %s: %s is not a directory.')
994
994
                        % (dst_parent, dst_parent))
995
995
 
1031
1031
        if auto:
1032
1032
            return self.run_auto(names_list, after, dry_run)
1033
1033
        elif dry_run:
1034
 
            raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
 
1034
            raise errors.CommandError(gettext('--dry-run requires --auto.'))
1035
1035
        if names_list is None:
1036
1036
            names_list = []
1037
1037
        if len(names_list) < 2:
1038
 
            raise errors.BzrCommandError(gettext("missing file argument"))
 
1038
            raise errors.CommandError(gettext("missing file argument"))
1039
1039
        tree, rel_names = WorkingTree.open_containing_paths(
1040
1040
            names_list, canonicalize=False)
1041
1041
        for file_name in rel_names[0:-1]:
1042
1042
            if file_name == '':
1043
 
                raise errors.BzrCommandError(
 
1043
                raise errors.CommandError(
1044
1044
                    gettext("can not move root of branch"))
1045
1045
        self.enter_context(tree.lock_tree_write())
1046
1046
        self._run(tree, names_list, rel_names, after)
1047
1047
 
1048
1048
    def run_auto(self, names_list, after, dry_run):
1049
1049
        if names_list is not None and len(names_list) > 1:
1050
 
            raise errors.BzrCommandError(
 
1050
            raise errors.CommandError(
1051
1051
                gettext('Only one path may be specified to --auto.'))
1052
1052
        if after:
1053
 
            raise errors.BzrCommandError(
 
1053
            raise errors.CommandError(
1054
1054
                gettext('--after cannot be specified with --auto.'))
1055
1055
        work_tree, file_list = WorkingTree.open_containing_paths(
1056
1056
            names_list, default_directory='.')
1087
1087
                    self.outf.write("%s => %s\n" % (src, dest))
1088
1088
        else:
1089
1089
            if len(names_list) != 2:
1090
 
                raise errors.BzrCommandError(gettext('to mv multiple files the'
 
1090
                raise errors.CommandError(gettext('to mv multiple files the'
1091
1091
                                                     ' destination must be a versioned'
1092
1092
                                                     ' directory'))
1093
1093
 
1230
1230
        stored_loc = branch_to.get_parent()
1231
1231
        if location is None:
1232
1232
            if stored_loc is None:
1233
 
                raise errors.BzrCommandError(gettext("No pull location known or"
 
1233
                raise errors.CommandError(gettext("No pull location known or"
1234
1234
                                                     " specified."))
1235
1235
            else:
1236
1236
                display_url = urlutils.unescape_for_display(stored_loc,
1243
1243
        revision = _get_one_revision('pull', revision)
1244
1244
        if mergeable is not None:
1245
1245
            if revision is not None:
1246
 
                raise errors.BzrCommandError(gettext(
 
1246
                raise errors.CommandError(gettext(
1247
1247
                    'Cannot use -r with merge directives or bundles'))
1248
1248
            mergeable.install_revisions(branch_to.repository)
1249
1249
            base_revision_id, revision_id, verified = \
1398
1398
                    # error by the feedback given to them. RBC 20080227.
1399
1399
                    stacked_on = parent_url
1400
1400
            if not stacked_on:
1401
 
                raise errors.BzrCommandError(gettext(
 
1401
                raise errors.CommandError(gettext(
1402
1402
                    "Could not determine branch to refer to."))
1403
1403
 
1404
1404
        # Get the destination location
1407
1407
            if stored_loc is None:
1408
1408
                parent_loc = br_from.get_parent()
1409
1409
                if parent_loc:
1410
 
                    raise errors.BzrCommandError(gettext(
 
1410
                    raise errors.CommandError(gettext(
1411
1411
                        "No push location known or specified. To push to the "
1412
1412
                        "parent branch (at %s), use 'brz push :parent'." %
1413
1413
                        urlutils.unescape_for_display(parent_loc,
1414
1414
                                                      self.outf.encoding)))
1415
1415
                else:
1416
 
                    raise errors.BzrCommandError(gettext(
 
1416
                    raise errors.CommandError(gettext(
1417
1417
                        "No push location known or specified."))
1418
1418
            else:
1419
1419
                display_url = urlutils.unescape_for_display(stored_loc,
1512
1512
                    to_transport)
1513
1513
            except errors.NotBranchError:
1514
1514
                if not use_existing_dir:
1515
 
                    raise errors.BzrCommandError(gettext('Target directory "%s" '
 
1515
                    raise errors.CommandError(gettext('Target directory "%s" '
1516
1516
                                                         'already exists.') % to_location)
1517
1517
                else:
1518
1518
                    to_dir = None
1524
1524
                else:
1525
1525
                    raise errors.AlreadyBranchError(to_location)
1526
1526
        except errors.NoSuchFile:
1527
 
            raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
 
1527
            raise errors.CommandError(gettext('Parent of "%s" does not exist.')
1528
1528
                                         % to_location)
1529
1529
        else:
1530
1530
            to_dir = None
1545
1545
                to_transport.delete_tree('.')
1546
1546
                msg = gettext("The branch {0} has no revision {1}.").format(
1547
1547
                    from_location, revision)
1548
 
                raise errors.BzrCommandError(msg)
 
1548
                raise errors.CommandError(msg)
1549
1549
        else:
1550
1550
            try:
1551
1551
                to_repo = to_dir.open_repository()
1601
1601
        if recursive:
1602
1602
            t = transport.get_transport(location, purpose='read')
1603
1603
            if not t.listable():
1604
 
                raise errors.BzrCommandError(
 
1604
                raise errors.CommandError(
1605
1605
                    "Can't scan this type of location.")
1606
1606
            for b in controldir.ControlDir.find_branches(t):
1607
1607
                self.outf.write("%s\n" % urlutils.unescape_for_display(
1807
1807
 
1808
1808
    def run(self, dir=None, revision=None, show_base=None):
1809
1809
        if revision is not None and len(revision) != 1:
1810
 
            raise errors.BzrCommandError(gettext(
 
1810
            raise errors.CommandError(gettext(
1811
1811
                "brz update --revision takes exactly one revision"))
1812
1812
        if dir is None:
1813
1813
            tree = WorkingTree.open_containing('.')[0]
1815
1815
            tree, relpath = WorkingTree.open_containing(dir)
1816
1816
            if relpath:
1817
1817
                # See bug 557886.
1818
 
                raise errors.BzrCommandError(gettext(
 
1818
                raise errors.CommandError(gettext(
1819
1819
                    "brz update can only update a whole tree, "
1820
1820
                    "not a file or subdirectory"))
1821
1821
        branch = tree.branch
1861
1861
                old_tip=old_tip,
1862
1862
                show_base=show_base)
1863
1863
        except errors.NoSuchRevision as e:
1864
 
            raise errors.BzrCommandError(gettext(
 
1864
            raise errors.CommandError(gettext(
1865
1865
                "branch has no revision %s\n"
1866
1866
                "brz update --revision only works"
1867
1867
                " for a revision in the branch history")
1963
1963
                                      specific_files=file_list).added
1964
1964
            file_list = sorted([f.path[1] for f in added], reverse=True)
1965
1965
            if len(file_list) == 0:
1966
 
                raise errors.BzrCommandError(gettext('No matching files.'))
 
1966
                raise errors.CommandError(gettext('No matching files.'))
1967
1967
        elif file_list is None:
1968
1968
            # missing files show up in iter_changes(basis) as
1969
1969
            # versioned-with-no-kind.
2125
2125
            to_transport.ensure_base()
2126
2126
        except errors.NoSuchFile:
2127
2127
            if not create_prefix:
2128
 
                raise errors.BzrCommandError(gettext("Parent directory of %s"
 
2128
                raise errors.CommandError(gettext("Parent directory of %s"
2129
2129
                                                     " does not exist."
2130
2130
                                                     "\nYou may supply --create-prefix to create all"
2131
2131
                                                     " leading parent directories.")
2160
2160
            try:
2161
2161
                branch.set_append_revisions_only(True)
2162
2162
            except errors.UpgradeRequired:
2163
 
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
 
2163
                raise errors.CommandError(gettext('This branch format cannot be set'
2164
2164
                                                     ' to append-revisions-only.  Try --default.'))
2165
2165
        if not is_quiet():
2166
2166
            from .info import describe_layout, describe_format
2404
2404
        elif u':' in prefix:
2405
2405
            old_label, new_label = prefix.split(u":")
2406
2406
        else:
2407
 
            raise errors.BzrCommandError(gettext(
 
2407
            raise errors.CommandError(gettext(
2408
2408
                '--prefix expects two values separated by a colon'
2409
2409
                ' (eg "old/:new/")'))
2410
2410
 
2411
2411
        if revision and len(revision) > 2:
2412
 
            raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
 
2412
            raise errors.CommandError(gettext('brz diff --revision takes exactly'
2413
2413
                                                 ' one or two revision specifiers'))
2414
2414
 
2415
2415
        if using is not None and format is not None:
2416
 
            raise errors.BzrCommandError(gettext(
 
2416
            raise errors.CommandError(gettext(
2417
2417
                '{0} and {1} are mutually exclusive').format(
2418
2418
                '--using', '--format'))
2419
2419
 
2538
2538
        return int(limitstring)
2539
2539
    except ValueError:
2540
2540
        msg = gettext("The limit argument must be an integer.")
2541
 
        raise errors.BzrCommandError(msg)
 
2541
        raise errors.CommandError(msg)
2542
2542
 
2543
2543
 
2544
2544
def _parse_levels(s):
2546
2546
        return int(s)
2547
2547
    except ValueError:
2548
2548
        msg = gettext("The levels argument must be an integer.")
2549
 
        raise errors.BzrCommandError(msg)
 
2549
        raise errors.CommandError(msg)
2550
2550
 
2551
2551
 
2552
2552
class cmd_log(Command):
2813
2813
            include_merged = False
2814
2814
        if (exclude_common_ancestry
2815
2815
                and (revision is None or len(revision) != 2)):
2816
 
            raise errors.BzrCommandError(gettext(
 
2816
            raise errors.CommandError(gettext(
2817
2817
                '--exclude-common-ancestry requires -r with two revisions'))
2818
2818
        if include_merged:
2819
2819
            if levels is None:
2820
2820
                levels = 0
2821
2821
            else:
2822
 
                raise errors.BzrCommandError(gettext(
 
2822
                raise errors.CommandError(gettext(
2823
2823
                    '{0} and {1} are mutually exclusive').format(
2824
2824
                    '--levels', '--include-merged'))
2825
2825
 
2827
2827
            if len(change) > 1:
2828
2828
                raise errors.RangeInChangeOption()
2829
2829
            if revision is not None:
2830
 
                raise errors.BzrCommandError(gettext(
 
2830
                raise errors.CommandError(gettext(
2831
2831
                    '{0} and {1} are mutually exclusive').format(
2832
2832
                    '--revision', '--change'))
2833
2833
            else:
2841
2841
                revision, file_list, self._exit_stack)
2842
2842
            for relpath, file_id, kind in file_info_list:
2843
2843
                if file_id is None:
2844
 
                    raise errors.BzrCommandError(gettext(
 
2844
                    raise errors.CommandError(gettext(
2845
2845
                        "Path unknown at end or start of revision range: %s") %
2846
2846
                        relpath)
2847
2847
                # If the relpath is the top of the tree, we log everything
2959
2959
            # b is taken from revision[0].get_branch(), and
2960
2960
            # show_log will use its revision_history. Having
2961
2961
            # different branches will lead to weird behaviors.
2962
 
            raise errors.BzrCommandError(gettext(
 
2962
            raise errors.CommandError(gettext(
2963
2963
                "brz %s doesn't accept two revisions in different"
2964
2964
                " branches.") % command_name)
2965
2965
        if start_spec.spec is None:
2975
2975
        else:
2976
2976
            rev2 = end_spec.in_history(branch)
2977
2977
    else:
2978
 
        raise errors.BzrCommandError(gettext(
 
2978
        raise errors.CommandError(gettext(
2979
2979
            'brz %s --revision takes one or two values.') % command_name)
2980
2980
    return rev1, rev2
2981
2981
 
3055
3055
            null=False, kind=None, show_ids=False, path=None, directory=None):
3056
3056
 
3057
3057
        if kind and kind not in ('file', 'directory', 'symlink', 'tree-reference'):
3058
 
            raise errors.BzrCommandError(gettext('invalid kind specified'))
 
3058
            raise errors.CommandError(gettext('invalid kind specified'))
3059
3059
 
3060
3060
        if verbose and null:
3061
 
            raise errors.BzrCommandError(
 
3061
            raise errors.CommandError(
3062
3062
                gettext('Cannot set both --verbose and --null'))
3063
3063
        all = not (unknown or versioned or ignored)
3064
3064
 
3068
3068
            fs_path = '.'
3069
3069
        else:
3070
3070
            if from_root:
3071
 
                raise errors.BzrCommandError(gettext('cannot specify both --from-root'
 
3071
                raise errors.CommandError(gettext('cannot specify both --from-root'
3072
3072
                                                     ' and PATH'))
3073
3073
            fs_path = path
3074
3074
        tree, branch, relpath = \
3245
3245
                self.outf.write("%s\n" % pattern)
3246
3246
            return
3247
3247
        if not name_pattern_list:
3248
 
            raise errors.BzrCommandError(gettext("ignore requires at least one "
 
3248
            raise errors.CommandError(gettext("ignore requires at least one "
3249
3249
                                                 "NAME_PATTERN or --default-rules."))
3250
3250
        name_pattern_list = [globbing.normalize_pattern(p)
3251
3251
                             for p in name_pattern_list]
3264
3264
        for name_pattern in name_pattern_list:
3265
3265
            if (name_pattern[0] == '/' or
3266
3266
                    (len(name_pattern) > 1 and name_pattern[1] == ':')):
3267
 
                raise errors.BzrCommandError(gettext(
 
3267
                raise errors.CommandError(gettext(
3268
3268
                    "NAME_PATTERN should not be an absolute path"))
3269
3269
        tree, relpath = WorkingTree.open_containing(directory)
3270
3270
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3325
3325
        try:
3326
3326
            revno = int(revno)
3327
3327
        except ValueError:
3328
 
            raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
 
3328
            raise errors.CommandError(gettext("not a valid revision-number: %r")
3329
3329
                                         % revno)
3330
3330
        revid = WorkingTree.open_containing(
3331
3331
            directory)[0].branch.get_rev_id(revno)
3396
3396
 
3397
3397
        if uncommitted:
3398
3398
            if tree is None:
3399
 
                raise errors.BzrCommandError(
 
3399
                raise errors.CommandError(
3400
3400
                    gettext("--uncommitted requires a working tree"))
3401
3401
            export_tree = tree
3402
3402
        else:
3424
3424
            export(export_tree, dest, format, root, subdir,
3425
3425
                   per_file_timestamps=per_file_timestamps)
3426
3426
        except errors.NoSuchExportFormat as e:
3427
 
            raise errors.BzrCommandError(
 
3427
            raise errors.CommandError(
3428
3428
                gettext('Unsupported export format: %s') % e.format)
3429
3429
 
3430
3430
 
3452
3452
    def run(self, filename, revision=None, name_from_revision=False,
3453
3453
            filters=False, directory=None):
3454
3454
        if revision is not None and len(revision) != 1:
3455
 
            raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
 
3455
            raise errors.CommandError(gettext("brz cat --revision takes exactly"
3456
3456
                                                 " one revision specifier"))
3457
3457
        tree, branch, relpath = \
3458
3458
            _open_directory_or_containing_tree_or_branch(filename, directory)
3471
3471
        if name_from_revision:
3472
3472
            # Try in revision if requested
3473
3473
            if not rev_tree.is_versioned(relpath):
3474
 
                raise errors.BzrCommandError(gettext(
 
3474
                raise errors.CommandError(gettext(
3475
3475
                    "{0!r} is not present in revision {1}").format(
3476
3476
                        filename, rev_tree.get_revision_id()))
3477
3477
            rev_tree_path = relpath
3485
3485
            if rev_tree_path is None:
3486
3486
                # Path didn't exist in working tree
3487
3487
                if not rev_tree.is_versioned(relpath):
3488
 
                    raise errors.BzrCommandError(gettext(
 
3488
                    raise errors.CommandError(gettext(
3489
3489
                        "{0!r} is not present in revision {1}").format(
3490
3490
                            filename, rev_tree.get_revision_id()))
3491
3491
                else:
3628
3628
                    default_bugtracker = branch_config.get(
3629
3629
                        "bugtracker")
3630
3630
                if default_bugtracker is None:
3631
 
                    raise errors.BzrCommandError(gettext(
 
3631
                    raise errors.CommandError(gettext(
3632
3632
                        "No tracker specified for bug %s. Use the form "
3633
3633
                        "'tracker:id' or specify a default bug tracker "
3634
3634
                        "using the `bugtracker` option.\nSee "
3637
3637
                tag = default_bugtracker
3638
3638
                bug_id = tokens[0]
3639
3639
            elif len(tokens) != 2:
3640
 
                raise errors.BzrCommandError(gettext(
 
3640
                raise errors.CommandError(gettext(
3641
3641
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3642
3642
                    "See \"brz help bugs\" for more information on this "
3643
3643
                    "feature.\nCommit refused.") % bug)
3646
3646
            try:
3647
3647
                yield bugtracker.get_bug_url(tag, branch, bug_id), status
3648
3648
            except bugtracker.UnknownBugTrackerAbbreviation:
3649
 
                raise errors.BzrCommandError(gettext(
 
3649
                raise errors.CommandError(gettext(
3650
3650
                    'Unrecognized bug %s. Commit refused.') % bug)
3651
3651
            except bugtracker.MalformedBugIdentifier as e:
3652
 
                raise errors.BzrCommandError(gettext(
 
3652
                raise errors.CommandError(gettext(
3653
3653
                    u"%s\nCommit refused.") % (e,))
3654
3654
 
3655
3655
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3676
3676
            try:
3677
3677
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3678
3678
            except ValueError as e:
3679
 
                raise errors.BzrCommandError(gettext(
 
3679
                raise errors.CommandError(gettext(
3680
3680
                    "Could not parse --commit-time: " + str(e)))
3681
3681
 
3682
3682
        properties = {}
3720
3720
                message = message.replace('\r\n', '\n')
3721
3721
                message = message.replace('\r', '\n')
3722
3722
            if file:
3723
 
                raise errors.BzrCommandError(gettext(
 
3723
                raise errors.CommandError(gettext(
3724
3724
                    "please specify either --message or --file"))
3725
3725
 
3726
3726
        def get_message(commit_obj):
3751
3751
                    my_message = edit_commit_message_encoded(text,
3752
3752
                                                             start_message=start_message)
3753
3753
                if my_message is None:
3754
 
                    raise errors.BzrCommandError(gettext("please specify a commit"
 
3754
                    raise errors.CommandError(gettext("please specify a commit"
3755
3755
                                                         " message with either --message or --file"))
3756
3756
                if my_message == "":
3757
 
                    raise errors.BzrCommandError(gettext("Empty commit message specified."
 
3757
                    raise errors.CommandError(gettext("Empty commit message specified."
3758
3758
                                                         " Please specify a commit message with either"
3759
3759
                                                         " --message or --file or leave a blank message"
3760
3760
                                                         " with --message \"\"."))
3774
3774
                        exclude=tree.safe_relpath_files(exclude),
3775
3775
                        lossy=lossy)
3776
3776
        except PointlessCommit:
3777
 
            raise errors.BzrCommandError(gettext("No changes to commit."
 
3777
            raise errors.CommandError(gettext("No changes to commit."
3778
3778
                                                 " Please 'brz add' the files you want to commit, or use"
3779
3779
                                                 " --unchanged to force an empty commit."))
3780
3780
        except ConflictsInTree:
3781
 
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
 
3781
            raise errors.CommandError(gettext('Conflicts detected in working '
3782
3782
                                                 'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
3783
3783
                                                 ' resolve.'))
3784
3784
        except StrictCommitFailed:
3785
 
            raise errors.BzrCommandError(gettext("Commit refused because there are"
 
3785
            raise errors.CommandError(gettext("Commit refused because there are"
3786
3786
                                                 " unknown files in the working tree."))
3787
3787
        except errors.BoundBranchOutOfDate as e:
3788
3788
            e.extra_help = (gettext("\n"
3964
3964
            return
3965
3965
 
3966
3966
        if email:
3967
 
            raise errors.BzrCommandError(gettext("--email can only be used to display existing "
 
3967
            raise errors.CommandError(gettext("--email can only be used to display existing "
3968
3968
                                                 "identity"))
3969
3969
 
3970
3970
        # display a warning if an email address isn't included in the given name.
4054
4054
 
4055
4055
    def remove_alias(self, alias_name):
4056
4056
        if alias_name is None:
4057
 
            raise errors.BzrCommandError(gettext(
 
4057
            raise errors.CommandError(gettext(
4058
4058
                'brz alias --remove expects an alias to remove.'))
4059
4059
        # If alias is not found, print something like:
4060
4060
        # unalias: foo: not found
4149
4149
            return test_server.FakeNFSServer
4150
4150
        msg = "No known transport type %s. Supported types are: sftp\n" %\
4151
4151
            (typestring)
4152
 
        raise errors.BzrCommandError(msg)
 
4152
        raise errors.CommandError(msg)
4153
4153
 
4154
4154
    hidden = True
4155
4155
    takes_args = ['testspecs*']
4234
4234
        try:
4235
4235
            from . import tests
4236
4236
        except ImportError as e:
4237
 
            raise errors.BzrCommandError("tests not available. Install the "
 
4237
            raise errors.CommandError("tests not available. Install the "
4238
4238
                                         "breezy tests to run the breezy testsuite.")
4239
4239
 
4240
4240
        if testspecs_list is not None:
4245
4245
            try:
4246
4246
                from .tests import SubUnitBzrRunnerv1
4247
4247
            except ImportError:
4248
 
                raise errors.BzrCommandError(gettext(
 
4248
                raise errors.CommandError(gettext(
4249
4249
                    "subunit not available. subunit needs to be installed "
4250
4250
                    "to use --subunit."))
4251
4251
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv1
4262
4262
            try:
4263
4263
                from .tests import SubUnitBzrRunnerv2
4264
4264
            except ImportError:
4265
 
                raise errors.BzrCommandError(gettext(
 
4265
                raise errors.CommandError(gettext(
4266
4266
                    "subunit not available. subunit "
4267
4267
                    "needs to be installed to use --subunit2."))
4268
4268
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv2
4271
4271
            self.additional_selftest_args.setdefault(
4272
4272
                'suite_decorators', []).append(parallel)
4273
4273
        if benchmark:
4274
 
            raise errors.BzrCommandError(gettext(
 
4274
            raise errors.CommandError(gettext(
4275
4275
                "--benchmark is no longer supported from brz 2.2; "
4276
4276
                "use bzr-usertest instead"))
4277
4277
        test_suite_factory = None
4499
4499
 
4500
4500
        tree = WorkingTree.open_containing(directory)[0]
4501
4501
        if tree.branch.last_revision() == _mod_revision.NULL_REVISION:
4502
 
            raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
 
4502
            raise errors.CommandError(gettext('Merging into empty branches not currently supported, '
4503
4503
                                                 'https://bugs.launchpad.net/bzr/+bug/308562'))
4504
4504
 
4505
4505
        # die as quickly as possible if there are uncommitted changes
4521
4521
                mergeable = None
4522
4522
            else:
4523
4523
                if uncommitted:
4524
 
                    raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
 
4524
                    raise errors.CommandError(gettext('Cannot use --uncommitted'
4525
4525
                                                         ' with bundles or merge directives.'))
4526
4526
 
4527
4527
                if revision is not None:
4528
 
                    raise errors.BzrCommandError(gettext(
 
4528
                    raise errors.CommandError(gettext(
4529
4529
                        'Cannot use -r with merge directives or bundles'))
4530
4530
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4531
4531
                                                                    mergeable)
4532
4532
 
4533
4533
        if merger is None and uncommitted:
4534
4534
            if revision is not None and len(revision) > 0:
4535
 
                raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
 
4535
                raise errors.CommandError(gettext('Cannot use --uncommitted and'
4536
4536
                                                     ' --revision at the same time.'))
4537
4537
            merger = self.get_merger_from_uncommitted(tree, location, None)
4538
4538
            allow_pending = False
4558
4558
            return 0
4559
4559
        if pull and not preview:
4560
4560
            if merger.interesting_files is not None:
4561
 
                raise errors.BzrCommandError(
 
4561
                raise errors.CommandError(
4562
4562
                    gettext('Cannot pull individual files'))
4563
4563
            if (merger.base_rev_id == tree.last_revision()):
4564
4564
                result = tree.pull(merger.other_branch, False,
4566
4566
                result.report(self.outf)
4567
4567
                return 0
4568
4568
        if merger.this_basis is None:
4569
 
            raise errors.BzrCommandError(gettext(
 
4569
            raise errors.CommandError(gettext(
4570
4570
                "This branch has no commits."
4571
4571
                " (perhaps you would prefer 'brz pull')"))
4572
4572
        if preview:
4625
4625
    def sanity_check_merger(self, merger):
4626
4626
        if (merger.show_base and
4627
4627
                merger.merge_type is not _mod_merge.Merge3Merger):
4628
 
            raise errors.BzrCommandError(gettext("Show-base is not supported for this"
 
4628
            raise errors.CommandError(gettext("Show-base is not supported for this"
4629
4629
                                                 " merge type. %s") % merger.merge_type)
4630
4630
        if merger.reprocess is None:
4631
4631
            if merger.show_base:
4634
4634
                # Use reprocess if the merger supports it
4635
4635
                merger.reprocess = merger.merge_type.supports_reprocess
4636
4636
        if merger.reprocess and not merger.merge_type.supports_reprocess:
4637
 
            raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
 
4637
            raise errors.CommandError(gettext("Conflict reduction is not supported"
4638
4638
                                                 " for merge type %s.") %
4639
4639
                                         merger.merge_type)
4640
4640
        if merger.reprocess and merger.show_base:
4641
 
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
 
4641
            raise errors.CommandError(gettext("Cannot do conflict reduction and"
4642
4642
                                                 " show base."))
4643
4643
 
4644
4644
        if (merger.merge_type.requires_file_merge_plan and
4646
4646
             not getattr(merger.other_tree, 'plan_file_merge', None) or
4647
4647
             (merger.base_tree is not None and
4648
4648
                 not getattr(merger.base_tree, 'plan_file_merge', None)))):
4649
 
            raise errors.BzrCommandError(
 
4649
            raise errors.CommandError(
4650
4650
                gettext('Plan file merge unsupported: '
4651
4651
                        'Merge type incompatible with tree formats.'))
4652
4652
 
4757
4757
            stored_location_type = "parent"
4758
4758
        mutter("%s", stored_location)
4759
4759
        if stored_location is None:
4760
 
            raise errors.BzrCommandError(
 
4760
            raise errors.CommandError(
4761
4761
                gettext("No location specified or remembered"))
4762
4762
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4763
4763
        note(gettext("{0} remembered {1} location {2}").format(verb_string,
4804
4804
        self.enter_context(tree.lock_write())
4805
4805
        parents = tree.get_parent_ids()
4806
4806
        if len(parents) != 2:
4807
 
            raise errors.BzrCommandError(
 
4807
            raise errors.CommandError(
4808
4808
                gettext("Sorry, remerge only works after normal"
4809
4809
                        " merges.  Not cherrypicking or multi-merges."))
4810
4810
        interesting_files = None
5079
5079
        if other_branch is None:
5080
5080
            other_branch = parent
5081
5081
            if other_branch is None:
5082
 
                raise errors.BzrCommandError(gettext("No peer location known"
 
5082
                raise errors.CommandError(gettext("No peer location known"
5083
5083
                                                     " or specified."))
5084
5084
            display_url = urlutils.unescape_for_display(parent,
5085
5085
                                                        self.outf.encoding)
5327
5327
 
5328
5328
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
5329
5329
        if revision_id_list is not None and revision is not None:
5330
 
            raise errors.BzrCommandError(
 
5330
            raise errors.CommandError(
5331
5331
                gettext('You can only supply one of revision_id or --revision'))
5332
5332
        if revision_id_list is None and revision is None:
5333
 
            raise errors.BzrCommandError(
 
5333
            raise errors.CommandError(
5334
5334
                gettext('You must supply either --revision or a revision_id'))
5335
5335
        b = WorkingTree.open_containing(directory)[0].branch
5336
5336
        self.enter_context(b.lock_write())
5358
5358
                if to_revid is None:
5359
5359
                    to_revno = b.revno()
5360
5360
                if from_revno is None or to_revno is None:
5361
 
                    raise errors.BzrCommandError(
 
5361
                    raise errors.CommandError(
5362
5362
                        gettext('Cannot sign a range of non-revision-history revisions'))
5363
5363
                with WriteGroup(b.repository):
5364
5364
                    for revno in range(from_revno, to_revno + 1):
5365
5365
                        b.repository.sign_revision(b.get_rev_id(revno),
5366
5366
                                                   gpg_strategy)
5367
5367
            else:
5368
 
                raise errors.BzrCommandError(
 
5368
                raise errors.CommandError(
5369
5369
                    gettext('Please supply either one revision, or a range.'))
5370
5370
 
5371
5371
 
5391
5391
            try:
5392
5392
                location = b.get_old_bound_location()
5393
5393
            except errors.UpgradeRequired:
5394
 
                raise errors.BzrCommandError(
 
5394
                raise errors.CommandError(
5395
5395
                    gettext('No location supplied.  '
5396
5396
                            'This format does not remember old locations.'))
5397
5397
            else:
5398
5398
                if location is None:
5399
5399
                    if b.get_bound_location() is not None:
5400
 
                        raise errors.BzrCommandError(
 
5400
                        raise errors.CommandError(
5401
5401
                            gettext('Branch is already bound'))
5402
5402
                    else:
5403
 
                        raise errors.BzrCommandError(
 
5403
                        raise errors.CommandError(
5404
5404
                            gettext('No location supplied'
5405
5405
                                    ' and no previous location known'))
5406
5406
        b_other = Branch.open(location)
5407
5407
        try:
5408
5408
            b.bind(b_other)
5409
5409
        except errors.DivergedBranches:
5410
 
            raise errors.BzrCommandError(
 
5410
            raise errors.CommandError(
5411
5411
                gettext('These branches have diverged.'
5412
5412
                        ' Try merging, and then bind again.'))
5413
5413
        if b.get_config().has_explicit_nickname():
5428
5428
    def run(self, directory=u'.'):
5429
5429
        b, relpath = Branch.open_containing(directory)
5430
5430
        if not b.unbind():
5431
 
            raise errors.BzrCommandError(gettext('Local branch is not bound'))
 
5431
            raise errors.CommandError(gettext('Local branch is not bound'))
5432
5432
 
5433
5433
 
5434
5434
class cmd_uncommit(Command):
5687
5687
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5688
5688
        repo = containing_tree.branch.repository
5689
5689
        if not repo.supports_rich_root():
5690
 
            raise errors.BzrCommandError(gettext(
 
5690
            raise errors.CommandError(gettext(
5691
5691
                "Can't join trees because %s doesn't support rich root data.\n"
5692
5692
                "You can use brz upgrade on the repository.")
5693
5693
                % (repo,))
5697
5697
            except BadReferenceTarget as e:
5698
5698
                # XXX: Would be better to just raise a nicely printable
5699
5699
                # exception from the real origin.  Also below.  mbp 20070306
5700
 
                raise errors.BzrCommandError(
 
5700
                raise errors.CommandError(
5701
5701
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5702
5702
        else:
5703
5703
            try:
5704
5704
                containing_tree.subsume(sub_tree)
5705
5705
            except errors.BadSubsumeSource as e:
5706
 
                raise errors.BzrCommandError(
 
5706
                raise errors.CommandError(
5707
5707
                    gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5708
5708
 
5709
5709
 
5795
5795
        if submit_branch is None:
5796
5796
            submit_branch = branch.get_parent()
5797
5797
        if submit_branch is None:
5798
 
            raise errors.BzrCommandError(
 
5798
            raise errors.CommandError(
5799
5799
                gettext('No submit branch specified or known'))
5800
5800
 
5801
5801
        stored_public_branch = branch.get_public_branch()
5805
5805
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-03
5806
5806
            branch.set_public_branch(public_branch)
5807
5807
        if not include_bundle and public_branch is None:
5808
 
            raise errors.BzrCommandError(
 
5808
            raise errors.CommandError(
5809
5809
                gettext('No public branch specified or known'))
5810
5810
        base_revision_id = None
5811
5811
        if revision is not None:
5812
5812
            if len(revision) > 2:
5813
 
                raise errors.BzrCommandError(
 
5813
                raise errors.CommandError(
5814
5814
                    gettext('brz merge-directive takes '
5815
5815
                            'at most two one revision identifiers'))
5816
5816
            revision_id = revision[-1].as_revision_id(branch)
5820
5820
            revision_id = branch.last_revision()
5821
5821
        revision_id = ensure_null(revision_id)
5822
5822
        if revision_id == NULL_REVISION:
5823
 
            raise errors.BzrCommandError(gettext('No revisions to bundle.'))
 
5823
            raise errors.CommandError(gettext('No revisions to bundle.'))
5824
5824
        directive = merge_directive.MergeDirective2.from_objects(
5825
5825
            branch.repository, revision_id, time.time(),
5826
5826
            osutils.local_time_offset(), submit_branch,
6067
6067
        self.enter_context(branch.lock_write())
6068
6068
        if delete:
6069
6069
            if tag_name is None:
6070
 
                raise errors.BzrCommandError(
 
6070
                raise errors.CommandError(
6071
6071
                    gettext("No tag specified to delete."))
6072
6072
            branch.tags.delete_tag(tag_name)
6073
6073
            note(gettext('Deleted tag %s.') % tag_name)
6074
6074
        else:
6075
6075
            if revision:
6076
6076
                if len(revision) != 1:
6077
 
                    raise errors.BzrCommandError(gettext(
 
6077
                    raise errors.CommandError(gettext(
6078
6078
                        "Tags can only be placed on a single revision, "
6079
6079
                        "not on a range"))
6080
6080
                revision_id = revision[0].as_revision_id(branch)
6083
6083
            if tag_name is None:
6084
6084
                tag_name = branch.automatic_tag_name(revision_id)
6085
6085
                if tag_name is None:
6086
 
                    raise errors.BzrCommandError(gettext(
 
6086
                    raise errors.CommandError(gettext(
6087
6087
                        "Please specify a tag name."))
6088
6088
            try:
6089
6089
                existing_target = branch.tags.lookup_tag(tag_name)
6247
6247
            stacked_on=None, unstacked=None):
6248
6248
        directory = controldir.ControlDir.open(location)
6249
6249
        if stacked_on and unstacked:
6250
 
            raise errors.BzrCommandError(
 
6250
            raise errors.CommandError(
6251
6251
                gettext("Can't use both --stacked-on and --unstacked"))
6252
6252
        elif stacked_on is not None:
6253
6253
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
6262
6262
            if stacked_on or unstacked:
6263
6263
                return
6264
6264
            else:
6265
 
                raise errors.BzrCommandError(gettext('No target configuration '
 
6265
                raise errors.CommandError(gettext('No target configuration '
6266
6266
                                                     'specified'))
6267
6267
        reconfiguration = None
6268
6268
        if tree_type == 'branch':
6341
6341
        possible_transports = [control_dir.root_transport]
6342
6342
        if to_location is None:
6343
6343
            if revision is None:
6344
 
                raise errors.BzrCommandError(gettext('You must supply either a'
 
6344
                raise errors.CommandError(gettext('You must supply either a'
6345
6345
                                                     ' revision or a location'))
6346
6346
            to_location = tree_location
6347
6347
        try:
6355
6355
            possible_transports.append(branch.user_transport)
6356
6356
        if create_branch:
6357
6357
            if branch is None:
6358
 
                raise errors.BzrCommandError(
 
6358
                raise errors.CommandError(
6359
6359
                    gettext('cannot create branch without source branch'))
6360
6360
            to_location = lookup_new_sibling_branch(
6361
6361
                control_dir, to_location,
6383
6383
                          store_uncommitted=store,
6384
6384
                          possible_transports=possible_transports)
6385
6385
        except controldir.BranchReferenceLoop:
6386
 
            raise errors.BzrCommandError(
 
6386
            raise errors.CommandError(
6387
6387
                gettext('switching would create a branch reference loop. '
6388
6388
                        'Use the "bzr up" command to switch to a '
6389
6389
                        'different revision.'))
6495
6495
            name = current_view
6496
6496
        if delete:
6497
6497
            if file_list:
6498
 
                raise errors.BzrCommandError(gettext(
 
6498
                raise errors.CommandError(gettext(
6499
6499
                    "Both --delete and a file list specified"))
6500
6500
            elif switch:
6501
 
                raise errors.BzrCommandError(gettext(
 
6501
                raise errors.CommandError(gettext(
6502
6502
                    "Both --delete and --switch specified"))
6503
6503
            elif all:
6504
6504
                tree.views.set_view_info(None, {})
6505
6505
                self.outf.write(gettext("Deleted all views.\n"))
6506
6506
            elif name is None:
6507
 
                raise errors.BzrCommandError(
 
6507
                raise errors.CommandError(
6508
6508
                    gettext("No current view to delete"))
6509
6509
            else:
6510
6510
                tree.views.delete_view(name)
6511
6511
                self.outf.write(gettext("Deleted '%s' view.\n") % name)
6512
6512
        elif switch:
6513
6513
            if file_list:
6514
 
                raise errors.BzrCommandError(gettext(
 
6514
                raise errors.CommandError(gettext(
6515
6515
                    "Both --switch and a file list specified"))
6516
6516
            elif all:
6517
 
                raise errors.BzrCommandError(gettext(
 
6517
                raise errors.CommandError(gettext(
6518
6518
                    "Both --switch and --all specified"))
6519
6519
            elif switch == 'off':
6520
6520
                if current_view is None:
6521
 
                    raise errors.BzrCommandError(
 
6521
                    raise errors.CommandError(
6522
6522
                        gettext("No current view to disable"))
6523
6523
                tree.views.set_view_info(None, view_dict)
6524
6524
                self.outf.write(gettext("Disabled '%s' view.\n") %
6545
6545
                # No name given and no current view set
6546
6546
                name = 'my'
6547
6547
            elif name == 'off':
6548
 
                raise errors.BzrCommandError(gettext(
 
6548
                raise errors.CommandError(gettext(
6549
6549
                    "Cannot change the 'off' pseudo view"))
6550
6550
            tree.views.set_view(name, sorted(file_list))
6551
6551
            view_str = views.view_display_str(tree.views.lookup_view())
6612
6612
                active_branch = None
6613
6613
            if (active_branch is not None and
6614
6614
                    br.control_url == active_branch.control_url):
6615
 
                raise errors.BzrCommandError(
 
6615
                raise errors.CommandError(
6616
6616
                    gettext("Branch is active. Use --force to remove it."))
6617
6617
        br.controldir.destroy_branch(br.name)
6618
6618
 
6981
6981
            path_list = ['.']
6982
6982
        else:
6983
6983
            if from_root:
6984
 
                raise errors.BzrCommandError(
 
6984
                raise errors.CommandError(
6985
6985
                    'cannot specify both --from-root and PATH.')
6986
6986
 
6987
6987
        if files_with_matches and files_without_match:
6988
 
            raise errors.BzrCommandError(
 
6988
            raise errors.CommandError(
6989
6989
                'cannot specify both '
6990
6990
                '-l/--files-with-matches and -L/--files-without-matches.')
6991
6991
 
6998
6998
            color = 'never'
6999
6999
 
7000
7000
        if color not in ['always', 'never', 'auto']:
7001
 
            raise errors.BzrCommandError('Valid values for --color are '
 
7001
            raise errors.CommandError('Valid values for --color are '
7002
7002
                                         '"always", "never" or "auto".')
7003
7003
 
7004
7004
        if levels is None: