~abentley/bzrtools/bzrtools.dev

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