~abentley/bzrtools/bzrtools.dev

246 by Aaron Bentley
Merged shelf_v2
1
"""\
2
Various useful plugins for working with bzr.
3
"""
364.1.4 by Aaron Bentley
Changed rpush to rspush
4
import rspush
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
5
from errors import CommandError
6
from patchsource import BzrPatchSource
246 by Aaron Bentley
Merged shelf_v2
7
from shelf import Shelf
360.1.1 by Aaron Bentley
Add switch command
8
from switch import cmd_switch
246 by Aaron Bentley
Merged shelf_v2
9
import sys
10
import os.path
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
11
12
import bzrlib.builtins
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
13
import bzrlib.branch
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
14
import bzrlib.commands
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
15
from bzrlib.commands import get_cmd_object
0.1.39 by Michael Ellerman
Fix shelve and unshelve to pass location to Shelf().
16
from bzrlib.errors import BzrCommandError
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
17
from bzrlib.help import command_usage
423 by Aaron Bentley
Add runtime ignores for shelf
18
import bzrlib.ignores
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
19
from bzrlib.option import Option
147.1.41 by Aaron Bentley
Merge from mainline
20
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
147.4.37 by Robert Collins
Convert push to rpush.
21
                                                 "external")))
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
22
423 by Aaron Bentley
Add runtime ignores for shelf
23
bzrlib.ignores.add_runtime_ignores(['./.shelf', './.bzr-shelf*'])
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
24
246 by Aaron Bentley
Merged shelf_v2
25
26
class cmd_clean_tree(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
27
    """Remove unwanted files from working tree.
417 by Aaron Bentley
Update clean-tree docs
28
29
    By default, only unknown files, not ignored files, are deleted.  Versioned
30
    files are never deleted.
31
32
    Another class is 'detritus', which includes files emitted by bzr during
33
    normal operations and selftests.  (The value of these files decreases with
34
    time.)
35
36
    If no options are specified, unknown files are deleted.  Otherwise, option
37
    flags are respected, and may be combined.
38
39
    To check what clean-tree will do, use --dry-run.
246 by Aaron Bentley
Merged shelf_v2
40
    """
386 by Aaron Bentley
Stop adding global options
41
    takes_options = [Option('ignored', help='delete all ignored files.'), 
417 by Aaron Bentley
Update clean-tree docs
42
                     Option('detritus', help='delete conflict files, merge'
43
                            ' backups, and failed selftest dirs.'), 
416 by Aaron Bentley
clean-tree --detritus no longer implies --unknown
44
                     Option('unknown', 
45
                            help='delete files unknown to bzr.  (default)'),
386 by Aaron Bentley
Stop adding global options
46
                     Option('dry-run', help='show files to delete instead of'
47
                            ' deleting them.')]
415.1.1 by Adeodato Simó
Make clean-tree --detritus or --ignored not delete also unknown files,
48
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
246 by Aaron Bentley
Merged shelf_v2
49
        from clean_tree import clean_tree
415.1.1 by Adeodato Simó
Make clean-tree --detritus or --ignored not delete also unknown files,
50
        if not (unknown or ignored or detritus):
51
            unknown = True
416 by Aaron Bentley
clean-tree --detritus no longer implies --unknown
52
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus, 
53
                   dry_run=dry_run)
