333
336
def run(self, revision_id=None, revision=None, directory=u'.'):
334
337
if revision_id is not None and revision is not None:
335
raise errors.BzrCommandError('You can only supply one of'
336
' revision_id or --revision')
338
raise errors.BzrCommandError(gettext('You can only supply one of'
339
' revision_id or --revision'))
337
340
if revision_id is None and revision is None:
338
raise errors.BzrCommandError('You must supply either'
339
' --revision or a revision_id')
341
raise errors.BzrCommandError(gettext('You must supply either'
342
' --revision or a revision_id'))
341
b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
344
b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
343
346
revisions = b.repository.revisions
344
347
if revisions is None:
345
raise errors.BzrCommandError('Repository %r does not support '
346
'access to raw revision texts')
348
raise errors.BzrCommandError(gettext('Repository %r does not support '
349
'access to raw revision texts'))
348
351
b.repository.lock_read()
557
559
takes_args = ['location?']
558
560
takes_options = [
559
561
Option('tree', help='Show revno of working tree'),
563
def run(self, tree=False, location=u'.'):
566
def run(self, tree=False, location=u'.', revision=None):
567
if revision is not None and tree:
568
raise errors.BzrCommandError(gettext("--tree and --revision can "
569
"not be used together"))
566
573
wt = WorkingTree.open_containing(location)[0]
567
574
self.add_cleanup(wt.lock_read().unlock)
568
575
except (errors.NoWorkingTree, errors.NotLocalUrl):
569
576
raise errors.NoWorkingTree(location)
570
578
revid = wt.last_revision()
572
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
except errors.NoSuchRevision:
575
revno = ".".join(str(n) for n in revno_t)
577
580
b = Branch.open_containing(location)[0]
578
581
self.add_cleanup(b.lock_read().unlock)
583
if len(revision) != 1:
584
raise errors.BzrCommandError(gettext(
585
"Tags can only be placed on a single revision, "
587
revid = revision[0].as_revision_id(b)
589
revid = b.last_revision()
591
revno_t = b.revision_id_to_dotted_revno(revid)
592
except errors.NoSuchRevision:
594
revno = ".".join(str(n) for n in revno_t)
580
595
self.cleanup_now()
581
self.outf.write(str(revno) + '\n')
596
self.outf.write(revno + '\n')
584
599
class cmd_revision_info(Command):
855
879
return self.run_auto(names_list, after, dry_run)
857
raise errors.BzrCommandError('--dry-run requires --auto.')
881
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
858
882
if names_list is None:
860
884
if len(names_list) < 2:
861
raise errors.BzrCommandError("missing file argument")
885
raise errors.BzrCommandError(gettext("missing file argument"))
862
886
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
887
for file_name in rel_names[0:-1]:
889
raise errors.BzrCommandError(gettext("can not move root of branch"))
863
890
self.add_cleanup(tree.lock_tree_write().unlock)
864
891
self._run(tree, names_list, rel_names, after)
866
893
def run_auto(self, names_list, after, dry_run):
867
894
if names_list is not None and len(names_list) > 1:
868
raise errors.BzrCommandError('Only one path may be specified to'
895
raise errors.BzrCommandError(gettext('Only one path may be specified to'
871
raise errors.BzrCommandError('--after cannot be specified with'
898
raise errors.BzrCommandError(gettext('--after cannot be specified with'
873
900
work_tree, file_list = WorkingTree.open_containing_paths(
874
901
names_list, default_directory='.')
875
902
self.add_cleanup(work_tree.lock_tree_write().unlock)
1035
1066
stored_loc = branch_to.get_parent()
1036
1067
if location is None:
1037
1068
if stored_loc is None:
1038
raise errors.BzrCommandError("No pull location known or"
1069
raise errors.BzrCommandError(gettext("No pull location known or"
1041
1072
display_url = urlutils.unescape_for_display(stored_loc,
1042
1073
self.outf.encoding)
1043
1074
if not is_quiet():
1044
self.outf.write("Using saved parent location: %s\n" % display_url)
1075
self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
1045
1076
location = stored_loc
1047
1078
revision = _get_one_revision('pull', revision)
1048
1079
if mergeable is not None:
1049
1080
if revision is not None:
1050
raise errors.BzrCommandError(
1051
'Cannot use -r with merge directives or bundles')
1081
raise errors.BzrCommandError(gettext(
1082
'Cannot use -r with merge directives or bundles'))
1052
1083
mergeable.install_revisions(branch_to.repository)
1053
1084
base_revision_id, revision_id, verified = \
1054
1085
mergeable.get_merge_request(branch_to.repository)
1183
1217
# error by the feedback given to them. RBC 20080227.
1184
1218
stacked_on = parent_url
1185
1219
if not stacked_on:
1186
raise errors.BzrCommandError(
1187
"Could not determine branch to refer to.")
1220
raise errors.BzrCommandError(gettext(
1221
"Could not determine branch to refer to."))
1189
1223
# Get the destination location
1190
1224
if location is None:
1191
1225
stored_loc = br_from.get_push_location()
1192
1226
if stored_loc is None:
1193
raise errors.BzrCommandError(
1194
"No push location known or specified.")
1227
raise errors.BzrCommandError(gettext(
1228
"No push location known or specified."))
1196
1230
display_url = urlutils.unescape_for_display(stored_loc,
1197
1231
self.outf.encoding)
1198
self.outf.write("Using saved push location: %s\n" % display_url)
1232
note(gettext("Using saved push location: %s") % display_url)
1199
1233
location = stored_loc
1201
1235
_show_push_branch(br_from, revision_id, location, self.outf,
1279
1313
revision_id = br_from.last_revision()
1280
1314
if to_location is None:
1281
to_location = urlutils.derive_to_location(from_location)
1315
to_location = getattr(br_from, "name", None)
1316
if to_location is None:
1317
to_location = urlutils.derive_to_location(from_location)
1282
1318
to_transport = transport.get_transport(to_location)
1284
1320
to_transport.mkdir('.')
1285
1321
except errors.FileExists:
1286
if not use_existing_dir:
1287
raise errors.BzrCommandError('Target directory "%s" '
1288
'already exists.' % to_location)
1323
to_dir = controldir.ControlDir.open_from_transport(
1325
except errors.NotBranchError:
1326
if not use_existing_dir:
1327
raise errors.BzrCommandError(gettext('Target directory "%s" '
1328
'already exists.') % to_location)
1291
bzrdir.BzrDir.open_from_transport(to_transport)
1333
to_dir.open_branch()
1292
1334
except errors.NotBranchError:
1295
1337
raise errors.AlreadyBranchError(to_location)
1296
1338
except errors.NoSuchFile:
1297
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1339
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1300
# preserve whatever source format we have.
1301
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1302
possible_transports=[to_transport],
1303
accelerator_tree=accelerator_tree,
1304
hardlink=hardlink, stacked=stacked,
1305
force_new_repo=standalone,
1306
create_tree_if_local=not no_tree,
1307
source_branch=br_from)
1308
branch = dir.open_branch()
1309
except errors.NoSuchRevision:
1310
to_transport.delete_tree('.')
1311
msg = "The branch %s has no revision %s." % (from_location,
1313
raise errors.BzrCommandError(msg)
1345
# preserve whatever source format we have.
1346
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1347
possible_transports=[to_transport],
1348
accelerator_tree=accelerator_tree,
1349
hardlink=hardlink, stacked=stacked,
1350
force_new_repo=standalone,
1351
create_tree_if_local=not no_tree,
1352
source_branch=br_from)
1353
branch = to_dir.open_branch()
1354
except errors.NoSuchRevision:
1355
to_transport.delete_tree('.')
1356
msg = gettext("The branch {0} has no revision {1}.").format(
1357
from_location, revision)
1358
raise errors.BzrCommandError(msg)
1360
branch = br_from.sprout(to_dir, revision_id=revision_id)
1314
1361
_merge_tags_if_possible(br_from, branch)
1315
1362
# If the source branch is stacked, the new branch may
1316
1363
# be stacked whether we asked for that explicitly or not.
1317
1364
# We therefore need a try/except here and not just 'if stacked:'
1319
note('Created new stacked branch referring to %s.' %
1366
note(gettext('Created new stacked branch referring to %s.') %
1320
1367
branch.get_stacked_on_url())
1321
1368
except (errors.NotStacked, errors.UnstackableBranchFormat,
1322
1369
errors.UnstackableRepositoryFormat), e:
1323
note('Branched %d revision(s).' % branch.revno())
1370
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1325
1372
# Bind to the parent
1326
1373
parent_branch = Branch.open(from_location)
1327
1374
branch.bind(parent_branch)
1328
note('New branch bound to %s' % from_location)
1375
note(gettext('New branch bound to %s') % from_location)
1330
1377
# Switch to the new branch
1331
1378
wt, _ = WorkingTree.open_containing('.')
1332
1379
_mod_switch.switch(wt.bzrdir, branch)
1333
note('Switched to branch: %s',
1380
note(gettext('Switched to branch: %s'),
1334
1381
urlutils.unescape_for_display(branch.base, 'utf-8'))
1384
class cmd_branches(Command):
1385
__doc__ = """List the branches available at the current location.
1387
This command will print the names of all the branches at the current
1391
takes_args = ['location?']
1393
Option('recursive', short_name='R',
1394
help='Recursively scan for branches rather than '
1395
'just looking in the specified location.')]
1397
def run(self, location=".", recursive=False):
1399
t = transport.get_transport(location)
1400
if not t.listable():
1401
raise errors.BzrCommandError(
1402
"Can't scan this type of location.")
1403
for b in controldir.ControlDir.find_branches(t):
1404
self.outf.write("%s\n" % urlutils.unescape_for_display(
1405
urlutils.relative_url(t.base, b.base),
1406
self.outf.encoding).rstrip("/"))
1408
dir = controldir.ControlDir.open_containing(location)[0]
1409
for branch in dir.list_branches():
1410
if branch.name is None:
1411
self.outf.write(gettext(" (default)\n"))
1413
self.outf.write(" %s\n" % branch.name.encode(
1414
self.outf.encoding))
1337
1417
class cmd_checkout(Command):
1338
1418
__doc__ = """Create a new checkout of an existing branch.
1441
1521
class cmd_update(Command):
1442
__doc__ = """Update a tree to have the latest code committed to its branch.
1444
This will perform a merge into the working tree, and may generate
1445
conflicts. If you have any local changes, you will still
1446
need to commit them after the update for the update to be complete.
1448
If you want to discard your local changes, you can just do a
1449
'bzr revert' instead of 'bzr commit' after the update.
1451
If you want to restore a file that has been removed locally, use
1452
'bzr revert' instead of 'bzr update'.
1454
If the tree's branch is bound to a master branch, it will also update
1522
__doc__ = """Update a working tree to a new revision.
1524
This will perform a merge of the destination revision (the tip of the
1525
branch, or the specified revision) into the working tree, and then make
1526
that revision the basis revision for the working tree.
1528
You can use this to visit an older revision, or to update a working tree
1529
that is out of date from its branch.
1531
If there are any uncommitted changes in the tree, they will be carried
1532
across and remain as uncommitted changes after the update. To discard
1533
these changes, use 'bzr revert'. The uncommitted changes may conflict
1534
with the changes brought in by the change in basis revision.
1536
If the tree's branch is bound to a master branch, bzr will also update
1455
1537
the branch from the master.
1539
You cannot update just a single file or directory, because each Bazaar
1540
working tree has just a single basis revision. If you want to restore a
1541
file that has been removed locally, use 'bzr revert' instead of 'bzr
1542
update'. If you want to restore a file to its state in a previous
1543
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1544
out the old content of that file to a new location.
1546
The 'dir' argument, if given, must be the location of the root of a
1547
working tree to update. By default, the working tree that contains the
1548
current working directory is used.
1458
1551
_see_also = ['pull', 'working-trees', 'status-flags']
1464
1557
aliases = ['up']
1466
def run(self, dir='.', revision=None, show_base=None):
1559
def run(self, dir=None, revision=None, show_base=None):
1467
1560
if revision is not None and len(revision) != 1:
1468
raise errors.BzrCommandError(
1469
"bzr update --revision takes exactly one revision")
1470
tree = WorkingTree.open_containing(dir)[0]
1561
raise errors.BzrCommandError(gettext(
1562
"bzr update --revision takes exactly one revision"))
1564
tree = WorkingTree.open_containing('.')[0]
1566
tree, relpath = WorkingTree.open_containing(dir)
1569
raise errors.BzrCommandError(gettext(
1570
"bzr update can only update a whole tree, "
1571
"not a file or subdirectory"))
1471
1572
branch = tree.branch
1472
1573
possible_transports = []
1473
1574
master = branch.get_master_branch(
1512
1613
old_tip=old_tip,
1513
1614
show_base=show_base)
1514
1615
except errors.NoSuchRevision, e:
1515
raise errors.BzrCommandError(
1616
raise errors.BzrCommandError(gettext(
1516
1617
"branch has no revision %s\n"
1517
1618
"bzr update --revision only works"
1518
" for a revision in the branch history"
1619
" for a revision in the branch history")
1519
1620
% (e.revision))
1520
1621
revno = tree.branch.revision_id_to_dotted_revno(
1521
1622
_mod_revision.ensure_null(tree.last_revision()))
1522
note('Updated to revision %s of branch %s' %
1523
('.'.join(map(str, revno)), branch_location))
1623
note(gettext('Updated to revision {0} of branch {1}').format(
1624
'.'.join(map(str, revno)), branch_location))
1524
1625
parent_ids = tree.get_parent_ids()
1525
1626
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1526
note('Your local commits will now show as pending merges with '
1527
"'bzr status', and can be committed with 'bzr commit'.")
1627
note(gettext('Your local commits will now show as pending merges with '
1628
"'bzr status', and can be committed with 'bzr commit'."))
1528
1629
if conflicts != 0:
2396
2506
Option('show-diff',
2397
2507
short_name='p',
2398
2508
help='Show changes made in each revision as a patch.'),
2399
Option('include-merges',
2509
Option('include-merged',
2400
2510
help='Show merged revisions like --levels 0 does.'),
2511
Option('include-merges', hidden=True,
2512
help='Historical alias for --include-merged.'),
2513
Option('omit-merges',
2514
help='Do not report commits with more than one parent.'),
2401
2515
Option('exclude-common-ancestry',
2402
2516
help='Display only the revisions that are not part'
2403
2517
' of both ancestries (require -rX..Y)'
2405
2519
Option('signatures',
2406
2520
help='Show digital signature validity'),
2523
help='Show revisions whose properties match this '
2526
ListOption('match-message',
2527
help='Show revisions whose message matches this '
2530
ListOption('match-committer',
2531
help='Show revisions whose committer matches this '
2534
ListOption('match-author',
2535
help='Show revisions whose authors match this '
2538
ListOption('match-bugs',
2539
help='Show revisions whose bugs match this '
2408
2543
encoding_type = 'replace'
2430
2572
_get_info_for_log_files,
2432
2574
direction = (forward and 'forward') or 'reverse'
2575
if symbol_versioning.deprecated_passed(include_merges):
2576
ui.ui_factory.show_user_warning(
2577
'deprecated_command_option',
2578
deprecated_name='--include-merges',
2579
recommended_name='--include-merged',
2580
deprecated_in_version='2.5',
2581
command=self.invoked_as)
2582
if include_merged is None:
2583
include_merged = include_merges
2585
raise errors.BzrCommandError(gettext(
2586
'{0} and {1} are mutually exclusive').format(
2587
'--include-merges', '--include-merged'))
2588
if include_merged is None:
2589
include_merged = False
2433
2590
if (exclude_common_ancestry
2434
2591
and (revision is None or len(revision) != 2)):
2435
raise errors.BzrCommandError(
2436
'--exclude-common-ancestry requires -r with two revisions')
2592
raise errors.BzrCommandError(gettext(
2593
'--exclude-common-ancestry requires -r with two revisions'))
2438
2595
if levels is None:
2441
raise errors.BzrCommandError(
2442
'--levels and --include-merges are mutually exclusive')
2598
raise errors.BzrCommandError(gettext(
2599
'{0} and {1} are mutually exclusive').format(
2600
'--levels', '--include-merged'))
2444
2602
if change is not None:
2445
2603
if len(change) > 1:
2446
2604
raise errors.RangeInChangeOption()
2447
2605
if revision is not None:
2448
raise errors.BzrCommandError(
2449
'--revision and --change are mutually exclusive')
2606
raise errors.BzrCommandError(gettext(
2607
'{0} and {1} are mutually exclusive').format(
2608
'--revision', '--change'))
2451
2610
revision = change
2845
3016
self.outf.write("%s\n" % pattern)
2847
3018
if not name_pattern_list:
2848
raise errors.BzrCommandError("ignore requires at least one "
2849
"NAME_PATTERN or --default-rules.")
3019
raise errors.BzrCommandError(gettext("ignore requires at least one "
3020
"NAME_PATTERN or --default-rules."))
2850
3021
name_pattern_list = [globbing.normalize_pattern(p)
2851
3022
for p in name_pattern_list]
2852
3023
bad_patterns = ''
3024
bad_patterns_count = 0
2853
3025
for p in name_pattern_list:
2854
3026
if not globbing.Globster.is_pattern_valid(p):
3027
bad_patterns_count += 1
2855
3028
bad_patterns += ('\n %s' % p)
2856
3029
if bad_patterns:
2857
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
3030
msg = (ngettext('Invalid ignore pattern found. %s',
3031
'Invalid ignore patterns found. %s',
3032
bad_patterns_count) % bad_patterns)
2858
3033
ui.ui_factory.show_error(msg)
2859
3034
raise errors.InvalidPattern('')
2860
3035
for name_pattern in name_pattern_list:
2861
3036
if (name_pattern[0] == '/' or
2862
3037
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2863
raise errors.BzrCommandError(
2864
"NAME_PATTERN should not be an absolute path")
3038
raise errors.BzrCommandError(gettext(
3039
"NAME_PATTERN should not be an absolute path"))
2865
3040
tree, relpath = WorkingTree.open_containing(directory)
2866
3041
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2867
3042
ignored = globbing.Globster(name_pattern_list)
3033
3208
old_file_id = rev_tree.path2id(relpath)
3210
# TODO: Split out this code to something that generically finds the
3211
# best id for a path across one or more trees; it's like
3212
# find_ids_across_trees but restricted to find just one. -- mbp
3035
3214
if name_from_revision:
3036
3215
# Try in revision if requested
3037
3216
if old_file_id is None:
3038
raise errors.BzrCommandError(
3039
"%r is not present in revision %s" % (
3217
raise errors.BzrCommandError(gettext(
3218
"{0!r} is not present in revision {1}").format(
3040
3219
filename, rev_tree.get_revision_id()))
3042
content = rev_tree.get_file_text(old_file_id)
3221
actual_file_id = old_file_id
3044
3223
cur_file_id = tree.path2id(relpath)
3046
if cur_file_id is not None:
3047
# Then try with the actual file id
3049
content = rev_tree.get_file_text(cur_file_id)
3051
except errors.NoSuchId:
3052
# The actual file id didn't exist at that time
3054
if not found and old_file_id is not None:
3055
# Finally try with the old file id
3056
content = rev_tree.get_file_text(old_file_id)
3059
# Can't be found anywhere
3060
raise errors.BzrCommandError(
3061
"%r is not present in revision %s" % (
3224
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3225
actual_file_id = cur_file_id
3226
elif old_file_id is not None:
3227
actual_file_id = old_file_id
3229
raise errors.BzrCommandError(gettext(
3230
"{0!r} is not present in revision {1}").format(
3062
3231
filename, rev_tree.get_revision_id()))
3064
from bzrlib.filters import (
3065
ContentFilterContext,
3066
filtered_output_bytes,
3068
filters = rev_tree._content_filter_stack(relpath)
3069
chunks = content.splitlines(True)
3070
content = filtered_output_bytes(chunks, filters,
3071
ContentFilterContext(relpath, rev_tree))
3073
self.outf.writelines(content)
3233
from bzrlib.filter_tree import ContentFilterTree
3234
filter_tree = ContentFilterTree(rev_tree,
3235
rev_tree._content_filter_stack)
3236
content = filter_tree.get_file_text(actual_file_id)
3076
self.outf.write(content)
3238
content = rev_tree.get_file_text(actual_file_id)
3240
self.outf.write(content)
3079
3243
class cmd_local_time_offset(Command):
3186
3350
aliases = ['ci', 'checkin']
3188
3352
def _iter_bug_fix_urls(self, fixes, branch):
3353
default_bugtracker = None
3189
3354
# Configure the properties for bug fixing attributes.
3190
3355
for fixed_bug in fixes:
3191
3356
tokens = fixed_bug.split(':')
3192
if len(tokens) != 2:
3193
raise errors.BzrCommandError(
3357
if len(tokens) == 1:
3358
if default_bugtracker is None:
3359
branch_config = branch.get_config()
3360
default_bugtracker = branch_config.get_user_option(
3362
if default_bugtracker is None:
3363
raise errors.BzrCommandError(gettext(
3364
"No tracker specified for bug %s. Use the form "
3365
"'tracker:id' or specify a default bug tracker "
3366
"using the `bugtracker` option.\nSee "
3367
"\"bzr help bugs\" for more information on this "
3368
"feature. Commit refused.") % fixed_bug)
3369
tag = default_bugtracker
3371
elif len(tokens) != 2:
3372
raise errors.BzrCommandError(gettext(
3194
3373
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3195
3374
"See \"bzr help bugs\" for more information on this "
3196
"feature.\nCommit refused." % fixed_bug)
3197
tag, bug_id = tokens
3375
"feature.\nCommit refused.") % fixed_bug)
3377
tag, bug_id = tokens
3199
3379
yield bugtracker.get_bug_url(tag, branch, bug_id)
3200
3380
except errors.UnknownBugTrackerAbbreviation:
3201
raise errors.BzrCommandError(
3202
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3381
raise errors.BzrCommandError(gettext(
3382
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3203
3383
except errors.MalformedBugIdentifier, e:
3204
raise errors.BzrCommandError(
3205
"%s\nCommit refused." % (str(e),))
3384
raise errors.BzrCommandError(gettext(
3385
"%s\nCommit refused.") % (str(e),))
3207
3387
def run(self, message=None, file=None, verbose=False, selected_list=None,
3208
3388
unchanged=False, strict=False, local=False, fixes=None,
3315
3498
exclude=tree.safe_relpath_files(exclude),
3317
3500
except PointlessCommit:
3318
raise errors.BzrCommandError("No changes to commit."
3501
raise errors.BzrCommandError(gettext("No changes to commit."
3319
3502
" Please 'bzr add' the files you want to commit, or use"
3320
" --unchanged to force an empty commit.")
3503
" --unchanged to force an empty commit."))
3321
3504
except ConflictsInTree:
3322
raise errors.BzrCommandError('Conflicts detected in working '
3505
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3323
3506
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3325
3508
except StrictCommitFailed:
3326
raise errors.BzrCommandError("Commit refused because there are"
3327
" unknown files in the working tree.")
3509
raise errors.BzrCommandError(gettext("Commit refused because there are"
3510
" unknown files in the working tree."))
3328
3511
except errors.BoundBranchOutOfDate, e:
3329
e.extra_help = ("\n"
3512
e.extra_help = (gettext("\n"
3330
3513
'To commit to master branch, run update and then commit.\n'
3331
3514
'You can also pass --local to commit to continue working '
4030
4213
mergeable = None
4032
4215
if uncommitted:
4033
raise errors.BzrCommandError('Cannot use --uncommitted'
4034
' with bundles or merge directives.')
4216
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4217
' with bundles or merge directives.'))
4036
4219
if revision is not None:
4037
raise errors.BzrCommandError(
4038
'Cannot use -r with merge directives or bundles')
4220
raise errors.BzrCommandError(gettext(
4221
'Cannot use -r with merge directives or bundles'))
4039
4222
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4040
4223
mergeable, None)
4042
4225
if merger is None and uncommitted:
4043
4226
if revision is not None and len(revision) > 0:
4044
raise errors.BzrCommandError('Cannot use --uncommitted and'
4045
' --revision at the same time.')
4227
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4228
' --revision at the same time.'))
4046
4229
merger = self.get_merger_from_uncommitted(tree, location, None)
4047
4230
allow_pending = False
4061
4244
if merger.interesting_files:
4062
4245
if not merger.other_tree.has_filename(
4063
4246
merger.interesting_files[0]):
4064
note("merger: " + str(merger))
4247
note(gettext("merger: ") + str(merger))
4065
4248
raise errors.PathsDoNotExist([location])
4066
note('Nothing to do.')
4249
note(gettext('Nothing to do.'))
4068
4251
if pull and not preview:
4069
4252
if merger.interesting_files is not None:
4070
raise errors.BzrCommandError('Cannot pull individual files')
4253
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4071
4254
if (merger.base_rev_id == tree.last_revision()):
4072
4255
result = tree.pull(merger.other_branch, False,
4073
4256
merger.other_rev_id)
4074
4257
result.report(self.outf)
4076
4259
if merger.this_basis is None:
4077
raise errors.BzrCommandError(
4260
raise errors.BzrCommandError(gettext(
4078
4261
"This branch has no commits."
4079
" (perhaps you would prefer 'bzr pull')")
4262
" (perhaps you would prefer 'bzr pull')"))
4081
4264
return self._do_preview(merger)
4082
4265
elif interactive:
4540
4725
theirs_only=False,
4541
4726
log_format=None, long=False, short=False, line=False,
4542
4727
show_ids=False, verbose=False, this=False, other=False,
4543
include_merges=False, revision=None, my_revision=None,
4728
include_merged=None, revision=None, my_revision=None,
4730
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4545
4731
from bzrlib.missing import find_unmerged, iter_log_revisions
4546
4732
def message(s):
4547
4733
if not is_quiet():
4548
4734
self.outf.write(s)
4736
if symbol_versioning.deprecated_passed(include_merges):
4737
ui.ui_factory.show_user_warning(
4738
'deprecated_command_option',
4739
deprecated_name='--include-merges',
4740
recommended_name='--include-merged',
4741
deprecated_in_version='2.5',
4742
command=self.invoked_as)
4743
if include_merged is None:
4744
include_merged = include_merges
4746
raise errors.BzrCommandError(gettext(
4747
'{0} and {1} are mutually exclusive').format(
4748
'--include-merges', '--include-merged'))
4749
if include_merged is None:
4750
include_merged = False
4551
4752
mine_only = this
4881
5086
location = b.get_old_bound_location()
4882
5087
except errors.UpgradeRequired:
4883
raise errors.BzrCommandError('No location supplied. '
4884
'This format does not remember old locations.')
5088
raise errors.BzrCommandError(gettext('No location supplied. '
5089
'This format does not remember old locations.'))
4886
5091
if location is None:
4887
5092
if b.get_bound_location() is not None:
4888
raise errors.BzrCommandError('Branch is already bound')
5093
raise errors.BzrCommandError(gettext('Branch is already bound'))
4890
raise errors.BzrCommandError('No location supplied '
4891
'and no previous location known')
5095
raise errors.BzrCommandError(gettext('No location supplied '
5096
'and no previous location known'))
4892
5097
b_other = Branch.open(location)
4894
5099
b.bind(b_other)
4895
5100
except errors.DivergedBranches:
4896
raise errors.BzrCommandError('These branches have diverged.'
4897
' Try merging, and then bind again.')
5101
raise errors.BzrCommandError(gettext('These branches have diverged.'
5102
' Try merging, and then bind again.'))
4898
5103
if b.get_config().has_explicit_nickname():
4899
5104
b.nick = b_other.nick
4966
5172
self.add_cleanup(tree.lock_write().unlock)
4968
5174
self.add_cleanup(b.lock_write().unlock)
4969
return self._run(b, tree, dry_run, verbose, revision, force, local=local)
5175
return self._run(b, tree, dry_run, verbose, revision, force,
4971
def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5178
def _run(self, b, tree, dry_run, verbose, revision, force, local,
4972
5180
from bzrlib.log import log_formatter, show_log
4973
5181
from bzrlib.uncommit import uncommit
5004
5212
end_revision=last_revno)
5007
self.outf.write('Dry-run, pretending to remove'
5008
' the above revisions.\n')
5215
self.outf.write(gettext('Dry-run, pretending to remove'
5216
' the above revisions.\n'))
5010
self.outf.write('The above revision(s) will be removed.\n')
5218
self.outf.write(gettext('The above revision(s) will be removed.\n'))
5013
5221
if not ui.ui_factory.confirm_action(
5014
u'Uncommit these revisions',
5222
gettext(u'Uncommit these revisions'),
5015
5223
'bzrlib.builtins.uncommit',
5017
self.outf.write('Canceled\n')
5225
self.outf.write(gettext('Canceled\n'))
5020
5228
mutter('Uncommitting from {%s} to {%s}',
5021
5229
last_rev_id, rev_id)
5022
5230
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5023
revno=revno, local=local)
5024
self.outf.write('You can restore the old tip by running:\n'
5025
' bzr pull . -r revid:%s\n' % last_rev_id)
5231
revno=revno, local=local, keep_tags=keep_tags)
5232
self.outf.write(gettext('You can restore the old tip by running:\n'
5233
' bzr pull . -r revid:%s\n') % last_rev_id)
5028
5236
class cmd_break_lock(Command):
5134
5344
return host, port
5136
5346
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5347
protocol=None, client_timeout=None):
5138
5348
from bzrlib import transport
5139
5349
if directory is None:
5140
5350
directory = os.getcwd()
5141
5351
if protocol is None:
5142
5352
protocol = transport.transport_server_registry.get()
5143
5353
host, port = self.get_host_and_port(port)
5144
url = urlutils.local_path_to_url(directory)
5354
url = transport.location_to_url(directory)
5145
5355
if not allow_writes:
5146
5356
url = 'readonly+' + url
5147
t = transport.get_transport(url)
5148
protocol(t, host, port, inet)
5357
t = transport.get_transport_from_url(url)
5359
protocol(t, host, port, inet, client_timeout)
5360
except TypeError, e:
5361
# We use symbol_versioning.deprecated_in just so that people
5362
# grepping can find it here.
5363
# symbol_versioning.deprecated_in((2, 5, 0))
5364
symbol_versioning.warn(
5365
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5366
'Most likely it needs to be updated to support a'
5367
' "timeout" parameter (added in bzr 2.5.0)'
5368
% (e, protocol.__module__, protocol),
5370
protocol(t, host, port, inet)
5151
5373
class cmd_join(Command):
5563
5785
self.add_cleanup(branch.lock_write().unlock)
5565
5787
if tag_name is None:
5566
raise errors.BzrCommandError("No tag specified to delete.")
5788
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5567
5789
branch.tags.delete_tag(tag_name)
5568
note('Deleted tag %s.' % tag_name)
5790
note(gettext('Deleted tag %s.') % tag_name)
5571
5793
if len(revision) != 1:
5572
raise errors.BzrCommandError(
5794
raise errors.BzrCommandError(gettext(
5573
5795
"Tags can only be placed on a single revision, "
5575
5797
revision_id = revision[0].as_revision_id(branch)
5577
5799
revision_id = branch.last_revision()
5578
5800
if tag_name is None:
5579
5801
tag_name = branch.automatic_tag_name(revision_id)
5580
5802
if tag_name is None:
5581
raise errors.BzrCommandError(
5582
"Please specify a tag name.")
5583
if (not force) and branch.tags.has_tag(tag_name):
5803
raise errors.BzrCommandError(gettext(
5804
"Please specify a tag name."))
5806
existing_target = branch.tags.lookup_tag(tag_name)
5807
except errors.NoSuchTag:
5808
existing_target = None
5809
if not force and existing_target not in (None, revision_id):
5584
5810
raise errors.TagAlreadyExists(tag_name)
5585
branch.tags.set_tag(tag_name, revision_id)
5586
note('Created tag %s.' % tag_name)
5811
if existing_target == revision_id:
5812
note(gettext('Tag %s already exists for that revision.') % tag_name)
5814
branch.tags.set_tag(tag_name, revision_id)
5815
if existing_target is None:
5816
note(gettext('Created tag %s.') % tag_name)
5818
note(gettext('Updated tag %s.') % tag_name)
5589
5821
class cmd_tags(Command):
5681
5915
takes_args = ['location?']
5682
5916
takes_options = [
5683
5917
RegistryOption.from_kwargs(
5685
title='Target type',
5686
help='The type to reconfigure the directory to.',
5920
help='The relation between branch and tree.',
5687
5921
value_switches=True, enum_switch=False,
5688
5922
branch='Reconfigure to be an unbound branch with no working tree.',
5689
5923
tree='Reconfigure to be an unbound branch with a working tree.',
5690
5924
checkout='Reconfigure to be a bound branch with a working tree.',
5691
5925
lightweight_checkout='Reconfigure to be a lightweight'
5692
5926
' checkout (with no local history).',
5928
RegistryOption.from_kwargs(
5930
title='Repository type',
5931
help='Location fo the repository.',
5932
value_switches=True, enum_switch=False,
5693
5933
standalone='Reconfigure to be a standalone branch '
5694
5934
'(i.e. stop using shared repository).',
5695
5935
use_shared='Reconfigure to use a shared repository.',
5937
RegistryOption.from_kwargs(
5939
title='Trees in Repository',
5940
help='Whether new branches in the repository have trees.',
5941
value_switches=True, enum_switch=False,
5696
5942
with_trees='Reconfigure repository to create '
5697
5943
'working trees on branches by default.',
5698
5944
with_no_trees='Reconfigure repository to not create '
5715
def run(self, location=None, target_type=None, bind_to=None, force=False,
5718
directory = bzrdir.BzrDir.open(location)
5961
def run(self, location=None, bind_to=None, force=False,
5962
tree_type=None, repository_type=None, repository_trees=None,
5963
stacked_on=None, unstacked=None):
5964
directory = controldir.ControlDir.open(location)
5719
5965
if stacked_on and unstacked:
5720
raise errors.BzrCommandError("Can't use both --stacked-on and --unstacked")
5966
raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5721
5967
elif stacked_on is not None:
5722
5968
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5723
5969
elif unstacked:
5725
5971
# At the moment you can use --stacked-on and a different
5726
5972
# reconfiguration shape at the same time; there seems no good reason
5728
if target_type is None:
5974
if (tree_type is None and
5975
repository_type is None and
5976
repository_trees is None):
5729
5977
if stacked_on or unstacked:
5732
raise errors.BzrCommandError('No target configuration '
5734
elif target_type == 'branch':
5980
raise errors.BzrCommandError(gettext('No target configuration '
5982
reconfiguration = None
5983
if tree_type == 'branch':
5735
5984
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5736
elif target_type == 'tree':
5985
elif tree_type == 'tree':
5737
5986
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5738
elif target_type == 'checkout':
5987
elif tree_type == 'checkout':
5739
5988
reconfiguration = reconfigure.Reconfigure.to_checkout(
5740
5989
directory, bind_to)
5741
elif target_type == 'lightweight-checkout':
5990
elif tree_type == 'lightweight-checkout':
5742
5991
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5743
5992
directory, bind_to)
5744
elif target_type == 'use-shared':
5994
reconfiguration.apply(force)
5995
reconfiguration = None
5996
if repository_type == 'use-shared':
5745
5997
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5746
elif target_type == 'standalone':
5998
elif repository_type == 'standalone':
5747
5999
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5748
elif target_type == 'with-trees':
6001
reconfiguration.apply(force)
6002
reconfiguration = None
6003
if repository_trees == 'with-trees':
5749
6004
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5750
6005
directory, True)
5751
elif target_type == 'with-no-trees':
6006
elif repository_trees == 'with-no-trees':
5752
6007
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5753
6008
directory, False)
5754
reconfiguration.apply(force)
6010
reconfiguration.apply(force)
6011
reconfiguration = None
5757
6014
class cmd_switch(Command):
5806
6063
had_explicit_nick = False
5807
6064
if create_branch:
5808
6065
if branch is None:
5809
raise errors.BzrCommandError('cannot create branch without'
6066
raise errors.BzrCommandError(gettext('cannot create branch without'
5811
6068
to_location = directory_service.directories.dereference(
5813
6070
if '/' not in to_location and '\\' not in to_location:
5814
6071
# This path is meant to be relative to the existing branch
5815
6072
this_url = self._get_branch_location(control_dir)
5816
to_location = urlutils.join(this_url, '..', to_location)
6073
# Perhaps the target control dir supports colocated branches?
6075
root = controldir.ControlDir.open(this_url,
6076
possible_transports=[control_dir.user_transport])
6077
except errors.NotBranchError:
6080
colocated = root._format.colocated_branches
6082
to_location = urlutils.join_segment_parameters(this_url,
6083
{"branch": urlutils.escape(to_location)})
6085
to_location = urlutils.join(
6086
this_url, '..', urlutils.escape(to_location))
5817
6087
to_branch = branch.bzrdir.sprout(to_location,
5818
6088
possible_transports=[branch.bzrdir.root_transport],
5819
6089
source_branch=branch).open_branch()
6091
# Perhaps it's a colocated branch?
5822
to_branch = Branch.open(to_location)
5823
except errors.NotBranchError:
5824
this_url = self._get_branch_location(control_dir)
5825
to_branch = Branch.open(
5826
urlutils.join(this_url, '..', to_location))
6093
to_branch = control_dir.open_branch(to_location)
6094
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6096
to_branch = Branch.open(to_location)
6097
except errors.NotBranchError:
6098
this_url = self._get_branch_location(control_dir)
6099
to_branch = Branch.open(
6101
this_url, '..', urlutils.escape(to_location)))
5827
6102
if revision is not None:
5828
6103
revision = revision.as_revision_id(to_branch)
5829
6104
switch.switch(control_dir, to_branch, force, revision_id=revision)
5830
6105
if had_explicit_nick:
5831
6106
branch = control_dir.open_branch() #get the new branch!
5832
6107
branch.nick = to_branch.nick
5833
note('Switched to branch: %s',
6108
note(gettext('Switched to branch: %s'),
5834
6109
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5836
6111
def _get_branch_location(self, control_dir):
5945
6220
name = current_view
5948
raise errors.BzrCommandError(
5949
"Both --delete and a file list specified")
6223
raise errors.BzrCommandError(gettext(
6224
"Both --delete and a file list specified"))
5951
raise errors.BzrCommandError(
5952
"Both --delete and --switch specified")
6226
raise errors.BzrCommandError(gettext(
6227
"Both --delete and --switch specified"))
5954
6229
tree.views.set_view_info(None, {})
5955
self.outf.write("Deleted all views.\n")
6230
self.outf.write(gettext("Deleted all views.\n"))
5956
6231
elif name is None:
5957
raise errors.BzrCommandError("No current view to delete")
6232
raise errors.BzrCommandError(gettext("No current view to delete"))
5959
6234
tree.views.delete_view(name)
5960
self.outf.write("Deleted '%s' view.\n" % name)
6235
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5963
raise errors.BzrCommandError(
5964
"Both --switch and a file list specified")
6238
raise errors.BzrCommandError(gettext(
6239
"Both --switch and a file list specified"))
5966
raise errors.BzrCommandError(
5967
"Both --switch and --all specified")
6241
raise errors.BzrCommandError(gettext(
6242
"Both --switch and --all specified"))
5968
6243
elif switch == 'off':
5969
6244
if current_view is None:
5970
raise errors.BzrCommandError("No current view to disable")
6245
raise errors.BzrCommandError(gettext("No current view to disable"))
5971
6246
tree.views.set_view_info(None, view_dict)
5972
self.outf.write("Disabled '%s' view.\n" % (current_view))
6247
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5974
6249
tree.views.set_view_info(switch, view_dict)
5975
6250
view_str = views.view_display_str(tree.views.lookup_view())
5976
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6251
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5979
self.outf.write('Views defined:\n')
6254
self.outf.write(gettext('Views defined:\n'))
5980
6255
for view in sorted(view_dict):
5981
6256
if view == current_view:
5985
6260
view_str = views.view_display_str(view_dict[view])
5986
6261
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5988
self.outf.write('No views defined.\n')
6263
self.outf.write(gettext('No views defined.\n'))
5989
6264
elif file_list:
5990
6265
if name is None:
5991
6266
# No name given and no current view set
5993
6268
elif name == 'off':
5994
raise errors.BzrCommandError(
5995
"Cannot change the 'off' pseudo view")
6269
raise errors.BzrCommandError(gettext(
6270
"Cannot change the 'off' pseudo view"))
5996
6271
tree.views.set_view(name, sorted(file_list))
5997
6272
view_str = views.view_display_str(tree.views.lookup_view())
5998
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6273
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
6000
6275
# list the files
6001
6276
if name is None:
6002
6277
# No name given and no current view set
6003
self.outf.write('No current view.\n')
6278
self.outf.write(gettext('No current view.\n'))
6005
6280
view_str = views.view_display_str(tree.views.lookup_view(name))
6006
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6281
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
6009
6284
class cmd_hooks(Command):