29
25
class cmd_clean_tree(bzrlib.commands.Command):
30
"""Remove unwanted files from working tree.
32
By default, only unknown files, not ignored files, are deleted. Versioned
33
files are never deleted.
35
Another class is 'detritus', which includes files emitted by bzr during
36
normal operations and selftests. (The value of these files decreases with
39
If no options are specified, unknown files are deleted. Otherwise, option
40
flags are respected, and may be combined.
42
To check what clean-tree will do, use --dry-run.
26
"""Remove unwanted files from working tree. <BZRTOOLS>
27
Normally, ignored files are left alone.
44
29
takes_options = [Option('ignored', help='delete all ignored files.'),
45
Option('detritus', help='delete conflict files, merge'
46
' backups, and failed selftest dirs.'),
48
help='delete files unknown to bzr. (default)'),
30
Option('detritus', help='delete conflict files merge'
31
' backups, and failed selftest dirs. (*.THIS, '
32
'*.BASE, *.OTHER, *~, *.tmp)'),
49
33
Option('dry-run', help='show files to delete instead of'
50
34
' deleting them.')]
51
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
35
def run(self, ignored=False, detritus=False, dry_run=False):
52
36
from clean_tree import clean_tree
53
if not (unknown or ignored or detritus):
55
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
37
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
58
39
class cmd_graph_ancestry(bzrlib.commands.Command):
59
"""Produce ancestry graphs using dot.
40
"""Produce ancestry graphs using dot. <BZRTOOLS>
61
42
Output format is detected according to file extension. Some of the more
62
43
common output formats are html, png, gif, svg, ps. An extension of '.dot'
181
159
s.shelve(source, all, message)
185
# The following classes are only used as subcommands for 'shelf', they're
186
# not to be registered directly with bzr.
188
class cmd_shelf_list(bzrlib.commands.Command):
189
"""List the patches on the current shelf."""
190
aliases = ['list', 'ls']
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)
203
class cmd_shelf_switch(bzrlib.commands.Command):
204
"""Switch to the other shelf, create it if necessary."""
206
takes_args = ['othershelf']
207
def run(self, othershelf):
208
s = Shelf(self.shelf.base, othershelf)
212
class cmd_shelf_show(bzrlib.commands.Command):
213
"""Show the contents of the specified or topmost patch."""
214
aliases = ['show', 'cat', 'display']
215
takes_args = ['patch?']
216
def run(self, patch=None):
217
self.shelf.display(patch)
220
class cmd_shelf_upgrade(bzrlib.commands.Command):
221
"""Upgrade old format shelves."""
222
aliases = ['upgrade']
227
162
class cmd_shelf(bzrlib.commands.Command):
228
"""Perform various operations on your shelved patches. See also shelve."""
163
"""Perform various operations on your shelved patches. See also shelve.
166
list (ls) List the patches on the current shelf.
167
delete (del) <patch> Delete a patch from the current shelf.
168
switch <shelf> Switch to the named shelf, create it if necessary.
169
show <patch> Show the contents of the specified patch.
170
upgrade Upgrade old format shelves.
229
172
takes_args = ['subcommand', 'args*']
231
subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
232
cmd_shelf_show, cmd_shelf_upgrade]
234
174
def run(self, subcommand, args_list):
237
cmd = self._get_cmd_object(subcommand)
238
177
source = BzrPatchSource()
239
178
s = Shelf(source.base)
241
return cmd.run_argv_aliases(args_list)
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:
248
raise CommandError("Unknown shelf subcommand '%s'" % cmd_name)
251
text = ["%s\n\nSubcommands:\n" % self.__doc__]
253
for cmd_class in self.subcommands:
254
text.extend(self.sub_help(cmd_class) + ['\n'])
258
def sub_help(self, cmd_class):
260
cmd_obj = cmd_class()
263
usage = command_usage(cmd_obj)
264
usage = usage.replace('bzr shelf-', '')
265
text.append('%s%s\n' % (indent, usage))
267
text.append('%s%s\n' % (2 * indent, cmd_class.__doc__))
269
# Somewhat copied from bzrlib.help.help_on_command_options
271
for option_name, option in sorted(cmd_obj.options().items()):
272
if option_name == 'help':
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))
281
if len(option_help) > 0:
282
text.append('%soptions:\n' % (2 * indent))
283
text.extend(option_help)
180
if subcommand == 'ls' or subcommand == 'list':
181
self.__check_no_args(args_list, "shelf list takes no arguments!")
183
elif subcommand == 'delete' or subcommand == 'del':
184
self.__check_one_arg(args_list, "shelf delete takes one argument!")
185
s.delete(args_list[0])
186
elif subcommand == 'switch':
187
self.__check_one_arg(args_list, "shelf switch takes one argument!")
188
s = Shelf(source.base, args_list[0])
190
elif subcommand == 'show':
191
self.__check_one_arg(args_list, "shelf show takes one argument!")
192
s.display(args_list[0])
193
elif subcommand == 'upgrade':
194
self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
197
raise CommandError("Unknown shelf subcommand '%s'" % subcommand)
199
def __check_one_arg(self, args, msg):
200
if args is None or len(args) != 1:
201
raise CommandError(msg)
203
def __check_no_args(self, args, msg):
205
raise CommandError(msg)
289
208
class cmd_unshelve(bzrlib.commands.Command):
290
"""Restore shelved changes.
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.
209
"""Restore the most recently shelved changes to current tree. <BZRTOOLS>
295
210
See 'shelve' for more information.
297
212
takes_options = [
298
213
Option('all', help='Unshelve all changes without prompting'),
299
214
Option('force', help='Force unshelving even if errors occur'),
301
takes_args = ['patch?']
302
def run(self, patch=None, all=False, force=False):
216
def run(self, all=False, force=False):
303
217
source = BzrPatchSource()
304
218
s = Shelf(source.base)
305
s.unshelve(source, patch, all, force)
219
s.unshelve(source, all, force)
309
223
class cmd_shell(bzrlib.commands.Command):
310
"""Begin an interactive shell tailored for bzr.
224
"""Begin an interactive shell tailored for bzr. <BZRTOOLS>
311
225
Bzr commands can be used without typing bzr first, and will be run natively
312
226
when possible. Tab completion is tailored for bzr. The shell prompt shows
313
227
the branch nick, revno, and path.
381
291
be produced if the source branch is in 0.7 format (or earlier).
383
293
takes_options = [Option("lightweight",
384
help="Create a lightweight checkout"), 'revision']
294
help="Create a lightweight checkout")]
385
295
takes_args = ["source", "target?"]
386
def run(self, source, target=None, lightweight=False, revision=None):
296
def run(self, source, target=None, lightweight=False):
387
297
from cbranch import cbranch
388
return cbranch(source, target, lightweight=lightweight,
298
return cbranch(source, target, lightweight=lightweight)
392
301
class cmd_branches(bzrlib.commands.Command):
393
"""Scan a location for branches"""
302
"""Scan a location for branches <BZRTOOLS>"""
394
303
takes_args = ["location?"]
395
304
def run(self, location=None):
396
305
from branches import branches
491
400
from shove import do_shove
492
401
do_shove(source, target)
494
class cmd_cdiff(bzrlib.commands.Command):
495
"""A color version of bzr's diff"""
496
takes_args = property(lambda x: get_cmd_object('diff').takes_args)
497
takes_options = property(lambda x: get_cmd_object('diff').takes_options)
498
def run(*args, **kwargs):
499
from colordiff import colordiff
500
colordiff(*args, **kwargs)
502
404
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
503
405
cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
504
406
cmd_branch_history, cmd_zap, cmd_cbranch, cmd_branches,
505
cmd_multi_pull, cmd_switch, cmd_branch_mark, cmd_import, cmd_shove,
407
cmd_multi_pull, cmd_switch, cmd_branch_mark, cmd_import, cmd_shove]
410
import bzrlib.builtins
509
411
commands.append(rspush.cmd_rspush)
511
413
from errors import NoPyBaz