75
74
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
77
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
78
78
def tree_files(file_list, default_branch=u'.', canonicalize=True,
81
return internal_tree_files(file_list, default_branch, canonicalize,
83
except errors.FileInWrongBranch, e:
84
raise errors.BzrCommandError("%s is not in the same branch as %s" %
85
(e.path, file_list[0]))
80
return internal_tree_files(file_list, default_branch, canonicalize,
88
84
def tree_files_for_add(file_list):
153
149
# XXX: Bad function name; should possibly also be a class method of
154
150
# WorkingTree rather than a function.
151
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
152
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
153
apply_view=True):
157
154
"""Convert command-line paths to a WorkingTree and relative paths.
156
Deprecated: use WorkingTree.open_containing_paths instead.
159
158
This is typically used for command-line processors that take one or
160
159
more filenames, and infer the workingtree that contains them.
172
171
:return: workingtree, [relative_paths]
174
if file_list is None or len(file_list) == 0:
175
tree = WorkingTree.open_containing(default_branch)[0]
176
if tree.supports_views() and apply_view:
177
view_files = tree.views.lookup_view()
179
file_list = view_files
180
view_str = views.view_display_str(view_files)
181
note("Ignoring files outside view. View is %s" % view_str)
182
return tree, file_list
183
tree = WorkingTree.open_containing(file_list[0])[0]
184
return tree, safe_relpath_files(tree, file_list, canonicalize,
185
apply_view=apply_view)
188
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
189
"""Convert file_list into a list of relpaths in tree.
191
:param tree: A tree to operate on.
192
:param file_list: A list of user provided paths or None.
193
:param apply_view: if True and a view is set, apply it or check that
194
specified files are within it
195
:return: A list of relative paths.
196
:raises errors.PathNotChild: When a provided path is in a different tree
199
if file_list is None:
201
if tree.supports_views() and apply_view:
202
view_files = tree.views.lookup_view()
206
# tree.relpath exists as a "thunk" to osutils, but canonical_relpath
207
# doesn't - fix that up here before we enter the loop.
209
fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
212
for filename in file_list:
214
relpath = fixer(osutils.dereference_path(filename))
215
if view_files and not osutils.is_inside_any(view_files, relpath):
216
raise errors.FileOutsideView(filename, view_files)
217
new_list.append(relpath)
218
except errors.PathNotChild:
219
raise errors.FileInWrongBranch(tree.branch, filename)
173
return WorkingTree.open_containing_paths(
174
file_list, default_directory='.',
223
179
def _get_view_info_for_change_reporter(tree):
294
250
To skip the display of pending merge information altogether, use
295
251
the no-pending option or specify a file/directory.
297
If a revision argument is given, the status is calculated against
298
that revision, or between two revisions if two are provided.
253
To compare the working directory to a specific revision, pass a
254
single revision to the revision argument.
256
To see which files have changed in a specific revision, or between
257
two revisions, pass a revision range to the revision argument.
258
This will produce the same results as calling 'bzr diff --summarize'.
301
261
# TODO: --no-recurse, --recurse options
966
927
"branch. Local pulls are not applied to "
967
928
"the master branch."
931
help="Show base revision text in conflicts.")
970
933
takes_args = ['location?']
971
934
encoding_type = 'replace'
973
936
def run(self, location=None, remember=False, overwrite=False,
974
937
revision=None, verbose=False,
975
directory=None, local=False):
938
directory=None, local=False,
976
940
# FIXME: too much stuff is in the command class
977
941
revision_id = None
1106
1077
def run(self, location=None, remember=False, overwrite=False,
1107
1078
create_prefix=False, verbose=False, revision=None,
1108
1079
use_existing_dir=False, directory=None, stacked_on=None,
1109
stacked=False, strict=None):
1080
stacked=False, strict=None, no_tree=False):
1110
1081
from bzrlib.push import _show_push_branch
1112
1083
if directory is None:
1158
1129
_show_push_branch(br_from, revision_id, location, self.outf,
1159
1130
verbose=verbose, overwrite=overwrite, remember=remember,
1160
1131
stacked_on=stacked_on, create_prefix=create_prefix,
1161
use_existing_dir=use_existing_dir)
1132
use_existing_dir=use_existing_dir, no_tree=no_tree)
1164
1135
class cmd_branch(Command):
1178
1149
_see_also = ['checkout']
1179
1150
takes_args = ['from_location', 'to_location?']
1180
takes_options = ['revision', Option('hardlink',
1181
help='Hard-link working tree files where possible.'),
1151
takes_options = ['revision',
1152
Option('hardlink', help='Hard-link working tree files where possible.'),
1153
Option('files-from', type=str,
1154
help="Get file contents from this tree."),
1182
1155
Option('no-tree',
1183
1156
help="Create a branch without a working-tree."),
1184
1157
Option('switch',
1203
1176
def run(self, from_location, to_location=None, revision=None,
1204
1177
hardlink=False, stacked=False, standalone=False, no_tree=False,
1205
use_existing_dir=False, switch=False, bind=False):
1178
use_existing_dir=False, switch=False, bind=False,
1206
1180
from bzrlib import switch as _mod_switch
1207
1181
from bzrlib.tag import _merge_tags_if_possible
1208
1182
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1184
if not (hardlink or files_from):
1185
# accelerator_tree is usually slower because you have to read N
1186
# files (no readahead, lots of seeks, etc), but allow the user to
1187
# explicitly request it
1188
accelerator_tree = None
1189
if files_from is not None and files_from != from_location:
1190
accelerator_tree = WorkingTree.open(files_from)
1210
1191
revision = _get_one_revision('branch', revision)
1211
1192
self.add_cleanup(br_from.lock_read().unlock)
1212
1193
if revision is not None:
1319
1300
to_location = branch_location
1320
1301
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1321
1302
branch_location)
1303
if not (hardlink or files_from):
1304
# accelerator_tree is usually slower because you have to read N
1305
# files (no readahead, lots of seeks, etc), but allow the user to
1306
# explicitly request it
1307
accelerator_tree = None
1322
1308
revision = _get_one_revision('checkout', revision)
1323
if files_from is not None:
1309
if files_from is not None and files_from != branch_location:
1324
1310
accelerator_tree = WorkingTree.open(files_from)
1325
1311
if revision is not None:
1326
1312
revision_id = revision.as_revision_id(source)
1382
1368
If you want to discard your local changes, you can just do a
1383
1369
'bzr revert' instead of 'bzr commit' after the update.
1371
If you want to restore a file that has been removed locally, use
1372
'bzr revert' instead of 'bzr update'.
1385
1374
If the tree's branch is bound to a master branch, it will also update
1386
1375
the branch from the master.
1389
1378
_see_also = ['pull', 'working-trees', 'status-flags']
1390
1379
takes_args = ['dir?']
1391
takes_options = ['revision']
1380
takes_options = ['revision',
1382
help="Show base revision text in conflicts."),
1392
1384
aliases = ['up']
1394
def run(self, dir='.', revision=None):
1386
def run(self, dir='.', revision=None, show_base=None):
1395
1387
if revision is not None and len(revision) != 1:
1396
1388
raise errors.BzrCommandError(
1397
1389
"bzr update --revision takes exactly one revision")
1505
1498
class cmd_remove(Command):
1506
1499
__doc__ = """Remove files or directories.
1508
This makes bzr stop tracking changes to the specified files. bzr will delete
1509
them if they can easily be recovered using revert. If no options or
1510
parameters are given bzr will scan for files that are being tracked by bzr
1511
but missing in your tree and stop tracking them for you.
1501
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1502
delete them if they can easily be recovered using revert otherwise they
1503
will be backed up (adding an extention of the form .~#~). If no options or
1504
parameters are given Bazaar will scan for files that are being tracked by
1505
Bazaar but missing in your tree and stop tracking them for you.
1513
1507
takes_args = ['file*']
1514
1508
takes_options = ['verbose',
1516
1510
RegistryOption.from_kwargs('file-deletion-strategy',
1517
1511
'The file deletion mode to be used.',
1518
1512
title='Deletion Strategy', value_switches=True, enum_switch=False,
1519
safe='Only delete files if they can be'
1520
' safely recovered (default).',
1513
safe='Backup changed files (default).',
1521
1514
keep='Delete from bzr but leave the working copy.',
1515
no_backup='Don\'t backup changed files.',
1522
1516
force='Delete all the specified files, even if they can not be '
1523
'recovered and even if they are non-empty directories.')]
1517
'recovered and even if they are non-empty directories. '
1518
'(deprecated, use no-backup)')]
1524
1519
aliases = ['rm', 'del']
1525
1520
encoding_type = 'replace'
1527
1522
def run(self, file_list, verbose=False, new=False,
1528
1523
file_deletion_strategy='safe'):
1529
tree, file_list = tree_files(file_list)
1524
if file_deletion_strategy == 'force':
1525
note("(The --force option is deprecated, rather use --no-backup "
1527
file_deletion_strategy = 'no-backup'
1529
tree, file_list = WorkingTree.open_containing_paths(file_list)
1531
1531
if file_list is not None:
1532
1532
file_list = [f for f in file_list]
1621
1621
_see_also = ['check']
1622
1622
takes_args = ['branch?']
1624
Option('canonicalize-chks',
1625
help='Make sure CHKs are in canonical form (repairs '
1624
def run(self, branch="."):
1630
def run(self, branch=".", canonicalize_chks=False):
1625
1631
from bzrlib.reconcile import reconcile
1626
1632
dir = bzrdir.BzrDir.open(branch)
1633
reconcile(dir, canonicalize_chks=canonicalize_chks)
1630
1636
class cmd_revision_history(Command):
1708
1714
Option('append-revisions-only',
1709
1715
help='Never change revnos or the existing log.'
1710
' Append revisions to it only.')
1716
' Append revisions to it only.'),
1718
'Create a branch without a working tree.')
1712
1720
def run(self, location=None, format=None, append_revisions_only=False,
1713
create_prefix=False):
1721
create_prefix=False, no_tree=False):
1714
1722
if format is None:
1715
1723
format = bzrdir.format_registry.make_bzrdir('default')
1716
1724
if location is None:
3289
3330
class cmd_upgrade(Command):
3290
__doc__ = """Upgrade branch storage to current format.
3292
The check command or bzr developers may sometimes advise you to run
3293
this command. When the default format has changed you may also be warned
3294
during other operations to upgrade.
3331
__doc__ = """Upgrade a repository, branch or working tree to a newer format.
3333
When the default format has changed after a major new release of
3334
Bazaar, you may be informed during certain operations that you
3335
should upgrade. Upgrading to a newer format may improve performance
3336
or make new features available. It may however limit interoperability
3337
with older repositories or with older versions of Bazaar.
3339
If you wish to upgrade to a particular format rather than the
3340
current default, that can be specified using the --format option.
3341
As a consequence, you can use the upgrade command this way to
3342
"downgrade" to an earlier format, though some conversions are
3343
a one way process (e.g. changing from the 1.x default to the
3344
2.x default) so downgrading is not always possible.
3346
A backup.bzr.~#~ directory is created at the start of the conversion
3347
process (where # is a number). By default, this is left there on
3348
completion. If the conversion fails, delete the new .bzr directory
3349
and rename this one back in its place. Use the --clean option to ask
3350
for the backup.bzr directory to be removed on successful conversion.
3351
Alternatively, you can delete it by hand if everything looks good
3354
If the location given is a shared repository, dependent branches
3355
are also converted provided the repository converts successfully.
3356
If the conversion of a branch fails, remaining branches are still
3359
For more information on upgrades, see the Bazaar Upgrade Guide,
3360
http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3297
_see_also = ['check']
3363
_see_also = ['check', 'reconcile', 'formats']
3298
3364
takes_args = ['url?']
3299
3365
takes_options = [
3300
RegistryOption('format',
3301
help='Upgrade to a specific format. See "bzr help'
3302
' formats" for details.',
3303
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3304
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3305
value_switches=True, title='Branch format'),
3366
RegistryOption('format',
3367
help='Upgrade to a specific format. See "bzr help'
3368
' formats" for details.',
3369
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3370
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3371
value_switches=True, title='Branch format'),
3373
help='Remove the backup.bzr directory if successful.'),
3375
help="Show what would be done, but don't actually do anything."),
3308
def run(self, url='.', format=None):
3378
def run(self, url='.', format=None, clean=False, dry_run=False):
3309
3379
from bzrlib.upgrade import upgrade
3310
upgrade(url, format)
3380
exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
3382
if len(exceptions) == 1:
3383
# Compatibility with historical behavior
3313
3389
class cmd_whoami(Command):
3436
3512
'bzr alias --remove expects an alias to remove.')
3437
3513
# If alias is not found, print something like:
3438
3514
# unalias: foo: not found
3439
c = config.GlobalConfig()
3515
c = _mod_config.GlobalConfig()
3440
3516
c.unset_alias(alias_name)
3442
3518
@display_command
3443
3519
def print_aliases(self):
3444
3520
"""Print out the defined aliases in a similar format to bash."""
3445
aliases = config.GlobalConfig().get_aliases()
3521
aliases = _mod_config.GlobalConfig().get_aliases()
3446
3522
for key, value in sorted(aliases.iteritems()):
3447
3523
self.outf.write('bzr alias %s="%s"\n' % (key, value))
3588
3667
randomize=None, exclude=None, strict=False,
3589
3668
load_list=None, debugflag=None, starting_with=None, subunit=False,
3590
3669
parallel=None, lsprof_tests=False):
3591
from bzrlib.tests import selftest
3593
# Make deprecation warnings visible, unless -Werror is set
3594
symbol_versioning.activate_deprecation_warnings(override=False)
3670
from bzrlib import tests
3596
3672
if testspecs_list is not None:
3597
3673
pattern = '|'.join(testspecs_list)
3701
3784
with bzr send. If neither is specified, the default is the upstream branch
3702
3785
or the branch most recently merged using --remember.
3704
When merging a branch, by default the tip will be merged. To pick a different
3705
revision, pass --revision. If you specify two values, the first will be used as
3706
BASE and the second one as OTHER. Merging individual revisions, or a subset of
3707
available revisions, like this is commonly referred to as "cherrypicking".
3709
Revision numbers are always relative to the branch being merged.
3711
By default, bzr will try to merge in all new work from the other
3712
branch, automatically determining an appropriate base. If this
3713
fails, you may need to give an explicit base.
3787
When merging from a branch, by default bzr will try to merge in all new
3788
work from the other branch, automatically determining an appropriate base
3789
revision. If this fails, you may need to give an explicit base.
3791
To pick a different ending revision, pass "--revision OTHER". bzr will
3792
try to merge in all new work up to and including revision OTHER.
3794
If you specify two values, "--revision BASE..OTHER", only revisions BASE
3795
through OTHER, excluding BASE but including OTHER, will be merged. If this
3796
causes some revisions to be skipped, i.e. if the destination branch does
3797
not already contain revision BASE, such a merge is commonly referred to as
3800
Revision numbers are always relative to the source branch.
3715
3802
Merge will do its best to combine the changes in two branches, but there
3716
3803
are some kinds of problems only a human can fix. When it encounters those,
3980
4067
if ((remember or tree.branch.get_submit_branch() is None) and
3981
4068
user_location is not None):
3982
4069
tree.branch.set_submit_branch(other_branch.base)
3983
_merge_tags_if_possible(other_branch, tree.branch)
4070
# Merge tags (but don't set them in the master branch yet, the user
4071
# might revert this merge). Commit will propagate them.
4072
_merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3984
4073
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3985
4074
other_revision_id, base_revision_id, other_branch, base_branch)
3986
4075
if other_path != '':
4154
4243
last committed revision is used.
4156
4245
To remove only some changes, without reverting to a prior version, use
4157
merge instead. For example, "merge . --revision -2..-3" will remove the
4158
changes introduced by -2, without affecting the changes introduced by -1.
4159
Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
4246
merge instead. For example, "merge . -r -2..-3" (don't forget the ".")
4247
will remove the changes introduced by the second last commit (-2), without
4248
affecting the changes introduced by the last commit (-1). To remove
4249
certain changes on a hunk-by-hunk basis, see the shelve command.
4161
4251
By default, any files that have been manually changed will be backed up
4162
4252
first. (Files changed only by merge are not backed up.) Backup files have
4838
4934
bzr break-lock bzr+ssh://example.com/bzr/foo
4935
bzr break-lock --conf ~/.bazaar
4840
4938
takes_args = ['location?']
4941
help='LOCATION is the directory where the config lock is.'),
4943
help='Do not ask for confirmation before breaking the lock.'),
4842
def run(self, location=None, show=False):
4946
def run(self, location=None, config=False, force=False):
4843
4947
if location is None:
4844
4948
location = u'.'
4845
control, relpath = bzrdir.BzrDir.open_containing(location)
4847
control.break_lock()
4848
except NotImplementedError:
4950
ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
4952
{'bzrlib.lockdir.break': True})
4954
conf = _mod_config.LockableConfig(file_name=location)
4957
control, relpath = bzrdir.BzrDir.open_containing(location)
4959
control.break_lock()
4960
except NotImplementedError:
4852
4964
class cmd_wait_until_signalled(Command):
5370
5482
takes_options = [
5371
5483
custom_help('directory',
5372
5484
help='Branch whose tags should be displayed.'),
5373
RegistryOption.from_kwargs('sort',
5485
RegistryOption('sort',
5374
5486
'Sort tags by different criteria.', title='Sorting',
5375
alpha='Sort tags lexicographically (default).',
5376
time='Sort tags chronologically.',
5487
lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5382
5493
@display_command
5494
def run(self, directory='.', sort=None, show_ids=False, revision=None):
5495
from bzrlib.tag import tag_sort_methods
5389
5496
branch, relpath = Branch.open_containing(directory)
5391
5498
tags = branch.tags.get_tag_dict().items()
5400
5507
# only show revisions between revid1 and revid2 (inclusive)
5401
5508
tags = [(tag, revid) for tag, revid in tags if
5402
5509
graph.is_between(revid, revid1, revid2)]
5405
elif sort == 'time':
5407
for tag, revid in tags:
5409
revobj = branch.repository.get_revision(revid)
5410
except errors.NoSuchRevision:
5411
timestamp = sys.maxint # place them at the end
5413
timestamp = revobj.timestamp
5414
timestamps[revid] = timestamp
5415
tags.sort(key=lambda x: timestamps[x[1]])
5511
sort = tag_sort_methods.get()
5416
5513
if not show_ids:
5417
5514
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5418
5515
for index, (tag, revid) in enumerate(tags):
5841
5939
You can put multiple items on the shelf, and by default, 'unshelve' will
5842
5940
restore the most recently shelved changes.
5942
For complicated changes, it is possible to edit the changes in a separate
5943
editor program to decide what the file remaining in the working copy
5944
should look like. To do this, add the configuration option
5946
change_editor = PROGRAM @new_path @old_path
5948
where @new_path is replaced with the path of the new version of the
5949
file and @old_path is replaced with the path of the old version of
5950
the file. The PROGRAM should save the new file with the desired
5951
contents of the file in the working tree.
5845
5955
takes_args = ['file*']
5857
5967
Option('destroy',
5858
5968
help='Destroy removed changes instead of shelving them.'),
5860
_see_also = ['unshelve']
5970
_see_also = ['unshelve', 'configuration']
5862
5972
def run(self, revision=None, all=False, file_list=None, message=None,
5863
writer=None, list=False, destroy=False, directory=u'.'):
5973
writer=None, list=False, destroy=False, directory=None):
5865
return self.run_for_list()
5975
return self.run_for_list(directory=directory)
5866
5976
from bzrlib.shelf_ui import Shelver
5867
5977
if writer is None:
5868
5978
writer = bzrlib.option.diff_writer_registry.get()
6012
6124
# be only called once.
6013
6125
for (name, aliases, module_name) in [
6014
6126
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6127
('cmd_config', [], 'bzrlib.config'),
6015
6128
('cmd_dpush', [], 'bzrlib.foreign'),
6016
6129
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6017
6130
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6018
6131
('cmd_conflicts', [], 'bzrlib.conflicts'),
6019
6132
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6133
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6021
6135
builtin_command_registry.register_lazy(name, aliases, module_name)