3
Various useful plugins for working with bzr.
8
from shelf import Shelf
11
from bzrlib.option import Option
13
from bzrlib.errors import BzrCommandError
14
from reweave_inventory import cmd_fix
15
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
18
Option.OPTIONS['ignored'] = Option('ignored',
19
help='delete all ignored files.')
20
Option.OPTIONS['detritus'] = Option('detritus',
21
help='delete conflict files merge backups, and failed selftest dirs.' +
22
'(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
23
Option.OPTIONS['dry-run'] = Option('dry-run',
24
help='show files to delete instead of deleting them.')
26
class cmd_clean_tree(bzrlib.commands.Command):
27
"""Remove unwanted files from working tree.
28
Normally, ignored files are left alone.
30
takes_options = ['ignored', 'detritus', 'dry-run']
31
def run(self, ignored=False, detritus=False, dry_run=False):
32
from clean_tree import clean_tree
33
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
35
Option.OPTIONS['no-collapse'] = Option('no-collapse')
36
Option.OPTIONS['no-antialias'] = Option('no-antialias')
37
Option.OPTIONS['cluster'] = Option('cluster')
38
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
40
class cmd_graph_ancestry(bzrlib.commands.Command):
41
"""Produce ancestry graphs using dot.
43
Output format is detected according to file extension. Some of the more
44
common output formats are png, gif, svg, ps. An extension of '.dot' will
45
cause a dot graph file to be produced.
47
Branches are labeled r?, where ? is the revno. If they have no revno,
48
with the last 5 characters of their revision identifier are used instead.
50
If --merge-branch is specified, the two branches are compared and a merge
58
blue COMMON non-history ancestor
59
dotted Missing from branch storage
61
Ancestry is usually collapsed by removing revisions with a single parent
62
and descendant. The number of skipped revisions is shown on the arrow.
63
This feature can be disabled with --no-collapse.
65
By default, revisions are ordered by distance from root, but they can be
66
clustered instead using --cluster.
68
If available, rsvg is used to antialias PNG and JPEG output, but this can
69
be disabled with --no-antialias.
71
takes_args = ['branch', 'file']
72
takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
73
def run(self, branch, file, no_collapse=False, no_antialias=False,
74
merge_branch=None, cluster=False):
80
graph.write_ancestry_file(branch, file, not no_collapse,
81
not no_antialias, merge_branch, ranking)
83
class cmd_fetch_ghosts(bzrlib.commands.Command):
84
"""Attempt to retrieve ghosts from another branch.
85
If the other branch is not supplied, the last-pulled branch is used.
87
aliases = ['fetch-missing']
88
takes_args = ['branch?']
89
takes_options = [Option('no-fix')]
90
def run(self, branch=None, no_fix=False):
91
from fetch_ghosts import fetch_ghosts
92
fetch_ghosts(branch, no_fix)
94
strip_help="""Strip the smallest prefix containing num leading slashes from \
95
each file name found in the patch file."""
96
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
97
class cmd_patch(bzrlib.commands.Command):
98
"""Apply a named patch to the current tree.
100
takes_args = ['filename?']
101
takes_options = ['strip']
102
def run(self, filename=None, strip=0):
103
from patch import patch
104
from bzrlib.branch import Branch
105
b = Branch.open_containing('.')[0]
106
return patch(b, filename, strip)
109
class cmd_shelve(bzrlib.commands.Command):
110
"""Temporarily remove some changes from the current tree.
111
Use 'unshelve' to restore these changes.
113
If filenames are specified, only changes to those files will be unshelved.
114
If a revision is specified, all changes since that revision will may be
117
takes_args = ['file*']
118
takes_options = ['all', 'message', 'revision']
119
def run(self, all=False, file_list=None, message=None, revision=None):
120
if file_list is not None and len(file_list) > 0:
121
branchdir = file_list[0]
125
if revision is not None and revision:
126
if len(revision) == 1:
127
revision = revision[0]
129
raise BzrCommandError("shelve only accepts a single revision "
133
return s.shelve(all, message, revision, file_list)
136
class cmd_unshelve(bzrlib.commands.Command):
137
"""Restore previously-shelved changes to the current tree.
144
class cmd_shell(bzrlib.commands.Command):
145
"""Begin an interactive shell tailored for bzr.
146
Bzr commands can be used without typing bzr first, and will be run natively
147
when possible. Tab completion is tailored for bzr. The shell prompt shows
148
the branch nick, revno, and path.
150
If it encounters any moderately complicated shell command, it will punt to
155
bzr bzrtools:287/> status
158
bzr bzrtools:287/> status --[TAB][TAB]
159
--all --help --revision --show-ids
160
bzr bzrtools:287/> status --
164
return shell.run_shell()
166
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
167
cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix]
169
command_decorators = []
171
command_decorators = []
173
import bzrlib.builtins
174
if not hasattr(bzrlib.builtins, "cmd_annotate"):
175
commands.append(annotate.cmd_annotate)
176
if not hasattr(bzrlib.builtins, "cmd_push"):
177
commands.append(push.cmd_push)
179
command_decorators.append(push.cmd_push)
181
from errors import NoPyBaz
184
commands.append(baz_import.cmd_baz_import_branch)
185
commands.append(baz_import.cmd_baz_import)
188
class cmd_baz_import(bzrlib.commands.Command):
189
"""Disabled. (Requires PyBaz)"""
190
takes_args = ['to_root_dir?', 'from_archive?']
191
takes_options = ['verbose']
192
def run(self, to_root_dir=None, from_archive=None, verbose=False):
193
print "This command is disabled. Please install PyBaz."
194
commands.append(cmd_baz_import)
197
if hasattr(bzrlib.commands, 'register_command'):
198
for command in commands:
199
bzrlib.commands.register_command(command)
200
for command in command_decorators:
201
command._original_command = bzrlib.commands.register_command(
208
from doctest import DocTestSuite
209
from unittest import TestSuite, TestLoader
214
result.addTest(DocTestSuite(bzrtools))
215
result.addTest(clean_tree.test_suite())
216
result.addTest(DocTestSuite(baz_import))
217
result.addTest(tests.test_suite())
218
result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
219
result.addTest(blackbox.test_suite())