556
561
_see_also = ['info']
557
562
takes_args = ['location?']
558
563
takes_options = [
559
Option('tree', help='Show revno of working tree'),
564
Option('tree', help='Show revno of working tree.'),
563
def run(self, tree=False, location=u'.'):
569
def run(self, tree=False, location=u'.', revision=None):
570
if revision is not None and tree:
571
raise errors.BzrCommandError(gettext("--tree and --revision can "
572
"not be used together"))
566
576
wt = WorkingTree.open_containing(location)[0]
567
577
self.add_cleanup(wt.lock_read().unlock)
568
578
except (errors.NoWorkingTree, errors.NotLocalUrl):
569
579
raise errors.NoWorkingTree(location)
570
581
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
583
b = Branch.open_containing(location)[0]
578
584
self.add_cleanup(b.lock_read().unlock)
586
if len(revision) != 1:
587
raise errors.BzrCommandError(gettext(
588
"Tags can only be placed on a single revision, "
590
revid = revision[0].as_revision_id(b)
592
revid = b.last_revision()
594
revno_t = b.revision_id_to_dotted_revno(revid)
595
except errors.NoSuchRevision:
597
revno = ".".join(str(n) for n in revno_t)
580
598
self.cleanup_now()
581
self.outf.write(str(revno) + '\n')
599
self.outf.write(revno + '\n')
584
602
class cmd_revision_info(Command):
736
758
takes_args = ['dir+']
762
help='No error if existing, make parent directories as needed.',
737
766
encoding_type = 'replace'
739
def run(self, dir_list):
741
wt, dd = WorkingTree.open_containing(d)
742
base = os.path.dirname(dd)
743
id = wt.path2id(base)
747
self.outf.write('added %s\n' % d)
769
def add_file_with_parents(cls, wt, relpath):
770
if wt.path2id(relpath) is not None:
772
cls.add_file_with_parents(wt, osutils.dirname(relpath))
776
def add_file_single(cls, wt, relpath):
779
def run(self, dir_list, parents=False):
781
add_file = self.add_file_with_parents
783
add_file = self.add_file_single
785
wt, relpath = WorkingTree.open_containing(dir)
790
if e.errno != errno.EEXIST:
749
raise errors.NotVersionedError(path=base)
794
add_file(wt, relpath)
796
self.outf.write(gettext('added %s\n') % dir)
752
799
class cmd_relpath(Command):
859
906
return self.run_auto(names_list, after, dry_run)
861
raise errors.BzrCommandError('--dry-run requires --auto.')
908
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
862
909
if names_list is None:
864
911
if len(names_list) < 2:
865
raise errors.BzrCommandError("missing file argument")
912
raise errors.BzrCommandError(gettext("missing file argument"))
866
913
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
914
for file_name in rel_names[0:-1]:
916
raise errors.BzrCommandError(gettext("can not move root of branch"))
867
917
self.add_cleanup(tree.lock_tree_write().unlock)
868
918
self._run(tree, names_list, rel_names, after)
870
920
def run_auto(self, names_list, after, dry_run):
871
921
if names_list is not None and len(names_list) > 1:
872
raise errors.BzrCommandError('Only one path may be specified to'
922
raise errors.BzrCommandError(gettext('Only one path may be specified to'
875
raise errors.BzrCommandError('--after cannot be specified with'
925
raise errors.BzrCommandError(gettext('--after cannot be specified with'
877
927
work_tree, file_list = WorkingTree.open_containing_paths(
878
928
names_list, default_directory='.')
879
929
self.add_cleanup(work_tree.lock_tree_write().unlock)
1186
1244
# error by the feedback given to them. RBC 20080227.
1187
1245
stacked_on = parent_url
1188
1246
if not stacked_on:
1189
raise errors.BzrCommandError(
1190
"Could not determine branch to refer to.")
1247
raise errors.BzrCommandError(gettext(
1248
"Could not determine branch to refer to."))
1192
1250
# Get the destination location
1193
1251
if location is None:
1194
1252
stored_loc = br_from.get_push_location()
1195
1253
if stored_loc is None:
1196
raise errors.BzrCommandError(
1197
"No push location known or specified.")
1254
parent_loc = br_from.get_parent()
1256
raise errors.BzrCommandError(gettext(
1257
"No push location known or specified. To push to the "
1258
"parent branch (at %s), use 'bzr push :parent'." %
1259
urlutils.unescape_for_display(parent_loc,
1260
self.outf.encoding)))
1262
raise errors.BzrCommandError(gettext(
1263
"No push location known or specified."))
1199
1265
display_url = urlutils.unescape_for_display(stored_loc,
1200
1266
self.outf.encoding)
1201
note("Using saved push location: %s" % display_url)
1267
note(gettext("Using saved push location: %s") % display_url)
1202
1268
location = stored_loc
1204
1270
_show_push_branch(br_from, revision_id, location, self.outf,
1282
1348
revision_id = br_from.last_revision()
1283
1349
if to_location is None:
1284
to_location = urlutils.derive_to_location(from_location)
1350
to_location = getattr(br_from, "name", None)
1351
if to_location is None:
1352
to_location = urlutils.derive_to_location(from_location)
1285
1353
to_transport = transport.get_transport(to_location)
1287
1355
to_transport.mkdir('.')
1288
1356
except errors.FileExists:
1289
if not use_existing_dir:
1290
raise errors.BzrCommandError('Target directory "%s" '
1291
'already exists.' % to_location)
1358
to_dir = controldir.ControlDir.open_from_transport(
1360
except errors.NotBranchError:
1361
if not use_existing_dir:
1362
raise errors.BzrCommandError(gettext('Target directory "%s" '
1363
'already exists.') % to_location)
1294
bzrdir.BzrDir.open_from_transport(to_transport)
1368
to_dir.open_branch()
1295
1369
except errors.NotBranchError:
1298
1372
raise errors.AlreadyBranchError(to_location)
1299
1373
except errors.NoSuchFile:
1300
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1374
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1303
# preserve whatever source format we have.
1304
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1305
possible_transports=[to_transport],
1306
accelerator_tree=accelerator_tree,
1307
hardlink=hardlink, stacked=stacked,
1308
force_new_repo=standalone,
1309
create_tree_if_local=not no_tree,
1310
source_branch=br_from)
1311
branch = dir.open_branch()
1312
except errors.NoSuchRevision:
1313
to_transport.delete_tree('.')
1314
msg = "The branch %s has no revision %s." % (from_location,
1316
raise errors.BzrCommandError(msg)
1380
# preserve whatever source format we have.
1381
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1382
possible_transports=[to_transport],
1383
accelerator_tree=accelerator_tree,
1384
hardlink=hardlink, stacked=stacked,
1385
force_new_repo=standalone,
1386
create_tree_if_local=not no_tree,
1387
source_branch=br_from)
1388
branch = to_dir.open_branch(
1389
possible_transports=[
1390
br_from.bzrdir.root_transport, to_transport])
1391
except errors.NoSuchRevision:
1392
to_transport.delete_tree('.')
1393
msg = gettext("The branch {0} has no revision {1}.").format(
1394
from_location, revision)
1395
raise errors.BzrCommandError(msg)
1397
branch = br_from.sprout(to_dir, revision_id=revision_id)
1317
1398
_merge_tags_if_possible(br_from, branch)
1318
1399
# If the source branch is stacked, the new branch may
1319
1400
# be stacked whether we asked for that explicitly or not.
1320
1401
# We therefore need a try/except here and not just 'if stacked:'
1322
note('Created new stacked branch referring to %s.' %
1403
note(gettext('Created new stacked branch referring to %s.') %
1323
1404
branch.get_stacked_on_url())
1324
1405
except (errors.NotStacked, errors.UnstackableBranchFormat,
1325
1406
errors.UnstackableRepositoryFormat), e:
1326
note('Branched %d revision(s).' % branch.revno())
1407
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1328
1409
# Bind to the parent
1329
1410
parent_branch = Branch.open(from_location)
1330
1411
branch.bind(parent_branch)
1331
note('New branch bound to %s' % from_location)
1412
note(gettext('New branch bound to %s') % from_location)
1333
1414
# Switch to the new branch
1334
1415
wt, _ = WorkingTree.open_containing('.')
1335
1416
_mod_switch.switch(wt.bzrdir, branch)
1336
note('Switched to branch: %s',
1417
note(gettext('Switched to branch: %s'),
1337
1418
urlutils.unescape_for_display(branch.base, 'utf-8'))
1340
1421
class cmd_branches(Command):
1341
1422
__doc__ = """List the branches available at the current location.
1343
This command will print the names of all the branches at the current location.
1424
This command will print the names of all the branches at the current
1346
1428
takes_args = ['location?']
1430
Option('recursive', short_name='R',
1431
help='Recursively scan for branches rather than '
1432
'just looking in the specified location.')]
1348
def run(self, location="."):
1349
dir = bzrdir.BzrDir.open_containing(location)[0]
1350
for branch in dir.list_branches():
1351
if branch.name is None:
1352
self.outf.write(" (default)\n")
1354
self.outf.write(" %s\n" % branch.name.encode(self.outf.encoding))
1434
def run(self, location=".", recursive=False):
1436
t = transport.get_transport(location)
1437
if not t.listable():
1438
raise errors.BzrCommandError(
1439
"Can't scan this type of location.")
1440
for b in controldir.ControlDir.find_branches(t):
1441
self.outf.write("%s\n" % urlutils.unescape_for_display(
1442
urlutils.relative_url(t.base, b.base),
1443
self.outf.encoding).rstrip("/"))
1445
dir = controldir.ControlDir.open_containing(location)[0]
1447
active_branch = dir.open_branch(name=None)
1448
except errors.NotBranchError:
1449
active_branch = None
1450
branches = dir.get_branches()
1452
for name, branch in branches.iteritems():
1455
active = (active_branch is not None and
1456
active_branch.base == branch.base)
1457
names[name] = active
1458
# Only mention the current branch explicitly if it's not
1459
# one of the colocated branches
1460
if not any(names.values()) and active_branch is not None:
1461
self.outf.write("* %s\n" % gettext("(default)"))
1462
for name in sorted(names.keys()):
1463
active = names[name]
1468
self.outf.write("%s %s\n" % (
1469
prefix, name.encode(self.outf.encoding)))
1357
1472
class cmd_checkout(Command):
1461
1576
class cmd_update(Command):
1462
__doc__ = """Update a tree to have the latest code committed to its branch.
1464
This will perform a merge into the working tree, and may generate
1465
conflicts. If you have any local changes, you will still
1466
need to commit them after the update for the update to be complete.
1468
If you want to discard your local changes, you can just do a
1469
'bzr revert' instead of 'bzr commit' after the update.
1471
If you want to restore a file that has been removed locally, use
1472
'bzr revert' instead of 'bzr update'.
1474
If the tree's branch is bound to a master branch, it will also update
1577
__doc__ = """Update a working tree to a new revision.
1579
This will perform a merge of the destination revision (the tip of the
1580
branch, or the specified revision) into the working tree, and then make
1581
that revision the basis revision for the working tree.
1583
You can use this to visit an older revision, or to update a working tree
1584
that is out of date from its branch.
1586
If there are any uncommitted changes in the tree, they will be carried
1587
across and remain as uncommitted changes after the update. To discard
1588
these changes, use 'bzr revert'. The uncommitted changes may conflict
1589
with the changes brought in by the change in basis revision.
1591
If the tree's branch is bound to a master branch, bzr will also update
1475
1592
the branch from the master.
1594
You cannot update just a single file or directory, because each Bazaar
1595
working tree has just a single basis revision. If you want to restore a
1596
file that has been removed locally, use 'bzr revert' instead of 'bzr
1597
update'. If you want to restore a file to its state in a previous
1598
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1599
out the old content of that file to a new location.
1601
The 'dir' argument, if given, must be the location of the root of a
1602
working tree to update. By default, the working tree that contains the
1603
current working directory is used.
1478
1606
_see_also = ['pull', 'working-trees', 'status-flags']
1532
1668
old_tip=old_tip,
1533
1669
show_base=show_base)
1534
1670
except errors.NoSuchRevision, e:
1535
raise errors.BzrCommandError(
1671
raise errors.BzrCommandError(gettext(
1536
1672
"branch has no revision %s\n"
1537
1673
"bzr update --revision only works"
1538
" for a revision in the branch history"
1674
" for a revision in the branch history")
1539
1675
% (e.revision))
1540
1676
revno = tree.branch.revision_id_to_dotted_revno(
1541
1677
_mod_revision.ensure_null(tree.last_revision()))
1542
note('Updated to revision %s of branch %s' %
1543
('.'.join(map(str, revno)), branch_location))
1678
note(gettext('Updated to revision {0} of branch {1}').format(
1679
'.'.join(map(str, revno)), branch_location))
1544
1680
parent_ids = tree.get_parent_ids()
1545
1681
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1546
note('Your local commits will now show as pending merges with '
1547
"'bzr status', and can be committed with 'bzr commit'.")
1682
note(gettext('Your local commits will now show as pending merges with '
1683
"'bzr status', and can be committed with 'bzr commit'."))
1548
1684
if conflicts != 0:
1940
2081
def run(self, location, format=None, no_trees=False):
1941
2082
if format is None:
1942
format = bzrdir.format_registry.make_bzrdir('default')
2083
format = controldir.format_registry.make_bzrdir('default')
1944
2085
if location is None:
1947
2088
to_transport = transport.get_transport(location)
1948
to_transport.ensure_base()
1950
newdir = format.initialize_on_transport(to_transport)
1951
repo = newdir.create_repository(shared=True)
1952
repo.set_make_working_trees(not no_trees)
2090
(repo, newdir, require_stacking, repository_policy) = (
2091
format.initialize_on_transport_ex(to_transport,
2092
create_prefix=True, make_working_trees=not no_trees,
2093
shared_repo=True, force_new_repo=True,
2094
use_existing_dir=True,
2095
repo_format_name=format.repository_format.get_format_string()))
1953
2096
if not is_quiet():
1954
2097
from bzrlib.info import show_bzrdir_info
1955
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
2098
show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
1958
2101
class cmd_diff(Command):
2479
2629
_get_info_for_log_files,
2481
2631
direction = (forward and 'forward') or 'reverse'
2632
if symbol_versioning.deprecated_passed(include_merges):
2633
ui.ui_factory.show_user_warning(
2634
'deprecated_command_option',
2635
deprecated_name='--include-merges',
2636
recommended_name='--include-merged',
2637
deprecated_in_version='2.5',
2638
command=self.invoked_as)
2639
if include_merged is None:
2640
include_merged = include_merges
2642
raise errors.BzrCommandError(gettext(
2643
'{0} and {1} are mutually exclusive').format(
2644
'--include-merges', '--include-merged'))
2645
if include_merged is None:
2646
include_merged = False
2482
2647
if (exclude_common_ancestry
2483
2648
and (revision is None or len(revision) != 2)):
2484
raise errors.BzrCommandError(
2485
'--exclude-common-ancestry requires -r with two revisions')
2649
raise errors.BzrCommandError(gettext(
2650
'--exclude-common-ancestry requires -r with two revisions'))
2487
2652
if levels is None:
2490
raise errors.BzrCommandError(
2491
'--levels and --include-merges are mutually exclusive')
2655
raise errors.BzrCommandError(gettext(
2656
'{0} and {1} are mutually exclusive').format(
2657
'--levels', '--include-merged'))
2493
2659
if change is not None:
2494
2660
if len(change) > 1:
2495
2661
raise errors.RangeInChangeOption()
2496
2662
if revision is not None:
2497
raise errors.BzrCommandError(
2498
'--revision and --change are mutually exclusive')
2663
raise errors.BzrCommandError(gettext(
2664
'{0} and {1} are mutually exclusive').format(
2665
'--revision', '--change'))
2500
2667
revision = change
2906
3073
self.outf.write("%s\n" % pattern)
2908
3075
if not name_pattern_list:
2909
raise errors.BzrCommandError("ignore requires at least one "
2910
"NAME_PATTERN or --default-rules.")
3076
raise errors.BzrCommandError(gettext("ignore requires at least one "
3077
"NAME_PATTERN or --default-rules."))
2911
3078
name_pattern_list = [globbing.normalize_pattern(p)
2912
3079
for p in name_pattern_list]
2913
3080
bad_patterns = ''
3081
bad_patterns_count = 0
2914
3082
for p in name_pattern_list:
2915
3083
if not globbing.Globster.is_pattern_valid(p):
3084
bad_patterns_count += 1
2916
3085
bad_patterns += ('\n %s' % p)
2917
3086
if bad_patterns:
2918
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
3087
msg = (ngettext('Invalid ignore pattern found. %s',
3088
'Invalid ignore patterns found. %s',
3089
bad_patterns_count) % bad_patterns)
2919
3090
ui.ui_factory.show_error(msg)
2920
3091
raise errors.InvalidPattern('')
2921
3092
for name_pattern in name_pattern_list:
2922
3093
if (name_pattern[0] == '/' or
2923
3094
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2924
raise errors.BzrCommandError(
2925
"NAME_PATTERN should not be an absolute path")
3095
raise errors.BzrCommandError(gettext(
3096
"NAME_PATTERN should not be an absolute path"))
2926
3097
tree, relpath = WorkingTree.open_containing(directory)
2927
3098
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2928
3099
ignored = globbing.Globster(name_pattern_list)
3032
3203
Option('per-file-timestamps',
3033
3204
help='Set modification time of files to that of the last '
3034
3205
'revision in which it was changed.'),
3206
Option('uncommitted',
3207
help='Export the working tree contents rather than that of the '
3036
3210
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3037
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
3211
root=None, filters=False, per_file_timestamps=False, uncommitted=False,
3038
3213
from bzrlib.export import export
3040
3215
if branch_or_subdir is None:
3041
tree = WorkingTree.open_containing(directory)[0]
3216
branch_or_subdir = directory
3218
(tree, b, subdir) = controldir.ControlDir.open_containing_tree_or_branch(
3220
if tree is not None:
3221
self.add_cleanup(tree.lock_read().unlock)
3225
raise errors.BzrCommandError(
3226
gettext("--uncommitted requires a working tree"))
3045
b, subdir = Branch.open_containing(branch_or_subdir)
3048
rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3229
export_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3050
export(rev_tree, dest, format, root, subdir, filtered=filters,
3231
export(export_tree, dest, format, root, subdir, filtered=filters,
3051
3232
per_file_timestamps=per_file_timestamps)
3052
3233
except errors.NoSuchExportFormat, e:
3053
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
3234
raise errors.BzrCommandError(
3235
gettext('Unsupported export format: %s') % e.format)
3056
3238
class cmd_cat(Command):
3236
3418
aliases = ['ci', 'checkin']
3238
3420
def _iter_bug_fix_urls(self, fixes, branch):
3421
default_bugtracker = None
3239
3422
# Configure the properties for bug fixing attributes.
3240
3423
for fixed_bug in fixes:
3241
3424
tokens = fixed_bug.split(':')
3242
if len(tokens) != 2:
3243
raise errors.BzrCommandError(
3425
if len(tokens) == 1:
3426
if default_bugtracker is None:
3427
branch_config = branch.get_config()
3428
default_bugtracker = branch_config.get_user_option(
3430
if default_bugtracker is None:
3431
raise errors.BzrCommandError(gettext(
3432
"No tracker specified for bug %s. Use the form "
3433
"'tracker:id' or specify a default bug tracker "
3434
"using the `bugtracker` option.\nSee "
3435
"\"bzr help bugs\" for more information on this "
3436
"feature. Commit refused.") % fixed_bug)
3437
tag = default_bugtracker
3439
elif len(tokens) != 2:
3440
raise errors.BzrCommandError(gettext(
3244
3441
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3245
3442
"See \"bzr help bugs\" for more information on this "
3246
"feature.\nCommit refused." % fixed_bug)
3247
tag, bug_id = tokens
3443
"feature.\nCommit refused.") % fixed_bug)
3445
tag, bug_id = tokens
3249
3447
yield bugtracker.get_bug_url(tag, branch, bug_id)
3250
3448
except errors.UnknownBugTrackerAbbreviation:
3251
raise errors.BzrCommandError(
3252
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3449
raise errors.BzrCommandError(gettext(
3450
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3253
3451
except errors.MalformedBugIdentifier, e:
3254
raise errors.BzrCommandError(
3255
"%s\nCommit refused." % (str(e),))
3452
raise errors.BzrCommandError(gettext(
3453
"%s\nCommit refused.") % (str(e),))
3257
3455
def run(self, message=None, file=None, verbose=False, selected_list=None,
3258
3456
unchanged=False, strict=False, local=False, fixes=None,
3368
3566
exclude=tree.safe_relpath_files(exclude),
3370
3568
except PointlessCommit:
3371
raise errors.BzrCommandError("No changes to commit."
3569
raise errors.BzrCommandError(gettext("No changes to commit."
3372
3570
" Please 'bzr add' the files you want to commit, or use"
3373
" --unchanged to force an empty commit.")
3571
" --unchanged to force an empty commit."))
3374
3572
except ConflictsInTree:
3375
raise errors.BzrCommandError('Conflicts detected in working '
3573
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3376
3574
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3378
3576
except StrictCommitFailed:
3379
raise errors.BzrCommandError("Commit refused because there are"
3380
" unknown files in the working tree.")
3577
raise errors.BzrCommandError(gettext("Commit refused because there are"
3578
" unknown files in the working tree."))
3381
3579
except errors.BoundBranchOutOfDate, e:
3382
e.extra_help = ("\n"
3580
e.extra_help = (gettext("\n"
3383
3581
'To commit to master branch, run update and then commit.\n'
3384
3582
'You can also pass --local to commit to continue working '
4587
4804
theirs_only=False,
4588
4805
log_format=None, long=False, short=False, line=False,
4589
4806
show_ids=False, verbose=False, this=False, other=False,
4590
include_merges=False, revision=None, my_revision=None,
4807
include_merged=None, revision=None, my_revision=None,
4809
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4592
4810
from bzrlib.missing import find_unmerged, iter_log_revisions
4593
4811
def message(s):
4594
4812
if not is_quiet():
4595
4813
self.outf.write(s)
4815
if symbol_versioning.deprecated_passed(include_merges):
4816
ui.ui_factory.show_user_warning(
4817
'deprecated_command_option',
4818
deprecated_name='--include-merges',
4819
recommended_name='--include-merged',
4820
deprecated_in_version='2.5',
4821
command=self.invoked_as)
4822
if include_merged is None:
4823
include_merged = include_merges
4825
raise errors.BzrCommandError(gettext(
4826
'{0} and {1} are mutually exclusive').format(
4827
'--include-merges', '--include-merged'))
4828
if include_merged is None:
4829
include_merged = False
4598
4831
mine_only = this
4928
5165
location = b.get_old_bound_location()
4929
5166
except errors.UpgradeRequired:
4930
raise errors.BzrCommandError('No location supplied. '
4931
'This format does not remember old locations.')
5167
raise errors.BzrCommandError(gettext('No location supplied. '
5168
'This format does not remember old locations.'))
4933
5170
if location is None:
4934
5171
if b.get_bound_location() is not None:
4935
raise errors.BzrCommandError('Branch is already bound')
5172
raise errors.BzrCommandError(gettext('Branch is already bound'))
4937
raise errors.BzrCommandError('No location supplied '
4938
'and no previous location known')
5174
raise errors.BzrCommandError(gettext('No location supplied '
5175
'and no previous location known'))
4939
5176
b_other = Branch.open(location)
4941
5178
b.bind(b_other)
4942
5179
except errors.DivergedBranches:
4943
raise errors.BzrCommandError('These branches have diverged.'
4944
' Try merging, and then bind again.')
5180
raise errors.BzrCommandError(gettext('These branches have diverged.'
5181
' Try merging, and then bind again.'))
4945
5182
if b.get_config().has_explicit_nickname():
4946
5183
b.nick = b_other.nick
5054
5291
end_revision=last_revno)
5057
self.outf.write('Dry-run, pretending to remove'
5058
' the above revisions.\n')
5294
self.outf.write(gettext('Dry-run, pretending to remove'
5295
' the above revisions.\n'))
5060
self.outf.write('The above revision(s) will be removed.\n')
5297
self.outf.write(gettext('The above revision(s) will be removed.\n'))
5063
5300
if not ui.ui_factory.confirm_action(
5064
u'Uncommit these revisions',
5301
gettext(u'Uncommit these revisions'),
5065
5302
'bzrlib.builtins.uncommit',
5067
self.outf.write('Canceled\n')
5304
self.outf.write(gettext('Canceled\n'))
5070
5307
mutter('Uncommitting from {%s} to {%s}',
5071
5308
last_rev_id, rev_id)
5072
5309
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5073
5310
revno=revno, local=local, keep_tags=keep_tags)
5074
self.outf.write('You can restore the old tip by running:\n'
5075
' bzr pull . -r revid:%s\n' % last_rev_id)
5311
self.outf.write(gettext('You can restore the old tip by running:\n'
5312
' bzr pull . -r revid:%s\n') % last_rev_id)
5078
5315
class cmd_break_lock(Command):
5184
5423
return host, port
5186
5425
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5426
protocol=None, client_timeout=None):
5188
5427
from bzrlib import transport
5189
5428
if directory is None:
5190
5429
directory = os.getcwd()
5191
5430
if protocol is None:
5192
5431
protocol = transport.transport_server_registry.get()
5193
5432
host, port = self.get_host_and_port(port)
5194
url = urlutils.local_path_to_url(directory)
5433
url = transport.location_to_url(directory)
5195
5434
if not allow_writes:
5196
5435
url = 'readonly+' + url
5197
t = transport.get_transport(url)
5198
protocol(t, host, port, inet)
5436
t = transport.get_transport_from_url(url)
5438
protocol(t, host, port, inet, client_timeout)
5439
except TypeError, e:
5440
# We use symbol_versioning.deprecated_in just so that people
5441
# grepping can find it here.
5442
# symbol_versioning.deprecated_in((2, 5, 0))
5443
symbol_versioning.warn(
5444
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5445
'Most likely it needs to be updated to support a'
5446
' "timeout" parameter (added in bzr 2.5.0)'
5447
% (e, protocol.__module__, protocol),
5449
protocol(t, host, port, inet)
5201
5452
class cmd_join(Command):
5613
5864
self.add_cleanup(branch.lock_write().unlock)
5615
5866
if tag_name is None:
5616
raise errors.BzrCommandError("No tag specified to delete.")
5867
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5617
5868
branch.tags.delete_tag(tag_name)
5618
note('Deleted tag %s.' % tag_name)
5869
note(gettext('Deleted tag %s.') % tag_name)
5621
5872
if len(revision) != 1:
5622
raise errors.BzrCommandError(
5873
raise errors.BzrCommandError(gettext(
5623
5874
"Tags can only be placed on a single revision, "
5625
5876
revision_id = revision[0].as_revision_id(branch)
5627
5878
revision_id = branch.last_revision()
5628
5879
if tag_name is None:
5629
5880
tag_name = branch.automatic_tag_name(revision_id)
5630
5881
if tag_name is None:
5631
raise errors.BzrCommandError(
5632
"Please specify a tag name.")
5633
if (not force) and branch.tags.has_tag(tag_name):
5882
raise errors.BzrCommandError(gettext(
5883
"Please specify a tag name."))
5885
existing_target = branch.tags.lookup_tag(tag_name)
5886
except errors.NoSuchTag:
5887
existing_target = None
5888
if not force and existing_target not in (None, revision_id):
5634
5889
raise errors.TagAlreadyExists(tag_name)
5635
branch.tags.set_tag(tag_name, revision_id)
5636
note('Created tag %s.' % tag_name)
5890
if existing_target == revision_id:
5891
note(gettext('Tag %s already exists for that revision.') % tag_name)
5893
branch.tags.set_tag(tag_name, revision_id)
5894
if existing_target is None:
5895
note(gettext('Created tag %s.') % tag_name)
5897
note(gettext('Updated tag %s.') % tag_name)
5639
5900
class cmd_tags(Command):
5690
5949
for tag, revspec in tags:
5691
5950
self.outf.write('%-20s %s\n' % (tag, revspec))
5952
def _tags_for_range(self, branch, revision):
5954
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5955
revid1, revid2 = rev1.rev_id, rev2.rev_id
5956
# _get_revision_range will always set revid2 if it's not specified.
5957
# If revid1 is None, it means we want to start from the branch
5958
# origin which is always a valid ancestor. If revid1 == revid2, the
5959
# ancestry check is useless.
5960
if revid1 and revid1 != revid2:
5961
# FIXME: We really want to use the same graph than
5962
# branch.iter_merge_sorted_revisions below, but this is not
5963
# easily available -- vila 2011-09-23
5964
if branch.repository.get_graph().is_ancestor(revid2, revid1):
5965
# We don't want to output anything in this case...
5967
# only show revisions between revid1 and revid2 (inclusive)
5968
tagged_revids = branch.tags.get_reverse_tag_dict()
5970
for r in branch.iter_merge_sorted_revisions(
5971
start_revision_id=revid2, stop_revision_id=revid1,
5972
stop_rule='include'):
5973
revid_tags = tagged_revids.get(r[0], None)
5975
found.extend([(tag, r[0]) for tag in revid_tags])
5694
5979
class cmd_reconfigure(Command):
5695
5980
__doc__ = """Reconfigure the type of a bzr directory.
5709
5994
takes_args = ['location?']
5710
5995
takes_options = [
5711
5996
RegistryOption.from_kwargs(
5713
title='Target type',
5714
help='The type to reconfigure the directory to.',
5999
help='The relation between branch and tree.',
5715
6000
value_switches=True, enum_switch=False,
5716
6001
branch='Reconfigure to be an unbound branch with no working tree.',
5717
6002
tree='Reconfigure to be an unbound branch with a working tree.',
5718
6003
checkout='Reconfigure to be a bound branch with a working tree.',
5719
6004
lightweight_checkout='Reconfigure to be a lightweight'
5720
6005
' checkout (with no local history).',
6007
RegistryOption.from_kwargs(
6009
title='Repository type',
6010
help='Location fo the repository.',
6011
value_switches=True, enum_switch=False,
5721
6012
standalone='Reconfigure to be a standalone branch '
5722
6013
'(i.e. stop using shared repository).',
5723
6014
use_shared='Reconfigure to use a shared repository.',
6016
RegistryOption.from_kwargs(
6018
title='Trees in Repository',
6019
help='Whether new branches in the repository have trees.',
6020
value_switches=True, enum_switch=False,
5724
6021
with_trees='Reconfigure repository to create '
5725
6022
'working trees on branches by default.',
5726
6023
with_no_trees='Reconfigure repository to not create '
5753
6050
# At the moment you can use --stacked-on and a different
5754
6051
# reconfiguration shape at the same time; there seems no good reason
5756
if target_type is None:
6053
if (tree_type is None and
6054
repository_type is None and
6055
repository_trees is None):
5757
6056
if stacked_on or unstacked:
5760
raise errors.BzrCommandError('No target configuration '
5762
elif target_type == 'branch':
6059
raise errors.BzrCommandError(gettext('No target configuration '
6061
reconfiguration = None
6062
if tree_type == 'branch':
5763
6063
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5764
elif target_type == 'tree':
6064
elif tree_type == 'tree':
5765
6065
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5766
elif target_type == 'checkout':
6066
elif tree_type == 'checkout':
5767
6067
reconfiguration = reconfigure.Reconfigure.to_checkout(
5768
6068
directory, bind_to)
5769
elif target_type == 'lightweight-checkout':
6069
elif tree_type == 'lightweight-checkout':
5770
6070
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5771
6071
directory, bind_to)
5772
elif target_type == 'use-shared':
6073
reconfiguration.apply(force)
6074
reconfiguration = None
6075
if repository_type == 'use-shared':
5773
6076
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5774
elif target_type == 'standalone':
6077
elif repository_type == 'standalone':
5775
6078
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5776
elif target_type == 'with-trees':
6080
reconfiguration.apply(force)
6081
reconfiguration = None
6082
if repository_trees == 'with-trees':
5777
6083
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5778
6084
directory, True)
5779
elif target_type == 'with-no-trees':
6085
elif repository_trees == 'with-no-trees':
5780
6086
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5781
6087
directory, False)
5782
reconfiguration.apply(force)
6089
reconfiguration.apply(force)
6090
reconfiguration = None
5785
6093
class cmd_switch(Command):
5834
6142
had_explicit_nick = False
5835
6143
if create_branch:
5836
6144
if branch is None:
5837
raise errors.BzrCommandError('cannot create branch without'
6145
raise errors.BzrCommandError(gettext('cannot create branch without'
5839
6147
to_location = directory_service.directories.dereference(
5841
6149
if '/' not in to_location and '\\' not in to_location:
5842
6150
# This path is meant to be relative to the existing branch
5843
6151
this_url = self._get_branch_location(control_dir)
5844
to_location = urlutils.join(this_url, '..', to_location)
6152
# Perhaps the target control dir supports colocated branches?
6154
root = controldir.ControlDir.open(this_url,
6155
possible_transports=[control_dir.user_transport])
6156
except errors.NotBranchError:
6159
colocated = root._format.colocated_branches
6161
to_location = urlutils.join_segment_parameters(this_url,
6162
{"branch": urlutils.escape(to_location)})
6164
to_location = urlutils.join(
6165
this_url, '..', urlutils.escape(to_location))
5845
6166
to_branch = branch.bzrdir.sprout(to_location,
5846
6167
possible_transports=[branch.bzrdir.root_transport],
5847
6168
source_branch=branch).open_branch()
6170
# Perhaps it's a colocated branch?
5850
to_branch = Branch.open(to_location)
5851
except errors.NotBranchError:
5852
this_url = self._get_branch_location(control_dir)
5853
to_branch = Branch.open(
5854
urlutils.join(this_url, '..', to_location))
6172
to_branch = control_dir.open_branch(to_location)
6173
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6175
to_branch = Branch.open(to_location)
6176
except errors.NotBranchError:
6177
this_url = self._get_branch_location(control_dir)
6178
to_branch = Branch.open(
6180
this_url, '..', urlutils.escape(to_location)))
5855
6181
if revision is not None:
5856
6182
revision = revision.as_revision_id(to_branch)
5857
6183
switch.switch(control_dir, to_branch, force, revision_id=revision)
5858
6184
if had_explicit_nick:
5859
6185
branch = control_dir.open_branch() #get the new branch!
5860
6186
branch.nick = to_branch.nick
5861
note('Switched to branch: %s',
6187
note(gettext('Switched to branch: %s'),
5862
6188
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5864
6190
def _get_branch_location(self, control_dir):
5973
6299
name = current_view
5976
raise errors.BzrCommandError(
5977
"Both --delete and a file list specified")
6302
raise errors.BzrCommandError(gettext(
6303
"Both --delete and a file list specified"))
5979
raise errors.BzrCommandError(
5980
"Both --delete and --switch specified")
6305
raise errors.BzrCommandError(gettext(
6306
"Both --delete and --switch specified"))
5982
6308
tree.views.set_view_info(None, {})
5983
self.outf.write("Deleted all views.\n")
6309
self.outf.write(gettext("Deleted all views.\n"))
5984
6310
elif name is None:
5985
raise errors.BzrCommandError("No current view to delete")
6311
raise errors.BzrCommandError(gettext("No current view to delete"))
5987
6313
tree.views.delete_view(name)
5988
self.outf.write("Deleted '%s' view.\n" % name)
6314
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5991
raise errors.BzrCommandError(
5992
"Both --switch and a file list specified")
6317
raise errors.BzrCommandError(gettext(
6318
"Both --switch and a file list specified"))
5994
raise errors.BzrCommandError(
5995
"Both --switch and --all specified")
6320
raise errors.BzrCommandError(gettext(
6321
"Both --switch and --all specified"))
5996
6322
elif switch == 'off':
5997
6323
if current_view is None:
5998
raise errors.BzrCommandError("No current view to disable")
6324
raise errors.BzrCommandError(gettext("No current view to disable"))
5999
6325
tree.views.set_view_info(None, view_dict)
6000
self.outf.write("Disabled '%s' view.\n" % (current_view))
6326
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
6002
6328
tree.views.set_view_info(switch, view_dict)
6003
6329
view_str = views.view_display_str(tree.views.lookup_view())
6004
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6330
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
6007
self.outf.write('Views defined:\n')
6333
self.outf.write(gettext('Views defined:\n'))
6008
6334
for view in sorted(view_dict):
6009
6335
if view == current_view:
6013
6339
view_str = views.view_display_str(view_dict[view])
6014
6340
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
6016
self.outf.write('No views defined.\n')
6342
self.outf.write(gettext('No views defined.\n'))
6017
6343
elif file_list:
6018
6344
if name is None:
6019
6345
# No name given and no current view set
6021
6347
elif name == 'off':
6022
raise errors.BzrCommandError(
6023
"Cannot change the 'off' pseudo view")
6348
raise errors.BzrCommandError(gettext(
6349
"Cannot change the 'off' pseudo view"))
6024
6350
tree.views.set_view(name, sorted(file_list))
6025
6351
view_str = views.view_display_str(tree.views.lookup_view())
6026
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6352
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
6028
6354
# list the files
6029
6355
if name is None:
6030
6356
# No name given and no current view set
6031
self.outf.write('No current view.\n')
6357
self.outf.write(gettext('No current view.\n'))
6033
6359
view_str = views.view_display_str(tree.views.lookup_view(name))
6034
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6360
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
6037
6363
class cmd_hooks(Command):