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(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)
173
return WorkingTree.open_containing_paths(
174
file_list, default_directory='.',
223
179
def _get_view_info_for_change_reporter(tree):
191
def _open_directory_or_containing_tree_or_branch(filename, directory):
192
"""Open the tree or branch containing the specified file, unless
193
the --directory option is used to specify a different branch."""
194
if directory is not None:
195
return (None, Branch.open(directory), filename)
196
return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
235
199
# TODO: Make sure no commands unconditionally use the working directory as a
236
200
# branch. If a filename argument is used, the first of them should be used to
237
201
# specify the branch. (Perhaps this can be factored out into some kind of
315
279
raise errors.BzrCommandError('bzr status --revision takes exactly'
316
280
' one or two revision specifiers')
318
tree, relfile_list = tree_files(file_list)
282
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
319
283
# Avoid asking for specific files when that is not needed.
320
284
if relfile_list == ['']:
321
285
relfile_list = None
353
317
self.outf.write(revtext.decode('utf-8'))
356
def run(self, revision_id=None, revision=None):
320
def run(self, revision_id=None, revision=None, directory=u'.'):
357
321
if revision_id is not None and revision is not None:
358
322
raise errors.BzrCommandError('You can only supply one of'
359
323
' revision_id or --revision')
360
324
if revision_id is None and revision is None:
361
325
raise errors.BzrCommandError('You must supply either'
362
326
' --revision or a revision_id')
363
b = WorkingTree.open_containing(u'.')[0].branch
327
b = WorkingTree.open_containing(directory)[0].branch
365
329
revisions = b.repository.revisions
366
330
if revisions is None:
504
468
if (working.has_changes()):
505
469
raise errors.UncommittedChanges(working)
470
if working.get_shelf_manager().last_shelf() is not None:
471
raise errors.ShelvedChanges(working)
507
473
if working.user_url != working.branch.user_url:
508
474
raise errors.BzrCommandError("You cannot remove the working tree"
552
518
takes_args = ['revision_info*']
553
519
takes_options = [
521
custom_help('directory',
556
522
help='Branch to examine, '
557
'rather than the one containing the working directory.',
523
'rather than the one containing the working directory.'),
561
524
Option('tree', help='Show revno of working tree'),
754
717
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
756
719
revision = _get_one_revision('inventory', revision)
757
work_tree, file_list = tree_files(file_list)
720
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
758
721
self.add_cleanup(work_tree.lock_read().unlock)
759
722
if revision is not None:
760
723
tree = revision.as_tree(work_tree.branch)
826
789
if len(names_list) < 2:
827
790
raise errors.BzrCommandError("missing file argument")
828
tree, rel_names = tree_files(names_list, canonicalize=False)
791
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
829
792
self.add_cleanup(tree.lock_tree_write().unlock)
830
793
self._run(tree, names_list, rel_names, after)
837
800
raise errors.BzrCommandError('--after cannot be specified with'
839
work_tree, file_list = tree_files(names_list, default_branch='.')
802
work_tree, file_list = WorkingTree.open_containing_paths(
803
names_list, default_directory='.')
840
804
self.add_cleanup(work_tree.lock_tree_write().unlock)
841
805
rename_map.RenameMap.guess_renames(work_tree, dry_run)
951
915
takes_options = ['remember', 'overwrite', 'revision',
952
916
custom_help('verbose',
953
917
help='Show logs of pulled revisions.'),
918
custom_help('directory',
955
919
help='Branch to pull into, '
956
'rather than the one containing the working directory.',
920
'rather than the one containing the working directory.'),
961
922
help="Perform a local pull in a bound "
962
923
"branch. Local pulls are not applied to "
1076
1037
Option('create-prefix',
1077
1038
help='Create the path leading up to the branch '
1078
1039
'if it does not already exist.'),
1040
custom_help('directory',
1080
1041
help='Branch to push from, '
1081
'rather than the one containing the working directory.',
1042
'rather than the one containing the working directory.'),
1085
1043
Option('use-existing-dir',
1086
1044
help='By default push will fail if the target'
1087
1045
' directory exists, but does not already'
1177
1135
_see_also = ['checkout']
1178
1136
takes_args = ['from_location', 'to_location?']
1179
takes_options = ['revision', Option('hardlink',
1180
help='Hard-link working tree files where possible.'),
1137
takes_options = ['revision',
1138
Option('hardlink', help='Hard-link working tree files where possible.'),
1139
Option('files-from', type=str,
1140
help="Get file contents from this tree."),
1181
1141
Option('no-tree',
1182
1142
help="Create a branch without a working-tree."),
1183
1143
Option('switch',
1202
1162
def run(self, from_location, to_location=None, revision=None,
1203
1163
hardlink=False, stacked=False, standalone=False, no_tree=False,
1204
use_existing_dir=False, switch=False, bind=False):
1164
use_existing_dir=False, switch=False, bind=False,
1205
1166
from bzrlib import switch as _mod_switch
1206
1167
from bzrlib.tag import _merge_tags_if_possible
1207
1168
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1170
if not (hardlink or files_from):
1171
# accelerator_tree is usually slower because you have to read N
1172
# files (no readahead, lots of seeks, etc), but allow the user to
1173
# explicitly request it
1174
accelerator_tree = None
1175
if files_from is not None and files_from != from_location:
1176
accelerator_tree = WorkingTree.open(files_from)
1209
1177
revision = _get_one_revision('branch', revision)
1210
1178
self.add_cleanup(br_from.lock_read().unlock)
1211
1179
if revision is not None:
1318
1286
to_location = branch_location
1319
1287
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1320
1288
branch_location)
1289
if not (hardlink or files_from):
1290
# accelerator_tree is usually slower because you have to read N
1291
# files (no readahead, lots of seeks, etc), but allow the user to
1292
# explicitly request it
1293
accelerator_tree = None
1321
1294
revision = _get_one_revision('checkout', revision)
1322
if files_from is not None:
1295
if files_from is not None and files_from != branch_location:
1323
1296
accelerator_tree = WorkingTree.open(files_from)
1324
1297
if revision is not None:
1325
1298
revision_id = revision.as_revision_id(source)
1381
1354
If you want to discard your local changes, you can just do a
1382
1355
'bzr revert' instead of 'bzr commit' after the update.
1357
If you want to restore a file that has been removed locally, use
1358
'bzr revert' instead of 'bzr update'.
1384
1360
If the tree's branch is bound to a master branch, it will also update
1385
1361
the branch from the master.
1504
1480
class cmd_remove(Command):
1505
1481
__doc__ = """Remove files or directories.
1507
This makes bzr stop tracking changes to the specified files. bzr will delete
1508
them if they can easily be recovered using revert. If no options or
1509
parameters are given bzr will scan for files that are being tracked by bzr
1510
but missing in your tree and stop tracking them for you.
1483
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1484
delete them if they can easily be recovered using revert otherwise they
1485
will be backed up (adding an extention of the form .~#~). If no options or
1486
parameters are given Bazaar will scan for files that are being tracked by
1487
Bazaar but missing in your tree and stop tracking them for you.
1512
1489
takes_args = ['file*']
1513
1490
takes_options = ['verbose',
1515
1492
RegistryOption.from_kwargs('file-deletion-strategy',
1516
1493
'The file deletion mode to be used.',
1517
1494
title='Deletion Strategy', value_switches=True, enum_switch=False,
1518
safe='Only delete files if they can be'
1519
' safely recovered (default).',
1495
safe='Backup changed files (default).',
1520
1496
keep='Delete from bzr but leave the working copy.',
1521
1497
force='Delete all the specified files, even if they can not be '
1522
1498
'recovered and even if they are non-empty directories.')]
1526
1502
def run(self, file_list, verbose=False, new=False,
1527
1503
file_deletion_strategy='safe'):
1528
tree, file_list = tree_files(file_list)
1504
tree, file_list = WorkingTree.open_containing_paths(file_list)
1530
1506
if file_list is not None:
1531
1507
file_list = [f for f in file_list]
1620
1596
_see_also = ['check']
1621
1597
takes_args = ['branch?']
1599
Option('canonicalize-chks',
1600
help='Make sure CHKs are in canonical form (repairs '
1623
def run(self, branch="."):
1605
def run(self, branch=".", canonicalize_chks=False):
1624
1606
from bzrlib.reconcile import reconcile
1625
1607
dir = bzrdir.BzrDir.open(branch)
1608
reconcile(dir, canonicalize_chks=canonicalize_chks)
1629
1611
class cmd_revision_history(Command):
1969
1955
old_branch, new_branch,
1970
1956
specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1971
1957
file_list, revision, old, new, self.add_cleanup, apply_view=True)
1958
# GNU diff on Windows uses ANSI encoding for filenames
1959
path_encoding = osutils.get_diff_header_encoding()
1972
1960
return show_diff_trees(old_tree, new_tree, sys.stdout,
1973
1961
specific_files=specific_files,
1974
1962
external_diff_options=diff_options,
1975
1963
old_label=old_label, new_label=new_label,
1976
extra_trees=extra_trees, using=using,
1964
extra_trees=extra_trees,
1965
path_encoding=path_encoding,
1977
1967
format_cls=format)
1987
1977
# level of effort but possibly much less IO. (Or possibly not,
1988
1978
# if the directories are very large...)
1989
1979
_see_also = ['status', 'ls']
1990
takes_options = ['show-ids']
1980
takes_options = ['directory', 'show-ids']
1992
1982
@display_command
1993
def run(self, show_ids=False):
1994
tree = WorkingTree.open_containing(u'.')[0]
1983
def run(self, show_ids=False, directory=u'.'):
1984
tree = WorkingTree.open_containing(directory)[0]
1995
1985
self.add_cleanup(tree.lock_read().unlock)
1996
1986
old = tree.basis_tree()
1997
1987
self.add_cleanup(old.lock_read().unlock)
2012
2002
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
2003
takes_options = ['directory', 'null']
2019
2005
@display_command
2020
def run(self, null=False):
2021
tree = WorkingTree.open_containing(u'.')[0]
2006
def run(self, null=False, directory=u'.'):
2007
tree = WorkingTree.open_containing(directory)[0]
2022
2008
td = tree.changes_from(tree.basis_tree())
2023
2009
for path, id, kind, text_modified, meta_modified in td.modified:
2035
2021
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2022
takes_options = ['directory', 'null']
2042
2024
@display_command
2043
def run(self, null=False):
2044
wt = WorkingTree.open_containing(u'.')[0]
2025
def run(self, null=False, directory=u'.'):
2026
wt = WorkingTree.open_containing(directory)[0]
2045
2027
self.add_cleanup(wt.lock_read().unlock)
2046
2028
basis = wt.basis_tree()
2047
2029
self.add_cleanup(basis.lock_read().unlock)
2053
2035
if inv.is_root(file_id) and len(basis_inv) == 0:
2055
2037
path = inv.id2path(file_id)
2056
if not os.access(osutils.abspath(path), os.F_OK):
2038
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2059
2041
self.outf.write(path + '\0')
2259
2241
help='Show just the specified revision.'
2260
2242
' See also "help revisionspec".'),
2244
RegistryOption('authors',
2245
'What names to list as authors - first, all or committer.',
2247
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2249
Option('levels',
2263
2250
short_name='n',
2264
2251
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2370
show_timezone=timezone,
2383
2371
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2373
show_advice=levels is None,
2374
author_list_handler=authors)
2387
2376
# Choose the algorithm for doing the logging. It's annoying
2388
2377
# having multiple code paths like this but necessary until
2505
2494
help='Recurse into subdirectories.'),
2506
2495
Option('from-root',
2507
2496
help='Print paths relative to the root of the branch.'),
2508
Option('unknown', help='Print unknown files.'),
2497
Option('unknown', short_name='u',
2498
help='Print unknown files.'),
2509
2499
Option('versioned', help='Print versioned files.',
2510
2500
short_name='V'),
2511
Option('ignored', help='Print ignored files.'),
2513
help='Write an ascii NUL (\\0) separator '
2514
'between files rather than a newline.'),
2501
Option('ignored', short_name='i',
2502
help='Print ignored files.'),
2503
Option('kind', short_name='k',
2516
2504
help='List entries of a particular kind: file, directory, symlink.',
2520
2510
@display_command
2521
2511
def run(self, revision=None, verbose=False,
2522
2512
recursive=False, from_root=False,
2523
2513
unknown=False, versioned=False, ignored=False,
2524
null=False, kind=None, show_ids=False, path=None):
2514
null=False, kind=None, show_ids=False, path=None, directory=None):
2526
2516
if kind and kind not in ('file', 'directory', 'symlink'):
2527
2517
raise errors.BzrCommandError('invalid kind specified')
2539
2529
raise errors.BzrCommandError('cannot specify both --from-root'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2532
tree, branch, relpath = \
2533
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2535
# Calculate the prefix to use
2616
2606
_see_also = ['ls']
2607
takes_options = ['directory']
2618
2609
@display_command
2620
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2610
def run(self, directory=u'.'):
2611
for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2612
self.outf.write(osutils.quotefn(f) + '\n')
2689
2680
_see_also = ['status', 'ignored', 'patterns']
2690
2681
takes_args = ['name_pattern*']
2682
takes_options = ['directory',
2692
2683
Option('default-rules',
2693
2684
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2687
def run(self, name_pattern_list=None, default_rules=None,
2697
2689
from bzrlib import ignores
2698
2690
if default_rules is not None:
2699
2691
# dump the default rules and exit
2705
2697
"NAME_PATTERN or --default-rules.")
2706
2698
name_pattern_list = [globbing.normalize_pattern(p)
2707
2699
for p in name_pattern_list]
2701
for p in name_pattern_list:
2702
if not globbing.Globster.is_pattern_valid(p):
2703
bad_patterns += ('\n %s' % p)
2705
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
2706
ui.ui_factory.show_error(msg)
2707
raise errors.InvalidPattern('')
2708
2708
for name_pattern in name_pattern_list:
2709
2709
if (name_pattern[0] == '/' or
2710
2710
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2711
raise errors.BzrCommandError(
2712
2712
"NAME_PATTERN should not be an absolute path")
2713
tree, relpath = WorkingTree.open_containing(u'.')
2713
tree, relpath = WorkingTree.open_containing(directory)
2714
2714
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2715
ignored = globbing.Globster(name_pattern_list)
2717
self.add_cleanup(tree.lock_read().unlock)
2718
2718
for entry in tree.list_files():
2720
2720
if id is not None:
2721
2721
filename = entry[0]
2722
2722
if ignored.match(filename):
2723
2723
matches.append(filename)
2725
2724
if len(matches) > 0:
2726
2725
self.outf.write("Warning: the following files are version controlled and"
2727
2726
" match your ignore pattern:\n%s"
2743
2742
encoding_type = 'replace'
2744
2743
_see_also = ['ignore', 'ls']
2744
takes_options = ['directory']
2746
2746
@display_command
2748
tree = WorkingTree.open_containing(u'.')[0]
2747
def run(self, directory=u'.'):
2748
tree = WorkingTree.open_containing(directory)[0]
2749
2749
self.add_cleanup(tree.lock_read().unlock)
2750
2750
for path, file_class, kind, file_id, entry in tree.list_files():
2751
2751
if file_class != 'I':
2765
2765
takes_args = ['revno']
2766
takes_options = ['directory']
2767
2768
@display_command
2768
def run(self, revno):
2769
def run(self, revno, directory=u'.'):
2770
2771
revno = int(revno)
2771
2772
except ValueError:
2772
2773
raise errors.BzrCommandError("not a valid revision-number: %r"
2774
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2775
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2776
self.outf.write("%s\n" % revid)
2804
2805
================= =========================
2806
2807
takes_args = ['dest', 'branch_or_subdir?']
2808
takes_options = ['directory',
2808
2809
Option('format',
2809
2810
help="Type of file to export to.",
2819
2820
'revision in which it was changed.'),
2821
2822
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
root=None, filters=False, per_file_timestamps=False):
2823
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2824
from bzrlib.export import export
2825
2826
if branch_or_subdir is None:
2826
tree = WorkingTree.open_containing(u'.')[0]
2827
tree = WorkingTree.open_containing(directory)[0]
2827
2828
b = tree.branch
2850
2851
_see_also = ['ls']
2852
takes_options = ['directory',
2852
2853
Option('name-from-revision', help='The path name in the old tree.'),
2853
2854
Option('filters', help='Apply content filters to display the '
2854
2855
'convenience form.'),
2860
2861
@display_command
2861
2862
def run(self, filename, revision=None, name_from_revision=False,
2863
filters=False, directory=None):
2863
2864
if revision is not None and len(revision) != 1:
2864
2865
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2866
" one revision specifier")
2866
2867
tree, branch, relpath = \
2867
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2868
_open_directory_or_containing_tree_or_branch(filename, directory)
2868
2869
self.add_cleanup(branch.lock_read().unlock)
2869
2870
return self._run(tree, branch, relpath, filename, revision,
2870
2871
name_from_revision, filters)
3102
3103
properties = {}
3104
tree, selected_list = tree_files(selected_list)
3105
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3105
3106
if selected_list == ['']:
3106
3107
# workaround - commit of root of tree should be exactly the same
3107
3108
# as just default commit in that tree, and succeed even though
3142
3143
def get_message(commit_obj):
3143
3144
"""Callback to get commit message"""
3145
my_message = codecs.open(
3146
file, 'rt', osutils.get_user_encoding()).read()
3148
my_message = f.read().decode(osutils.get_user_encoding())
3147
3151
elif message is not None:
3148
3152
my_message = message
3178
3182
reporter=None, verbose=verbose, revprops=properties,
3179
3183
authors=author, timestamp=commit_stamp,
3180
3184
timezone=offset,
3181
exclude=safe_relpath_files(tree, exclude))
3185
exclude=tree.safe_relpath_files(exclude))
3182
3186
except PointlessCommit:
3183
3187
raise errors.BzrCommandError("No changes to commit."
3184
3188
" Use --unchanged to commit anyhow.")
3304
3308
bzr whoami "Frank Chu <fchu@example.com>"
3306
takes_options = [ Option('email',
3310
takes_options = [ 'directory',
3307
3312
help='Display email address only.'),
3308
3313
Option('branch',
3309
3314
help='Set identity for the current branch instead of '
3313
3318
encoding_type = 'replace'
3315
3320
@display_command
3316
def run(self, email=False, branch=False, name=None):
3321
def run(self, email=False, branch=False, name=None, directory=None):
3317
3322
if name is None:
3318
# use branch if we're inside one; otherwise global config
3320
c = Branch.open_containing('.')[0].get_config()
3321
except errors.NotBranchError:
3322
c = config.GlobalConfig()
3323
if directory is None:
3324
# use branch if we're inside one; otherwise global config
3326
c = Branch.open_containing(u'.')[0].get_config()
3327
except errors.NotBranchError:
3328
c = _mod_config.GlobalConfig()
3330
c = Branch.open(directory).get_config()
3324
3332
self.outf.write(c.user_email() + '\n')
3329
3337
# display a warning if an email address isn't included in the given name.
3331
config.extract_email_address(name)
3339
_mod_config.extract_email_address(name)
3332
3340
except errors.NoEmailInUsername, e:
3333
3341
warning('"%s" does not seem to contain an email address. '
3334
3342
'This is allowed, but not recommended.', name)
3336
3344
# use global config unless --branch given
3338
c = Branch.open_containing('.')[0].get_config()
3346
if directory is None:
3347
c = Branch.open_containing(u'.')[0].get_config()
3349
c = Branch.open(directory).get_config()
3340
c = config.GlobalConfig()
3351
c = _mod_config.GlobalConfig()
3341
3352
c.set_user_option('email', name)
3354
3365
_see_also = ['info']
3355
3366
takes_args = ['nickname?']
3356
def run(self, nickname=None):
3357
branch = Branch.open_containing(u'.')[0]
3367
takes_options = ['directory']
3368
def run(self, nickname=None, directory=u'.'):
3369
branch = Branch.open_containing(directory)[0]
3358
3370
if nickname is None:
3359
3371
self.printme(branch)
3409
3421
'bzr alias --remove expects an alias to remove.')
3410
3422
# If alias is not found, print something like:
3411
3423
# unalias: foo: not found
3412
c = config.GlobalConfig()
3424
c = _mod_config.GlobalConfig()
3413
3425
c.unset_alias(alias_name)
3415
3427
@display_command
3416
3428
def print_aliases(self):
3417
3429
"""Print out the defined aliases in a similar format to bash."""
3418
aliases = config.GlobalConfig().get_aliases()
3430
aliases = _mod_config.GlobalConfig().get_aliases()
3419
3431
for key, value in sorted(aliases.iteritems()):
3420
3432
self.outf.write('bzr alias %s="%s"\n' % (key, value))
3432
3444
def set_alias(self, alias_name, alias_command):
3433
3445
"""Save the alias in the global config."""
3434
c = config.GlobalConfig()
3446
c = _mod_config.GlobalConfig()
3435
3447
c.set_alias(alias_name, alias_command)
3472
3484
If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
3473
3485
into a pdb postmortem session.
3487
The --coverage=DIRNAME global option produces a report with covered code
3476
3491
Run only tests relating to 'ignore'::
3510
3525
'throughout the test suite.',
3511
3526
type=get_transport_type),
3512
3527
Option('benchmark',
3513
help='Run the benchmarks rather than selftests.'),
3528
help='Run the benchmarks rather than selftests.',
3514
3530
Option('lsprof-timed',
3515
3531
help='Generate lsprof output for benchmarked'
3516
3532
' sections of code.'),
3517
3533
Option('lsprof-tests',
3518
3534
help='Generate lsprof output for each test.'),
3519
Option('cache-dir', type=str,
3520
help='Cache intermediate benchmark output in this '
3522
3535
Option('first',
3523
3536
help='Run all tests, but run specified tests first.',
3524
3537
short_name='f',
3559
3572
def run(self, testspecs_list=None, verbose=False, one=False,
3560
3573
transport=None, benchmark=None,
3561
lsprof_timed=None, cache_dir=None,
3562
3575
first=False, list_only=False,
3563
3576
randomize=None, exclude=None, strict=False,
3564
3577
load_list=None, debugflag=None, starting_with=None, subunit=False,
3565
3578
parallel=None, lsprof_tests=False):
3566
from bzrlib.tests import selftest
3567
import bzrlib.benchmarks as benchmarks
3568
from bzrlib.benchmarks import tree_creator
3570
# Make deprecation warnings visible, unless -Werror is set
3571
symbol_versioning.activate_deprecation_warnings(override=False)
3573
if cache_dir is not None:
3574
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3579
from bzrlib import tests
3575
3581
if testspecs_list is not None:
3576
3582
pattern = '|'.join(testspecs_list)
3585
3591
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3592
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3593
# stdout, which would corrupt the subunit stream.
3588
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3594
# FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3595
# following code can be deleted when it's sufficiently deployed
3596
# -- vila/mgz 20100514
3597
if (sys.platform == "win32"
3598
and getattr(sys.stdout, 'fileno', None) is not None):
3590
3600
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3592
3602
self.additional_selftest_args.setdefault(
3593
3603
'suite_decorators', []).append(parallel)
3595
test_suite_factory = benchmarks.test_suite
3596
# Unless user explicitly asks for quiet, be verbose in benchmarks
3597
verbose = not is_quiet()
3598
# TODO: should possibly lock the history file...
3599
benchfile = open(".perf_history", "at", buffering=1)
3600
self.add_cleanup(benchfile.close)
3602
test_suite_factory = None
3605
raise errors.BzrCommandError(
3606
"--benchmark is no longer supported from bzr 2.2; "
3607
"use bzr-usertest instead")
3608
test_suite_factory = None
3604
3609
selftest_kwargs = {"verbose": verbose,
3605
3610
"pattern": pattern,
3606
3611
"stop_on_failure": one,
3608
3613
"test_suite_factory": test_suite_factory,
3609
3614
"lsprof_timed": lsprof_timed,
3610
3615
"lsprof_tests": lsprof_tests,
3611
"bench_history": benchfile,
3612
3616
"matching_tests_first": first,
3613
3617
"list_only": list_only,
3614
3618
"random_seed": randomize,
3619
3623
"starting_with": starting_with
3621
3625
selftest_kwargs.update(self.additional_selftest_args)
3622
result = selftest(**selftest_kwargs)
3627
# Make deprecation warnings visible, unless -Werror is set
3628
cleanup = symbol_versioning.activate_deprecation_warnings(
3631
result = tests.selftest(**selftest_kwargs)
3623
3634
return int(not result)
3764
3775
' completely merged into the source, pull from the'
3765
3776
' source rather than merging. When this happens,'
3766
3777
' you do not need to commit the result.'),
3778
custom_help('directory',
3768
3779
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3780
'rather than the one containing the working directory.'),
3773
3781
Option('preview', help='Instead of merging, show a diff of the'
3775
3783
Option('interactive', help='Select changes interactively.',
3875
3883
def _do_preview(self, merger):
3876
3884
from bzrlib.diff import show_diff_trees
3877
3885
result_tree = self._get_preview(merger)
3886
path_encoding = osutils.get_diff_header_encoding()
3878
3887
show_diff_trees(merger.this_tree, result_tree, self.outf,
3879
old_label='', new_label='')
3888
old_label='', new_label='',
3889
path_encoding=path_encoding)
3881
3891
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3882
3892
merger.change_reporter = change_reporter
4069
4079
from bzrlib.conflicts import restore
4070
4080
if merge_type is None:
4071
4081
merge_type = _mod_merge.Merge3Merger
4072
tree, file_list = tree_files(file_list)
4082
tree, file_list = WorkingTree.open_containing_paths(file_list)
4073
4083
self.add_cleanup(tree.lock_write().unlock)
4074
4084
parents = tree.get_parent_ids()
4075
4085
if len(parents) != 2:
4186
4196
def run(self, revision=None, no_backup=False, file_list=None,
4187
4197
forget_merges=None):
4188
tree, file_list = tree_files(file_list)
4198
tree, file_list = WorkingTree.open_containing_paths(file_list)
4189
4199
self.add_cleanup(tree.lock_tree_write().unlock)
4190
4200
if forget_merges:
4191
4201
tree.set_parent_ids(tree.get_parent_ids()[:1])
4281
4291
_see_also = ['merge', 'pull']
4282
4292
takes_args = ['other_branch?']
4283
4293
takes_options = [
4284
4295
Option('reverse', 'Reverse the order of revisions.'),
4285
4296
Option('mine-only',
4286
4297
'Display changes in the local branch only.'),
4308
4319
theirs_only=False,
4309
4320
log_format=None, long=False, short=False, line=False,
4310
4321
show_ids=False, verbose=False, this=False, other=False,
4311
include_merges=False, revision=None, my_revision=None):
4322
include_merges=False, revision=None, my_revision=None,
4312
4324
from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4325
def message(s):
4314
4326
if not is_quiet():
4542
4554
Option('long', help='Show commit date in annotations.'),
4546
4559
encoding_type = 'exact'
4548
4561
@display_command
4549
4562
def run(self, filename, all=False, long=False, revision=None,
4563
show_ids=False, directory=None):
4551
4564
from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4565
wt, branch, relpath = \
4553
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4566
_open_directory_or_containing_tree_or_branch(filename, directory)
4554
4567
if wt is not None:
4555
4568
self.add_cleanup(wt.lock_read().unlock)
4581
4594
hidden = True # is this right ?
4582
4595
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4596
takes_options = ['directory', 'revision']
4585
def run(self, revision_id_list=None, revision=None):
4598
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4599
if revision_id_list is not None and revision is not None:
4587
4600
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4601
if revision_id_list is None and revision is None:
4589
4602
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
b = WorkingTree.open_containing(u'.')[0].branch
4603
b = WorkingTree.open_containing(directory)[0].branch
4591
4604
self.add_cleanup(b.lock_write().unlock)
4592
4605
return self._run(b, revision_id_list, revision)
4654
4667
_see_also = ['checkouts', 'unbind']
4655
4668
takes_args = ['location?']
4669
takes_options = ['directory']
4658
def run(self, location=None):
4659
b, relpath = Branch.open_containing(u'.')
4671
def run(self, location=None, directory=u'.'):
4672
b, relpath = Branch.open_containing(directory)
4660
4673
if location is None:
4662
4675
location = b.get_old_bound_location()
4690
4703
_see_also = ['checkouts', 'bind']
4691
4704
takes_args = []
4705
takes_options = ['directory']
4695
b, relpath = Branch.open_containing(u'.')
4707
def run(self, directory=u'.'):
4708
b, relpath = Branch.open_containing(directory)
4696
4709
if not b.unbind():
4697
4710
raise errors.BzrCommandError('Local branch is not bound')
4791
4804
self.outf.write('The above revision(s) will be removed.\n')
4794
if not ui.ui_factory.get_boolean('Are you sure'):
4795
self.outf.write('Canceled')
4807
if not ui.ui_factory.confirm_action(
4808
'Uncommit these revisions',
4809
'bzrlib.builtins.uncommit',
4811
self.outf.write('Canceled\n')
4798
4814
mutter('Uncommitting from {%s} to {%s}',
4806
4822
class cmd_break_lock(Command):
4807
__doc__ = """Break a dead lock on a repository, branch or working directory.
4823
__doc__ = """Break a dead lock.
4825
This command breaks a lock on a repository, branch, working directory or
4809
4828
CAUTION: Locks should only be broken when you are sure that the process
4810
4829
holding the lock has been stopped.
4817
4836
bzr break-lock bzr+ssh://example.com/bzr/foo
4837
bzr break-lock --conf ~/.bazaar
4819
4840
takes_args = ['location?']
4843
help='LOCATION is the directory where the config lock is.'),
4821
def run(self, location=None, show=False):
4846
def run(self, location=None, config=False):
4822
4847
if location is None:
4823
4848
location = u'.'
4824
control, relpath = bzrdir.BzrDir.open_containing(location)
4826
control.break_lock()
4827
except NotImplementedError:
4850
conf = _mod_config.LockableConfig(file_name=location)
4853
control, relpath = bzrdir.BzrDir.open_containing(location)
4855
control.break_lock()
4856
except NotImplementedError:
4831
4860
class cmd_wait_until_signalled(Command):
4860
4889
'result in a dynamically allocated port. The default port '
4861
4890
'depends on the protocol.',
4864
help='Serve contents of this directory.',
4892
custom_help('directory',
4893
help='Serve contents of this directory.'),
4866
4894
Option('allow-writes',
4867
4895
help='By default the server is a readonly server. Supplying '
4868
4896
'--allow-writes enables write access to the contents of '
4896
4924
def run(self, port=None, inet=False, directory=None, allow_writes=False,
4897
4925
protocol=None):
4898
from bzrlib.transport import get_transport, transport_server_registry
4926
from bzrlib import transport
4899
4927
if directory is None:
4900
4928
directory = os.getcwd()
4901
4929
if protocol is None:
4902
protocol = transport_server_registry.get()
4930
protocol = transport.transport_server_registry.get()
4903
4931
host, port = self.get_host_and_port(port)
4904
4932
url = urlutils.local_path_to_url(directory)
4905
4933
if not allow_writes:
4906
4934
url = 'readonly+' + url
4907
transport = get_transport(url)
4908
protocol(transport, host, port, inet)
4935
t = transport.get_transport(url)
4936
protocol(t, host, port, inet)
4911
4939
class cmd_join(Command):
4917
4945
not part of it. (Such trees can be produced by "bzr split", but also by
4918
4946
running "bzr branch" with the target inside a tree.)
4920
The result is a combined tree, with the subtree no longer an independant
4948
The result is a combined tree, with the subtree no longer an independent
4921
4949
part. This is marked as a merge of the subtree into the containing tree,
4922
4950
and all history is preserved.
5022
5051
encoding_type = 'exact'
5024
5053
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5025
sign=False, revision=None, mail_to=None, message=None):
5054
sign=False, revision=None, mail_to=None, message=None,
5026
5056
from bzrlib.revision import ensure_null, NULL_REVISION
5027
5057
include_patch, include_bundle = {
5028
5058
'plain': (False, False),
5029
5059
'diff': (True, False),
5030
5060
'bundle': (True, True),
5032
branch = Branch.open('.')
5062
branch = Branch.open(directory)
5033
5063
stored_submit_branch = branch.get_submit_branch()
5034
5064
if submit_branch is None:
5035
5065
submit_branch = stored_submit_branch
5120
5150
given, in which case it is sent to a file.
5122
5152
Mail is sent using your preferred mail program. This should be transparent
5123
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
5153
on Windows (it uses MAPI). On Unix, it requires the xdg-email utility.
5124
5154
If the preferred client can't be found (or used), your editor will be used.
5126
5156
To use a specific mail program, set the mail_client configuration option.
5297
5327
Option('delete',
5298
5328
help='Delete this tag rather than placing it.',
5301
help='Branch in which to place the tag.',
5330
custom_help('directory',
5331
help='Branch in which to place the tag.'),
5305
5332
Option('force',
5306
5333
help='Replace existing tags.',
5350
5377
_see_also = ['tag']
5351
5378
takes_options = [
5353
help='Branch whose tags should be displayed.',
5379
custom_help('directory',
5380
help='Branch whose tags should be displayed.'),
5357
5381
RegistryOption.from_kwargs('sort',
5358
5382
'Sort tags by different criteria.', title='Sorting',
5359
5383
alpha='Sort tags lexicographically (default).',
5531
5555
takes_args = ['to_location?']
5532
takes_options = [Option('force',
5556
takes_options = ['directory',
5533
5558
help='Switch even if local commits will be lost.'),
5535
5560
Option('create-branch', short_name='b',
5540
5565
def run(self, to_location=None, force=False, create_branch=False,
5566
revision=None, directory=u'.'):
5542
5567
from bzrlib import switch
5568
tree_location = directory
5544
5569
revision = _get_one_revision('switch', revision)
5545
5570
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5571
if to_location is None:
5547
5572
if revision is None:
5548
5573
raise errors.BzrCommandError('You must supply either a'
5549
5574
' revision or a location')
5575
to_location = tree_location
5552
5577
branch = control_dir.open_branch()
5553
5578
had_explicit_nick = branch.get_config().has_explicit_nickname()
5691
tree, file_list = tree_files(file_list, apply_view=False)
5716
tree, file_list = WorkingTree.open_containing_paths(file_list,
5692
5718
current_view, view_dict = tree.views.get_view_info()
5693
5719
if name is None:
5694
5720
name = current_view
5842
5869
_see_also = ['unshelve']
5844
5871
def run(self, revision=None, all=False, file_list=None, message=None,
5845
writer=None, list=False, destroy=False):
5872
writer=None, list=False, destroy=False, directory=u'.'):
5847
5874
return self.run_for_list()
5848
5875
from bzrlib.shelf_ui import Shelver
5850
5877
writer = bzrlib.option.diff_writer_registry.get()
5852
5879
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
file_list, message, destroy=destroy)
5880
file_list, message, destroy=destroy, directory=directory)
5885
5912
takes_args = ['shelf_id?']
5886
5913
takes_options = [
5887
5915
RegistryOption.from_kwargs(
5888
5916
'action', help="The action to perform.",
5889
5917
enum_switch=False, value_switches=True,
5898
5926
_see_also = ['shelve']
5900
def run(self, shelf_id=None, action='apply'):
5928
def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5929
from bzrlib.shelf_ui import Unshelver
5902
unshelver = Unshelver.from_args(shelf_id, action)
5930
unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5904
5932
unshelver.run()
5922
5950
To check what clean-tree will do, use --dry-run.
5924
takes_options = [Option('ignored', help='Delete all ignored files.'),
5952
takes_options = ['directory',
5953
Option('ignored', help='Delete all ignored files.'),
5925
5954
Option('detritus', help='Delete conflict files, merge'
5926
5955
' backups, and failed selftest dirs.'),
5927
5956
Option('unknown',
5930
5959
' deleting them.'),
5931
5960
Option('force', help='Do not prompt before deleting.')]
5932
5961
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5962
force=False, directory=u'.'):
5934
5963
from bzrlib.clean_tree import clean_tree
5935
5964
if not (unknown or ignored or detritus):
5939
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
dry_run=dry_run, no_prompt=force)
5968
clean_tree(directory, unknown=unknown, ignored=ignored,
5969
detritus=detritus, dry_run=dry_run, no_prompt=force)
5943
5972
class cmd_reference(Command):