~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-06-28 03:12:48 UTC
  • mfrom: (5215.4.4 find-bzrdirs-missing-repos)
  • Revision ID: pqm@pqm.ubuntu.com-20100628031248-icctusovofhlk7z9
(lifeless) Do not return bzrdirs in find_bzrdirs where there is a branch
 with no repository available to it. (Marius Kruger) (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    return view_info
233
233
 
234
234
 
 
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)
 
241
 
 
242
 
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
340
348
 
341
349
    hidden = True
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'
346
354
 
353
361
        self.outf.write(revtext.decode('utf-8'))
354
362
 
355
363
    @display_command
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
364
372
 
365
373
        revisions = b.repository.revisions
366
374
        if revisions is None:
483
491
    takes_options = [
484
492
        Option('force',
485
493
               help='Remove the working tree even if it has '
486
 
                    'uncommitted changes.'),
 
494
                    'uncommitted or shelved changes.'),
487
495
        ]
488
496
 
489
497
    def run(self, location_list, force=False):
503
511
            if not force:
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)
506
516
 
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 = [
554
564
        'revision',
555
 
        Option('directory',
 
565
        custom_help('directory',
556
566
            help='Branch to examine, '
557
 
                 'rather than the one containing the working directory.',
558
 
            short_name='d',
559
 
            type=unicode,
560
 
            ),
 
567
                 'rather than the one containing the working directory.'),
561
568
        Option('tree', help='Show revno of working tree'),
562
569
        ]
563
570
 
951
958
    takes_options = ['remember', 'overwrite', 'revision',
952
959
        custom_help('verbose',
953
960
            help='Show logs of pulled revisions.'),
954
 
        Option('directory',
 
961
        custom_help('directory',
955
962
            help='Branch to pull into, '
956
 
                 'rather than the one containing the working directory.',
957
 
            short_name='d',
958
 
            type=unicode,
959
 
            ),
 
963
                 'rather than the one containing the working directory.'),
960
964
        Option('local',
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.'),
1079
 
        Option('directory',
 
1083
        custom_help('directory',
1080
1084
            help='Branch to push from, '
1081
 
                 'rather than the one containing the working directory.',
1082
 
            short_name='d',
1083
 
            type=unicode,
1084
 
            ),
 
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,
 
1981
                               using=using,
1977
1982
                               format_cls=format)
1978
1983
 
1979
1984
 
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']
1991
1996
 
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)
2010
2015
 
2011
2016
    hidden = True
2012
2017
    _see_also = ['status', 'ls']
2013
 
    takes_options = [
2014
 
            Option('null',
2015
 
                   help='Write an ascii NUL (\\0) separator '
2016
 
                   'between files rather than a newline.')
2017
 
            ]
 
2018
    takes_options = ['directory', 'null']
2018
2019
 
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:
2024
2025
            if null:
2033
2034
 
2034
2035
    hidden = True
2035
2036
    _see_also = ['status', 'ls']
2036
 
    takes_options = [
2037
 
            Option('null',
2038
 
                   help='Write an ascii NUL (\\0) separator '
2039
 
                   'between files rather than a newline.')
2040
 
            ]
 
2037
    takes_options = ['directory', 'null']
2041
2038
 
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:
2054
2051
                continue
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):
2057
2054
                continue
2058
2055
            if null:
2059
2056
                self.outf.write(path + '\0')
2259
2256
                   help='Show just the specified revision.'
2260
2257
                   ' See also "help revisionspec".'),
2261
2258
            'log-format',
 
2259
            RegistryOption('authors',
 
2260
                'What names to list as authors - first, all or committer.',
 
2261
                title='Authors',
 
2262
                lazy_registry=('bzrlib.log', 'author_list_registry'),
 
2263
            ),
