~abentley/bzrtools/bzrtools.dev

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