63
63
from breezy.branch import Branch
64
from breezy.conflicts import ConflictList
65
64
from breezy.transport import memory
66
65
from breezy.smtp_connection import SMTPConnection
67
66
from breezy.workingtree import WorkingTree
396
395
from .status import show_tree_status
398
397
if revision and len(revision) > 2:
399
raise errors.BzrCommandError(
398
raise errors.CommandError(
400
399
gettext('brz status --revision takes exactly'
401
400
' one or two revision specifiers'))
442
441
def run(self, revision_id=None, revision=None, directory=u'.'):
443
442
if revision_id is not None and revision is not None:
444
raise errors.BzrCommandError(gettext('You can only supply one of'
443
raise errors.CommandError(gettext('You can only supply one of'
445
444
' revision_id or --revision'))
446
445
if revision_id is None and revision is None:
447
raise errors.BzrCommandError(
446
raise errors.CommandError(
448
447
gettext('You must supply either --revision or a revision_id'))
450
449
b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
452
451
revisions = getattr(b.repository, "revisions", None)
453
452
if revisions is None:
454
raise errors.BzrCommandError(
453
raise errors.CommandError(
455
454
gettext('Repository %r does not support '
456
455
'access to raw revision texts') % b.repository)
466
465
"The repository {0} contains no revision {1}.").format(
467
466
b.repository.base, revision_id.decode('utf-8'))
468
raise errors.BzrCommandError(msg)
467
raise errors.CommandError(msg)
469
468
elif revision is not None:
470
469
for rev in revision:
472
raise errors.BzrCommandError(
471
raise errors.CommandError(
473
472
gettext('You cannot specify a NULL revision.'))
474
473
rev_id = rev.as_revision_id(b)
475
474
self.print_revision(revisions, rev_id)
502
501
working = d.open_workingtree()
503
502
except errors.NoWorkingTree:
504
raise errors.BzrCommandError(
503
raise errors.CommandError(
505
504
gettext("No working tree to remove"))
506
505
except errors.NotLocalUrl:
507
raise errors.BzrCommandError(
506
raise errors.CommandError(
508
507
gettext("You cannot remove the working tree"
509
508
" of a remote path"))
514
513
raise errors.ShelvedChanges(working)
516
515
if working.user_url != working.branch.user_url:
517
raise errors.BzrCommandError(
516
raise errors.CommandError(
518
517
gettext("You cannot remove the working tree"
519
518
" from a lightweight checkout"))
555
554
pass # There seems to be a real error here, so we'll reset
558
raise errors.BzrCommandError(gettext(
557
raise errors.CommandError(gettext(
559
558
'The tree does not appear to be corrupt. You probably'
560
559
' want "brz revert" instead. Use "--force" if you are'
561
560
' sure you want to reset the working tree.'))
592
591
def run(self, tree=False, location=u'.', revision=None):
593
592
if revision is not None and tree:
594
raise errors.BzrCommandError(
593
raise errors.CommandError(
595
594
gettext("--tree and --revision can not be used together"))
607
606
self.enter_context(b.lock_read())
609
608
if len(revision) != 1:
610
raise errors.BzrCommandError(gettext(
609
raise errors.CommandError(gettext(
611
610
"Revision numbers only make sense for single "
612
611
"revisions, not ranges"))
613
612
revid = revision[0].as_revision_id(b)
871
870
def run(self, revision=None, show_ids=False, kind=None, include_root=False,
873
872
if kind and kind not in ['file', 'directory', 'symlink']:
874
raise errors.BzrCommandError(
873
raise errors.CommandError(
875
874
gettext('invalid kind %r specified') % (kind,))
877
876
revision = _get_one_revision('inventory', revision)
934
933
if names_list is None:
936
935
if len(names_list) < 2:
937
raise errors.BzrCommandError(gettext("missing file argument"))
936
raise errors.CommandError(gettext("missing file argument"))
938
937
tree, rel_names = WorkingTree.open_containing_paths(
939
938
names_list, canonicalize=False)
940
939
for file_name in rel_names[0:-1]:
941
940
if file_name == '':
942
raise errors.BzrCommandError(
941
raise errors.CommandError(
943
942
gettext("can not copy root of branch"))
944
943
self.enter_context(tree.lock_tree_write())
945
944
into_existing = osutils.isdir(names_list[-1])
962
961
src_kind = tree.stored_kind(src)
963
962
except errors.NoSuchFile:
964
raise errors.BzrCommandError(
963
raise errors.CommandError(
965
964
gettext('Could not copy %s => %s: %s is not versioned.')
966
965
% (src, dst, src))
967
966
if src_kind is None:
968
raise errors.BzrCommandError(
967
raise errors.CommandError(
969
968
gettext('Could not copy %s => %s . %s is not versioned\\.'
970
969
% (src, dst, src)))
971
970
if src_kind == 'directory':
972
raise errors.BzrCommandError(
971
raise errors.CommandError(
973
972
gettext('Could not copy %s => %s . %s is a directory.'
974
973
% (src, dst, src)))
975
974
dst_parent = osutils.split(dst)[0]
978
977
dst_parent_kind = tree.stored_kind(dst_parent)
979
978
except errors.NoSuchFile:
980
raise errors.BzrCommandError(
979
raise errors.CommandError(
981
980
gettext('Could not copy %s => %s: %s is not versioned.')
982
981
% (src, dst, dst_parent))
983
982
if dst_parent_kind != 'directory':
984
raise errors.BzrCommandError(
983
raise errors.CommandError(
985
984
gettext('Could not copy to %s: %s is not a directory.')
986
985
% (dst_parent, dst_parent))
1024
1023
return self.run_auto(names_list, after, dry_run)
1026
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
1025
raise errors.CommandError(gettext('--dry-run requires --auto.'))
1027
1026
if names_list is None:
1028
1027
names_list = []
1029
1028
if len(names_list) < 2:
1030
raise errors.BzrCommandError(gettext("missing file argument"))
1029
raise errors.CommandError(gettext("missing file argument"))
1031
1030
tree, rel_names = WorkingTree.open_containing_paths(
1032
1031
names_list, canonicalize=False)
1033
1032
for file_name in rel_names[0:-1]:
1034
1033
if file_name == '':
1035
raise errors.BzrCommandError(
1034
raise errors.CommandError(
1036
1035
gettext("can not move root of branch"))
1037
1036
self.enter_context(tree.lock_tree_write())
1038
1037
self._run(tree, names_list, rel_names, after)
1040
1039
def run_auto(self, names_list, after, dry_run):
1041
1040
if names_list is not None and len(names_list) > 1:
1042
raise errors.BzrCommandError(
1041
raise errors.CommandError(
1043
1042
gettext('Only one path may be specified to --auto.'))
1045
raise errors.BzrCommandError(
1044
raise errors.CommandError(
1046
1045
gettext('--after cannot be specified with --auto.'))
1047
1046
work_tree, file_list = WorkingTree.open_containing_paths(
1048
1047
names_list, default_directory='.')
1079
1078
self.outf.write("%s => %s\n" % (src, dest))
1081
1080
if len(names_list) != 2:
1082
raise errors.BzrCommandError(gettext('to mv multiple files the'
1081
raise errors.CommandError(gettext('to mv multiple files the'
1083
1082
' destination must be a versioned'
1222
1221
stored_loc = branch_to.get_parent()
1223
1222
if location is None:
1224
1223
if stored_loc is None:
1225
raise errors.BzrCommandError(gettext("No pull location known or"
1224
raise errors.CommandError(gettext("No pull location known or"
1226
1225
" specified."))
1228
1227
display_url = urlutils.unescape_for_display(stored_loc,
1235
1234
revision = _get_one_revision('pull', revision)
1236
1235
if mergeable is not None:
1237
1236
if revision is not None:
1238
raise errors.BzrCommandError(gettext(
1237
raise errors.CommandError(gettext(
1239
1238
'Cannot use -r with merge directives or bundles'))
1240
1239
mergeable.install_revisions(branch_to.repository)
1241
1240
base_revision_id, revision_id, verified = \
1390
1389
# error by the feedback given to them. RBC 20080227.
1391
1390
stacked_on = parent_url
1392
1391
if not stacked_on:
1393
raise errors.BzrCommandError(gettext(
1392
raise errors.CommandError(gettext(
1394
1393
"Could not determine branch to refer to."))
1396
1395
# Get the destination location
1399
1398
if stored_loc is None:
1400
1399
parent_loc = br_from.get_parent()
1402
raise errors.BzrCommandError(gettext(
1401
raise errors.CommandError(gettext(
1403
1402
"No push location known or specified. To push to the "
1404
1403
"parent branch (at %s), use 'brz push :parent'." %
1405
1404
urlutils.unescape_for_display(parent_loc,
1406
1405
self.outf.encoding)))
1408
raise errors.BzrCommandError(gettext(
1407
raise errors.CommandError(gettext(
1409
1408
"No push location known or specified."))
1411
1410
display_url = urlutils.unescape_for_display(stored_loc,
1434
1433
parameter, as in "branch foo/bar -r 5".
1437
1437
_see_also = ['checkout']
1438
1438
takes_args = ['from_location', 'to_location?']
1439
1439
takes_options = ['revision',
1461
1461
help="Bind new branch to from location."),
1462
1462
Option('no-recurse-nested',
1463
1463
help='Do not recursively check out nested trees.'),
1464
Option('colocated-branch', short_name='b',
1465
type=str, help='Name of colocated branch to sprout.'),
1466
1468
def run(self, from_location, to_location=None, revision=None,
1467
1469
hardlink=False, stacked=False, standalone=False, no_tree=False,
1468
1470
use_existing_dir=False, switch=False, bind=False,
1469
files_from=None, no_recurse_nested=False):
1471
files_from=None, no_recurse_nested=False, colocated_branch=None):
1470
1472
from breezy import switch as _mod_switch
1471
1473
accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1474
from_location, name=colocated_branch)
1473
1475
if no_recurse_nested:
1474
1476
recurse = 'none'
1514
1516
raise errors.AlreadyBranchError(to_location)
1515
1517
except errors.NoSuchFile:
1516
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1518
raise errors.CommandError(gettext('Parent of "%s" does not exist.')
1534
1536
to_transport.delete_tree('.')
1535
1537
msg = gettext("The branch {0} has no revision {1}.").format(
1536
1538
from_location, revision)
1537
raise errors.BzrCommandError(msg)
1539
raise errors.CommandError(msg)
1540
1542
to_repo = to_dir.open_repository()
1591
1593
t = transport.get_transport(location, purpose='read')
1592
1594
if not t.listable():
1593
raise errors.BzrCommandError(
1595
raise errors.CommandError(
1594
1596
"Can't scan this type of location.")
1595
1597
for b in controldir.ControlDir.find_branches(t):
1596
1598
self.outf.write("%s\n" % urlutils.unescape_for_display(
1695
1697
accelerator_tree, hardlink)
1700
class cmd_clone(Command):
1701
__doc__ = """Clone a control directory.
1704
takes_args = ['from_location', 'to_location?']
1705
takes_options = ['revision',
1706
Option('no-recurse-nested',
1707
help='Do not recursively check out nested trees.'),
1710
def run(self, from_location, to_location=None, revision=None, no_recurse_nested=False):
1711
accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1713
if no_recurse_nested:
1717
revision = _get_one_revision('branch', revision)
1718
self.enter_context(br_from.lock_read())
1719
if revision is not None:
1720
revision_id = revision.as_revision_id(br_from)
1722
# FIXME - wt.last_revision, fallback to branch, fall back to
1723
# None or perhaps NULL_REVISION to mean copy nothing
1725
revision_id = br_from.last_revision()
1726
if to_location is None:
1727
to_location = urlutils.derive_to_location(from_location)
1728
target_controldir = br_from.controldir.clone(to_location, revision_id=revision_id)
1729
note(gettext('Created new control directory.'))
1698
1732
class cmd_renames(Command):
1699
1733
__doc__ = """Show list of renamed files.
1764
1798
def run(self, dir=None, revision=None, show_base=None):
1765
1799
if revision is not None and len(revision) != 1:
1766
raise errors.BzrCommandError(gettext(
1800
raise errors.CommandError(gettext(
1767
1801
"brz update --revision takes exactly one revision"))
1768
1802
if dir is None:
1769
1803
tree = WorkingTree.open_containing('.')[0]
1771
1805
tree, relpath = WorkingTree.open_containing(dir)
1773
1807
# See bug 557886.
1774
raise errors.BzrCommandError(gettext(
1808
raise errors.CommandError(gettext(
1775
1809
"brz update can only update a whole tree, "
1776
1810
"not a file or subdirectory"))
1777
1811
branch = tree.branch
1817
1851
old_tip=old_tip,
1818
1852
show_base=show_base)
1819
1853
except errors.NoSuchRevision as e:
1820
raise errors.BzrCommandError(gettext(
1854
raise errors.CommandError(gettext(
1821
1855
"branch has no revision %s\n"
1822
1856
"brz update --revision only works"
1823
1857
" for a revision in the branch history")
1919
1953
specific_files=file_list).added
1920
1954
file_list = sorted([f.path[1] for f in added], reverse=True)
1921
1955
if len(file_list) == 0:
1922
raise errors.BzrCommandError(gettext('No matching files.'))
1956
raise errors.CommandError(gettext('No matching files.'))
1923
1957
elif file_list is None:
1924
1958
# missing files show up in iter_changes(basis) as
1925
1959
# versioned-with-no-kind.
2081
2115
to_transport.ensure_base()
2082
2116
except errors.NoSuchFile:
2083
2117
if not create_prefix:
2084
raise errors.BzrCommandError(gettext("Parent directory of %s"
2118
raise errors.CommandError(gettext("Parent directory of %s"
2085
2119
" does not exist."
2086
2120
"\nYou may supply --create-prefix to create all"
2087
2121
" leading parent directories.")
2117
2151
branch.set_append_revisions_only(True)
2118
2152
except errors.UpgradeRequired:
2119
raise errors.BzrCommandError(gettext('This branch format cannot be set'
2153
raise errors.CommandError(gettext('This branch format cannot be set'
2120
2154
' to append-revisions-only. Try --default.'))
2121
2155
if not is_quiet():
2122
2156
from .info import describe_layout, describe_format
2360
2394
elif u':' in prefix:
2361
2395
old_label, new_label = prefix.split(u":")
2363
raise errors.BzrCommandError(gettext(
2397
raise errors.CommandError(gettext(
2364
2398
'--prefix expects two values separated by a colon'
2365
2399
' (eg "old/:new/")'))
2367
2401
if revision and len(revision) > 2:
2368
raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
2402
raise errors.CommandError(gettext('brz diff --revision takes exactly'
2369
2403
' one or two revision specifiers'))
2371
2405
if using is not None and format is not None:
2372
raise errors.BzrCommandError(gettext(
2406
raise errors.CommandError(gettext(
2373
2407
'{0} and {1} are mutually exclusive').format(
2374
2408
'--using', '--format'))
2769
2803
include_merged = False
2770
2804
if (exclude_common_ancestry
2771
2805
and (revision is None or len(revision) != 2)):
2772
raise errors.BzrCommandError(gettext(
2806
raise errors.CommandError(gettext(
2773
2807
'--exclude-common-ancestry requires -r with two revisions'))
2774
2808
if include_merged:
2775
2809
if levels is None:
2778
raise errors.BzrCommandError(gettext(
2812
raise errors.CommandError(gettext(
2779
2813
'{0} and {1} are mutually exclusive').format(
2780
2814
'--levels', '--include-merged'))
2783
2817
if len(change) > 1:
2784
2818
raise errors.RangeInChangeOption()
2785
2819
if revision is not None:
2786
raise errors.BzrCommandError(gettext(
2820
raise errors.CommandError(gettext(
2787
2821
'{0} and {1} are mutually exclusive').format(
2788
2822
'--revision', '--change'))
2790
2824
revision = change
2793
2827
filter_by_dir = False
2795
2829
# find the file ids to log and check for directory filtering
2796
2830
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2797
2831
revision, file_list, self._exit_stack)
2798
for relpath, file_id, kind in file_info_list:
2800
raise errors.BzrCommandError(gettext(
2832
for relpath, kind in file_info_list:
2834
raise errors.CommandError(gettext(
2801
2835
"Path unknown at end or start of revision range: %s") %
2803
2837
# If the relpath is the top of the tree, we log everything
2804
2838
if relpath == '':
2808
file_ids.append(file_id)
2842
files.append(relpath)
2809
2843
filter_by_dir = filter_by_dir or (
2810
2844
kind in ['directory', 'tree-reference'])
2868
2902
# original algorithm - per-file-graph - for the "single
2869
2903
# file that isn't a directory without showing a delta" case.
2870
2904
partial_history = revision and b.repository._format.supports_chks
2871
match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2905
match_using_deltas = (len(files) != 1 or filter_by_dir
2872
2906
or delta_type or partial_history)
2874
2908
match_dict = {}
2884
2918
match_dict['bugs'] = match_bugs
2886
2920
# Build the LogRequest and execute it
2887
if len(file_ids) == 0:
2889
2923
rqst = make_log_request_dict(
2890
direction=direction, specific_fileids=file_ids,
2924
direction=direction, specific_files=files,
2891
2925
start_revision=rev1, end_revision=rev2, limit=limit,
2892
2926
message_search=message, delta_type=delta_type,
2893
2927
diff_type=diff_type, _match_using_deltas=match_using_deltas,
2915
2949
# b is taken from revision[0].get_branch(), and
2916
2950
# show_log will use its revision_history. Having
2917
2951
# different branches will lead to weird behaviors.
2918
raise errors.BzrCommandError(gettext(
2952
raise errors.CommandError(gettext(
2919
2953
"brz %s doesn't accept two revisions in different"
2920
2954
" branches.") % command_name)
2921
2955
if start_spec.spec is None:
3011
3045
null=False, kind=None, show_ids=False, path=None, directory=None):
3013
3047
if kind and kind not in ('file', 'directory', 'symlink', 'tree-reference'):
3014
raise errors.BzrCommandError(gettext('invalid kind specified'))
3048
raise errors.CommandError(gettext('invalid kind specified'))
3016
3050
if verbose and null:
3017
raise errors.BzrCommandError(
3051
raise errors.CommandError(
3018
3052
gettext('Cannot set both --verbose and --null'))
3019
3053
all = not (unknown or versioned or ignored)
3201
3235
self.outf.write("%s\n" % pattern)
3203
3237
if not name_pattern_list:
3204
raise errors.BzrCommandError(gettext("ignore requires at least one "
3238
raise errors.CommandError(gettext("ignore requires at least one "
3205
3239
"NAME_PATTERN or --default-rules."))
3206
3240
name_pattern_list = [globbing.normalize_pattern(p)
3207
3241
for p in name_pattern_list]
3220
3254
for name_pattern in name_pattern_list:
3221
3255
if (name_pattern[0] == '/' or
3222
3256
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3223
raise errors.BzrCommandError(gettext(
3257
raise errors.CommandError(gettext(
3224
3258
"NAME_PATTERN should not be an absolute path"))
3225
3259
tree, relpath = WorkingTree.open_containing(directory)
3226
3260
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3282
3316
revno = int(revno)
3283
3317
except ValueError:
3284
raise errors.BzrCommandError(gettext("not a valid revision-number: %r")
3318
raise errors.CommandError(gettext("not a valid revision-number: %r")
3286
3320
revid = WorkingTree.open_containing(
3287
3321
directory)[0].branch.get_rev_id(revno)
3380
3414
export(export_tree, dest, format, root, subdir,
3381
3415
per_file_timestamps=per_file_timestamps)
3382
3416
except errors.NoSuchExportFormat as e:
3383
raise errors.BzrCommandError(
3417
raise errors.CommandError(
3384
3418
gettext('Unsupported export format: %s') % e.format)
3408
3442
def run(self, filename, revision=None, name_from_revision=False,
3409
3443
filters=False, directory=None):
3410
3444
if revision is not None and len(revision) != 1:
3411
raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
3445
raise errors.CommandError(gettext("brz cat --revision takes exactly"
3412
3446
" one revision specifier"))
3413
3447
tree, branch, relpath = \
3414
3448
_open_directory_or_containing_tree_or_branch(filename, directory)
3427
3461
if name_from_revision:
3428
3462
# Try in revision if requested
3429
3463
if not rev_tree.is_versioned(relpath):
3430
raise errors.BzrCommandError(gettext(
3464
raise errors.CommandError(gettext(
3431
3465
"{0!r} is not present in revision {1}").format(
3432
3466
filename, rev_tree.get_revision_id()))
3433
3467
rev_tree_path = relpath
3441
3475
if rev_tree_path is None:
3442
3476
# Path didn't exist in working tree
3443
3477
if not rev_tree.is_versioned(relpath):
3444
raise errors.BzrCommandError(gettext(
3478
raise errors.CommandError(gettext(
3445
3479
"{0!r} is not present in revision {1}").format(
3446
3480
filename, rev_tree.get_revision_id()))
3584
3618
default_bugtracker = branch_config.get(
3586
3620
if default_bugtracker is None:
3587
raise errors.BzrCommandError(gettext(
3621
raise errors.CommandError(gettext(
3588
3622
"No tracker specified for bug %s. Use the form "
3589
3623
"'tracker:id' or specify a default bug tracker "
3590
3624
"using the `bugtracker` option.\nSee "
3593
3627
tag = default_bugtracker
3594
3628
bug_id = tokens[0]
3595
3629
elif len(tokens) != 2:
3596
raise errors.BzrCommandError(gettext(
3630
raise errors.CommandError(gettext(
3597
3631
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3598
3632
"See \"brz help bugs\" for more information on this "
3599
3633
"feature.\nCommit refused.") % bug)
3603
3637
yield bugtracker.get_bug_url(tag, branch, bug_id), status
3604
3638
except bugtracker.UnknownBugTrackerAbbreviation:
3605
raise errors.BzrCommandError(gettext(
3639
raise errors.CommandError(gettext(
3606
3640
'Unrecognized bug %s. Commit refused.') % bug)
3607
3641
except bugtracker.MalformedBugIdentifier as e:
3608
raise errors.BzrCommandError(gettext(
3642
raise errors.CommandError(gettext(
3609
3643
u"%s\nCommit refused.") % (e,))
3611
3645
def run(self, message=None, file=None, verbose=False, selected_list=None,
3633
3667
commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3634
3668
except ValueError as e:
3635
raise errors.BzrCommandError(gettext(
3669
raise errors.CommandError(gettext(
3636
3670
"Could not parse --commit-time: " + str(e)))
3638
3672
properties = {}
3676
3710
message = message.replace('\r\n', '\n')
3677
3711
message = message.replace('\r', '\n')
3679
raise errors.BzrCommandError(gettext(
3713
raise errors.CommandError(gettext(
3680
3714
"please specify either --message or --file"))
3682
3716
def get_message(commit_obj):
3707
3741
my_message = edit_commit_message_encoded(text,
3708
3742
start_message=start_message)
3709
3743
if my_message is None:
3710
raise errors.BzrCommandError(gettext("please specify a commit"
3744
raise errors.CommandError(gettext("please specify a commit"
3711
3745
" message with either --message or --file"))
3712
3746
if my_message == "":
3713
raise errors.BzrCommandError(gettext("Empty commit message specified."
3747
raise errors.CommandError(gettext("Empty commit message specified."
3714
3748
" Please specify a commit message with either"
3715
3749
" --message or --file or leave a blank message"
3716
3750
" with --message \"\"."))
3730
3764
exclude=tree.safe_relpath_files(exclude),
3732
3766
except PointlessCommit:
3733
raise errors.BzrCommandError(gettext("No changes to commit."
3767
raise errors.CommandError(gettext("No changes to commit."
3734
3768
" Please 'brz add' the files you want to commit, or use"
3735
3769
" --unchanged to force an empty commit."))
3736
3770
except ConflictsInTree:
3737
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3771
raise errors.CommandError(gettext('Conflicts detected in working '
3738
3772
'tree. Use "brz conflicts" to list, "brz resolve FILE" to'
3740
3774
except StrictCommitFailed:
3741
raise errors.BzrCommandError(gettext("Commit refused because there are"
3775
raise errors.CommandError(gettext("Commit refused because there are"
3742
3776
" unknown files in the working tree."))
3743
3777
except errors.BoundBranchOutOfDate as e:
3744
3778
e.extra_help = (gettext("\n"
4011
4045
def remove_alias(self, alias_name):
4012
4046
if alias_name is None:
4013
raise errors.BzrCommandError(gettext(
4047
raise errors.CommandError(gettext(
4014
4048
'brz alias --remove expects an alias to remove.'))
4015
4049
# If alias is not found, print something like:
4016
4050
# unalias: foo: not found
4105
4139
return test_server.FakeNFSServer
4106
4140
msg = "No known transport type %s. Supported types are: sftp\n" %\
4108
raise errors.BzrCommandError(msg)
4142
raise errors.CommandError(msg)
4111
4145
takes_args = ['testspecs*']
4202
4236
from .tests import SubUnitBzrRunnerv1
4203
4237
except ImportError:
4204
raise errors.BzrCommandError(gettext(
4238
raise errors.CommandError(gettext(
4205
4239
"subunit not available. subunit needs to be installed "
4206
4240
"to use --subunit."))
4207
4241
self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv1
4219
4253
from .tests import SubUnitBzrRunnerv2
4220
4254
except ImportError:
4221
raise errors.BzrCommandError(gettext(
4255
raise errors.CommandError(gettext(
4222
4256
"subunit not available. subunit "
4223
4257
"needs to be installed to use --subunit2."))
4224
4258
self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv2
4227
4261
self.additional_selftest_args.setdefault(
4228
4262
'suite_decorators', []).append(parallel)
4230
raise errors.BzrCommandError(gettext(
4264
raise errors.CommandError(gettext(
4231
4265
"--benchmark is no longer supported from brz 2.2; "
4232
4266
"use bzr-usertest instead"))
4233
4267
test_suite_factory = None
4456
4490
tree = WorkingTree.open_containing(directory)[0]
4457
4491
if tree.branch.last_revision() == _mod_revision.NULL_REVISION:
4458
raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
4492
raise errors.CommandError(gettext('Merging into empty branches not currently supported, '
4459
4493
'https://bugs.launchpad.net/bzr/+bug/308562'))
4461
4495
# die as quickly as possible if there are uncommitted changes
4477
4511
mergeable = None
4479
4513
if uncommitted:
4480
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4514
raise errors.CommandError(gettext('Cannot use --uncommitted'
4481
4515
' with bundles or merge directives.'))
4483
4517
if revision is not None:
4484
raise errors.BzrCommandError(gettext(
4518
raise errors.CommandError(gettext(
4485
4519
'Cannot use -r with merge directives or bundles'))
4486
4520
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4489
4523
if merger is None and uncommitted:
4490
4524
if revision is not None and len(revision) > 0:
4491
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4525
raise errors.CommandError(gettext('Cannot use --uncommitted and'
4492
4526
' --revision at the same time.'))
4493
4527
merger = self.get_merger_from_uncommitted(tree, location, None)
4494
4528
allow_pending = False
4515
4549
if pull and not preview:
4516
4550
if merger.interesting_files is not None:
4517
raise errors.BzrCommandError(
4551
raise errors.CommandError(
4518
4552
gettext('Cannot pull individual files'))
4519
4553
if (merger.base_rev_id == tree.last_revision()):
4520
4554
result = tree.pull(merger.other_branch, False,
4522
4556
result.report(self.outf)
4524
4558
if merger.this_basis is None:
4525
raise errors.BzrCommandError(gettext(
4559
raise errors.CommandError(gettext(
4526
4560
"This branch has no commits."
4527
4561
" (perhaps you would prefer 'brz pull')"))
4581
4615
def sanity_check_merger(self, merger):
4582
4616
if (merger.show_base and
4583
4617
merger.merge_type is not _mod_merge.Merge3Merger):
4584
raise errors.BzrCommandError(gettext("Show-base is not supported for this"
4618
raise errors.CommandError(gettext("Show-base is not supported for this"
4585
4619
" merge type. %s") % merger.merge_type)
4586
4620
if merger.reprocess is None:
4587
4621
if merger.show_base:
4590
4624
# Use reprocess if the merger supports it
4591
4625
merger.reprocess = merger.merge_type.supports_reprocess
4592
4626
if merger.reprocess and not merger.merge_type.supports_reprocess:
4593
raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
4627
raise errors.CommandError(gettext("Conflict reduction is not supported"
4594
4628
" for merge type %s.") %
4595
4629
merger.merge_type)
4596
4630
if merger.reprocess and merger.show_base:
4597
raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
4631
raise errors.CommandError(gettext("Cannot do conflict reduction and"
4598
4632
" show base."))
4600
4634
if (merger.merge_type.requires_file_merge_plan and
4602
4636
not getattr(merger.other_tree, 'plan_file_merge', None) or
4603
4637
(merger.base_tree is not None and
4604
4638
not getattr(merger.base_tree, 'plan_file_merge', None)))):
4605
raise errors.BzrCommandError(
4639
raise errors.CommandError(
4606
4640
gettext('Plan file merge unsupported: '
4607
4641
'Merge type incompatible with tree formats.'))
4713
4747
stored_location_type = "parent"
4714
4748
mutter("%s", stored_location)
4715
4749
if stored_location is None:
4716
raise errors.BzrCommandError(
4750
raise errors.CommandError(
4717
4751
gettext("No location specified or remembered"))
4718
4752
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4719
4753
note(gettext("{0} remembered {1} location {2}").format(verb_string,
4760
4794
self.enter_context(tree.lock_write())
4761
4795
parents = tree.get_parent_ids()
4762
4796
if len(parents) != 2:
4763
raise errors.BzrCommandError(
4797
raise errors.CommandError(
4764
4798
gettext("Sorry, remerge only works after normal"
4765
4799
" merges. Not cherrypicking or multi-merges."))
4766
4800
interesting_files = None
4785
4819
restore_files = [c.path for c in conflicts
4786
4820
if c.typestring in allowed_conflicts]
4787
4821
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_files)
4788
tree.set_conflicts(ConflictList(new_conflicts))
4822
tree.set_conflicts(new_conflicts)
4789
4823
if file_list is not None:
4790
4824
restore_files = file_list
4791
4825
for filename in restore_files:
5284
5318
def run(self, revision_id_list=None, revision=None, directory=u'.'):
5285
5319
if revision_id_list is not None and revision is not None:
5286
raise errors.BzrCommandError(
5320
raise errors.CommandError(
5287
5321
gettext('You can only supply one of revision_id or --revision'))
5288
5322
if revision_id_list is None and revision is None:
5289
raise errors.BzrCommandError(
5323
raise errors.CommandError(
5290
5324
gettext('You must supply either --revision or a revision_id'))
5291
5325
b = WorkingTree.open_containing(directory)[0].branch
5292
5326
self.enter_context(b.lock_write())
5314
5348
if to_revid is None:
5315
5349
to_revno = b.revno()
5316
5350
if from_revno is None or to_revno is None:
5317
raise errors.BzrCommandError(
5351
raise errors.CommandError(
5318
5352
gettext('Cannot sign a range of non-revision-history revisions'))
5319
5353
with WriteGroup(b.repository):
5320
5354
for revno in range(from_revno, to_revno + 1):
5321
5355
b.repository.sign_revision(b.get_rev_id(revno),
5324
raise errors.BzrCommandError(
5358
raise errors.CommandError(
5325
5359
gettext('Please supply either one revision, or a range.'))
5348
5382
location = b.get_old_bound_location()
5349
5383
except errors.UpgradeRequired:
5350
raise errors.BzrCommandError(
5384
raise errors.CommandError(
5351
5385
gettext('No location supplied. '
5352
5386
'This format does not remember old locations.'))
5354
5388
if location is None:
5355
5389
if b.get_bound_location() is not None:
5356
raise errors.BzrCommandError(
5390
raise errors.CommandError(
5357
5391
gettext('Branch is already bound'))
5359
raise errors.BzrCommandError(
5393
raise errors.CommandError(
5360
5394
gettext('No location supplied'
5361
5395
' and no previous location known'))
5362
5396
b_other = Branch.open(location)
5364
5398
b.bind(b_other)
5365
5399
except errors.DivergedBranches:
5366
raise errors.BzrCommandError(
5400
raise errors.CommandError(
5367
5401
gettext('These branches have diverged.'
5368
5402
' Try merging, and then bind again.'))
5369
5403
if b.get_config().has_explicit_nickname():
5384
5418
def run(self, directory=u'.'):
5385
5419
b, relpath = Branch.open_containing(directory)
5386
5420
if not b.unbind():
5387
raise errors.BzrCommandError(gettext('Local branch is not bound'))
5421
raise errors.CommandError(gettext('Local branch is not bound'))
5390
5424
class cmd_uncommit(Command):
5643
5677
containing_tree = WorkingTree.open_containing(parent_dir)[0]
5644
5678
repo = containing_tree.branch.repository
5645
5679
if not repo.supports_rich_root():
5646
raise errors.BzrCommandError(gettext(
5680
raise errors.CommandError(gettext(
5647
5681
"Can't join trees because %s doesn't support rich root data.\n"
5648
5682
"You can use brz upgrade on the repository.")
5653
5687
except BadReferenceTarget as e:
5654
5688
# XXX: Would be better to just raise a nicely printable
5655
5689
# exception from the real origin. Also below. mbp 20070306
5656
raise errors.BzrCommandError(
5690
raise errors.CommandError(
5657
5691
gettext("Cannot join {0}. {1}").format(tree, e.reason))
5660
5694
containing_tree.subsume(sub_tree)
5661
5695
except errors.BadSubsumeSource as e:
5662
raise errors.BzrCommandError(
5696
raise errors.CommandError(
5663
5697
gettext("Cannot join {0}. {1}").format(tree, e.reason))
5751
5785
if submit_branch is None:
5752
5786
submit_branch = branch.get_parent()
5753
5787
if submit_branch is None:
5754
raise errors.BzrCommandError(
5788
raise errors.CommandError(
5755
5789
gettext('No submit branch specified or known'))
5757
5791
stored_public_branch = branch.get_public_branch()
5761
5795
# FIXME: Should be done only if we succeed ? -- vila 2012-01-03
5762
5796
branch.set_public_branch(public_branch)
5763
5797
if not include_bundle and public_branch is None:
5764
raise errors.BzrCommandError(
5798
raise errors.CommandError(
5765
5799
gettext('No public branch specified or known'))
5766
5800
base_revision_id = None
5767
5801
if revision is not None:
5768
5802
if len(revision) > 2:
5769
raise errors.BzrCommandError(
5803
raise errors.CommandError(
5770
5804
gettext('brz merge-directive takes '
5771
5805
'at most two one revision identifiers'))
5772
5806
revision_id = revision[-1].as_revision_id(branch)
5776
5810
revision_id = branch.last_revision()
5777
5811
revision_id = ensure_null(revision_id)
5778
5812
if revision_id == NULL_REVISION:
5779
raise errors.BzrCommandError(gettext('No revisions to bundle.'))
5813
raise errors.CommandError(gettext('No revisions to bundle.'))
5780
5814
directive = merge_directive.MergeDirective2.from_objects(
5781
5815
branch.repository, revision_id, time.time(),
5782
5816
osutils.local_time_offset(), submit_branch,
6023
6057
self.enter_context(branch.lock_write())
6025
6059
if tag_name is None:
6026
raise errors.BzrCommandError(
6060
raise errors.CommandError(
6027
6061
gettext("No tag specified to delete."))
6028
6062
branch.tags.delete_tag(tag_name)
6029
6063
note(gettext('Deleted tag %s.') % tag_name)
6032
6066
if len(revision) != 1:
6033
raise errors.BzrCommandError(gettext(
6067
raise errors.CommandError(gettext(
6034
6068
"Tags can only be placed on a single revision, "
6035
6069
"not on a range"))
6036
6070
revision_id = revision[0].as_revision_id(branch)
6039
6073
if tag_name is None:
6040
6074
tag_name = branch.automatic_tag_name(revision_id)
6041
6075
if tag_name is None:
6042
raise errors.BzrCommandError(gettext(
6076
raise errors.CommandError(gettext(
6043
6077
"Please specify a tag name."))
6045
6079
existing_target = branch.tags.lookup_tag(tag_name)
6203
6237
stacked_on=None, unstacked=None):
6204
6238
directory = controldir.ControlDir.open(location)
6205
6239
if stacked_on and unstacked:
6206
raise errors.BzrCommandError(
6240
raise errors.CommandError(
6207
6241
gettext("Can't use both --stacked-on and --unstacked"))
6208
6242
elif stacked_on is not None:
6209
6243
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
6297
6331
possible_transports = [control_dir.root_transport]
6298
6332
if to_location is None:
6299
6333
if revision is None:
6300
raise errors.BzrCommandError(gettext('You must supply either a'
6334
raise errors.CommandError(gettext('You must supply either a'
6301
6335
' revision or a location'))
6302
6336
to_location = tree_location
6311
6345
possible_transports.append(branch.user_transport)
6312
6346
if create_branch:
6313
6347
if branch is None:
6314
raise errors.BzrCommandError(
6348
raise errors.CommandError(
6315
6349
gettext('cannot create branch without source branch'))
6316
6350
to_location = lookup_new_sibling_branch(
6317
6351
control_dir, to_location,
6339
6373
store_uncommitted=store,
6340
6374
possible_transports=possible_transports)
6341
6375
except controldir.BranchReferenceLoop:
6342
raise errors.BzrCommandError(
6376
raise errors.CommandError(
6343
6377
gettext('switching would create a branch reference loop. '
6344
6378
'Use the "bzr up" command to switch to a '
6345
6379
'different revision.'))
6451
6485
name = current_view
6454
raise errors.BzrCommandError(gettext(
6488
raise errors.CommandError(gettext(
6455
6489
"Both --delete and a file list specified"))
6457
raise errors.BzrCommandError(gettext(
6491
raise errors.CommandError(gettext(
6458
6492
"Both --delete and --switch specified"))
6460
6494
tree.views.set_view_info(None, {})
6461
6495
self.outf.write(gettext("Deleted all views.\n"))
6462
6496
elif name is None:
6463
raise errors.BzrCommandError(
6497
raise errors.CommandError(
6464
6498
gettext("No current view to delete"))
6466
6500
tree.views.delete_view(name)
6467
6501
self.outf.write(gettext("Deleted '%s' view.\n") % name)
6470
raise errors.BzrCommandError(gettext(
6504
raise errors.CommandError(gettext(
6471
6505
"Both --switch and a file list specified"))
6473
raise errors.BzrCommandError(gettext(
6507
raise errors.CommandError(gettext(
6474
6508
"Both --switch and --all specified"))
6475
6509
elif switch == 'off':
6476
6510
if current_view is None:
6477
raise errors.BzrCommandError(
6511
raise errors.CommandError(
6478
6512
gettext("No current view to disable"))
6479
6513
tree.views.set_view_info(None, view_dict)
6480
6514
self.outf.write(gettext("Disabled '%s' view.\n") %
6501
6535
# No name given and no current view set
6503
6537
elif name == 'off':
6504
raise errors.BzrCommandError(gettext(
6538
raise errors.CommandError(gettext(
6505
6539
"Cannot change the 'off' pseudo view"))
6506
6540
tree.views.set_view(name, sorted(file_list))
6507
6541
view_str = views.view_display_str(tree.views.lookup_view())
6568
6602
active_branch = None
6569
6603
if (active_branch is not None and
6570
6604
br.control_url == active_branch.control_url):
6571
raise errors.BzrCommandError(
6605
raise errors.CommandError(
6572
6606
gettext("Branch is active. Use --force to remove it."))
6573
6607
br.controldir.destroy_branch(br.name)
6937
6971
path_list = ['.']
6940
raise errors.BzrCommandError(
6974
raise errors.CommandError(
6941
6975
'cannot specify both --from-root and PATH.')
6943
6977
if files_with_matches and files_without_match:
6944
raise errors.BzrCommandError(
6978
raise errors.CommandError(
6945
6979
'cannot specify both '
6946
6980
'-l/--files-with-matches and -L/--files-without-matches.')
6954
6988
color = 'never'
6956
6990
if color not in ['always', 'never', 'auto']:
6957
raise errors.BzrCommandError('Valid values for --color are '
6991
raise errors.CommandError('Valid values for --color are '
6958
6992
'"always", "never" or "auto".')
6960
6994
if levels is None: