235
def _open_directory_or_containing_tree_or_branch(filename, directory):
236
"""Open the tree or branch containing the specified file, unless
237
the --directory option is used to specify a different branch."""
238
if directory is not None:
239
return (None, Branch.open(directory), filename)
240
return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
235
243
# TODO: Make sure no commands unconditionally use the working directory as a
236
244
# branch. If a filename argument is used, the first of them should be used to
237
245
# specify the branch. (Perhaps this can be factored out into some kind of
342
350
takes_args = ['revision_id?']
343
takes_options = ['revision']
351
takes_options = ['directory', 'revision']
344
352
# cat-revision is more for frontends so should be exact
345
353
encoding = 'strict'
353
361
self.outf.write(revtext.decode('utf-8'))
356
def run(self, revision_id=None, revision=None):
364
def run(self, revision_id=None, revision=None, directory=u'.'):
357
365
if revision_id is not None and revision is not None:
358
366
raise errors.BzrCommandError('You can only supply one of'
359
367
' revision_id or --revision')
360
368
if revision_id is None and revision is None:
361
369
raise errors.BzrCommandError('You must supply either'
362
370
' --revision or a revision_id')
363
b = WorkingTree.open_containing(u'.')[0].branch
371
b = WorkingTree.open_containing(directory)[0].branch
365
373
revisions = b.repository.revisions
366
374
if revisions is None:
483
491
takes_options = [
485
493
help='Remove the working tree even if it has '
486
'uncommitted changes.'),
494
'uncommitted or shelved changes.'),
489
497
def run(self, location_list, force=False):
504
512
if (working.has_changes()):
505
513
raise errors.UncommittedChanges(working)
514
if working.get_shelf_manager().last_shelf() is not None:
515
raise errors.ShelvedChanges(working)
507
517
if working.user_url != working.branch.user_url:
508
518
raise errors.BzrCommandError("You cannot remove the working tree"
552
562
takes_args = ['revision_info*']
553
563
takes_options = [
565
custom_help('directory',
556
566
help='Branch to examine, '
557
'rather than the one containing the working directory.',
567
'rather than the one containing the working directory.'),
561
568
Option('tree', help='Show revno of working tree'),
951
958
takes_options = ['remember', 'overwrite', 'revision',
952
959
custom_help('verbose',
953
960
help='Show logs of pulled revisions.'),
961
custom_help('directory',
955
962
help='Branch to pull into, '
956
'rather than the one containing the working directory.',
963
'rather than the one containing the working directory.'),
961
965
help="Perform a local pull in a bound "
962
966
"branch. Local pulls are not applied to "
1076
1080
Option('create-prefix',
1077
1081
help='Create the path leading up to the branch '
1078
1082
'if it does not already exist.'),
1083
custom_help('directory',
1080
1084
help='Branch to push from, '
1081
'rather than the one containing the working directory.',
1085
'rather than the one containing the working directory.'),
1085
1086
Option('use-existing-dir',
1086
1087
help='By default push will fail if the target'
1087
1088
' directory exists, but does not already'
1969
1970
old_branch, new_branch,
1970
1971
specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1971
1972
file_list, revision, old, new, self.add_cleanup, apply_view=True)
1973
# GNU diff on Windows uses ANSI encoding for filenames
1974
path_encoding = osutils.get_diff_header_encoding()
1972
1975
return show_diff_trees(old_tree, new_tree, sys.stdout,
1973
1976
specific_files=specific_files,
1974
1977
external_diff_options=diff_options,
1975
1978
old_label=old_label, new_label=new_label,
1976
extra_trees=extra_trees, using=using,
1979
extra_trees=extra_trees,
1980
path_encoding=path_encoding,
1977
1982
format_cls=format)
1987
1992
# level of effort but possibly much less IO. (Or possibly not,
1988
1993
# if the directories are very large...)
1989
1994
_see_also = ['status', 'ls']
1990
takes_options = ['show-ids']
1995
takes_options = ['directory', 'show-ids']
1992
1997
@display_command
1993
def run(self, show_ids=False):
1994
tree = WorkingTree.open_containing(u'.')[0]
1998
def run(self, show_ids=False, directory=u'.'):
1999
tree = WorkingTree.open_containing(directory)[0]
1995
2000
self.add_cleanup(tree.lock_read().unlock)
1996
2001
old = tree.basis_tree()
1997
2002
self.add_cleanup(old.lock_read().unlock)
2012
2017
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
2018
takes_options = ['directory', 'null']
2019
2020
@display_command
2020
def run(self, null=False):
2021
tree = WorkingTree.open_containing(u'.')[0]
2021
def run(self, null=False, directory=u'.'):
2022
tree = WorkingTree.open_containing(directory)[0]
2022
2023
td = tree.changes_from(tree.basis_tree())
2023
2024
for path, id, kind, text_modified, meta_modified in td.modified:
2035
2036
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2037
takes_options = ['directory', 'null']
2042
2039
@display_command
2043
def run(self, null=False):
2044
wt = WorkingTree.open_containing(u'.')[0]
2040
def run(self, null=False, directory=u'.'):
2041
wt = WorkingTree.open_containing(directory)[0]
2045
2042
self.add_cleanup(wt.lock_read().unlock)
2046
2043
basis = wt.basis_tree()
2047
2044
self.add_cleanup(basis.lock_read().unlock)
2053
2050
if inv.is_root(file_id) and len(basis_inv) == 0:
2055
2052
path = inv.id2path(file_id)
2056
if not os.access(osutils.abspath(path), os.F_OK):
2053
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2059
2056
self.outf.write(path + '\0')
2259
2256
help='Show just the specified revision.'
2260
2257
' See also "help revisionspec".'),
2259
RegistryOption('authors',
2260
'What names to list as authors - first, all or committer.',
2262
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2264
Option('levels',
2263
2265
short_name='n',
2264
2266
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2385
show_timezone=timezone,
2383
2386
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2388
show_advice=levels is None,
2389
author_list_handler=authors)
2387
2391
# Choose the algorithm for doing the logging. It's annoying
2388
2392
# having multiple code paths like this but necessary until
2505
2509
help='Recurse into subdirectories.'),
2506
2510
Option('from-root',
2507
2511
help='Print paths relative to the root of the branch.'),
2508
Option('unknown', help='Print unknown files.'),
2512
Option('unknown', short_name='u',
2513
help='Print unknown files.'),
2509
2514
Option('versioned', help='Print versioned files.',
2510
2515
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.'),
2516
Option('ignored', short_name='i',
2517
help='Print ignored files.'),
2518
Option('kind', short_name='k',
2516
2519
help='List entries of a particular kind: file, directory, symlink.',
2520
2525
@display_command
2521
2526
def run(self, revision=None, verbose=False,
2522
2527
recursive=False, from_root=False,
2523
2528
unknown=False, versioned=False, ignored=False,
2524
null=False, kind=None, show_ids=False, path=None):
2529
null=False, kind=None, show_ids=False, path=None, directory=None):
2526
2531
if kind and kind not in ('file', 'directory', 'symlink'):
2527
2532
raise errors.BzrCommandError('invalid kind specified')
2539
2544
raise errors.BzrCommandError('cannot specify both --from-root'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2547
tree, branch, relpath = \
2548
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2550
# Calculate the prefix to use
2616
2621
_see_also = ['ls']
2622
takes_options = ['directory']
2618
2624
@display_command
2620
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2625
def run(self, directory=u'.'):
2626
for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2627
self.outf.write(osutils.quotefn(f) + '\n')
2689
2695
_see_also = ['status', 'ignored', 'patterns']
2690
2696
takes_args = ['name_pattern*']
2697
takes_options = ['directory',
2692
2698
Option('default-rules',
2693
2699
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2702
def run(self, name_pattern_list=None, default_rules=None,
2697
2704
from bzrlib import ignores
2698
2705
if default_rules is not None:
2699
2706
# dump the default rules and exit
2710
2717
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2718
raise errors.BzrCommandError(
2712
2719
"NAME_PATTERN should not be an absolute path")
2713
tree, relpath = WorkingTree.open_containing(u'.')
2720
tree, relpath = WorkingTree.open_containing(directory)
2714
2721
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2722
ignored = globbing.Globster(name_pattern_list)
2743
2750
encoding_type = 'replace'
2744
2751
_see_also = ['ignore', 'ls']
2752
takes_options = ['directory']
2746
2754
@display_command
2748
tree = WorkingTree.open_containing(u'.')[0]
2755
def run(self, directory=u'.'):
2756
tree = WorkingTree.open_containing(directory)[0]
2749
2757
self.add_cleanup(tree.lock_read().unlock)
2750
2758
for path, file_class, kind, file_id, entry in tree.list_files():
2751
2759
if file_class != 'I':
2765
2773
takes_args = ['revno']
2774
takes_options = ['directory']
2767
2776
@display_command
2768
def run(self, revno):
2777
def run(self, revno, directory=u'.'):
2770
2779
revno = int(revno)
2771
2780
except ValueError:
2772
2781
raise errors.BzrCommandError("not a valid revision-number: %r"
2774
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2783
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2784
self.outf.write("%s\n" % revid)
2804
2813
================= =========================
2806
2815
takes_args = ['dest', 'branch_or_subdir?']
2816
takes_options = ['directory',
2808
2817
Option('format',
2809
2818
help="Type of file to export to.",
2819
2828
'revision in which it was changed.'),
2821
2830
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
root=None, filters=False, per_file_timestamps=False):
2831
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2832
from bzrlib.export import export
2825
2834
if branch_or_subdir is None:
2826
tree = WorkingTree.open_containing(u'.')[0]
2835
tree = WorkingTree.open_containing(directory)[0]
2827
2836
b = tree.branch
2850
2859
_see_also = ['ls']
2860
takes_options = ['directory',
2852
2861
Option('name-from-revision', help='The path name in the old tree.'),
2853
2862
Option('filters', help='Apply content filters to display the '
2854
2863
'convenience form.'),
2860
2869
@display_command
2861
2870
def run(self, filename, revision=None, name_from_revision=False,
2871
filters=False, directory=None):
2863
2872
if revision is not None and len(revision) != 1:
2864
2873
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2874
" one revision specifier")
2866
2875
tree, branch, relpath = \
2867
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2876
_open_directory_or_containing_tree_or_branch(filename, directory)
2868
2877
self.add_cleanup(branch.lock_read().unlock)
2869
2878
return self._run(tree, branch, relpath, filename, revision,
2870
2879
name_from_revision, filters)
3142
3151
def get_message(commit_obj):
3143
3152
"""Callback to get commit message"""
3145
my_message = codecs.open(
3146
file, 'rt', osutils.get_user_encoding()).read()
3154
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3156
my_message = f.read()
3147
3159
elif message is not None:
3148
3160
my_message = message
3304
3316
bzr whoami "Frank Chu <fchu@example.com>"
3306
takes_options = [ Option('email',
3318
takes_options = [ 'directory',
3307
3320
help='Display email address only.'),
3308
3321
Option('branch',
3309
3322
help='Set identity for the current branch instead of '
3313
3326
encoding_type = 'replace'
3315
3328
@display_command
3316
def run(self, email=False, branch=False, name=None):
3329
def run(self, email=False, branch=False, name=None, directory=None):
3317
3330
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()
3331
if directory is None:
3332
# use branch if we're inside one; otherwise global config
3334
c = Branch.open_containing(u'.')[0].get_config()
3335
except errors.NotBranchError:
3336
c = config.GlobalConfig()
3338
c = Branch.open(directory).get_config()
3324
3340
self.outf.write(c.user_email() + '\n')
3336
3352
# use global config unless --branch given
3338
c = Branch.open_containing('.')[0].get_config()
3354
if directory is None:
3355
c = Branch.open_containing(u'.')[0].get_config()
3357
c = Branch.open(directory).get_config()
3340
3359
c = config.GlobalConfig()
3341
3360
c.set_user_option('email', name)
3354
3373
_see_also = ['info']
3355
3374
takes_args = ['nickname?']
3356
def run(self, nickname=None):
3357
branch = Branch.open_containing(u'.')[0]
3375
takes_options = ['directory']
3376
def run(self, nickname=None, directory=u'.'):
3377
branch = Branch.open_containing(directory)[0]
3358
3378
if nickname is None:
3359
3379
self.printme(branch)
3585
3605
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3606
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3607
# stdout, which would corrupt the subunit stream.
3588
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3608
# FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3609
# following code can be deleted when it's sufficiently deployed
3610
# -- vila/mgz 20100514
3611
if (sys.platform == "win32"
3612
and getattr(sys.stdout, 'fileno', None) is not None):
3590
3614
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3764
3788
' completely merged into the source, pull from the'
3765
3789
' source rather than merging. When this happens,'
3766
3790
' you do not need to commit the result.'),
3791
custom_help('directory',
3768
3792
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3793
'rather than the one containing the working directory.'),
3773
3794
Option('preview', help='Instead of merging, show a diff of the'
3775
3796
Option('interactive', help='Select changes interactively.',
3875
3896
def _do_preview(self, merger):
3876
3897
from bzrlib.diff import show_diff_trees
3877
3898
result_tree = self._get_preview(merger)
3899
path_encoding = osutils.get_diff_header_encoding()
3878
3900
show_diff_trees(merger.this_tree, result_tree, self.outf,
3879
old_label='', new_label='')
3901
old_label='', new_label='',
3902
path_encoding=path_encoding)
3881
3904
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3882
3905
merger.change_reporter = change_reporter
4281
4304
_see_also = ['merge', 'pull']
4282
4305
takes_args = ['other_branch?']
4283
4306
takes_options = [
4284
4308
Option('reverse', 'Reverse the order of revisions.'),
4285
4309
Option('mine-only',
4286
4310
'Display changes in the local branch only.'),
4308
4332
theirs_only=False,
4309
4333
log_format=None, long=False, short=False, line=False,
4310
4334
show_ids=False, verbose=False, this=False, other=False,
4311
include_merges=False, revision=None, my_revision=None):
4335
include_merges=False, revision=None, my_revision=None,
4312
4337
from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4338
def message(s):
4314
4339
if not is_quiet():
4542
4567
Option('long', help='Show commit date in annotations.'),
4546
4572
encoding_type = 'exact'
4548
4574
@display_command
4549
4575
def run(self, filename, all=False, long=False, revision=None,
4576
show_ids=False, directory=None):
4551
4577
from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4578
wt, branch, relpath = \
4553
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4579
_open_directory_or_containing_tree_or_branch(filename, directory)
4554
4580
if wt is not None:
4555
4581
self.add_cleanup(wt.lock_read().unlock)
4581
4607
hidden = True # is this right ?
4582
4608
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4609
takes_options = ['directory', 'revision']
4585
def run(self, revision_id_list=None, revision=None):
4611
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4612
if revision_id_list is not None and revision is not None:
4587
4613
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4614
if revision_id_list is None and revision is None:
4589
4615
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
b = WorkingTree.open_containing(u'.')[0].branch
4616
b = WorkingTree.open_containing(directory)[0].branch
4591
4617
self.add_cleanup(b.lock_write().unlock)
4592
4618
return self._run(b, revision_id_list, revision)
4654
4680
_see_also = ['checkouts', 'unbind']
4655
4681
takes_args = ['location?']
4682
takes_options = ['directory']
4658
def run(self, location=None):
4659
b, relpath = Branch.open_containing(u'.')
4684
def run(self, location=None, directory=u'.'):
4685
b, relpath = Branch.open_containing(directory)
4660
4686
if location is None:
4662
4688
location = b.get_old_bound_location()
4690
4716
_see_also = ['checkouts', 'bind']
4691
4717
takes_args = []
4718
takes_options = ['directory']
4695
b, relpath = Branch.open_containing(u'.')
4720
def run(self, directory=u'.'):
4721
b, relpath = Branch.open_containing(directory)
4696
4722
if not b.unbind():
4697
4723
raise errors.BzrCommandError('Local branch is not bound')
4860
4886
'result in a dynamically allocated port. The default port '
4861
4887
'depends on the protocol.',
4864
help='Serve contents of this directory.',
4889
custom_help('directory',
4890
help='Serve contents of this directory.'),
4866
4891
Option('allow-writes',
4867
4892
help='By default the server is a readonly server. Supplying '
4868
4893
'--allow-writes enables write access to the contents of '
5022
5048
encoding_type = 'exact'
5024
5050
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5025
sign=False, revision=None, mail_to=None, message=None):
5051
sign=False, revision=None, mail_to=None, message=None,
5026
5053
from bzrlib.revision import ensure_null, NULL_REVISION
5027
5054
include_patch, include_bundle = {
5028
5055
'plain': (False, False),
5029
5056
'diff': (True, False),
5030
5057
'bundle': (True, True),
5032
branch = Branch.open('.')
5059
branch = Branch.open(directory)
5033
5060
stored_submit_branch = branch.get_submit_branch()
5034
5061
if submit_branch is None:
5035
5062
submit_branch = stored_submit_branch
5120
5147
given, in which case it is sent to a file.
5122
5149
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.
5150
on Windows (it uses MAPI). On Unix, it requires the xdg-email utility.
5124
5151
If the preferred client can't be found (or used), your editor will be used.
5126
5153
To use a specific mail program, set the mail_client configuration option.
5297
5324
Option('delete',
5298
5325
help='Delete this tag rather than placing it.',
5301
help='Branch in which to place the tag.',
5327
custom_help('directory',
5328
help='Branch in which to place the tag.'),
5305
5329
Option('force',
5306
5330
help='Replace existing tags.',
5350
5374
_see_also = ['tag']
5351
5375
takes_options = [
5353
help='Branch whose tags should be displayed.',
5376
custom_help('directory',
5377
help='Branch whose tags should be displayed.'),
5357
5378
RegistryOption.from_kwargs('sort',
5358
5379
'Sort tags by different criteria.', title='Sorting',
5359
5380
alpha='Sort tags lexicographically (default).',
5531
5552
takes_args = ['to_location?']
5532
takes_options = [Option('force',
5553
takes_options = ['directory',
5533
5555
help='Switch even if local commits will be lost.'),
5535
5557
Option('create-branch', short_name='b',
5540
5562
def run(self, to_location=None, force=False, create_branch=False,
5563
revision=None, directory=u'.'):
5542
5564
from bzrlib import switch
5565
tree_location = directory
5544
5566
revision = _get_one_revision('switch', revision)
5545
5567
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5568
if to_location is None:
5547
5569
if revision is None:
5548
5570
raise errors.BzrCommandError('You must supply either a'
5549
5571
' revision or a location')
5572
to_location = tree_location
5552
5574
branch = control_dir.open_branch()
5553
5575
had_explicit_nick = branch.get_config().has_explicit_nickname()
5842
5865
_see_also = ['unshelve']
5844
5867
def run(self, revision=None, all=False, file_list=None, message=None,
5845
writer=None, list=False, destroy=False):
5868
writer=None, list=False, destroy=False, directory=u'.'):
5847
5870
return self.run_for_list()
5848
5871
from bzrlib.shelf_ui import Shelver
5850
5873
writer = bzrlib.option.diff_writer_registry.get()
5852
5875
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
file_list, message, destroy=destroy)
5876
file_list, message, destroy=destroy, directory=directory)
5885
5908
takes_args = ['shelf_id?']
5886
5909
takes_options = [
5887
5911
RegistryOption.from_kwargs(
5888
5912
'action', help="The action to perform.",
5889
5913
enum_switch=False, value_switches=True,
5898
5922
_see_also = ['shelve']
5900
def run(self, shelf_id=None, action='apply'):
5924
def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5925
from bzrlib.shelf_ui import Unshelver
5902
unshelver = Unshelver.from_args(shelf_id, action)
5926
unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5904
5928
unshelver.run()
5922
5946
To check what clean-tree will do, use --dry-run.
5924
takes_options = [Option('ignored', help='Delete all ignored files.'),
5948
takes_options = ['directory',
5949
Option('ignored', help='Delete all ignored files.'),
5925
5950
Option('detritus', help='Delete conflict files, merge'
5926
5951
' backups, and failed selftest dirs.'),
5927
5952
Option('unknown',
5930
5955
' deleting them.'),
5931
5956
Option('force', help='Do not prompt before deleting.')]
5932
5957
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5958
force=False, directory=u'.'):
5934
5959
from bzrlib.clean_tree import clean_tree
5935
5960
if not (unknown or ignored or detritus):
5939
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
dry_run=dry_run, no_prompt=force)
5964
clean_tree(directory, unknown=unknown, ignored=ignored,
5965
detritus=detritus, dry_run=dry_run, no_prompt=force)
5943
5968
class cmd_reference(Command):