2262
2264
            Option('levels',
2263
2265
                   short_name='n',
2264
2266
                   help='Number of levels to display - 0 for all, 1 for flat.',
2299
2301
            limit=None,
2300
2302
            show_diff=False,
2301
2303
            include_merges=False,
 
2304
            authors=None,
2302
2305
            exclude_common_ancestry=False,
2303
2306
            ):
2304
2307
        from bzrlib.log import (
2382
2385
                        show_timezone=timezone,
2383
2386
                        delta_format=get_verbosity_level(),
2384
2387
                        levels=levels,
2385
 
                        show_advice=levels is None)
 
2388
                        show_advice=levels is None,
 
2389
                        author_list_handler=authors)
2386
2390
 
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.'),
2512
 
            Option('null',
2513
 
                   help='Write an ascii NUL (\\0) separator '
2514
 
                   'between files rather than a newline.'),
2515
 
            Option('kind',
 
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.',
2517
2520
                   type=unicode),
 
2521
            'null',
2518
2522
            'show-ids',
 
2523
            'directory',
2519
2524
            ]
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):
2525
2530
 
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'
2540
2545
                                             ' and PATH')
2541
2546
            fs_path = path
2542
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2543
 
            fs_path)
 
2547
        tree, branch, relpath = \
 
2548
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2544
2549
 
2545
2550
        # Calculate the prefix to use
2546
2551
        prefix = None
2614
2619
 
2615
2620
    hidden = True
2616
2621
    _see_also = ['ls']
 
2622
    takes_options = ['directory']
2617
2623
 
2618
2624
    @display_command
2619
 
    def run(self):
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')
2622
2628
 
2623
2629
 
2688
2694
 
2689
2695
    _see_also = ['status', 'ignored', 'patterns']
2690
2696
    takes_args = ['name_pattern*']
2691
 
    takes_options = [
 
2697
    takes_options = ['directory',
2692
2698
        Option('default-rules',
2693
2699
               help='Display the default ignore rules that bzr uses.')
2694
2700
        ]
2695
2701
 
2696
 
    def run(self, name_pattern_list=None, default_rules=None):
 
2702
    def run(self, name_pattern_list=None, default_rules=None,
 
2703
            directory=u'.'):
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)
2716
2723
        matches = []
2742
2749
 
2743
2750
    encoding_type = 'replace'
2744
2751
    _see_also = ['ignore', 'ls']
 
2752
    takes_options = ['directory']
2745
2753
 
2746
2754
    @display_command
2747
 
    def run(self):
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':
2763
2771
    """
2764
2772
    hidden = True
2765
2773
    takes_args = ['revno']
 
2774
    takes_options = ['directory']
2766
2775
 
2767
2776
    @display_command
2768
 
    def run(self, revno):
 
2777
    def run(self, revno, directory=u'.'):
2769
2778
        try:
2770
2779
            revno = int(revno)
2771
2780
        except ValueError:
2772
2781
            raise errors.BzrCommandError("not a valid revision-number: %r"
2773
2782
                                         % revno)
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)
2776
2785
 
2777
2786
 
2804
2813
      =================       =========================
2805
2814
    """
2806
2815
    takes_args = ['dest', 'branch_or_subdir?']
2807
 
    takes_options = [
 
2816
    takes_options = ['directory',
2808
2817
        Option('format',
2809
2818
               help="Type of file to export to.",
2810
2819
               type=unicode),
2819
2828
                    'revision in which it was changed.'),
2820
2829
        ]
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
2824
2833
 
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
2828
2837
            subdir = None
2829
2838
        else:
2848
2857
    """
2849
2858
 
2850
2859
    _see_also = ['ls']
2851
 
    takes_options = [
 
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.'),
2859
2868
 
2860
2869
    @display_command
2861
2870
    def run(self, filename, revision=None, name_from_revision=False,
2862
 
            filters=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"""
3144
3153
            if file:
3145
 
                my_message = codecs.open(
3146
 
                    file, 'rt', osutils.get_user_encoding()).read()
 
3154
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
 
3155
                try:
 