246 by Aaron Bentley
Merged shelf_v2
54
55
class cmd_graph_ancestry(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
56
    """Produce ancestry graphs using dot.
246 by Aaron Bentley
Merged shelf_v2
57
    
58
    Output format is detected according to file extension.  Some of the more
296 by Aaron Bentley
Updated graph-ancestry help
59
    common output formats are html, png, gif, svg, ps.  An extension of '.dot'
60
    will cause a dot graph file to be produced.  HTML output has mouseovers
61
    that show the commit message.
246 by Aaron Bentley
Merged shelf_v2
62
63
    Branches are labeled r?, where ? is the revno.  If they have no revno,
64
    with the last 5 characters of their revision identifier are used instead.
296 by Aaron Bentley
Updated graph-ancestry help
65
66
    The value starting with d is "(maximum) distance from the null revision".
246 by Aaron Bentley
Merged shelf_v2
67
    
68
    If --merge-branch is specified, the two branches are compared and a merge
69
    base is selected.
70
    
71
    Legend:
72
    white    normal revision
73
    yellow   THIS  history
74
    red      OTHER history
75
    orange   COMMON history
76
    blue     COMMON non-history ancestor
296 by Aaron Bentley
Updated graph-ancestry help
77
    green    Merge base (COMMON ancestor farthest from the null revision)
78
    dotted   Ghost revision (missing from branch storage)
246 by Aaron Bentley
Merged shelf_v2
79
296 by Aaron Bentley
Updated graph-ancestry help
80
    Ancestry is usually collapsed by skipping revisions with a single parent
246 by Aaron Bentley
Merged shelf_v2
81
    and descendant.  The number of skipped revisions is shown on the arrow.
82
    This feature can be disabled with --no-collapse.
83
84
    By default, revisions are ordered by distance from root, but they can be
85
    clustered instead using --cluster.
86
87
    If available, rsvg is used to antialias PNG and JPEG output, but this can
88
    be disabled with --no-antialias.
89
    """
90
    takes_args = ['branch', 'file']
296 by Aaron Bentley
Updated graph-ancestry help
91
    takes_options = [Option('no-collapse', help="Do not skip simple nodes"), 
92
                     Option('no-antialias',
93
                     help="Do not use rsvg to produce antialiased output"), 
94
                     Option('merge-branch', type=str, 
95
                     help="Use this branch to calcuate a merge base"), 
96
                     Option('cluster', help="Use clustered output.")]
246 by Aaron Bentley
Merged shelf_v2
97
    def run(self, branch, file, no_collapse=False, no_antialias=False,
98
        merge_branch=None, cluster=False):
99
        import graph
100
        if cluster:
101
            ranking = "cluster"
102
        else:
103
            ranking = "forced"
104
        graph.write_ancestry_file(branch, file, not no_collapse, 
105
                                  not no_antialias, merge_branch, ranking)
106
107
class cmd_fetch_ghosts(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
108
    """Attempt to retrieve ghosts from another branch.
246 by Aaron Bentley
Merged shelf_v2
109
    If the other branch is not supplied, the last-pulled branch is used.
110
    """
111
    aliases = ['fetch-missing']
112
    takes_args = ['branch?']
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
113
    takes_options = [Option('no-fix')]
114
    def run(self, branch=None, no_fix=False):
246 by Aaron Bentley
Merged shelf_v2
115
        from fetch_ghosts import fetch_ghosts
275.1.3 by Daniel Silverstone
Fix up fetch_ghosts to lock the branches, and to invoke bzr fix if it fetches any ghosts into the tree
116
        fetch_ghosts(branch, no_fix)
246 by Aaron Bentley
Merged shelf_v2
117
118
strip_help="""Strip the smallest prefix containing num leading slashes  from \
119
each file name found in the patch file."""
321.2.1 by ghigo
add support for bazaar diff
120
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
121
                                help="""Handle extra bzr tags""")
246 by Aaron Bentley
Merged shelf_v2
122
class cmd_patch(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
123
    """Apply a named patch to the current tree.
246 by Aaron Bentley
Merged shelf_v2
124
    """
125
    takes_args = ['filename?']
386 by Aaron Bentley
Stop adding global options
126
    takes_options = [Option('strip', type=int, help=strip_help)]
321.2.1 by ghigo
add support for bazaar diff
127
    def run(self, filename=None, strip=-1, bzrdiff=0):
246 by Aaron Bentley
Merged shelf_v2
128
        from patch import patch
340 by Aaron Bentley
Fixed patch on checkouts
129
        from bzrlib.workingtree import WorkingTree
130
        wt = WorkingTree.open_containing('.')[0]
321.2.1 by ghigo
add support for bazaar diff
131
        if strip == -1:
132
            if bzrdiff: strip = 0
369 by Aaron Bentley
Treat patches as p0 by default
133
            else:       strip = 0
321.2.1 by ghigo
add support for bazaar diff
134
340 by Aaron Bentley
Fixed patch on checkouts
135
        return patch(wt, filename, strip, legacy= not bzrdiff)
246 by Aaron Bentley
Merged shelf_v2
136
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
137
class cmd_shelve(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
138
    """Temporarily set aside some changes from the current tree.
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
139
140
    Shelve allows you to temporarily put changes you've made "on the shelf",
141
    ie. out of the way, until a later time when you can bring them back from
142
    the shelf with the 'unshelve' command.
143
289 by Aaron Bentley
Updated shelf help
144
    Shelve is intended to help separate several sets of text changes that have
145
    been inappropriately mingled.  If you just want to get rid of all changes
146
    (text and otherwise) and you don't need to restore them later, use revert.
147
    If you want to shelve all text changes at once, use shelve --all.
148
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
149
    By default shelve asks you what you want to shelve, press '?' at the
150
    prompt to get help. To shelve everything run shelve --all.
151
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
152
    If filenames are specified, only the changes to those files will be
153
    shelved, other files will be left untouched.
154
155
    If a revision is specified, changes since that revision will be shelved.
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
156
157
    You can put multiple items on the shelf. Normally each time you run
158
    unshelve the most recently shelved changes will be reinstated. However,
159
    you can also unshelve changes in a different order by explicitly
160
    specifiying which changes to unshelve. This works best when the changes
161
    don't depend on each other.
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
162
    """
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
163
164
    takes_args = ['file*']
0.1.90 by Michael Ellerman
Update help text to try and be clearer, some stolen from bzrtools.
165
    takes_options = ['message', 'revision',
166
            Option('all', help='Shelve all changes without prompting')]
167
0.1.80 by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be
168
    def run(self, all=False, file_list=None, message=None, revision=None):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
169
        if revision is not None and revision:
170
            if len(revision) == 1:
171
                revision = revision[0]
172
            else:
173
                raise CommandError("shelve only accepts a single revision "
174
                                  "parameter.")
175
176
        source = BzrPatchSource(revision, file_list)
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
177
        s = Shelf(source.base)
0.1.80 by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be
178
        s.shelve(source, all, message)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
179
        return 0
180
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
181
182
# The following classes are only used as subcommands for 'shelf', they're
183
# not to be registered directly with bzr.
184
185
class cmd_shelf_list(bzrlib.commands.Command):
186
    """List the patches on the current shelf."""
187
    aliases = ['list', 'ls']
188
    def run(self):
189
        self.shelf.list()
190
191
192
class cmd_shelf_delete(bzrlib.commands.Command):
193
    """Delete the patch from the current shelf."""
194
    aliases = ['delete', 'del']
195
    takes_args = ['patch']
196
    def run(self, patch):
197
        self.shelf.delete(patch)
198
199
200
class cmd_shelf_switch(bzrlib.commands.Command):
201
    """Switch to the other shelf, create it if necessary."""
202
    aliases = ['switch']
0.1.117 by Michael Ellerman
Arg names with hyphens don't seem to work (broke shelf switch).
203
    takes_args = ['othershelf']
204
    def run(self, othershelf):
205
        s = Shelf(self.shelf.base, othershelf)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
206
        s.make_default()
207
208
209
class cmd_shelf_show(bzrlib.commands.Command):
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
210
    """Show the contents of the specified or topmost patch."""
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
211
    aliases = ['show', 'cat', 'display']
0.1.110 by Michael Ellerman
Make the patch argument to 'shelf show' optional.
212
    takes_args = ['patch?']
213
    def run(self, patch=None):
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
214
        self.shelf.display(patch)
215
216
217
class cmd_shelf_upgrade(bzrlib.commands.Command):
218
    """Upgrade old format shelves."""
219
    aliases = ['upgrade']
220
    def run(self):
221
        self.shelf.upgrade()
222
223
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
224
class cmd_shelf(bzrlib.commands.Command):
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
225
    """Perform various operations on your shelved patches. See also shelve."""
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
226
    takes_args = ['subcommand', 'args*']
227
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
228
    subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
229
        cmd_shelf_show, cmd_shelf_upgrade]
230
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
231
    def run(self, subcommand, args_list):
232
        import sys
233
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
234
        cmd = self._get_cmd_object(subcommand)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
235
        source = BzrPatchSource()
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
236
        s = Shelf(source.base)
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
237
        cmd.shelf = s
238
        return cmd.run_argv_aliases(args_list)
239
240
    def _get_cmd_object(self, cmd_name):
241
        for cmd_class in self.subcommands:
242
            for alias in cmd_class.aliases:
243
                if alias == cmd_name:
244
                    return cmd_class()
245
        raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
246
247
    def help(self):
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
248
        text = ["%s\n\nSubcommands:\n" % self.__doc__]
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
249
250
        for cmd_class in self.subcommands:
0.1.111 by Michael Ellerman
Make help for subcommands more readable, print options in help also.
251
            text.extend(self.sub_help(cmd_class) + ['\n'])
252
253
        return ''.join(text)
254
255
    def sub_help(self, cmd_class):
256
        text = []
257
        cmd_obj = cmd_class()
258
        indent = 2 * ' '
259
260
        usage = command_usage(cmd_obj)
261
        usage = usage.replace('bzr shelf-', '')
262
        text.append('%s%s\n' % (indent, usage))
263
264
        text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
265
266
        # Somewhat copied from bzrlib.help.help_on_command_options
267
        option_help = []
268
        for option_name, option in sorted(cmd_obj.options().items()):
269
            if option_name == 'help':
270
                continue
271
            option_help.append('%s--%s' % (3 * indent, option_name))
272
            if option.type is not None:
273
                option_help.append(' %s' % option.argname.upper())
274
            if option.short_name():
275
                option_help.append(', -%s' % option.short_name())
276
            option_help.append('%s%s\n' % (2 * indent, option.help))
277
278
        if len(option_help) > 0:
279
            text.append('%soptions:\n' % (2 * indent))
280
            text.extend(option_help)
281
282
        return text
0.1.109 by Michael Ellerman
Hijack the bzr command infrastructure to do subcommands for 'shelf'.
283
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
284
246 by Aaron Bentley
Merged shelf_v2
285
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
286
class cmd_unshelve(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
287
    """Restore shelved changes.
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
288
289
    By default the most recently shelved changes are restored. However if you
290
    specify a patch by name those changes will be restored instead.
291
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
292
    See 'shelve' for more information.
293
    """
0.1.91 by Michael Ellerman
Add --force option to unshelve, which runs the shelved changes through
294
    takes_options = [
295
            Option('all', help='Unshelve all changes without prompting'),
296
            Option('force', help='Force unshelving even if errors occur'),
297
    ]
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
298
    takes_args = ['patch?']
299
    def run(self, patch=None, all=False, force=False):
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
300
        source = BzrPatchSource()
0.1.74 by Michael Ellerman
Adapt to BzrDir changes and deprecation of show_diff().
301
        s = Shelf(source.base)
0.1.113 by Michael Ellerman
Support for unshelving in arbitrary order.
302
        s.unshelve(source, patch, all, force)
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
303
        return 0
304
0.1.22 by Michael Ellerman
Add __init__.py, put cmd_shelve/unshelve in there.
305
249 by Aaron Bentley
Got the shell basics working properly
306
class cmd_shell(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
307
    """Begin an interactive shell tailored for bzr.
287 by Aaron Bentley
Added shell docstring
308
    Bzr commands can be used without typing bzr first, and will be run natively
309
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
310
    the branch nick, revno, and path.
311
312
    If it encounters any moderately complicated shell command, it will punt to
313
    the system shell.
314
315
    Example:
316
    $ bzr shell
317
    bzr bzrtools:287/> status
318
    modified:
319
      __init__.py
320
    bzr bzrtools:287/> status --[TAB][TAB]
321
    --all        --help       --revision   --show-ids
322
    bzr bzrtools:287/> status --
323
    """
249 by Aaron Bentley
Got the shell basics working properly
324
    def run(self):
325
        import shell
281 by Aaron Bentley
Handled whitespace branch names better
326
        return shell.run_shell()
246 by Aaron Bentley
Merged shelf_v2
327
292 by Aaron Bentley
Introduced branch-history command
328
class cmd_branch_history(bzrlib.commands.Command):
329
    """\
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
330
    Display the development history of a branch.
292 by Aaron Bentley
Introduced branch-history command
331
293 by Aaron Bentley
Updated help
332
    Each different committer or branch nick is considered a different line of
333
    development.  Committers are treated as the same if they have the same
334
    name, or if they have the same email address.
292 by Aaron Bentley
Introduced branch-history command
335
    """
336
    takes_args = ["branch?"]
337
    def run(self, branch=None):
338
        from branchhistory import branch_history 
339
        return branch_history(branch)
340
345 by Aaron Bentley
Added zap command
341
342
class cmd_zap(bzrlib.commands.Command):
343
    """\
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
344
    Remove a lightweight checkout, if it can be done safely.
411 by Aaron Bentley
Update zap documentation
345
346
    This command will remove a lightweight checkout without losing data.  That
347
    means it only removes lightweight checkouts, and only if they have no
348
    uncommitted changes.
349
350
    If --branch is specified, the branch will be deleted too, but only if the
351
    the branch has no new commits (relative to its parent).
345 by Aaron Bentley
Added zap command
352
    """
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
353
    takes_options = [Option("branch", help="Remove associtated branch from"
354
                                           " repository")]
345 by Aaron Bentley
Added zap command
355
    takes_args = ["checkout"]
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
356
    def run(self, checkout, branch=False):
345 by Aaron Bentley
Added zap command
357
        from zap import zap
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
358
        return zap(checkout, remove_branch=branch)
345 by Aaron Bentley
Added zap command
359
360
349 by Aaron Bentley
Added cbranch command
361
class cmd_cbranch(bzrlib.commands.Command):
362
    """
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
363
    Create a new checkout, associated with a new repository branch.
349 by Aaron Bentley
Added cbranch command
364
    
365
    When you cbranch, bzr looks up the repository associated with your current
366
    directory in branches.conf.  It creates a new branch in that repository
367
    with the same name and relative path as the checkout you request.
351 by Aaron Bentley
Improved cbranch docs
368
369
    The branches.conf parameter is "cbranch_root".  So if you want 
370
    cbranch operations in /home/jrandom/bigproject to produce branches in 
371
    /home/jrandom/bigproject/repository, you'd add this:
372
373
    [/home/jrandom/bigproject]
374
    cbranch_root = /home/jrandom/bigproject/repository
375
376
    Note that if "/home/jrandom/bigproject/repository" isn't a repository,
377
    standalone branches will be produced.  Standalone branches will also
378
    be produced if the source branch is in 0.7 format (or earlier).
349 by Aaron Bentley
Added cbranch command
379
    """
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
380
    takes_options = [Option("lightweight", 
418 by Aaron Bentley
Cbranch takes a revision option
381
                            help="Create a lightweight checkout"), 'revision']
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
382
    takes_args = ["source", "target?"]
418 by Aaron Bentley
Cbranch takes a revision option
383
    def run(self, source, target=None, lightweight=False, revision=None):
349 by Aaron Bentley
Added cbranch command
384
        from cbranch import cbranch
418 by Aaron Bentley
Cbranch takes a revision option
385
        return cbranch(source, target, lightweight=lightweight, 
386
                       revision=revision)
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
387
349 by Aaron Bentley
Added cbranch command
388
352 by Aaron Bentley
Added branches subcommand
389
class cmd_branches(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
390
    """Scan a location for branches"""
352 by Aaron Bentley
Added branches subcommand
391
    takes_args = ["location?"]
392
    def run(self, location=None):
393
        from branches import branches
394
        return branches(location)
395
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
396
397
class cmd_multi_pull(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
398
    """Pull all the branches under a location, e.g. a repository.
353 by Aaron Bentley
Added multi-pull, working on branches and checkouts
399
    
400
    Both branches present in the directory and the branches of checkouts are
401
    pulled.
402
    """
403
    takes_args = ["location?"]
404
    def run(self, location=None):
405
        from bzrlib.branch import Branch
406
        from bzrlib.transport import get_transport
407
        from bzrtools import iter_branch_tree
408
        if location is None:
409
            location = '.'
410
        t = get_transport(location)
411
        if not t.listable():
412
            print "Can't list this type of location."
413
            return 3
414
        for branch, wt in iter_branch_tree(t):
415
            if wt is None:
416
                pullable = branch
417
            else:
418
                pullable = wt
419
            parent = branch.get_parent()
420
            if parent is None:
421
                continue
422
            if wt is not None:
423
                base = wt.basedir
424
            else:
425
                base = branch.base
426
            if base.startswith(t.base):
427
                relpath = base[len(t.base):].rstrip('/')
428
            else:
429
                relpath = base
430
            print "Pulling %s from %s" % (relpath, parent)
431
            try:
432
                pullable.pull(Branch.open(parent))
433
            except Exception, e:
434
                print e
435
436
360.1.3 by Aaron Bentley
Add experimental branch-mark command
437
class cmd_branch_mark(bzrlib.commands.Command):
438
    """
439
    Add, view or list branch markers <EXPERIMENTAL>
440
441
    To add a mark, do 'bzr branch-mark MARK'.
442
    To list marks, do 'bzr branch-mark' (this lists all marks for the branch's
443
    repository).
444
    To delete a mark, do 'bzr branch-mark --delete MARK'
445
446
    These marks can be used to track a branch's status.
447
    """
448
    takes_args = ['mark?', 'branch?']
449
    takes_options = [Option('delete', help='Delete this mark')]
450
    def run(self, mark=None, branch=None, delete=False):
451
        from branch_mark import branch_mark
452
        branch_mark(mark, branch, delete)
453
377 by Aaron Bentley
Got import command working
454
class cmd_import(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
455
    """Import sources from a tarball
380 by Aaron Bentley
Got import working decently
456
    
457
    This command will import a tarball into a bzr tree, replacing any versioned
458
    files already present.  If a directory is specified, it is used as the
459
    target.  If the directory does not exist, or is not versioned, it is
460
    created.
461
462
    Tarballs may be gzip or bzip2 compressed.  This is autodetected.
463
464
    If the tarball has a single root directory, that directory is stripped
465
    when extracting the tarball.
466
    """
467
    
468
    takes_args = ['source', 'tree?']
469
    def run(self, source, tree=None):
377 by Aaron Bentley
Got import command working
470
        from upstream_import import do_import
380 by Aaron Bentley
Got import working decently
471
        do_import(source, tree)
377 by Aaron Bentley
Got import command working
472
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
473
class cmd_shove(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
474
    """Apply uncommitted changes to another tree
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
475
    
476
    This is useful when you start to make changes in one tree, then realize
477
    they should really be done in a different tree.
478
479
    Shove is implemented using merge, so:
480
     - All changes, including renames and adds, will be applied.
481
     - No changes that have already been applied will be applied.
482
     - If the target is significantly different from the source, conflicts may
483
       be produced.
484
    """
485
408 by Aaron Bentley
Revert shove to previous argument order
486
    takes_args = ['target', 'source?']
392.1.1 by Aaron Bentley
Implement 'shove' for moving changes to other trees
487
    def run(self, target, source='.'):
488
        from shove import do_shove
489
        do_shove(source, target)
490
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
491
class cmd_cdiff(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
492
    """A color version of bzr's diff"""
410 by Aaron Bentley
Ensure the option settings come from the right 'diff' in colordiff
493
    takes_args = property(lambda x: get_cmd_object('diff').takes_args)
494
    takes_options = property(lambda x: get_cmd_object('diff').takes_options)
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
495
    def run(*args, **kwargs):
496
        from colordiff import colordiff
497
        colordiff(*args, **kwargs)
360.1.3 by Aaron Bentley
Add experimental branch-mark command
498
391 by Aaron Bentley
Updates from the bzr clean-tree branch
499
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
500
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
501
            cmd_branch_history, cmd_zap, cmd_cbranch, cmd_branches, 
399 by Aaron Bentley
Implement cdiff (based on old Fai code)
502
            cmd_multi_pull, cmd_switch, cmd_branch_mark, cmd_import, cmd_shove,
503
            cmd_cdiff]
504
505
364.1.4 by Aaron Bentley
Changed rpush to rspush
506
commands.append(rspush.cmd_rspush)
246 by Aaron Bentley
Merged shelf_v2
507
508
from errors import NoPyBaz
509
try:
510
    import baz_import
147.1.41 by Aaron Bentley
Merge from mainline
511
    commands.append(baz_import.cmd_baz_import_branch)
246 by Aaron Bentley
Merged shelf_v2
512
    commands.append(baz_import.cmd_baz_import)
513
514
except NoPyBaz:
147.1.72 by Aaron Bentley
Handle missing pybaz properly
515
    class cmd_baz_import_branch(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
516
        """Disabled. (Requires PyBaz)"""
147.1.72 by Aaron Bentley
Handle missing pybaz properly
517
        takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
518
        takes_options = ['verbose', Option('max-count', type=int)]
519
        def run(self, to_location=None, from_branch=None, fast=False, 
520
                max_count=None, verbose=False, dry_run=False,
521
                reuse_history_list=[]):
522
            print "This command is disabled.  Please install PyBaz."
523
524
246 by Aaron Bentley
Merged shelf_v2
525
    class cmd_baz_import(bzrlib.commands.Command):
415 by Aaron Bentley
Remove <BZRTOOLS> tag from command descriptions
526
        """Disabled. (Requires PyBaz)"""
147.1.72 by Aaron Bentley
Handle missing pybaz properly
527
        takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
528
        takes_options = ['verbose', Option('prefixes', type=str,
529
                         help="Prefixes of branches to import")]
530
        def run(self, to_root_dir=None, from_archive=None, verbose=False,
531
                reuse_history_list=[], prefixes=None):
532
                print "This command is disabled.  Please install PyBaz."
533
    commands.extend((cmd_baz_import_branch, cmd_baz_import))
246 by Aaron Bentley
Merged shelf_v2
534
271 by Aaron Bentley
Cherry-picked Robert's diff and push fixes
535
246 by Aaron Bentley
Merged shelf_v2
536
if hasattr(bzrlib.commands, 'register_command'):
537
    for command in commands:
538
        bzrlib.commands.register_command(command)
271 by Aaron Bentley
Cherry-picked Robert's diff and push fixes
539
0.1.73 by Michael Ellerman
Merge most of the standalone shelf branch. This brings in a few changes which
540
541
def test_suite():
542
    from bzrlib.tests.TestUtil import TestLoader
147.1.41 by Aaron Bentley
Merge from mainline
543
    import tests
321.1.3 by Aaron Bentley
Fixed up Robert's test changes
544
    from doctest import DocTestSuite, ELLIPSIS
325.1.2 by Aaron Bentley
Merge shelf v2
545
    from unittest import TestSuite
391 by Aaron Bentley
Updates from the bzr clean-tree branch
546
    import tests.clean_tree
374 by Aaron Bentley
Start work on import plugin
547
    import upstream_import
345 by Aaron Bentley
Added zap command
548
    import zap
339 by Aaron Bentley
Moved tests into a subdir
549
    import tests.blackbox
550
    import tests.shelf_tests
246 by Aaron Bentley
Merged shelf_v2
551
    result = TestSuite()
321.1.3 by Aaron Bentley
Fixed up Robert's test changes
552
    result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
391 by Aaron Bentley
Updates from the bzr clean-tree branch
553
    result.addTest(tests.clean_tree.test_suite())
387 by Aaron Bentley
Got test suite running with PyBaz unavailable
554
    try:
555
        import baz_import
556
        result.addTest(DocTestSuite(baz_import))
557
    except NoPyBaz:
558
        pass
147.1.41 by Aaron Bentley
Merge from mainline
559
    result.addTest(tests.test_suite())
339 by Aaron Bentley
Moved tests into a subdir
560
    result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
561
    result.addTest(tests.blackbox.test_suite())
374 by Aaron Bentley
Start work on import plugin
562
    result.addTest(upstream_import.test_suite())
345 by Aaron Bentley
Added zap command
563
    result.addTest(zap.test_suite())
246 by Aaron Bentley
Merged shelf_v2
564
    return result