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)
243
235
# TODO: Make sure no commands unconditionally use the working directory as a
244
236
# branch. If a filename argument is used, the first of them should be used to
245
237
# specify the branch. (Perhaps this can be factored out into some kind of
350
342
takes_args = ['revision_id?']
351
takes_options = ['directory', 'revision']
343
takes_options = ['revision']
352
344
# cat-revision is more for frontends so should be exact
353
345
encoding = 'strict'
361
353
self.outf.write(revtext.decode('utf-8'))
364
def run(self, revision_id=None, revision=None, directory=u'.'):
356
def run(self, revision_id=None, revision=None):
365
357
if revision_id is not None and revision is not None:
366
358
raise errors.BzrCommandError('You can only supply one of'
367
359
' revision_id or --revision')
368
360
if revision_id is None and revision is None:
369
361
raise errors.BzrCommandError('You must supply either'
370
362
' --revision or a revision_id')
371
b = WorkingTree.open_containing(directory)[0].branch
363
b = WorkingTree.open_containing(u'.')[0].branch
373
365
revisions = b.repository.revisions
374
366
if revisions is None:
562
554
takes_args = ['revision_info*']
563
555
takes_options = [
565
custom_help('directory',
566
558
help='Branch to examine, '
567
'rather than the one containing the working directory.'),
559
'rather than the one containing the working directory.',
568
563
Option('tree', help='Show revno of working tree'),
965
960
takes_options = ['remember', 'overwrite', 'revision',
966
961
custom_help('verbose',
967
962
help='Show logs of pulled revisions.'),
968
custom_help('directory',
969
964
help='Branch to pull into, '
970
'rather than the one containing the working directory.'),
965
'rather than the one containing the working directory.',
972
970
help="Perform a local pull in a bound "
973
971
"branch. Local pulls are not applied to "
1090
1088
Option('create-prefix',
1091
1089
help='Create the path leading up to the branch '
1092
1090
'if it does not already exist.'),
1093
custom_help('directory',
1094
1092
help='Branch to push from, '
1095
'rather than the one containing the working directory.'),
1093
'rather than the one containing the working directory.',
1096
1097
Option('use-existing-dir',
1097
1098
help='By default push will fail if the target'
1098
1099
' directory exists, but does not already'
2002
2003
# level of effort but possibly much less IO. (Or possibly not,
2003
2004
# if the directories are very large...)
2004
2005
_see_also = ['status', 'ls']
2005
takes_options = ['directory', 'show-ids']
2006
takes_options = ['show-ids']
2007
2008
@display_command
2008
def run(self, show_ids=False, directory=u'.'):
2009
tree = WorkingTree.open_containing(directory)[0]
2009
def run(self, show_ids=False):
2010
tree = WorkingTree.open_containing(u'.')[0]
2010
2011
tree.lock_read()
2011
2012
self.add_cleanup(tree.unlock)
2012
2013
old = tree.basis_tree()
2029
2030
_see_also = ['status', 'ls']
2030
takes_options = ['directory', 'null']
2033
help='Write an ascii NUL (\\0) separator '
2034
'between files rather than a newline.')
2032
2037
@display_command
2033
def run(self, null=False, directory=u'.'):
2034
tree = WorkingTree.open_containing(directory)[0]
2038
def run(self, null=False):
2039
tree = WorkingTree.open_containing(u'.')[0]
2035
2040
td = tree.changes_from(tree.basis_tree())
2036
2041
for path, id, kind, text_modified, meta_modified in td.modified:
2048
2053
_see_also = ['status', 'ls']
2049
takes_options = ['directory', 'null']
2056
help='Write an ascii NUL (\\0) separator '
2057
'between files rather than a newline.')
2051
2060
@display_command
2052
def run(self, null=False, directory=u'.'):
2053
wt = WorkingTree.open_containing(directory)[0]
2061
def run(self, null=False):
2062
wt = WorkingTree.open_containing(u'.')[0]
2055
2064
self.add_cleanup(wt.unlock)
2056
2065
basis = wt.basis_tree()
2064
2073
if inv.is_root(file_id) and len(basis_inv) == 0:
2066
2075
path = inv.id2path(file_id)
2067
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2076
if not os.access(osutils.abspath(path), os.F_OK):
2070
2079
self.outf.write(path + '\0')
2519
2528
help='Recurse into subdirectories.'),
2520
2529
Option('from-root',
2521
2530
help='Print paths relative to the root of the branch.'),
2522
Option('unknown', short_name='u',
2523
help='Print unknown files.'),
2531
Option('unknown', help='Print unknown files.'),
2524
2532
Option('versioned', help='Print versioned files.',
2525
2533
short_name='V'),
2526
Option('ignored', short_name='i',
2527
help='Print ignored files.'),
2528
Option('kind', short_name='k',
2534
Option('ignored', help='Print ignored files.'),
2536
help='Write an ascii NUL (\\0) separator '
2537
'between files rather than a newline.'),
2529
2539
help='List entries of a particular kind: file, directory, symlink.',
2535
2543
@display_command
2536
2544
def run(self, revision=None, verbose=False,
2537
2545
recursive=False, from_root=False,
2538
2546
unknown=False, versioned=False, ignored=False,
2539
null=False, kind=None, show_ids=False, path=None, directory=None):
2547
null=False, kind=None, show_ids=False, path=None):
2541
2549
if kind and kind not in ('file', 'directory', 'symlink'):
2542
2550
raise errors.BzrCommandError('invalid kind specified')
2554
2562
raise errors.BzrCommandError('cannot specify both --from-root'
2557
tree, branch, relpath = \
2558
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2565
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2560
2568
# Calculate the prefix to use
2632
2640
_see_also = ['ls']
2633
takes_options = ['directory']
2635
2642
@display_command
2636
def run(self, directory=u'.'):
2637
for f in WorkingTree.open_containing(directory)[0].unknowns():
2644
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2638
2645
self.outf.write(osutils.quotefn(f) + '\n')
2706
2713
_see_also = ['status', 'ignored', 'patterns']
2707
2714
takes_args = ['name_pattern*']
2708
takes_options = ['directory',
2709
2716
Option('default-rules',
2710
2717
help='Display the default ignore rules that bzr uses.')
2713
def run(self, name_pattern_list=None, default_rules=None,
2720
def run(self, name_pattern_list=None, default_rules=None):
2715
2721
from bzrlib import ignores
2716
2722
if default_rules is not None:
2717
2723
# dump the default rules and exit
2728
2734
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2729
2735
raise errors.BzrCommandError(
2730
2736
"NAME_PATTERN should not be an absolute path")
2731
tree, relpath = WorkingTree.open_containing(directory)
2737
tree, relpath = WorkingTree.open_containing(u'.')
2732
2738
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2733
2739
ignored = globbing.Globster(name_pattern_list)
2761
2767
encoding_type = 'replace'
2762
2768
_see_also = ['ignore', 'ls']
2763
takes_options = ['directory']
2765
2770
@display_command
2766
def run(self, directory=u'.'):
2767
tree = WorkingTree.open_containing(directory)[0]
2772
tree = WorkingTree.open_containing(u'.')[0]
2768
2773
tree.lock_read()
2769
2774
self.add_cleanup(tree.unlock)
2770
2775
for path, file_class, kind, file_id, entry in tree.list_files():
2785
2790
takes_args = ['revno']
2786
takes_options = ['directory']
2788
2792
@display_command
2789
def run(self, revno, directory=u'.'):
2793
def run(self, revno):
2791
2795
revno = int(revno)
2792
2796
except ValueError:
2793
2797
raise errors.BzrCommandError("not a valid revision-number: %r"
2795
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2799
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2796
2800
self.outf.write("%s\n" % revid)
2825
2829
================= =========================
2827
2831
takes_args = ['dest', 'branch_or_subdir?']
2828
takes_options = ['directory',
2829
2833
Option('format',
2830
2834
help="Type of file to export to.",
2840
2844
'revision in which it was changed.'),
2842
2846
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2843
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2847
root=None, filters=False, per_file_timestamps=False):
2844
2848
from bzrlib.export import export
2846
2850
if branch_or_subdir is None:
2847
tree = WorkingTree.open_containing(directory)[0]
2851
tree = WorkingTree.open_containing(u'.')[0]
2848
2852
b = tree.branch
2871
2875
_see_also = ['ls']
2872
takes_options = ['directory',
2873
2877
Option('name-from-revision', help='The path name in the old tree.'),
2874
2878
Option('filters', help='Apply content filters to display the '
2875
2879
'convenience form.'),
2881
2885
@display_command
2882
2886
def run(self, filename, revision=None, name_from_revision=False,
2883
filters=False, directory=None):
2884
2888
if revision is not None and len(revision) != 1:
2885
2889
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2886
2890
" one revision specifier")
2887
2891
tree, branch, relpath = \
2888
_open_directory_or_containing_tree_or_branch(filename, directory)
2892
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2889
2893
branch.lock_read()
2890
2894
self.add_cleanup(branch.unlock)
2891
2895
return self._run(tree, branch, relpath, filename, revision,
3377
3381
_see_also = ['info']
3378
3382
takes_args = ['nickname?']
3379
takes_options = ['directory']
3380
def run(self, nickname=None, directory=u'.'):
3381
branch = Branch.open_containing(directory)[0]
3383
def run(self, nickname=None):
3384
branch = Branch.open_containing(u'.')[0]
3382
3385
if nickname is None:
3383
3386
self.printme(branch)
3790
3793
' completely merged into the source, pull from the'
3791
3794
' source rather than merging. When this happens,'
3792
3795
' you do not need to commit the result.'),
3793
custom_help('directory',
3794
3797
help='Branch to merge into, '
3795
'rather than the one containing the working directory.'),
3798
'rather than the one containing the working directory.',
3796
3802
Option('preview', help='Instead of merging, show a diff of the'
3798
3804
Option('interactive', help='Select changes interactively.',
4572
4578
Option('long', help='Show commit date in annotations.'),
4577
4582
encoding_type = 'exact'
4579
4584
@display_command
4580
4585
def run(self, filename, all=False, long=False, revision=None,
4581
show_ids=False, directory=None):
4582
4587
from bzrlib.annotate import annotate_file, annotate_file_tree
4583
4588
wt, branch, relpath = \
4584
_open_directory_or_containing_tree_or_branch(filename, directory)
4589
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4585
4590
if wt is not None:
4587
4592
self.add_cleanup(wt.unlock)
4615
4620
hidden = True # is this right ?
4616
4621
takes_args = ['revision_id*']
4617
takes_options = ['directory', 'revision']
4622
takes_options = ['revision']
4619
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4624
def run(self, revision_id_list=None, revision=None):
4620
4625
if revision_id_list is not None and revision is not None:
4621
4626
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4622
4627
if revision_id_list is None and revision is None:
4623
4628
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4624
b = WorkingTree.open_containing(directory)[0].branch
4629
b = WorkingTree.open_containing(u'.')[0].branch
4626
4631
self.add_cleanup(b.unlock)
4627
4632
return self._run(b, revision_id_list, revision)
4689
4694
_see_also = ['checkouts', 'unbind']
4690
4695
takes_args = ['location?']
4691
takes_options = ['directory']
4693
def run(self, location=None, directory=u'.'):
4694
b, relpath = Branch.open_containing(directory)
4698
def run(self, location=None):
4699
b, relpath = Branch.open_containing(u'.')
4695
4700
if location is None:
4697
4702
location = b.get_old_bound_location()
4725
4730
_see_also = ['checkouts', 'bind']
4726
4731
takes_args = []
4727
takes_options = ['directory']
4729
def run(self, directory=u'.'):
4730
b, relpath = Branch.open_containing(directory)
4735
b, relpath = Branch.open_containing(u'.')
4731
4736
if not b.unbind():
4732
4737
raise errors.BzrCommandError('Local branch is not bound')
4897
4902
'result in a dynamically allocated port. The default port '
4898
4903
'depends on the protocol.',
4900
custom_help('directory',
4901
help='Serve contents of this directory.'),
4906
help='Serve contents of this directory.',
4902
4908
Option('allow-writes',
4903
4909
help='By default the server is a readonly server. Supplying '
4904
4910
'--allow-writes enables write access to the contents of '
5333
5339
Option('delete',
5334
5340
help='Delete this tag rather than placing it.',
5336
custom_help('directory',
5337
help='Branch in which to place the tag.'),
5343
help='Branch in which to place the tag.',
5338
5347
Option('force',
5339
5348
help='Replace existing tags.',
5384
5393
_see_also = ['tag']
5385
5394
takes_options = [
5386
custom_help('directory',
5387
help='Branch whose tags should be displayed.'),
5396
help='Branch whose tags should be displayed.',
5388
5400
RegistryOption.from_kwargs('sort',
5389
5401
'Sort tags by different criteria.', title='Sorting',
5390
5402
alpha='Sort tags lexicographically (default).',
5955
5967
To check what clean-tree will do, use --dry-run.
5957
takes_options = ['directory',
5958
Option('ignored', help='Delete all ignored files.'),
5969
takes_options = [Option('ignored', help='Delete all ignored files.'),
5959
5970
Option('detritus', help='Delete conflict files, merge'
5960
5971
' backups, and failed selftest dirs.'),
5961
5972
Option('unknown',
5964
5975
' deleting them.'),
5965
5976
Option('force', help='Do not prompt before deleting.')]
5966
5977
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5967
force=False, directory=u'.'):
5968
5979
from bzrlib.clean_tree import clean_tree
5969
5980
if not (unknown or ignored or detritus):
5973
clean_tree(directory, unknown=unknown, ignored=ignored,
5974
detritus=detritus, dry_run=dry_run, no_prompt=force)
5984
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5985
dry_run=dry_run, no_prompt=force)
5977
5988
class cmd_reference(Command):