72
73
_parse_revision_str,
74
75
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
80
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
81
78
def tree_files(file_list, default_branch=u'.', canonicalize=True,
83
return internal_tree_files(file_list, default_branch, canonicalize,
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]))
87
88
def tree_files_for_add(file_list):
152
153
# XXX: Bad function name; should possibly also be a class method of
153
154
# WorkingTree rather than a function.
154
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
155
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
156
apply_view=True):
157
157
"""Convert command-line paths to a WorkingTree and relative paths.
159
Deprecated: use WorkingTree.open_containing_paths instead.
161
159
This is typically used for command-line processors that take one or
162
160
more filenames, and infer the workingtree that contains them.
174
172
:return: workingtree, [relative_paths]
176
return WorkingTree.open_containing_paths(
177
file_list, default_directory='.',
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(osutils.realpath(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)
182
223
def _get_view_info_for_change_reporter(tree):
233
274
Not versioned and not matching an ignore pattern.
235
Additionally for directories, symlinks and files with a changed
236
executable bit, Bazaar indicates their type using a trailing
237
character: '/', '@' or '*' respectively. These decorations can be
238
disabled using the '--no-classify' option.
276
Additionally for directories, symlinks and files with an executable
277
bit, Bazaar indicates their type using a trailing character: '/', '@'
240
280
To see ignored files use 'bzr ignored'. For details on the
241
281
changes to file texts, use 'bzr diff'.
254
294
To skip the display of pending merge information altogether, use
255
295
the no-pending option or specify a file/directory.
257
To compare the working directory to a specific revision, pass a
258
single revision to the revision argument.
260
To see which files have changed in a specific revision, or between
261
two revisions, pass a revision range to the revision argument.
262
This will produce the same results as calling 'bzr diff --summarize'.
297
If a revision argument is given, the status is calculated against
298
that revision, or between two revisions if two are provided.
265
301
# TODO: --no-recurse, --recurse options
285
318
def run(self, show_ids=False, file_list=None, revision=None, short=False,
286
versioned=False, no_pending=False, verbose=False,
319
versioned=False, no_pending=False, verbose=False):
288
320
from bzrlib.status import show_tree_status
290
322
if revision and len(revision) > 2:
291
323
raise errors.BzrCommandError('bzr status --revision takes exactly'
292
324
' one or two revision specifiers')
294
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
326
tree, relfile_list = tree_files(file_list)
295
327
# Avoid asking for specific files when that is not needed.
296
328
if relfile_list == ['']:
297
329
relfile_list = None
304
336
show_tree_status(tree, show_ids=show_ids,
305
337
specific_files=relfile_list, revision=revision,
306
338
to_file=self.outf, short=short, versioned=versioned,
307
show_pending=(not no_pending), verbose=verbose,
308
classify=not no_classify)
339
show_pending=(not no_pending), verbose=verbose)
311
342
class cmd_cat_revision(Command):
494
519
d.destroy_workingtree()
497
class cmd_repair_workingtree(Command):
498
__doc__ = """Reset the working tree state file.
500
This is not meant to be used normally, but more as a way to recover from
501
filesystem corruption, etc. This rebuilds the working inventory back to a
502
'known good' state. Any new modifications (adding a file, renaming, etc)
503
will be lost, though modified files will still be detected as such.
505
Most users will want something more like "bzr revert" or "bzr update"
506
unless the state file has become corrupted.
508
By default this attempts to recover the current state by looking at the
509
headers of the state file. If the state file is too corrupted to even do
510
that, you can supply --revision to force the state of the tree.
513
takes_options = ['revision', 'directory',
515
help='Reset the tree even if it doesn\'t appear to be'
520
def run(self, revision=None, directory='.', force=False):
521
tree, _ = WorkingTree.open_containing(directory)
522
self.add_cleanup(tree.lock_tree_write().unlock)
526
except errors.BzrError:
527
pass # There seems to be a real error here, so we'll reset
530
raise errors.BzrCommandError(
531
'The tree does not appear to be corrupt. You probably'
532
' want "bzr revert" instead. Use "--force" if you are'
533
' sure you want to reset the working tree.')
537
revision_ids = [r.as_revision_id(tree.branch) for r in revision]
539
tree.reset_state(revision_ids)
540
except errors.BzrError, e:
541
if revision_ids is None:
542
extra = (', the header appears corrupt, try passing -r -1'
543
' to set the state to the last commit')
546
raise errors.BzrCommandError('failed to reset the tree state'
550
522
class cmd_revno(Command):
551
523
__doc__ = """Show current revision number.
972
942
match the remote one, use pull --overwrite. This will work even if the two
973
943
branches have diverged.
975
If there is no default location set, the first pull will set it (use
976
--no-remember to avoid settting it). After that, you can omit the
977
location to use the default. To change the default, use --remember. The
978
value will only be saved if the remote location can be accessed.
945
If there is no default location set, the first pull will set it. After
946
that, you can omit the location to use the default. To change the
947
default, use --remember. The value will only be saved if the remote
948
location can be accessed.
980
950
Note: The location can be specified either in the form of a branch,
981
951
or in the form of a path to a file containing a merge directive generated
994
964
"branch. Local pulls are not applied to "
995
965
"the master branch."
998
help="Show base revision text in conflicts.")
1000
968
takes_args = ['location?']
1001
969
encoding_type = 'replace'
1003
def run(self, location=None, remember=None, overwrite=False,
971
def run(self, location=None, remember=False, overwrite=False,
1004
972
revision=None, verbose=False,
1005
directory=None, local=False,
973
directory=None, local=False):
1007
974
# FIXME: too much stuff is in the command class
1008
975
revision_id = None
1009
976
mergeable = None
1109
1067
do a merge (see bzr help merge) from the other branch, and commit that.
1110
1068
After that you will be able to do a push without '--overwrite'.
1112
If there is no default push location set, the first push will set it (use
1113
--no-remember to avoid settting it). After that, you can omit the
1114
location to use the default. To change the default, use --remember. The
1115
value will only be saved if the remote location can be accessed.
1070
If there is no default push location set, the first push will set it.
1071
After that, you can omit the location to use the default. To change the
1072
default, use --remember. The value will only be saved if the remote
1073
location can be accessed.
1118
1076
_see_also = ['pull', 'update', 'working-trees']
1139
1097
Option('strict',
1140
1098
help='Refuse to push if there are uncommitted changes in'
1141
1099
' the working tree, --no-strict disables the check.'),
1143
help="Don't populate the working tree, even for protocols"
1144
" that support it."),
1146
1101
takes_args = ['location?']
1147
1102
encoding_type = 'replace'
1149
def run(self, location=None, remember=None, overwrite=False,
1104
def run(self, location=None, remember=False, overwrite=False,
1150
1105
create_prefix=False, verbose=False, revision=None,
1151
1106
use_existing_dir=False, directory=None, stacked_on=None,
1152
stacked=False, strict=None, no_tree=False):
1107
stacked=False, strict=None):
1153
1108
from bzrlib.push import _show_push_branch
1155
1110
if directory is None:
1201
1156
_show_push_branch(br_from, revision_id, location, self.outf,
1202
1157
verbose=verbose, overwrite=overwrite, remember=remember,
1203
1158
stacked_on=stacked_on, create_prefix=create_prefix,
1204
use_existing_dir=use_existing_dir, no_tree=no_tree)
1159
use_existing_dir=use_existing_dir)
1207
1162
class cmd_branch(Command):
1217
1172
To retrieve the branch as of a particular revision, supply the --revision
1218
1173
parameter, as in "branch foo/bar -r 5".
1220
The synonyms 'clone' and 'get' for this command are deprecated.
1223
1176
_see_also = ['checkout']
1224
1177
takes_args = ['from_location', 'to_location?']
1225
takes_options = ['revision',
1226
Option('hardlink', help='Hard-link working tree files where possible.'),
1227
Option('files-from', type=str,
1228
help="Get file contents from this tree."),
1178
takes_options = ['revision', Option('hardlink',
1179
help='Hard-link working tree files where possible.'),
1229
1180
Option('no-tree',
1230
1181
help="Create a branch without a working-tree."),
1231
1182
Option('switch',
1250
1201
def run(self, from_location, to_location=None, revision=None,
1251
1202
hardlink=False, stacked=False, standalone=False, no_tree=False,
1252
use_existing_dir=False, switch=False, bind=False,
1203
use_existing_dir=False, switch=False, bind=False):
1254
1204
from bzrlib import switch as _mod_switch
1255
1205
from bzrlib.tag import _merge_tags_if_possible
1256
if self.invoked_as in ['get', 'clone']:
1257
ui.ui_factory.show_user_warning(
1258
'deprecated_command',
1259
deprecated_name=self.invoked_as,
1260
recommended_name='branch',
1261
deprecated_in_version='2.4')
1262
1206
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1264
if not (hardlink or files_from):
1265
# accelerator_tree is usually slower because you have to read N
1266
# files (no readahead, lots of seeks, etc), but allow the user to
1267
# explicitly request it
1268
accelerator_tree = None
1269
if files_from is not None and files_from != from_location:
1270
accelerator_tree = WorkingTree.open(files_from)
1271
1208
revision = _get_one_revision('branch', revision)
1272
1209
self.add_cleanup(br_from.lock_read().unlock)
1273
1210
if revision is not None:
1380
1317
to_location = branch_location
1381
1318
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1382
1319
branch_location)
1383
if not (hardlink or files_from):
1384
# accelerator_tree is usually slower because you have to read N
1385
# files (no readahead, lots of seeks, etc), but allow the user to
1386
# explicitly request it
1387
accelerator_tree = None
1388
1320
revision = _get_one_revision('checkout', revision)
1389
if files_from is not None and files_from != branch_location:
1321
if files_from is not None:
1390
1322
accelerator_tree = WorkingTree.open(files_from)
1391
1323
if revision is not None:
1392
1324
revision_id = revision.as_revision_id(source)
1448
1380
If you want to discard your local changes, you can just do a
1449
1381
'bzr revert' instead of 'bzr commit' after the update.
1451
If you want to restore a file that has been removed locally, use
1452
'bzr revert' instead of 'bzr update'.
1454
1383
If the tree's branch is bound to a master branch, it will also update
1455
1384
the branch from the master.
1458
1387
_see_also = ['pull', 'working-trees', 'status-flags']
1459
1388
takes_args = ['dir?']
1460
takes_options = ['revision',
1462
help="Show base revision text in conflicts."),
1389
takes_options = ['revision']
1464
1390
aliases = ['up']
1466
def run(self, dir='.', revision=None, show_base=None):
1392
def run(self, dir='.', revision=None):
1467
1393
if revision is not None and len(revision) != 1:
1468
1394
raise errors.BzrCommandError(
1469
1395
"bzr update --revision takes exactly one revision")
1578
1503
class cmd_remove(Command):
1579
1504
__doc__ = """Remove files or directories.
1581
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1582
delete them if they can easily be recovered using revert otherwise they
1583
will be backed up (adding an extention of the form .~#~). If no options or
1584
parameters are given Bazaar will scan for files that are being tracked by
1585
Bazaar but missing in your tree and stop tracking them for you.
1506
This makes bzr stop tracking changes to the specified files. bzr will delete
1507
them if they can easily be recovered using revert. If no options or
1508
parameters are given bzr will scan for files that are being tracked by bzr
1509
but missing in your tree and stop tracking them for you.
1587
1511
takes_args = ['file*']
1588
1512
takes_options = ['verbose',
1590
1514
RegistryOption.from_kwargs('file-deletion-strategy',
1591
1515
'The file deletion mode to be used.',
1592
1516
title='Deletion Strategy', value_switches=True, enum_switch=False,
1593
safe='Backup changed files (default).',
1517
safe='Only delete files if they can be'
1518
' safely recovered (default).',
1594
1519
keep='Delete from bzr but leave the working copy.',
1595
no_backup='Don\'t backup changed files.',
1596
1520
force='Delete all the specified files, even if they can not be '
1597
'recovered and even if they are non-empty directories. '
1598
'(deprecated, use no-backup)')]
1521
'recovered and even if they are non-empty directories.')]
1599
1522
aliases = ['rm', 'del']
1600
1523
encoding_type = 'replace'
1602
1525
def run(self, file_list, verbose=False, new=False,
1603
1526
file_deletion_strategy='safe'):
1604
if file_deletion_strategy == 'force':
1605
note("(The --force option is deprecated, rather use --no-backup "
1607
file_deletion_strategy = 'no-backup'
1609
tree, file_list = WorkingTree.open_containing_paths(file_list)
1527
tree, file_list = tree_files(file_list)
1611
1529
if file_list is not None:
1612
1530
file_list = [f for f in file_list]
1701
1619
_see_also = ['check']
1702
1620
takes_args = ['branch?']
1704
Option('canonicalize-chks',
1705
help='Make sure CHKs are in canonical form (repairs '
1710
def run(self, branch=".", canonicalize_chks=False):
1622
def run(self, branch="."):
1711
1623
from bzrlib.reconcile import reconcile
1712
1624
dir = bzrdir.BzrDir.open(branch)
1713
reconcile(dir, canonicalize_chks=canonicalize_chks)
1716
1628
class cmd_revision_history(Command):
1749
1661
last_revision = wt.last_revision()
1751
self.add_cleanup(b.repository.lock_read().unlock)
1752
graph = b.repository.get_graph()
1753
revisions = [revid for revid, parents in
1754
graph.iter_ancestry([last_revision])]
1755
for revision_id in reversed(revisions):
1756
if _mod_revision.is_null(revision_id):
1663
revision_ids = b.repository.get_ancestry(last_revision)
1665
for revision_id in revision_ids:
1758
1666
self.outf.write(revision_id + '\n')
1798
1706
Option('append-revisions-only',
1799
1707
help='Never change revnos or the existing log.'
1800
' Append revisions to it only.'),
1802
'Create a branch without a working tree.')
1708
' Append revisions to it only.')
1804
1710
def run(self, location=None, format=None, append_revisions_only=False,
1805
create_prefix=False, no_tree=False):
1711
create_prefix=False):
1806
1712
if format is None:
1807
1713
format = bzrdir.format_registry.make_bzrdir('default')
1808
1714
if location is None:
2085
1968
old_branch, new_branch,
2086
1969
specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
2087
1970
file_list, revision, old, new, self.add_cleanup, apply_view=True)
2088
# GNU diff on Windows uses ANSI encoding for filenames
2089
path_encoding = osutils.get_diff_header_encoding()
2090
1971
return show_diff_trees(old_tree, new_tree, sys.stdout,
2091
1972
specific_files=specific_files,
2092
1973
external_diff_options=diff_options,
2093
1974
old_label=old_label, new_label=new_label,
2094
extra_trees=extra_trees,
2095
path_encoding=path_encoding,
1975
extra_trees=extra_trees, using=using,
2097
1976
format_cls=format)
2849
2706
"NAME_PATTERN or --default-rules.")
2850
2707
name_pattern_list = [globbing.normalize_pattern(p)
2851
2708
for p in name_pattern_list]
2853
for p in name_pattern_list:
2854
if not globbing.Globster.is_pattern_valid(p):
2855
bad_patterns += ('\n %s' % p)
2857
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
2858
ui.ui_factory.show_error(msg)
2859
raise errors.InvalidPattern('')
2860
2709
for name_pattern in name_pattern_list:
2861
2710
if (name_pattern[0] == '/' or
2862
2711
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3140
2989
to trigger updates to external systems like bug trackers. The --fixes
3141
2990
option can be used to record the association between a revision and
3142
2991
one or more bugs. See ``bzr help bugs`` for details.
2993
A selective commit may fail in some cases where the committed
2994
tree would be invalid. Consider::
2999
bzr commit foo -m "committing foo"
3000
bzr mv foo/bar foo/baz
3003
bzr commit foo/bar -m "committing bar but not baz"
3005
In the example above, the last commit will fail by design. This gives
3006
the user the opportunity to decide whether they want to commit the
3007
rename at the same time, separately first, or not at all. (As a general
3008
rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
3010
# TODO: Run hooks on tree to-be-committed, and after commit.
3012
# TODO: Strict commit that fails if there are deleted files.
3013
# (what does "deleted files" mean ??)
3015
# TODO: Give better message for -s, --summary, used by tla people
3017
# XXX: verbose currently does nothing
3145
3019
_see_also = ['add', 'bugs', 'hooks', 'uncommit']
3146
3020
takes_args = ['selected*']
3207
3077
def run(self, message=None, file=None, verbose=False, selected_list=None,
3208
3078
unchanged=False, strict=False, local=False, fixes=None,
3209
author=None, show_diff=False, exclude=None, commit_time=None,
3079
author=None, show_diff=False, exclude=None, commit_time=None):
3211
3080
from bzrlib.errors import (
3212
3081
PointlessCommit,
3213
3082
ConflictsInTree,
3228
3096
raise errors.BzrCommandError(
3229
3097
"Could not parse --commit-time: " + str(e))
3099
# TODO: Need a blackbox test for invoking the external editor; may be
3100
# slightly problematic to run this cross-platform.
3102
# TODO: do more checks that the commit will succeed before
3103
# spending the user's valuable time typing a commit message.
3231
3105
properties = {}
3233
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3107
tree, selected_list = tree_files(selected_list)
3234
3108
if selected_list == ['']:
3235
3109
# workaround - commit of root of tree should be exactly the same
3236
3110
# as just default commit in that tree, and succeed even though
3289
3163
# make_commit_message_template_encoded returns user encoding.
3290
3164
# We probably want to be using edit_commit_message instead to
3292
my_message = set_commit_message(commit_obj)
3293
if my_message is None:
3294
start_message = generate_commit_message_template(commit_obj)
3295
my_message = edit_commit_message_encoded(text,
3296
start_message=start_message)
3166
start_message = generate_commit_message_template(commit_obj)
3167
my_message = edit_commit_message_encoded(text,
3168
start_message=start_message)
3297
3169
if my_message is None:
3298
3170
raise errors.BzrCommandError("please specify a commit"
3299
3171
" message with either --message or --file")
3312
3184
reporter=None, verbose=verbose, revprops=properties,
3313
3185
authors=author, timestamp=commit_stamp,
3314
3186
timezone=offset,
3315
exclude=tree.safe_relpath_files(exclude),
3187
exclude=safe_relpath_files(tree, exclude))
3317
3188
except PointlessCommit:
3318
3189
raise errors.BzrCommandError("No changes to commit."
3319
" Please 'bzr add' the files you want to commit, or use"
3320
" --unchanged to force an empty commit.")
3190
" Use --unchanged to commit anyhow.")
3321
3191
except ConflictsInTree:
3322
3192
raise errors.BzrCommandError('Conflicts detected in working '
3323
3193
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3406
3276
class cmd_upgrade(Command):
3407
__doc__ = """Upgrade a repository, branch or working tree to a newer format.
3409
When the default format has changed after a major new release of
3410
Bazaar, you may be informed during certain operations that you
3411
should upgrade. Upgrading to a newer format may improve performance
3412
or make new features available. It may however limit interoperability
3413
with older repositories or with older versions of Bazaar.
3415
If you wish to upgrade to a particular format rather than the
3416
current default, that can be specified using the --format option.
3417
As a consequence, you can use the upgrade command this way to
3418
"downgrade" to an earlier format, though some conversions are
3419
a one way process (e.g. changing from the 1.x default to the
3420
2.x default) so downgrading is not always possible.
3422
A backup.bzr.~#~ directory is created at the start of the conversion
3423
process (where # is a number). By default, this is left there on
3424
completion. If the conversion fails, delete the new .bzr directory
3425
and rename this one back in its place. Use the --clean option to ask
3426
for the backup.bzr directory to be removed on successful conversion.
3427
Alternatively, you can delete it by hand if everything looks good
3430
If the location given is a shared repository, dependent branches
3431
are also converted provided the repository converts successfully.
3432
If the conversion of a branch fails, remaining branches are still
3435
For more information on upgrades, see the Bazaar Upgrade Guide,
3436
http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3277
__doc__ = """Upgrade branch storage to current format.
3279
The check command or bzr developers may sometimes advise you to run
3280
this command. When the default format has changed you may also be warned
3281
during other operations to upgrade.
3439
_see_also = ['check', 'reconcile', 'formats']
3284
_see_also = ['check']
3440
3285
takes_args = ['url?']
3441
3286
takes_options = [
3442
RegistryOption('format',
3443
help='Upgrade to a specific format. See "bzr help'
3444
' formats" for details.',
3445
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3446
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3447
value_switches=True, title='Branch format'),
3449
help='Remove the backup.bzr directory if successful.'),
3451
help="Show what would be done, but don't actually do anything."),
3287
RegistryOption('format',
3288
help='Upgrade to a specific format. See "bzr help'
3289
' formats" for details.',
3290
lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3291
converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3292
value_switches=True, title='Branch format'),
3454
def run(self, url='.', format=None, clean=False, dry_run=False):
3295
def run(self, url='.', format=None):
3455
3296
from bzrlib.upgrade import upgrade
3456
exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
3458
if len(exceptions) == 1:
3459
# Compatibility with historical behavior
3297
upgrade(url, format)
3465
3300
class cmd_whoami(Command):
3485
3319
encoding_type = 'replace'
3487
3321
@display_command
3488
def run(self, email=False, branch=False, name=None, directory=None):
3322
def run(self, email=False, branch=False, name=None):
3489
3323
if name is None:
3490
if directory is None:
3491
# use branch if we're inside one; otherwise global config
3493
c = Branch.open_containing(u'.')[0].get_config()
3494
except errors.NotBranchError:
3495
c = _mod_config.GlobalConfig()
3497
c = Branch.open(directory).get_config()
3324
# use branch if we're inside one; otherwise global config
3326
c = Branch.open_containing('.')[0].get_config()
3327
except errors.NotBranchError:
3328
c = config.GlobalConfig()
3499
3330
self.outf.write(c.user_email() + '\n')
3501
3332
self.outf.write(c.username() + '\n')
3505
raise errors.BzrCommandError("--email can only be used to display existing "
3508
3335
# display a warning if an email address isn't included in the given name.
3510
_mod_config.extract_email_address(name)
3337
config.extract_email_address(name)
3511
3338
except errors.NoEmailInUsername, e:
3512
3339
warning('"%s" does not seem to contain an email address. '
3513
3340
'This is allowed, but not recommended.', name)
3515
3342
# use global config unless --branch given
3517
if directory is None:
3518
c = Branch.open_containing(u'.')[0].get_config()
3520
c = Branch.open(directory).get_config()
3344
c = Branch.open_containing('.')[0].get_config()
3522
c = _mod_config.GlobalConfig()
3346
c = config.GlobalConfig()
3523
3347
c.set_user_option('email', name)
3592
3416
'bzr alias --remove expects an alias to remove.')
3593
3417
# If alias is not found, print something like:
3594
3418
# unalias: foo: not found
3595
c = _mod_config.GlobalConfig()
3419
c = config.GlobalConfig()
3596
3420
c.unset_alias(alias_name)
3598
3422
@display_command
3599
3423
def print_aliases(self):
3600
3424
"""Print out the defined aliases in a similar format to bash."""
3601
aliases = _mod_config.GlobalConfig().get_aliases()
3425
aliases = config.GlobalConfig().get_aliases()
3602
3426
for key, value in sorted(aliases.iteritems()):
3603
3427
self.outf.write('bzr alias %s="%s"\n' % (key, value))
3674
3495
if typestring == "sftp":
3675
3496
from bzrlib.tests import stub_sftp
3676
3497
return stub_sftp.SFTPAbsoluteServer
3677
elif typestring == "memory":
3498
if typestring == "memory":
3678
3499
from bzrlib.tests import test_server
3679
3500
return memory.MemoryServer
3680
elif typestring == "fakenfs":
3501
if typestring == "fakenfs":
3681
3502
from bzrlib.tests import test_server
3682
3503
return test_server.FakeNFSServer
3683
3504
msg = "No known transport type %s. Supported types are: sftp\n" %\
3696
3517
'throughout the test suite.',
3697
3518
type=get_transport_type),
3698
3519
Option('benchmark',
3699
help='Run the benchmarks rather than selftests.',
3520
help='Run the benchmarks rather than selftests.'),
3701
3521
Option('lsprof-timed',
3702
3522
help='Generate lsprof output for benchmarked'
3703
3523
' sections of code.'),
3704
3524
Option('lsprof-tests',
3705
3525
help='Generate lsprof output for each test.'),
3526
Option('cache-dir', type=str,
3527
help='Cache intermediate benchmark output in this '
3706
3529
Option('first',
3707
3530
help='Run all tests, but run specified tests first.',
3708
3531
short_name='f',
3717
3540
Option('randomize', type=str, argname="SEED",
3718
3541
help='Randomize the order of tests using the given'
3719
3542
' seed or "now" for the current time.'),
3720
ListOption('exclude', type=str, argname="PATTERN",
3722
help='Exclude tests that match this regular'
3543
Option('exclude', type=str, argname="PATTERN",
3545
help='Exclude tests that match this regular'
3724
3547
Option('subunit',
3725
3548
help='Output test progress via subunit.'),
3726
3549
Option('strict', help='Fail on missing dependencies or '
3743
3566
def run(self, testspecs_list=None, verbose=False, one=False,
3744
3567
transport=None, benchmark=None,
3568
lsprof_timed=None, cache_dir=None,
3746
3569
first=False, list_only=False,
3747
3570
randomize=None, exclude=None, strict=False,
3748
3571
load_list=None, debugflag=None, starting_with=None, subunit=False,
3749
3572
parallel=None, lsprof_tests=False):
3750
from bzrlib import tests
3573
from bzrlib.tests import selftest
3574
import bzrlib.benchmarks as benchmarks
3575
from bzrlib.benchmarks import tree_creator
3577
# Make deprecation warnings visible, unless -Werror is set
3578
symbol_versioning.activate_deprecation_warnings(override=False)
3580
if cache_dir is not None:
3581
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3752
3582
if testspecs_list is not None:
3753
3583
pattern = '|'.join(testspecs_list)
3773
3603
self.additional_selftest_args.setdefault(
3774
3604
'suite_decorators', []).append(parallel)
3776
raise errors.BzrCommandError(
3777
"--benchmark is no longer supported from bzr 2.2; "
3778
"use bzr-usertest instead")
3779
test_suite_factory = None
3781
exclude_pattern = None
3606
test_suite_factory = benchmarks.test_suite
3607
# Unless user explicitly asks for quiet, be verbose in benchmarks
3608
verbose = not is_quiet()
3609
# TODO: should possibly lock the history file...
3610
benchfile = open(".perf_history", "at", buffering=1)
3611
self.add_cleanup(benchfile.close)
3783
exclude_pattern = '(' + '|'.join(exclude) + ')'
3613
test_suite_factory = None
3784
3615
selftest_kwargs = {"verbose": verbose,
3785
3616
"pattern": pattern,
3786
3617
"stop_on_failure": one,
3788
3619
"test_suite_factory": test_suite_factory,
3789
3620
"lsprof_timed": lsprof_timed,
3790
3621
"lsprof_tests": lsprof_tests,
3622
"bench_history": benchfile,
3791
3623
"matching_tests_first": first,
3792
3624
"list_only": list_only,
3793
3625
"random_seed": randomize,
3794
"exclude_pattern": exclude_pattern,
3626
"exclude_pattern": exclude,
3795
3627
"strict": strict,
3796
3628
"load_list": load_list,
3797
3629
"debug_flags": debugflag,
3798
3630
"starting_with": starting_with
3800
3632
selftest_kwargs.update(self.additional_selftest_args)
3802
# Make deprecation warnings visible, unless -Werror is set
3803
cleanup = symbol_versioning.activate_deprecation_warnings(
3806
result = tests.selftest(**selftest_kwargs)
3633
result = selftest(**selftest_kwargs)
3809
3634
return int(not result)
3866
3691
The source of the merge can be specified either in the form of a branch,
3867
3692
or in the form of a path to a file containing a merge directive generated
3868
3693
with bzr send. If neither is specified, the default is the upstream branch
3869
or the branch most recently merged using --remember. The source of the
3870
merge may also be specified in the form of a path to a file in another
3871
branch: in this case, only the modifications to that file are merged into
3872
the current working tree.
3874
When merging from a branch, by default bzr will try to merge in all new
3875
work from the other branch, automatically determining an appropriate base
3876
revision. If this fails, you may need to give an explicit base.
3878
To pick a different ending revision, pass "--revision OTHER". bzr will
3879
try to merge in all new work up to and including revision OTHER.
3881
If you specify two values, "--revision BASE..OTHER", only revisions BASE
3882
through OTHER, excluding BASE but including OTHER, will be merged. If this
3883
causes some revisions to be skipped, i.e. if the destination branch does
3884
not already contain revision BASE, such a merge is commonly referred to as
3885
a "cherrypick". Unlike a normal merge, Bazaar does not currently track
3886
cherrypicks. The changes look like a normal commit, and the history of the
3887
changes from the other branch is not stored in the commit.
3889
Revision numbers are always relative to the source branch.
3694
or the branch most recently merged using --remember.
3696
When merging a branch, by default the tip will be merged. To pick a different
3697
revision, pass --revision. If you specify two values, the first will be used as
3698
BASE and the second one as OTHER. Merging individual revisions, or a subset of
3699
available revisions, like this is commonly referred to as "cherrypicking".
3701
Revision numbers are always relative to the branch being merged.
3703
By default, bzr will try to merge in all new work from the other
3704
branch, automatically determining an appropriate base. If this
3705
fails, you may need to give an explicit base.
3891
3707
Merge will do its best to combine the changes in two branches, but there
3892
3708
are some kinds of problems only a human can fix. When it encounters those,
3896
3712
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
3898
If there is no default branch set, the first merge will set it (use
3899
--no-remember to avoid settting it). After that, you can omit the branch
3900
to use the default. To change the default, use --remember. The value will
3901
only be saved if the remote location can be accessed.
3714
If there is no default branch set, the first merge will set it. After
3715
that, you can omit the branch to use the default. To change the
3716
default, use --remember. The value will only be saved if the remote
3717
location can be accessed.
3903
3719
The results of the merge are placed into the destination working
3904
3720
directory, where they can be reviewed (with bzr diff), tested, and then
3905
3721
committed to record the result of the merge.
3907
3723
merge refuses to run if there are any uncommitted changes, unless
3908
--force is given. If --force is given, then the changes from the source
3909
will be merged with the current working tree, including any uncommitted
3910
changes in the tree. The --force option can also be used to create a
3724
--force is given. The --force option can also be used to create a
3911
3725
merge revision which has more than two parents.
3913
3727
If one would like to merge changes from the working tree of the other
3973
3787
def run(self, location=None, revision=None, force=False,
3974
merge_type=None, show_base=False, reprocess=None, remember=None,
3788
merge_type=None, show_base=False, reprocess=None, remember=False,
3975
3789
uncommitted=False, pull=False,
3976
3790
directory=None,
4041
3851
self.sanity_check_merger(merger)
4042
3852
if (merger.base_rev_id == merger.other_rev_id and
4043
3853
merger.other_rev_id is not None):
4044
# check if location is a nonexistent file (and not a branch) to
4045
# disambiguate the 'Nothing to do'
4046
if merger.interesting_files:
4047
if not merger.other_tree.has_filename(
4048
merger.interesting_files[0]):
4049
note("merger: " + str(merger))
4050
raise errors.PathsDoNotExist([location])
4051
3854
note('Nothing to do.')
4053
if pull and not preview:
4054
3857
if merger.interesting_files is not None:
4055
3858
raise errors.BzrCommandError('Cannot pull individual files')
4056
3859
if (merger.base_rev_id == tree.last_revision()):
4080
3883
def _do_preview(self, merger):
4081
3884
from bzrlib.diff import show_diff_trees
4082
3885
result_tree = self._get_preview(merger)
4083
path_encoding = osutils.get_diff_header_encoding()
4084
3886
show_diff_trees(merger.this_tree, result_tree, self.outf,
4085
old_label='', new_label='',
4086
path_encoding=path_encoding)
3887
old_label='', new_label='')
4088
3889
def _do_merge(self, merger, change_reporter, allow_pending, verified):
4089
3890
merger.change_reporter = change_reporter
4165
3966
if other_revision_id is None:
4166
3967
other_revision_id = _mod_revision.ensure_null(
4167
3968
other_branch.last_revision())
4168
# Remember where we merge from. We need to remember if:
4169
# - user specify a location (and we don't merge from the parent
4171
# - user ask to remember or there is no previous location set to merge
4172
# from and user didn't ask to *not* remember
4173
if (user_location is not None
4175
or (remember is None
4176
and tree.branch.get_submit_branch() is None)))):
3969
# Remember where we merge from
3970
if ((remember or tree.branch.get_submit_branch() is None) and
3971
user_location is not None):
4177
3972
tree.branch.set_submit_branch(other_branch.base)
4178
# Merge tags (but don't set them in the master branch yet, the user
4179
# might revert this merge). Commit will propagate them.
4180
_merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3973
_merge_tags_if_possible(other_branch, tree.branch)
4181
3974
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
4182
3975
other_revision_id, base_revision_id, other_branch, base_branch)
4183
3976
if other_path != '':
4351
4144
last committed revision is used.
4353
4146
To remove only some changes, without reverting to a prior version, use
4354
merge instead. For example, "merge . -r -2..-3" (don't forget the ".")
4355
will remove the changes introduced by the second last commit (-2), without
4356
affecting the changes introduced by the last commit (-1). To remove
4357
certain changes on a hunk-by-hunk basis, see the shelve command.
4147
merge instead. For example, "merge . --revision -2..-3" will remove the
4148
changes introduced by -2, without affecting the changes introduced by -1.
4149
Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
4359
4151
By default, any files that have been manually changed will be backed up
4360
4152
first. (Files changed only by merge are not backed up.) Backup files have
4525
4316
theirs_only=False,
4526
4317
log_format=None, long=False, short=False, line=False,
4527
4318
show_ids=False, verbose=False, this=False, other=False,
4528
include_merges=False, revision=None, my_revision=None,
4319
include_merges=False, revision=None, my_revision=None):
4530
4320
from bzrlib.missing import find_unmerged, iter_log_revisions
4531
4321
def message(s):
4532
4322
if not is_quiet():
4690
4480
@display_command
4691
4481
def run(self, verbose=False):
4692
from bzrlib import plugin
4693
# Don't give writelines a generator as some codecs don't like that
4694
self.outf.writelines(
4695
list(plugin.describe_plugins(show_paths=verbose)))
4482
import bzrlib.plugin
4483
from inspect import getdoc
4485
for name, plugin in bzrlib.plugin.plugins().items():
4486
version = plugin.__version__
4487
if version == 'unknown':
4489
name_ver = '%s %s' % (name, version)
4490
d = getdoc(plugin.module)
4492
doc = d.split('\n')[0]
4494
doc = '(no description)'
4495
result.append((name_ver, doc, plugin.path()))
4496
for name_ver, doc, path in sorted(result):
4497
self.outf.write("%s\n" % name_ver)
4498
self.outf.write(" %s\n" % doc)
4500
self.outf.write(" %s\n" % path)
4501
self.outf.write("\n")
4698
4504
class cmd_testament(Command):
4762
4566
self.add_cleanup(branch.lock_read().unlock)
4763
4567
tree = _get_one_revision_tree('annotate', revision, branch=branch)
4764
4568
self.add_cleanup(tree.lock_read().unlock)
4765
if wt is not None and revision is None:
4766
4570
file_id = wt.path2id(relpath)
4768
4572
file_id = tree.path2id(relpath)
4769
4573
if file_id is None:
4770
4574
raise errors.NotVersionedError(filename)
4575
file_version = tree.inventory[file_id].revision
4771
4576
if wt is not None and revision is None:
4772
4577
# If there is a tree and we're not annotating historical
4773
4578
# versions, annotate the working tree's content.
4774
4579
annotate_file_tree(wt, file_id, self.outf, long, all,
4775
4580
show_ids=show_ids)
4777
annotate_file_tree(tree, file_id, self.outf, long, all,
4778
show_ids=show_ids, branch=branch)
4582
annotate_file(branch, file_version, file_id, long, all, self.outf,
4781
4586
class cmd_re_sign(Command):
5027
4826
bzr break-lock bzr+ssh://example.com/bzr/foo
5028
bzr break-lock --conf ~/.bazaar
5031
4828
takes_args = ['location?']
5034
help='LOCATION is the directory where the config lock is.'),
5036
help='Do not ask for confirmation before breaking the lock.'),
5039
def run(self, location=None, config=False, force=False):
4830
def run(self, location=None, show=False):
5040
4831
if location is None:
5041
4832
location = u'.'
5043
ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
5045
{'bzrlib.lockdir.break': True})
5047
conf = _mod_config.LockableConfig(file_name=location)
5050
control, relpath = bzrdir.BzrDir.open_containing(location)
5052
control.break_lock()
5053
except NotImplementedError:
4833
control, relpath = bzrdir.BzrDir.open_containing(location)
4835
control.break_lock()
4836
except NotImplementedError:
5057
4840
class cmd_wait_until_signalled(Command):
5121
4904
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5122
4905
protocol=None):
5123
from bzrlib import transport
4906
from bzrlib.transport import get_transport, transport_server_registry
5124
4907
if directory is None:
5125
4908
directory = os.getcwd()
5126
4909
if protocol is None:
5127
protocol = transport.transport_server_registry.get()
4910
protocol = transport_server_registry.get()
5128
4911
host, port = self.get_host_and_port(port)
5129
4912
url = urlutils.local_path_to_url(directory)
5130
4913
if not allow_writes:
5131
4914
url = 'readonly+' + url
5132
t = transport.get_transport(url)
5133
protocol(t, host, port, inet)
4915
transport = get_transport(url)
4916
protocol(transport, host, port, inet)
5136
4919
class cmd_join(Command):
5248
5030
encoding_type = 'exact'
5250
5032
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5251
sign=False, revision=None, mail_to=None, message=None,
5033
sign=False, revision=None, mail_to=None, message=None):
5253
5034
from bzrlib.revision import ensure_null, NULL_REVISION
5254
5035
include_patch, include_bundle = {
5255
5036
'plain': (False, False),
5256
5037
'diff': (True, False),
5257
5038
'bundle': (True, True),
5259
branch = Branch.open(directory)
5040
branch = Branch.open('.')
5260
5041
stored_submit_branch = branch.get_submit_branch()
5261
5042
if submit_branch is None:
5262
5043
submit_branch = stored_submit_branch
5338
5119
source branch defaults to that containing the working directory, but can
5339
5120
be changed using --from.
5341
Both the submit branch and the public branch follow the usual behavior with
5342
respect to --remember: If there is no default location set, the first send
5343
will set it (use --no-remember to avoid settting it). After that, you can
5344
omit the location to use the default. To change the default, use
5345
--remember. The value will only be saved if the location can be accessed.
5347
5122
In order to calculate those changes, bzr must analyse the submit branch.
5348
5123
Therefore it is most efficient for the submit branch to be a local mirror.
5349
5124
If a public location is known for the submit_branch, that location is used
5420
5195
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5421
no_patch=False, revision=None, remember=None, output=None,
5196
no_patch=False, revision=None, remember=False, output=None,
5422
5197
format=None, mail_to=None, message=None, body=None,
5423
5198
strict=None, **kwargs):
5424
5199
from bzrlib.send import send
5581
5356
takes_options = [
5582
5357
custom_help('directory',
5583
5358
help='Branch whose tags should be displayed.'),
5584
RegistryOption('sort',
5359
RegistryOption.from_kwargs('sort',
5585
5360
'Sort tags by different criteria.', title='Sorting',
5586
lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5361
alpha='Sort tags lexicographically (default).',
5362
time='Sort tags chronologically.',
5592
5368
@display_command
5593
def run(self, directory='.', sort=None, show_ids=False, revision=None):
5594
from bzrlib.tag import tag_sort_methods
5595
5375
branch, relpath = Branch.open_containing(directory)
5597
5377
tags = branch.tags.get_tag_dict().items()
5606
5386
# only show revisions between revid1 and revid2 (inclusive)
5607
5387
tags = [(tag, revid) for tag, revid in tags if
5608
5388
graph.is_between(revid, revid1, revid2)]
5610
sort = tag_sort_methods.get()
5391
elif sort == 'time':
5393
for tag, revid in tags:
5395
revobj = branch.repository.get_revision(revid)
5396
except errors.NoSuchRevision:
5397
timestamp = sys.maxint # place them at the end
5399
timestamp = revobj.timestamp
5400
timestamps[revid] = timestamp
5401
tags.sort(key=lambda x: timestamps[x[1]])
5612
5402
if not show_ids:
5613
5403
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5614
5404
for index, (tag, revid) in enumerate(tags):
5753
5542
def run(self, to_location=None, force=False, create_branch=False,
5754
revision=None, directory=u'.'):
5755
5544
from bzrlib import switch
5756
tree_location = directory
5757
5546
revision = _get_one_revision('switch', revision)
5758
5547
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5759
5548
if to_location is None:
5760
5549
if revision is None:
5761
5550
raise errors.BzrCommandError('You must supply either a'
5762
5551
' revision or a location')
5763
to_location = tree_location
5765
5554
branch = control_dir.open_branch()
5766
5555
had_explicit_nick = branch.get_config().has_explicit_nickname()
6038
5826
You can put multiple items on the shelf, and by default, 'unshelve' will
6039
5827
restore the most recently shelved changes.
6041
For complicated changes, it is possible to edit the changes in a separate
6042
editor program to decide what the file remaining in the working copy
6043
should look like. To do this, add the configuration option
6045
change_editor = PROGRAM @new_path @old_path
6047
where @new_path is replaced with the path of the new version of the
6048
file and @old_path is replaced with the path of the old version of
6049
the file. The PROGRAM should save the new file with the desired
6050
contents of the file in the working tree.
6054
5830
takes_args = ['file*']
6056
5832
takes_options = [
6059
5834
Option('all', help='Shelve all changes.'),
6066
5841
Option('destroy',
6067
5842
help='Destroy removed changes instead of shelving them.'),
6069
_see_also = ['unshelve', 'configuration']
5844
_see_also = ['unshelve']
6071
5846
def run(self, revision=None, all=False, file_list=None, message=None,
6072
writer=None, list=False, destroy=False, directory=None):
5847
writer=None, list=False, destroy=False):
6074
return self.run_for_list(directory=directory)
5849
return self.run_for_list()
6075
5850
from bzrlib.shelf_ui import Shelver
6076
5851
if writer is None:
6077
5852
writer = bzrlib.option.diff_writer_registry.get()
6079
5854
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
6080
file_list, message, destroy=destroy, directory=directory)
5855
file_list, message, destroy=destroy)
6154
5926
takes_options = ['directory',
6155
5927
Option('ignored', help='Delete all ignored files.'),
6156
Option('detritus', help='Delete conflict files, merge and revert'
5928
Option('detritus', help='Delete conflict files, merge'
6157
5929
' backups, and failed selftest dirs.'),
6158
5930
Option('unknown',
6159
5931
help='Delete files unknown to bzr (default).'),
6218
5990
self.outf.write('%s %s\n' % (path, location))
6221
class cmd_export_pot(Command):
6222
__doc__ = """Export command helps and error messages in po format."""
6227
from bzrlib.export_pot import export_pot
6228
export_pot(self.outf)
6231
5993
def _register_lazy_builtins():
6232
5994
# register lazy builtins from other modules; called at startup and should
6233
5995
# be only called once.
6234
5996
for (name, aliases, module_name) in [
6235
5997
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6236
('cmd_config', [], 'bzrlib.config'),
6237
5998
('cmd_dpush', [], 'bzrlib.foreign'),
6238
5999
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6239
6000
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6240
6001
('cmd_conflicts', [], 'bzrlib.conflicts'),
6241
('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
6242
('cmd_verify_signatures', [],
6243
'bzrlib.commit_signature_commands'),
6244
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6002
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6246
6004
builtin_command_registry.register_lazy(name, aliases, module_name)