16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
Various useful plugins for working with bzr.
43
40
from bzrlib.errors import BzrCommandError
44
41
import bzrlib.ignores
45
42
from bzrlib.trace import note
46
from bzrlib.option import Option
47
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
43
from bzrlib.option import Option, RegistryOption
44
from bzrlib.workingtree import WorkingTree
51
46
from command import BzrToolsCommand
53
bzrlib.ignores.add_runtime_ignores(['./.shelf'])
56
class cmd_clean_tree(BzrToolsCommand):
57
"""Remove unwanted files from working tree.
59
By default, only unknown files, not ignored files, are deleted. Versioned
60
files are never deleted.
62
Another class is 'detritus', which includes files emitted by bzr during
63
normal operations and selftests. (The value of these files decreases with
66
If no options are specified, unknown files are deleted. Otherwise, option
67
flags are respected, and may be combined.
69
To check what clean-tree will do, use --dry-run.
71
takes_options = [Option('ignored', help='Delete all ignored files.'),
72
Option('detritus', help='Delete conflict files, merge'
73
' backups, and failed selftest dirs.'),
75
help='Delete files unknown to bzr (default).'),
76
Option('dry-run', help='Show files to delete instead of'
78
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False):
79
from clean_tree import clean_tree
80
if not (unknown or ignored or detritus):
82
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
86
49
class cmd_graph_ancestry(BzrToolsCommand):
87
50
"""Produce ancestry graphs using dot.
89
52
Output format is detected according to file extension. Some of the more
90
53
common output formats are html, png, gif, svg, ps. An extension of '.dot'
91
54
will cause a dot graph file to be produced. HTML output has mouseovers
157
120
takes_options = [Option('no-fix', help="Skip additional synchonization.")]
158
121
def run(self, branch=None, no_fix=False):
159
122
from fetch_ghosts import fetch_ghosts
160
fetch_ghosts(branch, no_fix)
123
fetch_ghosts(branch, do_reconcile=not no_fix)
162
125
strip_help="""Strip the smallest prefix containing num leading slashes from \
163
126
each file name found in the patch file."""
167
130
"""Apply a named patch to the current tree.
169
132
takes_args = ['filename?']
170
takes_options = [Option('strip', type=int, help=strip_help),
133
takes_options = [Option('strip', type=int, short_name='p',
171
135
Option('silent', help='Suppress chatter.')]
172
136
def run(self, filename=None, strip=None, silent=False):
173
137
from patch import patch
178
142
return patch(wt, filename, strip, silent)
181
class cmd_shelve(BzrToolsCommand):
145
class cmd_shelve1(BzrToolsCommand):
182
146
"""Temporarily set aside some changes from the current tree.
184
148
Shelve allows you to temporarily put changes you've made "on the shelf",
185
149
ie. out of the way, until a later time when you can bring them back from
186
the shelf with the 'unshelve' command.
150
the shelf with the 'unshelve1' command.
188
152
Shelve is intended to help separate several sets of text changes that have
189
153
been inappropriately mingled. If you just want to get rid of all changes
190
154
(text and otherwise) and you don't need to restore them later, use revert.
191
If you want to shelve all text changes at once, use shelve --all.
155
If you want to shelve all text changes at once, use shelve1 --all.
193
By default shelve asks you what you want to shelve, press '?' at the
194
prompt to get help. To shelve everything run shelve --all.
157
By default shelve1 asks you what you want to shelve, press '?' at the
158
prompt to get help. To shelve everything run shelve1 --all.
196
160
If filenames are specified, only the changes to those files will be
197
161
shelved, other files will be left untouched.
199
163
If a revision is specified, changes since that revision will be shelved.
201
165
You can put multiple items on the shelf. Normally each time you run
202
unshelve the most recently shelved changes will be reinstated. However,
166
unshelve1 the most recently shelved changes will be reinstated. However,
203
167
you can also unshelve changes in a different order by explicitly
204
specifiying which changes to unshelve. This works best when the changes
168
specifiying which changes to unshelve1. This works best when the changes
205
169
don't depend on each other.
207
171
While you have patches on the shelf you can view and manipulate them with
208
the 'shelf' command. Run 'bzr shelf -h' for more info.
172
the 'shelf1' command. Run 'bzr shelf1 -h' for more info.
211
175
takes_args = ['file*']
273
237
self.shelf.upgrade()
276
class cmd_shelf(BzrToolsCommand):
277
"""Perform various operations on your shelved patches. See also shelve."""
240
class cmd_shelf1(BzrToolsCommand):
241
"""Perform various operations on your shelved patches. See also shelve1."""
278
242
takes_args = ['subcommand', 'args*']
280
244
subcommands = [cmd_shelf_list, cmd_shelf_delete, cmd_shelf_switch,
342
class cmd_unshelve(BzrToolsCommand):
306
class cmd_unshelve1(BzrToolsCommand):
343
307
"""Restore shelved changes.
345
309
By default the most recently shelved changes are restored. However if you
346
310
specify a patch by name those changes will be restored instead.
348
See 'shelve' for more information.
312
See 'shelve1' for more information.
350
314
takes_options = [
351
315
Option('all', help='Unshelve all changes without prompting.'),
378
342
--all --help --revision --show-ids
379
343
bzr bzrtools:287/> status --
347
help='Branch in which to start the shell, '
348
'rather than the one containing the working directory.',
353
def run(self, directory=None):
383
return shell.run_shell()
355
return shell.run_shell(directory)
386
358
class cmd_branch_history(BzrToolsCommand):
538
510
"""A color version of bzr's diff"""
539
511
takes_args = property(lambda x: get_cmd_object('diff').takes_args)
540
512
takes_options = list(get_cmd_object('diff').takes_options) + [
513
RegistryOption.from_kwargs('color',
514
'Color mode to use.',
515
title='Color Mode', value_switches=False, enum_switch=True,
516
never='Never colorize output.',
517
auto='Only colorize output if terminal supports it and STDOUT is a'
519
always='Always colorize output (default).'),
541
520
Option('check-style',
542
521
help='Warn if trailing whitespace or spurious changes have been'
545
def run(self, check_style=False, *args, **kwargs):
524
def run(self, color='always', check_style=False, *args, **kwargs):
546
525
from colordiff import colordiff
547
colordiff(check_style, *args, **kwargs)
526
colordiff(color, check_style, *args, **kwargs)
529
class cmd_conflict_diff(BzrToolsCommand):
531
"""Compare a conflicted file against BASE."""
533
encoding_type = 'exact'
534
takes_args = ['file*']
536
RegistryOption.from_kwargs('direction', 'Direction of comparison.',
537
value_switches=True, enum_switch=False,
538
other='Compare OTHER against common base.',
539
this='Compare THIS against common base.')]
541
def run(self, file_list, direction='other'):
542
from bzrlib.plugins.bzrtools.colordiff import DiffWriter
543
from conflict_diff import ConflictDiffer
544
dw = DiffWriter(self.outf, check_style=False, color='auto')
545
ConflictDiffer().run(dw, file_list, direction)
550
548
class cmd_rspush(BzrToolsCommand):
592
590
target_tree.unlock()
594
from heads import cmd_heads
618
if hasattr(bzrlib.commands, 'register_command'):
619
for command in commands:
620
bzrlib.commands.register_command(command)
624
from bzrlib.tests.TestUtil import TestLoader
626
from doctest import DocTestSuite, ELLIPSIS
627
from unittest import TestSuite
629
import tests.clean_tree
630
import tests.test_dotgraph
631
import tests.is_clean
632
import tests.test_cbranch
633
import tests.test_link_tree
634
import tests.test_patch
635
import tests.test_rspush
636
import tests.upstream_import
638
import tests.blackbox
639
import tests.shelf_tests
641
result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
642
result.addTest(tests.clean_tree.test_suite())
643
result.addTest(tests.test_suite())
644
result.addTest(TestLoader().loadTestsFromModule(tests.shelf_tests))
645
result.addTest(tests.blackbox.test_suite())
646
result.addTest(tests.upstream_import.test_suite())
647
result.addTest(zap.test_suite())
648
result.addTest(TestLoader().loadTestsFromModule(tests.test_dotgraph))
649
result.addTest(TestLoader().loadTestsFromModule(tests.is_clean))
650
result.addTest(TestLoader().loadTestsFromModule(tests.test_link_tree))
651
result.addTest(TestLoader().loadTestsFromModule(tests.test_patch))
652
result.addTest(TestLoader().loadTestsFromModule(tests.test_rspush))
653
result.addTest(TestLoader().loadTestsFromModule(tests.test_cbranch))
593
class cmd_create_mirror(BzrToolsCommand):
594
"""Create a mirror of another branch.
596
This is similar to `bzr branch`, but copies more settings, including the
597
submit branch and nickname.
599
It sets the public branch and parent of the target to the source location.
602
takes_args = ['source', 'target']
604
def run(self, source, target):
605
source_branch = Branch.open(source)
606
from bzrlib.plugins.bzrtools.mirror import create_mirror
607
create_mirror(source_branch, target, [])