3156
                    my_message = f.read()
 
3157
                finally:
 
3158
                    f.close()
3147
3159
            elif message is not None:
3148
3160
                my_message = message
3149
3161
            else:
3303
3315
 
3304
3316
            bzr whoami "Frank Chu <fchu@example.com>"
3305
3317
    """
3306
 
    takes_options = [ Option('email',
 
3318
    takes_options = [ 'directory',
 
3319
                      Option('email',
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'
3314
3327
 
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
3319
 
            try:
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
 
3333
                try:
 
3334
                    c = Branch.open_containing(u'.')[0].get_config()
 
3335
                except errors.NotBranchError:
 
3336
                    c = config.GlobalConfig()
 
3337
            else:
 
3338
                c = Branch.open(directory).get_config()
3323
3339
            if email:
3324
3340
                self.outf.write(c.user_email() + '\n')
3325
3341
            else:
3335
3351
 
3336
3352
        # use global config unless --branch given
3337
3353
        if branch:
3338
 
            c = Branch.open_containing('.')[0].get_config()
 
3354
            if directory is None:
 
3355
                c = Branch.open_containing(u'.')[0].get_config()
 
3356
            else:
 
3357
                c = Branch.open(directory).get_config()
3339
3358
        else:
3340
3359
            c = config.GlobalConfig()
3341
3360
        c.set_user_option('email', name)
3353
3372
 
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)
3360
3380
        else:
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):
3589
3613
                import msvcrt
3590
3614
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3591
3615
        if parallel:
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.'),
3767
 
        Option('directory',
 
3791
        custom_help('directory',
3768
3792
               help='Branch to merge into, '
3769
 
                    'rather than the one containing the working directory.',
3770
 
               short_name='d',
3771
 
               type=unicode,
3772
 
               ),
 
3793
                    'rather than the one containing the working directory.'),
3773
3794
        Option('preview', help='Instead of merging, show a diff of the'
3774
3795
               ' merge.'),
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)
3880
3903
 
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 = [
 
4307
        'directory',
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,
 
4336
            directory=u'.'):
4312
4337
        from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4338
        def message(s):
4314
4339
            if not is_quiet():
4327
4352
        elif theirs_only:
4328
4353
            restrict = 'remote'
4329
4354
 
4330
 
        local_branch = Branch.open_containing(u".")[0]
 
4355
        local_branch = Branch.open_containing(directory)[0]
4331
4356
        self.add_cleanup(local_branch.lock_read().unlock)
4332
4357
 
4333
4358
        parent = local_branch.get_parent()
4542
4567
                     Option('long', help='Show commit date in annotations.'),
4543
4568
                     'revision',
4544
4569
                     'show-ids',
 
4570
                     'directory',
4545
4571
                     ]
4546
4572
    encoding_type = 'exact'
4547
4573
 
4548
4574
    @display_command
4549
4575
    def run(self, filename, all=False, long=False, revision=None,
4550
 
            show_ids=False):
 
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)
4556
4582
        else:
4580
4606
 
4581
4607
    hidden = True # is this right ?
4582
4608
    takes_args = ['revision_id*']
4583
 
    takes_options = ['revision']
 
4609
    takes_options = ['directory', 'revision']
4584
4610
 
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)
4593
4619
 
4653
4679
 
4654
4680
    _see_also = ['checkouts', 'unbind']
4655
4681
    takes_args = ['location?']
4656
 
    takes_options = []
 
4682
    takes_options = ['directory']
4657
4683
 
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:
4661
4687
            try:
4662
4688
                location = b.get_old_bound_location()
4689
4715
 
4690
4716
    _see_also = ['checkouts', 'bind']
4691
4717
    takes_args = []
4692
 
    takes_options = []
 
4718
    takes_options = ['directory']
4693
4719
 
4694
 
    def run(self):
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')
4698
4724
 
4860
4886
                    'result in a dynamically allocated port.  The default port '
4861
4887
                    'depends on the protocol.',
4862
4888
               type=str),
4863
 
        Option('directory',
4864
 
               help='Serve contents of this directory.',
4865
 
               type=unicode),
 
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 '
5004
5029
    _see_also = ['send']
5005
5030
 
5006
5031
    takes_options = [
 
5032
        'directory',
5007
5033
        RegistryOption.from_kwargs('patch-type',
5008
5034
            'The type of patch to include in the directive.',
5009
5035
            title='Patch type',
5022
5048
    encoding_type = 'exact'
5023
5049
 
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,
 
5052
            directory=u'.'):
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),
5031
5058
            }[patch_type]
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.
5121
5148
 
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.
5125
5152
 
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.',
5299
5326
            ),
5300
 
        Option('directory',
5301
 
            help='Branch in which to place the tag.',
5302
 
            short_name='d',
5303
 
            type=unicode,
5304
 
            ),
 
5327
        custom_help('directory',
 
5328
            help='Branch in which to place the tag.'),
5305
5329
        Option('force',
5306
5330
            help='Replace existing tags.',
5307
5331
            ),
5349
5373
 
5350
5374
    _see_also = ['tag']
5351
5375
    takes_options = [
5352
 
        Option('directory',
5353
 
            help='Branch whose tags should be displayed.',
5354
 
            short_name='d',
5355
 
            type=unicode,
5356
 
            ),
 
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).',
5529
5550
    """
