288
280
def run(self, show_ids=False, file_list=None, revision=None, short=False,
289
versioned=False, no_pending=False, verbose=False,
281
versioned=False, no_pending=False, verbose=False):
291
282
from bzrlib.status import show_tree_status
293
284
if revision and len(revision) > 2:
294
raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
295
' one or two revision specifiers'))
285
raise errors.BzrCommandError('bzr status --revision takes exactly'
286
' one or two revision specifiers')
297
288
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
298
289
# Avoid asking for specific files when that is not needed.
336
326
def run(self, revision_id=None, revision=None, directory=u'.'):
337
327
if revision_id is not None and revision is not None:
338
raise errors.BzrCommandError(gettext('You can only supply one of'
339
' revision_id or --revision'))
328
raise errors.BzrCommandError('You can only supply one of'
329
' revision_id or --revision')
340
330
if revision_id is None and revision is None:
341
raise errors.BzrCommandError(gettext('You must supply either'
342
' --revision or a revision_id'))
331
raise errors.BzrCommandError('You must supply either'
332
' --revision or a revision_id')
344
b = controldir.ControlDir.open_containing_tree_or_branch(directory)[1]
334
b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
346
336
revisions = b.repository.revisions
347
337
if revisions is None:
348
raise errors.BzrCommandError(gettext('Repository %r does not support '
349
'access to raw revision texts'))
338
raise errors.BzrCommandError('Repository %r does not support '
339
'access to raw revision texts')
351
341
b.repository.lock_read()
559
550
takes_args = ['location?']
560
551
takes_options = [
561
552
Option('tree', help='Show revno of working tree'),
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"))
556
def run(self, tree=False, location=u'.'):
573
559
wt = WorkingTree.open_containing(location)[0]
574
560
self.add_cleanup(wt.lock_read().unlock)
575
561
except (errors.NoWorkingTree, errors.NotLocalUrl):
576
562
raise errors.NoWorkingTree(location)
578
563
revid = wt.last_revision()
565
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
566
except errors.NoSuchRevision:
568
revno = ".".join(str(n) for n in revno_t)
580
570
b = Branch.open_containing(location)[0]
581
571
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)
595
573
self.cleanup_now()
596
self.outf.write(revno + '\n')
574
self.outf.write(str(revno) + '\n')
599
577
class cmd_revision_info(Command):
879
847
return self.run_auto(names_list, after, dry_run)
881
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
849
raise errors.BzrCommandError('--dry-run requires --auto.')
882
850
if names_list is None:
884
852
if len(names_list) < 2:
885
raise errors.BzrCommandError(gettext("missing file argument"))
853
raise errors.BzrCommandError("missing file argument")
886
854
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
887
855
self.add_cleanup(tree.lock_tree_write().unlock)
888
856
self._run(tree, names_list, rel_names, after)
890
858
def run_auto(self, names_list, after, dry_run):
891
859
if names_list is not None and len(names_list) > 1:
892
raise errors.BzrCommandError(gettext('Only one path may be specified to'
860
raise errors.BzrCommandError('Only one path may be specified to'
895
raise errors.BzrCommandError(gettext('--after cannot be specified with'
863
raise errors.BzrCommandError('--after cannot be specified with'
897
865
work_tree, file_list = WorkingTree.open_containing_paths(
898
866
names_list, default_directory='.')
899
867
self.add_cleanup(work_tree.lock_tree_write().unlock)
1063
1027
stored_loc = branch_to.get_parent()
1064
1028
if location is None:
1065
1029
if stored_loc is None:
1066
raise errors.BzrCommandError(gettext("No pull location known or"
1030
raise errors.BzrCommandError("No pull location known or"
1069
1033
display_url = urlutils.unescape_for_display(stored_loc,
1070
1034
self.outf.encoding)
1071
1035
if not is_quiet():
1072
self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
1036
self.outf.write("Using saved parent location: %s\n" % display_url)
1073
1037
location = stored_loc
1075
1039
revision = _get_one_revision('pull', revision)
1076
1040
if mergeable is not None:
1077
1041
if revision is not None:
1078
raise errors.BzrCommandError(gettext(
1079
'Cannot use -r with merge directives or bundles'))
1042
raise errors.BzrCommandError(
1043
'Cannot use -r with merge directives or bundles')
1080
1044
mergeable.install_revisions(branch_to.repository)
1081
1045
base_revision_id, revision_id, verified = \
1082
1046
mergeable.get_merge_request(branch_to.repository)
1214
1175
# error by the feedback given to them. RBC 20080227.
1215
1176
stacked_on = parent_url
1216
1177
if not stacked_on:
1217
raise errors.BzrCommandError(gettext(
1218
"Could not determine branch to refer to."))
1178
raise errors.BzrCommandError(
1179
"Could not determine branch to refer to.")
1220
1181
# Get the destination location
1221
1182
if location is None:
1222
1183
stored_loc = br_from.get_push_location()
1223
1184
if stored_loc is None:
1224
raise errors.BzrCommandError(gettext(
1225
"No push location known or specified."))
1185
raise errors.BzrCommandError(
1186
"No push location known or specified.")
1227
1188
display_url = urlutils.unescape_for_display(stored_loc,
1228
1189
self.outf.encoding)
1229
note(gettext("Using saved push location: %s") % display_url)
1190
self.outf.write("Using saved push location: %s\n" % display_url)
1230
1191
location = stored_loc
1232
1193
_show_push_branch(br_from, revision_id, location, self.outf,
1315
1276
to_transport.mkdir('.')
1316
1277
except errors.FileExists:
1317
1278
if not use_existing_dir:
1318
raise errors.BzrCommandError(gettext('Target directory "%s" '
1319
'already exists.') % to_location)
1279
raise errors.BzrCommandError('Target directory "%s" '
1280
'already exists.' % to_location)
1322
to_dir = controldir.ControlDir.open_from_transport(
1283
bzrdir.BzrDir.open_from_transport(to_transport)
1324
1284
except errors.NotBranchError:
1328
to_dir.open_branch()
1329
except errors.NotBranchError:
1332
raise errors.AlreadyBranchError(to_location)
1287
raise errors.AlreadyBranchError(to_location)
1333
1288
except errors.NoSuchFile:
1334
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1289
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1340
# preserve whatever source format we have.
1341
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1342
possible_transports=[to_transport],
1343
accelerator_tree=accelerator_tree,
1344
hardlink=hardlink, stacked=stacked,
1345
force_new_repo=standalone,
1346
create_tree_if_local=not no_tree,
1347
source_branch=br_from)
1348
branch = to_dir.open_branch()
1349
except errors.NoSuchRevision:
1350
to_transport.delete_tree('.')
1351
msg = gettext("The branch {0} has no revision {1}.").format(
1352
from_location, revision)
1353
raise errors.BzrCommandError(msg)
1355
branch = br_from.sprout(to_dir, revision_id=revision_id)
1292
# preserve whatever source format we have.
1293
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1294
possible_transports=[to_transport],
1295
accelerator_tree=accelerator_tree,
1296
hardlink=hardlink, stacked=stacked,
1297
force_new_repo=standalone,
1298
create_tree_if_local=not no_tree,
1299
source_branch=br_from)
1300
branch = dir.open_branch()
1301
except errors.NoSuchRevision:
1302
to_transport.delete_tree('.')
1303
msg = "The branch %s has no revision %s." % (from_location,
1305
raise errors.BzrCommandError(msg)
1356
1306
_merge_tags_if_possible(br_from, branch)
1357
1307
# If the source branch is stacked, the new branch may
1358
1308
# be stacked whether we asked for that explicitly or not.
1359
1309
# We therefore need a try/except here and not just 'if stacked:'
1361
note(gettext('Created new stacked branch referring to %s.') %
1311
note('Created new stacked branch referring to %s.' %
1362
1312
branch.get_stacked_on_url())
1363
1313
except (errors.NotStacked, errors.UnstackableBranchFormat,
1364
1314
errors.UnstackableRepositoryFormat), e:
1365
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1315
note('Branched %d revision(s).' % branch.revno())
1367
1317
# Bind to the parent
1368
1318
parent_branch = Branch.open(from_location)
1369
1319
branch.bind(parent_branch)
1370
note(gettext('New branch bound to %s') % from_location)
1320
note('New branch bound to %s' % from_location)
1372
1322
# Switch to the new branch
1373
1323
wt, _ = WorkingTree.open_containing('.')
1374
1324
_mod_switch.switch(wt.bzrdir, branch)
1375
note(gettext('Switched to branch: %s'),
1325
note('Switched to branch: %s',
1376
1326
urlutils.unescape_for_display(branch.base, 'utf-8'))
1379
class cmd_branches(Command):
1380
__doc__ = """List the branches available at the current location.
1382
This command will print the names of all the branches at the current
1386
takes_args = ['location?']
1388
Option('recursive', short_name='R',
1389
help='Recursively scan for branches rather than '
1390
'just looking in the specified location.')]
1392
def run(self, location=".", recursive=False):
1394
t = transport.get_transport(location)
1395
if not t.listable():
1396
raise errors.BzrCommandError(
1397
"Can't scan this type of location.")
1398
for b in controldir.ControlDir.find_branches(t):
1399
self.outf.write("%s\n" % urlutils.unescape_for_display(
1400
urlutils.relative_url(t.base, b.base),
1401
self.outf.encoding).rstrip("/"))
1403
dir = controldir.ControlDir.open_containing(location)[0]
1404
for branch in dir.list_branches():
1405
if branch.name is None:
1406
self.outf.write(gettext(" (default)\n"))
1408
self.outf.write(" %s\n" % branch.name.encode(
1409
self.outf.encoding))
1412
1329
class cmd_checkout(Command):
1413
1330
__doc__ = """Create a new checkout of an existing branch.
1516
1433
class cmd_update(Command):
1517
__doc__ = """Update a working tree to a new revision.
1519
This will perform a merge of the destination revision (the tip of the
1520
branch, or the specified revision) into the working tree, and then make
1521
that revision the basis revision for the working tree.
1523
You can use this to visit an older revision, or to update a working tree
1524
that is out of date from its branch.
1526
If there are any uncommitted changes in the tree, they will be carried
1527
across and remain as uncommitted changes after the update. To discard
1528
these changes, use 'bzr revert'. The uncommitted changes may conflict
1529
with the changes brought in by the change in basis revision.
1531
If the tree's branch is bound to a master branch, bzr will also update
1434
__doc__ = """Update a tree to have the latest code committed to its branch.
1436
This will perform a merge into the working tree, and may generate
1437
conflicts. If you have any local changes, you will still
1438
need to commit them after the update for the update to be complete.
1440
If you want to discard your local changes, you can just do a
1441
'bzr revert' instead of 'bzr commit' after the update.
1443
If you want to restore a file that has been removed locally, use
1444
'bzr revert' instead of 'bzr update'.
1446
If the tree's branch is bound to a master branch, it will also update
1532
1447
the branch from the master.
1534
You cannot update just a single file or directory, because each Bazaar
1535
working tree has just a single basis revision. If you want to restore a
1536
file that has been removed locally, use 'bzr revert' instead of 'bzr
1537
update'. If you want to restore a file to its state in a previous
1538
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1539
out the old content of that file to a new location.
1541
The 'dir' argument, if given, must be the location of the root of a
1542
working tree to update. By default, the working tree that contains the
1543
current working directory is used.
1546
1450
_see_also = ['pull', 'working-trees', 'status-flags']
1552
1456
aliases = ['up']
1554
def run(self, dir=None, revision=None, show_base=None):
1458
def run(self, dir='.', revision=None, show_base=None):
1555
1459
if revision is not None and len(revision) != 1:
1556
raise errors.BzrCommandError(gettext(
1557
"bzr update --revision takes exactly one revision"))
1559
tree = WorkingTree.open_containing('.')[0]
1561
tree, relpath = WorkingTree.open_containing(dir)
1564
raise errors.BzrCommandError(gettext(
1565
"bzr update can only update a whole tree, "
1566
"not a file or subdirectory"))
1460
raise errors.BzrCommandError(
1461
"bzr update --revision takes exactly one revision")
1462
tree = WorkingTree.open_containing(dir)[0]
1567
1463
branch = tree.branch
1568
1464
possible_transports = []
1569
1465
master = branch.get_master_branch(
1608
1504
old_tip=old_tip,
1609
1505
show_base=show_base)
1610
1506
except errors.NoSuchRevision, e:
1611
raise errors.BzrCommandError(gettext(
1507
raise errors.BzrCommandError(
1612
1508
"branch has no revision %s\n"
1613
1509
"bzr update --revision only works"
1614
" for a revision in the branch history")
1510
" for a revision in the branch history"
1615
1511
% (e.revision))
1616
1512
revno = tree.branch.revision_id_to_dotted_revno(
1617
1513
_mod_revision.ensure_null(tree.last_revision()))
1618
note(gettext('Updated to revision {0} of branch {1}').format(
1619
'.'.join(map(str, revno)), branch_location))
1514
note('Updated to revision %s of branch %s' %
1515
('.'.join(map(str, revno)), branch_location))
1620
1516
parent_ids = tree.get_parent_ids()
1621
1517
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1622
note(gettext('Your local commits will now show as pending merges with '
1623
"'bzr status', and can be committed with 'bzr commit'."))
1518
note('Your local commits will now show as pending merges with '
1519
"'bzr status', and can be committed with 'bzr commit'.")
1624
1520
if conflicts != 0:
2501
2386
Option('show-diff',
2502
2387
short_name='p',
2503
2388
help='Show changes made in each revision as a patch.'),
2504
Option('include-merged',
2389
Option('include-merges',
2505
2390
help='Show merged revisions like --levels 0 does.'),
2506
Option('include-merges', hidden=True,
2507
help='Historical alias for --include-merged.'),
2508
Option('omit-merges',
2509
help='Do not report commits with more than one parent.'),
2510
2391
Option('exclude-common-ancestry',
2511
2392
help='Display only the revisions that are not part'
2512
2393
' of both ancestries (require -rX..Y)'
2514
Option('signatures',
2515
help='Show digital signature validity'),
2518
help='Show revisions whose properties match this '
2521
ListOption('match-message',
2522
help='Show revisions whose message matches this '
2525
ListOption('match-committer',
2526
help='Show revisions whose committer matches this '
2529
ListOption('match-author',
2530
help='Show revisions whose authors match this '
2533
ListOption('match-bugs',
2534
help='Show revisions whose bugs match this '
2538
2396
encoding_type = 'replace'
2567
2417
_get_info_for_log_files,
2569
2419
direction = (forward and 'forward') or 'reverse'
2570
if symbol_versioning.deprecated_passed(include_merges):
2571
ui.ui_factory.show_user_warning(
2572
'deprecated_command_option',
2573
deprecated_name='--include-merges',
2574
recommended_name='--include-merged',
2575
deprecated_in_version='2.5',
2576
command=self.invoked_as)
2577
if include_merged is None:
2578
include_merged = include_merges
2580
raise errors.BzrCommandError(gettext(
2581
'{0} and {1} are mutually exclusive').format(
2582
'--include-merges', '--include-merged'))
2583
if include_merged is None:
2584
include_merged = False
2585
2420
if (exclude_common_ancestry
2586
2421
and (revision is None or len(revision) != 2)):
2587
raise errors.BzrCommandError(gettext(
2588
'--exclude-common-ancestry requires -r with two revisions'))
2422
raise errors.BzrCommandError(
2423
'--exclude-common-ancestry requires -r with two revisions')
2590
2425
if levels is None:
2593
raise errors.BzrCommandError(gettext(
2594
'{0} and {1} are mutually exclusive').format(
2595
'--levels', '--include-merged'))
2428
raise errors.BzrCommandError(
2429
'--levels and --include-merges are mutually exclusive')
2597
2431
if change is not None:
2598
2432
if len(change) > 1:
2599
2433
raise errors.RangeInChangeOption()
2600
2434
if revision is not None:
2601
raise errors.BzrCommandError(gettext(
2602
'{0} and {1} are mutually exclusive').format(
2603
'--revision', '--change'))
2435
raise errors.BzrCommandError(
2436
'--revision and --change are mutually exclusive')
2605
2438
revision = change
3011
2824
self.outf.write("%s\n" % pattern)
3013
2826
if not name_pattern_list:
3014
raise errors.BzrCommandError(gettext("ignore requires at least one "
3015
"NAME_PATTERN or --default-rules."))
2827
raise errors.BzrCommandError("ignore requires at least one "
2828
"NAME_PATTERN or --default-rules.")
3016
2829
name_pattern_list = [globbing.normalize_pattern(p)
3017
2830
for p in name_pattern_list]
3018
2831
bad_patterns = ''
3019
bad_patterns_count = 0
3020
2832
for p in name_pattern_list:
3021
2833
if not globbing.Globster.is_pattern_valid(p):
3022
bad_patterns_count += 1
3023
2834
bad_patterns += ('\n %s' % p)
3024
2835
if bad_patterns:
3025
msg = (ngettext('Invalid ignore pattern found. %s',
3026
'Invalid ignore patterns found. %s',
3027
bad_patterns_count) % bad_patterns)
2836
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
3028
2837
ui.ui_factory.show_error(msg)
3029
2838
raise errors.InvalidPattern('')
3030
2839
for name_pattern in name_pattern_list:
3031
2840
if (name_pattern[0] == '/' or
3032
2841
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3033
raise errors.BzrCommandError(gettext(
3034
"NAME_PATTERN should not be an absolute path"))
2842
raise errors.BzrCommandError(
2843
"NAME_PATTERN should not be an absolute path")
3035
2844
tree, relpath = WorkingTree.open_containing(directory)
3036
2845
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3037
2846
ignored = globbing.Globster(name_pattern_list)
3203
3012
old_file_id = rev_tree.path2id(relpath)
3205
# TODO: Split out this code to something that generically finds the
3206
# best id for a path across one or more trees; it's like
3207
# find_ids_across_trees but restricted to find just one. -- mbp
3209
3014
if name_from_revision:
3210
3015
# Try in revision if requested
3211
3016
if old_file_id is None:
3212
raise errors.BzrCommandError(gettext(
3213
"{0!r} is not present in revision {1}").format(
3017
raise errors.BzrCommandError(
3018
"%r is not present in revision %s" % (
3214
3019
filename, rev_tree.get_revision_id()))
3216
actual_file_id = old_file_id
3021
content = rev_tree.get_file_text(old_file_id)
3218
3023
cur_file_id = tree.path2id(relpath)
3219
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3220
actual_file_id = cur_file_id
3221
elif old_file_id is not None:
3222
actual_file_id = old_file_id
3224
raise errors.BzrCommandError(gettext(
3225
"{0!r} is not present in revision {1}").format(
3025
if cur_file_id is not None:
3026
# Then try with the actual file id
3028
content = rev_tree.get_file_text(cur_file_id)
3030
except errors.NoSuchId:
3031
# The actual file id didn't exist at that time
3033
if not found and old_file_id is not None:
3034
# Finally try with the old file id
3035
content = rev_tree.get_file_text(old_file_id)
3038
# Can't be found anywhere
3039
raise errors.BzrCommandError(
3040
"%r is not present in revision %s" % (
3226
3041
filename, rev_tree.get_revision_id()))
3228
from bzrlib.filter_tree import ContentFilterTree
3229
filter_tree = ContentFilterTree(rev_tree,
3230
rev_tree._content_filter_stack)
3231
content = filter_tree.get_file_text(actual_file_id)
3043
from bzrlib.filters import (
3044
ContentFilterContext,
3045
filtered_output_bytes,
3047
filters = rev_tree._content_filter_stack(relpath)
3048
chunks = content.splitlines(True)
3049
content = filtered_output_bytes(chunks, filters,
3050
ContentFilterContext(relpath, rev_tree))
3052
self.outf.writelines(content)
3233
content = rev_tree.get_file_text(actual_file_id)
3235
self.outf.write(content)
3055
self.outf.write(content)
3238
3058
class cmd_local_time_offset(Command):
3345
3165
aliases = ['ci', 'checkin']
3347
3167
def _iter_bug_fix_urls(self, fixes, branch):
3348
default_bugtracker = None
3349
3168
# Configure the properties for bug fixing attributes.
3350
3169
for fixed_bug in fixes:
3351
3170
tokens = fixed_bug.split(':')
3352
if len(tokens) == 1:
3353
if default_bugtracker is None:
3354
branch_config = branch.get_config()
3355
default_bugtracker = branch_config.get_user_option(
3357
if default_bugtracker is None:
3358
raise errors.BzrCommandError(gettext(
3359
"No tracker specified for bug %s. Use the form "
3360
"'tracker:id' or specify a default bug tracker "
3361
"using the `bugtracker` option.\nSee "
3362
"\"bzr help bugs\" for more information on this "
3363
"feature. Commit refused.") % fixed_bug)
3364
tag = default_bugtracker
3366
elif len(tokens) != 2:
3367
raise errors.BzrCommandError(gettext(
3171
if len(tokens) != 2:
3172
raise errors.BzrCommandError(
3368
3173
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3369
3174
"See \"bzr help bugs\" for more information on this "
3370
"feature.\nCommit refused.") % fixed_bug)
3372
tag, bug_id = tokens
3175
"feature.\nCommit refused." % fixed_bug)
3176
tag, bug_id = tokens
3374
3178
yield bugtracker.get_bug_url(tag, branch, bug_id)
3375
3179
except errors.UnknownBugTrackerAbbreviation:
3376
raise errors.BzrCommandError(gettext(
3377
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3180
raise errors.BzrCommandError(
3181
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3378
3182
except errors.MalformedBugIdentifier, e:
3379
raise errors.BzrCommandError(gettext(
3380
"%s\nCommit refused.") % (str(e),))
3183
raise errors.BzrCommandError(
3184
"%s\nCommit refused." % (str(e),))
3382
3186
def run(self, message=None, file=None, verbose=False, selected_list=None,
3383
3187
unchanged=False, strict=False, local=False, fixes=None,
3493
3294
exclude=tree.safe_relpath_files(exclude),
3495
3296
except PointlessCommit:
3496
raise errors.BzrCommandError(gettext("No changes to commit."
3297
raise errors.BzrCommandError("No changes to commit."
3497
3298
" Please 'bzr add' the files you want to commit, or use"
3498
" --unchanged to force an empty commit."))
3299
" --unchanged to force an empty commit.")
3499
3300
except ConflictsInTree:
3500
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3301
raise errors.BzrCommandError('Conflicts detected in working '
3501
3302
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3503
3304
except StrictCommitFailed:
3504
raise errors.BzrCommandError(gettext("Commit refused because there are"
3505
" unknown files in the working tree."))
3305
raise errors.BzrCommandError("Commit refused because there are"
3306
" unknown files in the working tree.")
3506
3307
except errors.BoundBranchOutOfDate, e:
3507
e.extra_help = (gettext("\n"
3308
e.extra_help = ("\n"
3508
3309
'To commit to master branch, run update and then commit.\n'
3509
3310
'You can also pass --local to commit to continue working '
4208
3994
mergeable = None
4210
3996
if uncommitted:
4211
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4212
' with bundles or merge directives.'))
3997
raise errors.BzrCommandError('Cannot use --uncommitted'
3998
' with bundles or merge directives.')
4214
4000
if revision is not None:
4215
raise errors.BzrCommandError(gettext(
4216
'Cannot use -r with merge directives or bundles'))
4001
raise errors.BzrCommandError(
4002
'Cannot use -r with merge directives or bundles')
4217
4003
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4218
4004
mergeable, None)
4220
4006
if merger is None and uncommitted:
4221
4007
if revision is not None and len(revision) > 0:
4222
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4223
' --revision at the same time.'))
4008
raise errors.BzrCommandError('Cannot use --uncommitted and'
4009
' --revision at the same time.')
4224
4010
merger = self.get_merger_from_uncommitted(tree, location, None)
4225
4011
allow_pending = False
4239
4025
if merger.interesting_files:
4240
4026
if not merger.other_tree.has_filename(
4241
4027
merger.interesting_files[0]):
4242
note(gettext("merger: ") + str(merger))
4028
note("merger: " + str(merger))
4243
4029
raise errors.PathsDoNotExist([location])
4244
note(gettext('Nothing to do.'))
4030
note('Nothing to do.')
4246
4032
if pull and not preview:
4247
4033
if merger.interesting_files is not None:
4248
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4034
raise errors.BzrCommandError('Cannot pull individual files')
4249
4035
if (merger.base_rev_id == tree.last_revision()):
4250
4036
result = tree.pull(merger.other_branch, False,
4251
4037
merger.other_rev_id)
4252
4038
result.report(self.outf)
4254
4040
if merger.this_basis is None:
4255
raise errors.BzrCommandError(gettext(
4041
raise errors.BzrCommandError(
4256
4042
"This branch has no commits."
4257
" (perhaps you would prefer 'bzr pull')"))
4043
" (perhaps you would prefer 'bzr pull')")
4259
4045
return self._do_preview(merger)
4260
4046
elif interactive:
4720
4504
theirs_only=False,
4721
4505
log_format=None, long=False, short=False, line=False,
4722
4506
show_ids=False, verbose=False, this=False, other=False,
4723
include_merged=None, revision=None, my_revision=None,
4725
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4507
include_merges=False, revision=None, my_revision=None,
4726
4509
from bzrlib.missing import find_unmerged, iter_log_revisions
4727
4510
def message(s):
4728
4511
if not is_quiet():
4729
4512
self.outf.write(s)
4731
if symbol_versioning.deprecated_passed(include_merges):
4732
ui.ui_factory.show_user_warning(
4733
'deprecated_command_option',
4734
deprecated_name='--include-merges',
4735
recommended_name='--include-merged',
4736
deprecated_in_version='2.5',
4737
command=self.invoked_as)
4738
if include_merged is None:
4739
include_merged = include_merges
4741
raise errors.BzrCommandError(gettext(
4742
'{0} and {1} are mutually exclusive').format(
4743
'--include-merges', '--include-merged'))
4744
if include_merged is None:
4745
include_merged = False
4747
4515
mine_only = this
5081
4845
location = b.get_old_bound_location()
5082
4846
except errors.UpgradeRequired:
5083
raise errors.BzrCommandError(gettext('No location supplied. '
5084
'This format does not remember old locations.'))
4847
raise errors.BzrCommandError('No location supplied. '
4848
'This format does not remember old locations.')
5086
4850
if location is None:
5087
4851
if b.get_bound_location() is not None:
5088
raise errors.BzrCommandError(gettext('Branch is already bound'))
4852
raise errors.BzrCommandError('Branch is already bound')
5090
raise errors.BzrCommandError(gettext('No location supplied '
5091
'and no previous location known'))
4854
raise errors.BzrCommandError('No location supplied '
4855
'and no previous location known')
5092
4856
b_other = Branch.open(location)
5094
4858
b.bind(b_other)
5095
4859
except errors.DivergedBranches:
5096
raise errors.BzrCommandError(gettext('These branches have diverged.'
5097
' Try merging, and then bind again.'))
4860
raise errors.BzrCommandError('These branches have diverged.'
4861
' Try merging, and then bind again.')
5098
4862
if b.get_config().has_explicit_nickname():
5099
4863
b.nick = b_other.nick
5167
4930
self.add_cleanup(tree.lock_write().unlock)
5169
4932
self.add_cleanup(b.lock_write().unlock)
5170
return self._run(b, tree, dry_run, verbose, revision, force,
4933
return self._run(b, tree, dry_run, verbose, revision, force, local=local)
5173
def _run(self, b, tree, dry_run, verbose, revision, force, local,
4935
def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5175
4936
from bzrlib.log import log_formatter, show_log
5176
4937
from bzrlib.uncommit import uncommit
5207
4968
end_revision=last_revno)
5210
self.outf.write(gettext('Dry-run, pretending to remove'
5211
' the above revisions.\n'))
4971
self.outf.write('Dry-run, pretending to remove'
4972
' the above revisions.\n')
5213
self.outf.write(gettext('The above revision(s) will be removed.\n'))
4974
self.outf.write('The above revision(s) will be removed.\n')
5216
4977
if not ui.ui_factory.confirm_action(
5217
gettext(u'Uncommit these revisions'),
4978
u'Uncommit these revisions',
5218
4979
'bzrlib.builtins.uncommit',
5220
self.outf.write(gettext('Canceled\n'))
4981
self.outf.write('Canceled\n')
5223
4984
mutter('Uncommitting from {%s} to {%s}',
5224
4985
last_rev_id, rev_id)
5225
4986
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5226
revno=revno, local=local, keep_tags=keep_tags)
5227
self.outf.write(gettext('You can restore the old tip by running:\n'
5228
' bzr pull . -r revid:%s\n') % last_rev_id)
4987
revno=revno, local=local)
4988
self.outf.write('You can restore the old tip by running:\n'
4989
' bzr pull . -r revid:%s\n' % last_rev_id)
5231
4992
class cmd_break_lock(Command):
5350
5109
if not allow_writes:
5351
5110
url = 'readonly+' + url
5352
5111
t = transport.get_transport(url)
5354
protocol(t, host, port, inet, client_timeout)
5355
except TypeError, e:
5356
# We use symbol_versioning.deprecated_in just so that people
5357
# grepping can find it here.
5358
# symbol_versioning.deprecated_in((2, 5, 0))
5359
symbol_versioning.warn(
5360
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5361
'Most likely it needs to be updated to support a'
5362
' "timeout" parameter (added in bzr 2.5.0)'
5363
% (e, protocol.__module__, protocol),
5365
protocol(t, host, port, inet)
5112
protocol(t, host, port, inet)
5368
5115
class cmd_join(Command):
5780
5527
self.add_cleanup(branch.lock_write().unlock)
5782
5529
if tag_name is None:
5783
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5530
raise errors.BzrCommandError("No tag specified to delete.")
5784
5531
branch.tags.delete_tag(tag_name)
5785
note(gettext('Deleted tag %s.') % tag_name)
5532
note('Deleted tag %s.' % tag_name)
5788
5535
if len(revision) != 1:
5789
raise errors.BzrCommandError(gettext(
5536
raise errors.BzrCommandError(
5790
5537
"Tags can only be placed on a single revision, "
5792
5539
revision_id = revision[0].as_revision_id(branch)
5794
5541
revision_id = branch.last_revision()
5795
5542
if tag_name is None:
5796
5543
tag_name = branch.automatic_tag_name(revision_id)
5797
5544
if tag_name is None:
5798
raise errors.BzrCommandError(gettext(
5799
"Please specify a tag name."))
5801
existing_target = branch.tags.lookup_tag(tag_name)
5802
except errors.NoSuchTag:
5803
existing_target = None
5804
if not force and existing_target not in (None, revision_id):
5545
raise errors.BzrCommandError(
5546
"Please specify a tag name.")
5547
if (not force) and branch.tags.has_tag(tag_name):
5805
5548
raise errors.TagAlreadyExists(tag_name)
5806
if existing_target == revision_id:
5807
note(gettext('Tag %s already exists for that revision.') % tag_name)
5809
branch.tags.set_tag(tag_name, revision_id)
5810
if existing_target is None:
5811
note(gettext('Created tag %s.') % tag_name)
5813
note(gettext('Updated tag %s.') % tag_name)
5549
branch.tags.set_tag(tag_name, revision_id)
5550
note('Created tag %s.' % tag_name)
5816
5553
class cmd_tags(Command):
5865
5604
for tag, revspec in tags:
5866
5605
self.outf.write('%-20s %s\n' % (tag, revspec))
5868
def _tags_for_range(self, branch, revision):
5870
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5871
revid1, revid2 = rev1.rev_id, rev2.rev_id
5872
# _get_revision_range will always set revid2 if it's not specified.
5873
# If revid1 is None, it means we want to start from the branch
5874
# origin which is always a valid ancestor. If revid1 == revid2, the
5875
# ancestry check is useless.
5876
if revid1 and revid1 != revid2:
5877
# FIXME: We really want to use the same graph than
5878
# branch.iter_merge_sorted_revisions below, but this is not
5879
# easily available -- vila 2011-09-23
5880
if branch.repository.get_graph().is_ancestor(revid2, revid1):
5881
# We don't want to output anything in this case...
5883
# only show revisions between revid1 and revid2 (inclusive)
5884
tagged_revids = branch.tags.get_reverse_tag_dict()
5886
for r in branch.iter_merge_sorted_revisions(
5887
start_revision_id=revid2, stop_revision_id=revid1,
5888
stop_rule='include'):
5889
revid_tags = tagged_revids.get(r[0], None)
5891
found.extend([(tag, r[0]) for tag in revid_tags])
5895
5608
class cmd_reconfigure(Command):
5896
5609
__doc__ = """Reconfigure the type of a bzr directory.
5910
5623
takes_args = ['location?']
5911
5624
takes_options = [
5912
5625
RegistryOption.from_kwargs(
5915
help='The relation between branch and tree.',
5627
title='Target type',
5628
help='The type to reconfigure the directory to.',
5916
5629
value_switches=True, enum_switch=False,
5917
5630
branch='Reconfigure to be an unbound branch with no working tree.',
5918
5631
tree='Reconfigure to be an unbound branch with a working tree.',
5919
5632
checkout='Reconfigure to be a bound branch with a working tree.',
5920
5633
lightweight_checkout='Reconfigure to be a lightweight'
5921
5634
' checkout (with no local history).',
5923
RegistryOption.from_kwargs(
5925
title='Repository type',
5926
help='Location fo the repository.',
5927
value_switches=True, enum_switch=False,
5928
5635
standalone='Reconfigure to be a standalone branch '
5929
5636
'(i.e. stop using shared repository).',
5930
5637
use_shared='Reconfigure to use a shared repository.',
5932
RegistryOption.from_kwargs(
5934
title='Trees in Repository',
5935
help='Whether new branches in the repository have trees.',
5936
value_switches=True, enum_switch=False,
5937
5638
with_trees='Reconfigure repository to create '
5938
5639
'working trees on branches by default.',
5939
5640
with_no_trees='Reconfigure repository to not create '
5956
def run(self, location=None, bind_to=None, force=False,
5957
tree_type=None, repository_type=None, repository_trees=None,
5958
stacked_on=None, unstacked=None):
5959
directory = controldir.ControlDir.open(location)
5657
def run(self, location=None, target_type=None, bind_to=None, force=False,
5660
directory = bzrdir.BzrDir.open(location)
5960
5661
if stacked_on and unstacked:
5961
raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5662
raise errors.BzrCommandError("Can't use both --stacked-on and --unstacked")
5962
5663
elif stacked_on is not None:
5963
5664
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5964
5665
elif unstacked:
5966
5667
# At the moment you can use --stacked-on and a different
5967
5668
# reconfiguration shape at the same time; there seems no good reason
5969
if (tree_type is None and
5970
repository_type is None and
5971
repository_trees is None):
5670
if target_type is None:
5972
5671
if stacked_on or unstacked:
5975
raise errors.BzrCommandError(gettext('No target configuration '
5977
reconfiguration = None
5978
if tree_type == 'branch':
5674
raise errors.BzrCommandError('No target configuration '
5676
elif target_type == 'branch':
5979
5677
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5980
elif tree_type == 'tree':
5678
elif target_type == 'tree':
5981
5679
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5982
elif tree_type == 'checkout':
5680
elif target_type == 'checkout':
5983
5681
reconfiguration = reconfigure.Reconfigure.to_checkout(
5984
5682
directory, bind_to)
5985
elif tree_type == 'lightweight-checkout':
5683
elif target_type == 'lightweight-checkout':
5986
5684
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5987
5685
directory, bind_to)
5989
reconfiguration.apply(force)
5990
reconfiguration = None
5991
if repository_type == 'use-shared':
5686
elif target_type == 'use-shared':
5992
5687
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5993
elif repository_type == 'standalone':
5688
elif target_type == 'standalone':
5994
5689
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5996
reconfiguration.apply(force)
5997
reconfiguration = None
5998
if repository_trees == 'with-trees':
5690
elif target_type == 'with-trees':
5999
5691
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6000
5692
directory, True)
6001
elif repository_trees == 'with-no-trees':
5693
elif target_type == 'with-no-trees':
6002
5694
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6003
5695
directory, False)
6005
reconfiguration.apply(force)
6006
reconfiguration = None
5696
reconfiguration.apply(force)
6009
5699
class cmd_switch(Command):
6197
5887
name = current_view
6200
raise errors.BzrCommandError(gettext(
6201
"Both --delete and a file list specified"))
5890
raise errors.BzrCommandError(
5891
"Both --delete and a file list specified")
6203
raise errors.BzrCommandError(gettext(
6204
"Both --delete and --switch specified"))
5893
raise errors.BzrCommandError(
5894
"Both --delete and --switch specified")
6206
5896
tree.views.set_view_info(None, {})
6207
self.outf.write(gettext("Deleted all views.\n"))
5897
self.outf.write("Deleted all views.\n")
6208
5898
elif name is None:
6209
raise errors.BzrCommandError(gettext("No current view to delete"))
5899
raise errors.BzrCommandError("No current view to delete")
6211
5901
tree.views.delete_view(name)
6212
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5902
self.outf.write("Deleted '%s' view.\n" % name)
6215
raise errors.BzrCommandError(gettext(
6216
"Both --switch and a file list specified"))
5905
raise errors.BzrCommandError(
5906
"Both --switch and a file list specified")
6218
raise errors.BzrCommandError(gettext(
6219
"Both --switch and --all specified"))
5908
raise errors.BzrCommandError(
5909
"Both --switch and --all specified")
6220
5910
elif switch == 'off':
6221
5911
if current_view is None:
6222
raise errors.BzrCommandError(gettext("No current view to disable"))
5912
raise errors.BzrCommandError("No current view to disable")
6223
5913
tree.views.set_view_info(None, view_dict)
6224
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5914
self.outf.write("Disabled '%s' view.\n" % (current_view))
6226
5916
tree.views.set_view_info(switch, view_dict)
6227
5917
view_str = views.view_display_str(tree.views.lookup_view())
6228
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5918
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6231
self.outf.write(gettext('Views defined:\n'))
5921
self.outf.write('Views defined:\n')
6232
5922
for view in sorted(view_dict):
6233
5923
if view == current_view:
6237
5927
view_str = views.view_display_str(view_dict[view])
6238
5928
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
6240
self.outf.write(gettext('No views defined.\n'))
5930
self.outf.write('No views defined.\n')
6241
5931
elif file_list:
6242
5932
if name is None:
6243
5933
# No name given and no current view set
6245
5935
elif name == 'off':
6246
raise errors.BzrCommandError(gettext(
6247
"Cannot change the 'off' pseudo view"))
5936
raise errors.BzrCommandError(
5937
"Cannot change the 'off' pseudo view")
6248
5938
tree.views.set_view(name, sorted(file_list))
6249
5939
view_str = views.view_display_str(tree.views.lookup_view())
6250
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5940
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6252
5942
# list the files
6253
5943
if name is None:
6254
5944
# No name given and no current view set
6255
self.outf.write(gettext('No current view.\n'))
5945
self.outf.write('No current view.\n')
6257
5947
view_str = views.view_display_str(tree.views.lookup_view(name))
6258
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
5948
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6261
5951
class cmd_hooks(Command):
6531
6217
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6532
6218
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6533
6219
('cmd_conflicts', [], 'bzrlib.conflicts'),
6534
('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
6535
('cmd_verify_signatures', [],
6536
'bzrlib.commit_signature_commands'),
6220
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6537
6221
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6539
6223
builtin_command_registry.register_lazy(name, aliases, module_name)