1
# Copyright (C) 2005, 2006, 2007, 2011 Aaron Bentley <aaron@aaronbentley.com>
2
# Copyright (C) 2005, 2006, 2011 Canonical Limited.
1
# Copyright (C) 2005, 2006, 2007 Aaron Bentley <aaron@aaronbentley.com>
2
# Copyright (C) 2005, 2006 Canonical Limited.
3
3
# Copyright (C) 2006 Michael Ellerman.
5
5
# This program is free software; you can redistribute it and/or modify
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
from bzrlib import help, urlutils
24
from bzrlib.plugins.bzrtools import shelf
27
from bzrlib.plugins import bzrtools
28
27
from command import BzrToolsCommand
29
28
from errors import CommandError
30
29
from patchsource import BzrPatchSource
33
import bzrlib.builtins
32
34
import bzrlib.commands
33
35
from bzrlib.branch import Branch
36
from bzrlib.bzrdir import BzrDir
34
37
from bzrlib.commands import get_cmd_object
35
38
from bzrlib.errors import BzrCommandError
36
from bzrlib.option import Option, RegistryOption
40
from bzrlib.trace import note
41
from bzrlib.option import Option
43
from command import BzrToolsCommand
46
class cmd_clean_tree(BzrToolsCommand):
47
"""Remove unwanted files from working tree.
49
By default, only unknown files, not ignored files, are deleted. Versioned
50
files are never deleted.
52
Another class is 'detritus', which includes files emitted by bzr during
53
normal operations and selftests. (The value of these files decreases with
56
If no options are specified, unknown files are deleted. Otherwise, option
57
flags are respected, and may be combined.
59
To check what clean-tree will do, use --dry-run.
61
takes_options = [Option('ignored', help='Delete all ignored files.'),
62
Option('detritus', help='Delete conflict files, merge'
63
' backups, and failed selftest dirs.'),
65
help='Delete files unknown to bzr (default).'),
66
Option('dry-run', help='Show files to delete instead of'
68
Option('force', help='Do not prompt before deleting.')]
69
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
71
from clean_tree import clean_tree
72
if not (unknown or ignored or detritus):
76
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
77
dry_run=dry_run, no_prompt=force)
39
80
class cmd_graph_ancestry(BzrToolsCommand):
40
81
"""Produce ancestry graphs using dot.
42
83
Output format is detected according to file extension. Some of the more
43
84
common output formats are html, png, gif, svg, ps. An extension of '.dot'
44
85
will cause a dot graph file to be produced. HTML output has mouseovers
110
151
takes_options = [Option('no-fix', help="Skip additional synchonization.")]
111
152
def run(self, branch=None, no_fix=False):
112
153
from fetch_ghosts import fetch_ghosts
113
fetch_ghosts(branch, do_reconcile=not no_fix)
154
fetch_ghosts(branch, no_fix)
115
156
strip_help="""Strip the smallest prefix containing num leading slashes from \
116
157
each file name found in the patch file."""
120
161
"""Apply a named patch to the current tree.
122
163
takes_args = ['filename?']
123
takes_options = [Option('strip', type=int, short_name='p',
164
takes_options = [Option('strip', type=int, help=strip_help),
125
165
Option('silent', help='Suppress chatter.')]
126
166
def run(self, filename=None, strip=None, silent=False):
127
167
from patch import patch
332
374
--all --help --revision --show-ids
333
375
bzr bzrtools:287/> status --
337
help='Branch in which to start the shell, '
338
'rather than the one containing the working directory.',
343
def run(self, directory=None):
345
return shell.run_shell(directory)
379
return shell.run_shell()
348
382
class cmd_branch_history(BzrToolsCommand):
370
404
If --branch is specified, the branch will be deleted too, but only if the
371
405
the branch has no new commits (relative to its parent).
373
If bzr-pipeline is also installed, the --store option will store changes
374
in the branch before deleting the tree. To restore the changes, do::
376
bzr checkout --lightweight $BRANCH $CHECKOUT
377
bzr switch-pipe -d $CHECKOUT `bzr nick -d $CHECKOUT`
379
407
takes_options = [Option("branch", help="Remove associated branch from"
381
RegistryOption('change_policy',
382
'How to handle changed files',
384
('bzrlib.plugins.bzrtools.zap',
385
'change_policy_registry'),
409
Option('force', help='Delete tree even if contents are'
388
411
takes_args = ["checkout"]
389
def run(self, checkout, branch=False, change_policy=None):
391
change_policy_registry,
395
if change_policy is None:
396
change_policy = change_policy_registry.get()
397
if change_policy is StoreChanges:
399
import bzrlib.plugins.pipeline
401
raise BzrCommandError('--store requires bzr-pipeline.')
402
return zap(checkout, remove_branch=branch, policy=change_policy)
412
def run(self, checkout, branch=False, force=False):
414
return zap(checkout, remove_branch=branch, allow_modified=force)
405
417
class cmd_cbranch(BzrToolsCommand):
438
450
hardlink=hardlink)
441
class cmd_list_branches(BzrToolsCommand):
453
class cmd_branches(BzrToolsCommand):
442
454
"""Scan a location for branches"""
445
from bzrlib import commands
446
return commands.plugin_cmds.get_info('list-branches').aliases
448
455
takes_args = ["location?"]
449
456
def run(self, location=None):
450
457
from branches import branches
527
534
"""A color version of bzr's diff"""
528
535
takes_args = property(lambda x: get_cmd_object('diff').takes_args)
529
536
takes_options = list(get_cmd_object('diff').takes_options) + [
530
RegistryOption.from_kwargs('color',
531
'Color mode to use.',
532
title='Color Mode', value_switches=False, enum_switch=True,
533
never='Never colorize output.',
534
auto='Only colorize output if terminal supports it and STDOUT is a'
536
always='Always colorize output (default).'),
537
537
Option('check-style',
538
538
help='Warn if trailing whitespace or spurious changes have been'
541
def run(self, color='always', check_style=False, *args, **kwargs):
541
def run(self, check_style=False, *args, **kwargs):
542
542
from colordiff import colordiff
543
colordiff(color, check_style, *args, **kwargs)
546
class cmd_conflict_diff(BzrToolsCommand):
548
"""Compare a conflicted file against BASE."""
550
encoding_type = 'exact'
551
takes_args = ['file*']
553
RegistryOption.from_kwargs('direction', 'Direction of comparison.',
554
value_switches=True, enum_switch=False,
555
other='Compare OTHER against common base.',
556
this='Compare THIS against common base.')]
558
def run(self, file_list, direction='other'):
559
from bzrlib.plugins.bzrtools.colordiff import DiffWriter
560
from conflict_diff import ConflictDiffer
561
dw = DiffWriter(self.outf, check_style=False, color='auto')
562
ConflictDiffer().run(dw, file_list, direction)
543
colordiff(check_style, *args, **kwargs)
565
546
class cmd_rspush(BzrToolsCommand):
605
586
source_tree.unlock()
607
588
target_tree.unlock()
610
class cmd_create_mirror(BzrToolsCommand):
611
"""Create a mirror of another branch.
613
This is similar to `bzr branch`, but copies more settings, including the
614
submit branch and nickname.
616
It sets the public branch and parent of the target to the source location.
619
takes_args = ['source', 'target']
621
def run(self, source, target):
622
source_branch = Branch.open(source)
623
from bzrlib.plugins.bzrtools.mirror import create_mirror
624
create_mirror(source_branch, target, [])