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'
1987
1988
# level of effort but possibly much less IO. (Or possibly not,
1988
1989
# if the directories are very large...)
1989
1990
_see_also = ['status', 'ls']
1990
takes_options = ['show-ids']
1991
takes_options = ['directory', 'show-ids']
1992
1993
@display_command
1993
def run(self, show_ids=False):
1994
tree = WorkingTree.open_containing(u'.')[0]
1994
def run(self, show_ids=False, directory=u'.'):
1995
tree = WorkingTree.open_containing(directory)[0]
1995
1996
self.add_cleanup(tree.lock_read().unlock)
1996
1997
old = tree.basis_tree()
1997
1998
self.add_cleanup(old.lock_read().unlock)
2012
2013
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
2014
takes_options = ['directory', 'null']
2019
2016
@display_command
2020
def run(self, null=False):
2021
tree = WorkingTree.open_containing(u'.')[0]
2017
def run(self, null=False, directory=u'.'):
2018
tree = WorkingTree.open_containing(directory)[0]
2022
2019
td = tree.changes_from(tree.basis_tree())
2023
2020
for path, id, kind, text_modified, meta_modified in td.modified:
2035
2032
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2033
takes_options = ['directory', 'null']
2042
2035
@display_command
2043
def run(self, null=False):
2044
wt = WorkingTree.open_containing(u'.')[0]
2036
def run(self, null=False, directory=u'.'):
2037
wt = WorkingTree.open_containing(directory)[0]
2045
2038
self.add_cleanup(wt.lock_read().unlock)
2046
2039
basis = wt.basis_tree()
2047
2040
self.add_cleanup(basis.lock_read().unlock)
2053
2046
if inv.is_root(file_id) and len(basis_inv) == 0:
2055
2048
path = inv.id2path(file_id)
2056
if not os.access(osutils.abspath(path), os.F_OK):
2049
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2059
2052
self.outf.write(path + '\0')
2259
2252
help='Show just the specified revision.'
2260
2253
' See also "help revisionspec".'),
2255
RegistryOption('authors',
2256
'What names to list as authors - first, all or committer.',
2258
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2260
Option('levels',
2263
2261
short_name='n',
2264
2262
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2381
show_timezone=timezone,
2383
2382
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2384
show_advice=levels is None,
2385
author_list_handler=authors)
2387
2387
# Choose the algorithm for doing the logging. It's annoying
2388
2388
# having multiple code paths like this but necessary until
2505
2505
help='Recurse into subdirectories.'),
2506
2506
Option('from-root',
2507
2507
help='Print paths relative to the root of the branch.'),
2508
Option('unknown', help='Print unknown files.'),
2508
Option('unknown', short_name='u',
2509
help='Print unknown files.'),
2509
2510
Option('versioned', help='Print versioned files.',
2510
2511
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.'),
2512
Option('ignored', short_name='i',
2513
help='Print ignored files.'),
2514
Option('kind', short_name='k',
2516
2515
help='List entries of a particular kind: file, directory, symlink.',
2520
2521
@display_command
2521
2522
def run(self, revision=None, verbose=False,
2522
2523
recursive=False, from_root=False,
2523
2524
unknown=False, versioned=False, ignored=False,
2524
null=False, kind=None, show_ids=False, path=None):
2525
null=False, kind=None, show_ids=False, path=None, directory=None):
2526
2527
if kind and kind not in ('file', 'directory', 'symlink'):
2527
2528
raise errors.BzrCommandError('invalid kind specified')
2539
2540
raise errors.BzrCommandError('cannot specify both --from-root'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2543
tree, branch, relpath = \
2544
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2546
# Calculate the prefix to use
2616
2617
_see_also = ['ls']
2618
takes_options = ['directory']
2618
2620
@display_command
2620
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2621
def run(self, directory=u'.'):
2622
for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2623
self.outf.write(osutils.quotefn(f) + '\n')
2689
2691
_see_also = ['status', 'ignored', 'patterns']
2690
2692
takes_args = ['name_pattern*']
2693
takes_options = ['directory',
2692
2694
Option('default-rules',
2693
2695
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2698
def run(self, name_pattern_list=None, default_rules=None,
2697
2700
from bzrlib import ignores
2698
2701
if default_rules is not None:
2699
2702
# dump the default rules and exit
2710
2713
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2714
raise errors.BzrCommandError(
2712
2715
"NAME_PATTERN should not be an absolute path")
2713
tree, relpath = WorkingTree.open_containing(u'.')
2716
tree, relpath = WorkingTree.open_containing(directory)
2714
2717
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2718
ignored = globbing.Globster(name_pattern_list)
2743
2746
encoding_type = 'replace'
2744
2747
_see_also = ['ignore', 'ls']
2748
takes_options = ['directory']
2746
2750
@display_command
2748
tree = WorkingTree.open_containing(u'.')[0]
2751
def run(self, directory=u'.'):
2752
tree = WorkingTree.open_containing(directory)[0]
2749
2753
self.add_cleanup(tree.lock_read().unlock)
2750
2754
for path, file_class, kind, file_id, entry in tree.list_files():
2751
2755
if file_class != 'I':
2765
2769
takes_args = ['revno']
2770
takes_options = ['directory']
2767
2772
@display_command
2768
def run(self, revno):
2773
def run(self, revno, directory=u'.'):
2770
2775
revno = int(revno)
2771
2776
except ValueError:
2772
2777
raise errors.BzrCommandError("not a valid revision-number: %r"
2774
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2779
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2780
self.outf.write("%s\n" % revid)
2804
2809
================= =========================
2806
2811
takes_args = ['dest', 'branch_or_subdir?']
2812
takes_options = ['directory',
2808
2813
Option('format',
2809
2814
help="Type of file to export to.",
2819
2824
'revision in which it was changed.'),
2821
2826
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
root=None, filters=False, per_file_timestamps=False):
2827
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2828
from bzrlib.export import export
2825
2830
if branch_or_subdir is None:
2826
tree = WorkingTree.open_containing(u'.')[0]
2831
tree = WorkingTree.open_containing(directory)[0]
2827
2832
b = tree.branch
2850
2855
_see_also = ['ls']
2856
takes_options = ['directory',
2852
2857
Option('name-from-revision', help='The path name in the old tree.'),
2853
2858
Option('filters', help='Apply content filters to display the '
2854
2859
'convenience form.'),
2860
2865
@display_command
2861
2866
def run(self, filename, revision=None, name_from_revision=False,
2867
filters=False, directory=None):
2863
2868
if revision is not None and len(revision) != 1:
2864
2869
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2870
" one revision specifier")
2866
2871
tree, branch, relpath = \
2867
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2872
_open_directory_or_containing_tree_or_branch(filename, directory)
2868
2873
self.add_cleanup(branch.lock_read().unlock)
2869
2874
return self._run(tree, branch, relpath, filename, revision,
2870
2875
name_from_revision, filters)
3142
3147
def get_message(commit_obj):
3143
3148
"""Callback to get commit message"""
3145
my_message = codecs.open(
3146
file, 'rt', osutils.get_user_encoding()).read()
3150
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3152
my_message = f.read()
3147
3155
elif message is not None:
3148
3156
my_message = message
3304
3312
bzr whoami "Frank Chu <fchu@example.com>"
3306
takes_options = [ Option('email',
3314
takes_options = [ 'directory',
3307
3316
help='Display email address only.'),
3308
3317
Option('branch',
3309
3318
help='Set identity for the current branch instead of '
3313
3322
encoding_type = 'replace'
3315
3324
@display_command
3316
def run(self, email=False, branch=False, name=None):
3325
def run(self, email=False, branch=False, name=None, directory=None):
3317
3326
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()
3327
if directory is None:
3328
# use branch if we're inside one; otherwise global config
3330
c = Branch.open_containing(u'.')[0].get_config()
3331
except errors.NotBranchError:
3332
c = config.GlobalConfig()
3334
c = Branch.open(directory).get_config()
3324
3336
self.outf.write(c.user_email() + '\n')
3336
3348
# use global config unless --branch given
3338
c = Branch.open_containing('.')[0].get_config()
3350
if directory is None:
3351
c = Branch.open_containing(u'.')[0].get_config()
3353
c = Branch.open(directory).get_config()
3340
3355
c = config.GlobalConfig()
3341
3356
c.set_user_option('email', name)
3354
3369
_see_also = ['info']
3355
3370
takes_args = ['nickname?']
3356
def run(self, nickname=None):
3357
branch = Branch.open_containing(u'.')[0]
3371
takes_options = ['directory']
3372
def run(self, nickname=None, directory=u'.'):
3373
branch = Branch.open_containing(directory)[0]
3358
3374
if nickname is None:
3359
3375
self.printme(branch)
3585
3601
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3602
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3603
# stdout, which would corrupt the subunit stream.
3588
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3604
# FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3605
# following code can be deleted when it's sufficiently deployed
3606
# -- vila/mgz 20100514
3607
if (sys.platform == "win32"
3608
and getattr(sys.stdout, 'fileno', None) is not None):
3590
3610
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3764
3784
' completely merged into the source, pull from the'
3765
3785
' source rather than merging. When this happens,'
3766
3786
' you do not need to commit the result.'),
3787
custom_help('directory',
3768
3788
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3789
'rather than the one containing the working directory.'),
3773
3790
Option('preview', help='Instead of merging, show a diff of the'
3775
3792
Option('interactive', help='Select changes interactively.',
4281
4298
_see_also = ['merge', 'pull']
4282
4299
takes_args = ['other_branch?']
4283
4300
takes_options = [
4284
4302
Option('reverse', 'Reverse the order of revisions.'),
4285
4303
Option('mine-only',
4286
4304
'Display changes in the local branch only.'),
4308
4326
theirs_only=False,
4309
4327
log_format=None, long=False, short=False, line=False,
4310
4328
show_ids=False, verbose=False, this=False, other=False,
4311
include_merges=False, revision=None, my_revision=None):
4329
include_merges=False, revision=None, my_revision=None,
4312
4331
from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4332
def message(s):
4314
4333
if not is_quiet():
4542
4561
Option('long', help='Show commit date in annotations.'),
4546
4566
encoding_type = 'exact'
4548
4568
@display_command
4549
4569
def run(self, filename, all=False, long=False, revision=None,
4570
show_ids=False, directory=None):
4551
4571
from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4572
wt, branch, relpath = \
4553
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4573
_open_directory_or_containing_tree_or_branch(filename, directory)
4554
4574
if wt is not None:
4555
4575
self.add_cleanup(wt.lock_read().unlock)
4581
4601
hidden = True # is this right ?
4582
4602
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4603
takes_options = ['directory', 'revision']
4585
def run(self, revision_id_list=None, revision=None):
4605
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4606
if revision_id_list is not None and revision is not None:
4587
4607
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4608
if revision_id_list is None and revision is None:
4589
4609
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
b = WorkingTree.open_containing(u'.')[0].branch
4610
b = WorkingTree.open_containing(directory)[0].branch
4591
4611
self.add_cleanup(b.lock_write().unlock)
4592
4612
return self._run(b, revision_id_list, revision)
4654
4674
_see_also = ['checkouts', 'unbind']
4655
4675
takes_args = ['location?']
4676
takes_options = ['directory']
4658
def run(self, location=None):
4659
b, relpath = Branch.open_containing(u'.')
4678
def run(self, location=None, directory=u'.'):
4679
b, relpath = Branch.open_containing(directory)
4660
4680
if location is None:
4662
4682
location = b.get_old_bound_location()
4690
4710
_see_also = ['checkouts', 'bind']
4691
4711
takes_args = []
4712
takes_options = ['directory']
4695
b, relpath = Branch.open_containing(u'.')
4714
def run(self, directory=u'.'):
4715
b, relpath = Branch.open_containing(directory)
4696
4716
if not b.unbind():
4697
4717
raise errors.BzrCommandError('Local branch is not bound')
4860
4880
'result in a dynamically allocated port. The default port '
4861
4881
'depends on the protocol.',
4864
help='Serve contents of this directory.',
4883
custom_help('directory',
4884
help='Serve contents of this directory.'),
4866
4885
Option('allow-writes',
4867
4886
help='By default the server is a readonly server. Supplying '
4868
4887
'--allow-writes enables write access to the contents of '
5022
5042
encoding_type = 'exact'
5024
5044
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5025
sign=False, revision=None, mail_to=None, message=None):
5045
sign=False, revision=None, mail_to=None, message=None,
5026
5047
from bzrlib.revision import ensure_null, NULL_REVISION
5027
5048
include_patch, include_bundle = {
5028
5049
'plain': (False, False),
5029
5050
'diff': (True, False),
5030
5051
'bundle': (True, True),
5032
branch = Branch.open('.')
5053
branch = Branch.open(directory)
5033
5054
stored_submit_branch = branch.get_submit_branch()
5034
5055
if submit_branch is None:
5035
5056
submit_branch = stored_submit_branch
5120
5141
given, in which case it is sent to a file.
5122
5143
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.
5144
on Windows (it uses MAPI). On Unix, it requires the xdg-email utility.
5124
5145
If the preferred client can't be found (or used), your editor will be used.
5126
5147
To use a specific mail program, set the mail_client configuration option.
5297
5318
Option('delete',
5298
5319
help='Delete this tag rather than placing it.',
5301
help='Branch in which to place the tag.',
5321
custom_help('directory',
5322
help='Branch in which to place the tag.'),
5305
5323
Option('force',
5306
5324
help='Replace existing tags.',
5350
5368
_see_also = ['tag']
5351
5369
takes_options = [
5353
help='Branch whose tags should be displayed.',
5370
custom_help('directory',
5371
help='Branch whose tags should be displayed.'),
5357
5372
RegistryOption.from_kwargs('sort',
5358
5373
'Sort tags by different criteria.', title='Sorting',
5359
5374
alpha='Sort tags lexicographically (default).',
5531
5546
takes_args = ['to_location?']
5532
takes_options = [Option('force',
5547
takes_options = ['directory',
5533
5549
help='Switch even if local commits will be lost.'),
5535
5551
Option('create-branch', short_name='b',
5540
5556
def run(self, to_location=None, force=False, create_branch=False,
5557
revision=None, directory=u'.'):
5542
5558
from bzrlib import switch
5559
tree_location = directory
5544
5560
revision = _get_one_revision('switch', revision)
5545
5561
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5562
if to_location is None:
5547
5563
if revision is None:
5548
5564
raise errors.BzrCommandError('You must supply either a'
5549
5565
' revision or a location')
5566
to_location = tree_location
5552
5568
branch = control_dir.open_branch()
5553
5569
had_explicit_nick = branch.get_config().has_explicit_nickname()
5842
5859
_see_also = ['unshelve']
5844
5861
def run(self, revision=None, all=False, file_list=None, message=None,
5845
writer=None, list=False, destroy=False):
5862
writer=None, list=False, destroy=False, directory=u'.'):
5847
5864
return self.run_for_list()
5848
5865
from bzrlib.shelf_ui import Shelver
5850
5867
writer = bzrlib.option.diff_writer_registry.get()
5852
5869
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
file_list, message, destroy=destroy)
5870
file_list, message, destroy=destroy, directory=directory)
5885
5902
takes_args = ['shelf_id?']
5886
5903
takes_options = [
5887
5905
RegistryOption.from_kwargs(
5888
5906
'action', help="The action to perform.",
5889
5907
enum_switch=False, value_switches=True,
5898
5916
_see_also = ['shelve']
5900
def run(self, shelf_id=None, action='apply'):
5918
def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5919
from bzrlib.shelf_ui import Unshelver
5902
unshelver = Unshelver.from_args(shelf_id, action)
5920
unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5904
5922
unshelver.run()
5922
5940
To check what clean-tree will do, use --dry-run.
5924
takes_options = [Option('ignored', help='Delete all ignored files.'),
5942
takes_options = ['directory',
5943
Option('ignored', help='Delete all ignored files.'),
5925
5944
Option('detritus', help='Delete conflict files, merge'
5926
5945
' backups, and failed selftest dirs.'),
5927
5946
Option('unknown',
5930
5949
' deleting them.'),
5931
5950
Option('force', help='Do not prompt before deleting.')]
5932
5951
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5952
force=False, directory=u'.'):
5934
5953
from bzrlib.clean_tree import clean_tree
5935
5954
if not (unknown or ignored or detritus):
5939
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
dry_run=dry_run, no_prompt=force)
5958
clean_tree(directory, unknown=unknown, ignored=ignored,
5959
detritus=detritus, dry_run=dry_run, no_prompt=force)
5943
5962
class cmd_reference(Command):