5530
5551
 
5531
5552
    takes_args = ['to_location?']
5532
 
    takes_options = [Option('force',
 
5553
    takes_options = ['directory',
 
5554
                     Option('force',
5533
5555
                        help='Switch even if local commits will be lost.'),
5534
5556
                     'revision',
5535
5557
                     Option('create-branch', short_name='b',
5538
5560
                    ]
5539
5561
 
5540
5562
    def run(self, to_location=None, force=False, create_branch=False,
5541
 
            revision=None):
 
5563
            revision=None, directory=u'.'):
5542
5564
        from bzrlib import switch
5543
 
        tree_location = '.'
 
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')
5550
 
            to_location = '.'
 
5572
            to_location = tree_location
5551
5573
        try:
5552
5574
            branch = control_dir.open_branch()
5553
5575
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5828
5850
    takes_args = ['file*']
5829
5851
 
5830
5852
    takes_options = [
 
5853
        'directory',
5831
5854
        'revision',
5832
5855
        Option('all', help='Shelve all changes.'),
5833
5856
        'message',
5842
5865
    _see_also = ['unshelve']
5843
5866
 
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'.'):
5846
5869
        if list:
5847
5870
            return self.run_for_list()
5848
5871
        from bzrlib.shelf_ui import Shelver
5850
5873
            writer = bzrlib.option.diff_writer_registry.get()
5851
5874
        try:
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)
5854
5877
            try:
5855
5878
                shelver.run()
5856
5879
            finally:
5884
5907
 
5885
5908
    takes_args = ['shelf_id?']
5886
5909
    takes_options = [
 
5910
        'directory',
5887
5911
        RegistryOption.from_kwargs(
5888
5912
            'action', help="The action to perform.",
5889
5913
            enum_switch=False, value_switches=True,
5897
5921
    ]
5898
5922
    _see_also = ['shelve']
5899
5923
 
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)
5903
5927
        try:
5904
5928
            unshelver.run()
5905
5929
        finally:
5921
5945
 
5922
5946
    To check what clean-tree will do, use --dry-run.
5923
5947
    """
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,
5933
 
            force=False):
 
5958
            force=False, directory=u'.'):
5934
5959
        from bzrlib.clean_tree import clean_tree
5935
5960
        if not (unknown or ignored or detritus):
5936
5961
            unknown = True
5937
5962
        if dry_run:
5938
5963
            force = True
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)
5941
5966
 
5942
5967
 
5943
5968
class cmd_reference(Command):