~abentley/bzrtools/bzrtools.dev

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