2
"""Shelf - temporarily set aside changes, then bring them back."""
3
Various useful plugins for working with bzr.
4
5
import bzrlib.commands
5
7
from errors import CommandError
6
from bzrlib.option import Option
7
8
from patchsource import BzrPatchSource
8
9
from shelf import Shelf
12
from bzrlib.option import Option
14
from bzrlib.errors import BzrCommandError
15
from reweave_inventory import cmd_fix
16
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
9
18
from bzrlib import DEFAULT_IGNORE
11
21
DEFAULT_IGNORE.append('./.shelf')
22
DEFAULT_IGNORE.append('./.bzr-shelf*')
25
Option.OPTIONS['ignored'] = Option('ignored',
26
help='delete all ignored files.')
27
Option.OPTIONS['detritus'] = Option('detritus',
28
help='delete conflict files merge backups, and failed selftest dirs.' +
29
'(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
30
Option.OPTIONS['dry-run'] = Option('dry-run',
31
help='show files to delete instead of deleting them.')
33
class cmd_clean_tree(bzrlib.commands.Command):
34
"""Remove unwanted files from working tree.
35
Normally, ignored files are left alone.
37
takes_options = ['ignored', 'detritus', 'dry-run']
38
def run(self, ignored=False, detritus=False, dry_run=False):
39
from clean_tree import clean_tree
40
clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
42
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
44
class cmd_graph_ancestry(bzrlib.commands.Command):
45
"""Produce ancestry graphs using dot.
47
Output format is detected according to file extension. Some of the more
48
common output formats are html, png, gif, svg, ps. An extension of '.dot'
49
will cause a dot graph file to be produced. HTML output has mouseovers
50
that show the commit message.
52
Branches are labeled r?, where ? is the revno. If they have no revno,
53
with the last 5 characters of their revision identifier are used instead.
55
The value starting with d is "(maximum) distance from the null revision".
57
If --merge-branch is specified, the two branches are compared and a merge
65
blue COMMON non-history ancestor
66
green Merge base (COMMON ancestor farthest from the null revision)
67
dotted Ghost revision (missing from branch storage)
69
Ancestry is usually collapsed by skipping revisions with a single parent
70
and descendant. The number of skipped revisions is shown on the arrow.
71
This feature can be disabled with --no-collapse.
73
By default, revisions are ordered by distance from root, but they can be
74
clustered instead using --cluster.
76
If available, rsvg is used to antialias PNG and JPEG output, but this can
77
be disabled with --no-antialias.
79
takes_args = ['branch', 'file']
80
takes_options = [Option('no-collapse', help="Do not skip simple nodes"),
81
Option('no-antialias',
82
help="Do not use rsvg to produce antialiased output"),
83
Option('merge-branch', type=str,
84
help="Use this branch to calcuate a merge base"),
85
Option('cluster', help="Use clustered output.")]
86
def run(self, branch, file, no_collapse=False, no_antialias=False,
87
merge_branch=None, cluster=False):
93
graph.write_ancestry_file(branch, file, not no_collapse,
94
not no_antialias, merge_branch, ranking)
96
class cmd_fetch_ghosts(bzrlib.commands.Command):
97
"""Attempt to retrieve ghosts from another branch.
98
If the other branch is not supplied, the last-pulled branch is used.
100
aliases = ['fetch-missing']
101
takes_args = ['branch?']
102
takes_options = [Option('no-fix')]
103
def run(self, branch=None, no_fix=False):
104
from fetch_ghosts import fetch_ghosts
105
fetch_ghosts(branch, no_fix)
107
strip_help="""Strip the smallest prefix containing num leading slashes from \
108
each file name found in the patch file."""
109
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
110
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
111
help="""Handle extra bzr tags""")
112
class cmd_patch(bzrlib.commands.Command):
113
"""Apply a named patch to the current tree.
115
takes_args = ['filename?']
116
takes_options = ['strip','bzrdiff']
117
def run(self, filename=None, strip=-1, bzrdiff=0):
118
from patch import patch
119
from bzrlib.branch import Branch
120
b = Branch.open_containing('.')[0]
122
if bzrdiff: strip = 0
125
return patch(b, filename, strip, legacy= not bzrdiff)
13
127
class cmd_shelve(bzrlib.commands.Command):
14
"""Temporarily set aside some changes to the current working tree.
128
"""Temporarily set aside some changes from the current tree.
16
130
Shelve allows you to temporarily put changes you've made "on the shelf",
17
131
ie. out of the way, until a later time when you can bring them back from
18
132
the shelf with the 'unshelve' command.
134
Shelve is intended to help separate several sets of text changes that have
135
been inappropriately mingled. If you just want to get rid of all changes
136
(text and otherwise) and you don't need to restore them later, use revert.
137
If you want to shelve all text changes at once, use shelve --all.
139
By default shelve asks you what you want to shelve, press '?' at the
140
prompt to get help. To shelve everything run shelve --all.
20
142
You can put multiple items on the shelf, each time you run unshelve the
21
143
most recently shelved changes will be reinstated.
73
196
elif subcommand == 'show':
74
197
self.__check_one_arg(args_list, "shelf show takes one argument!")
75
198
s.display(args_list[0])
199
elif subcommand == 'upgrade':
200
self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
77
203
print subcommand, args_list
78
204
print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
80
206
def __check_one_arg(self, args, msg):
81
207
if args is None or len(args) != 1:
82
raise BzrCommandError(msg)
208
raise CommandError(msg)
84
210
def __check_no_args(self, args, msg):
85
211
if args is not None:
86
raise BzrCommandError(msg)
212
raise CommandError(msg)
88
215
class cmd_unshelve(bzrlib.commands.Command):
89
"""Reinstate the most recently shelved changes.
216
"""Restore the most recently shelved changes to the current tree.
90
217
See 'shelve' for more information.
92
takes_options = [Option('all')]
93
def run(self, all=False):
220
Option('all', help='Unshelve all changes without prompting'),
221
Option('force', help='Force unshelving even if errors occur'),
223
def run(self, all=False, force=False):
94
224
source = BzrPatchSource()
95
225
s = Shelf(source.base)
96
s.unshelve(source, all)
226
s.unshelve(source, all, force)
99
bzrlib.commands.register_command(cmd_shelf)
100
bzrlib.commands.register_command(cmd_shelve)
101
bzrlib.commands.register_command(cmd_unshelve)
230
class cmd_shell(bzrlib.commands.Command):
231
"""Begin an interactive shell tailored for bzr.
232
Bzr commands can be used without typing bzr first, and will be run natively
233
when possible. Tab completion is tailored for bzr. The shell prompt shows
234
the branch nick, revno, and path.
236
If it encounters any moderately complicated shell command, it will punt to
241
bzr bzrtools:287/> status
244
bzr bzrtools:287/> status --[TAB][TAB]
245
--all --help --revision --show-ids
246
bzr bzrtools:287/> status --
250
return shell.run_shell()
252
class cmd_branch_history(bzrlib.commands.Command):
254
Display the revision history with reference to lines of development.
256
Each different committer or branch nick is considered a different line of
257
development. Committers are treated as the same if they have the same
258
name, or if they have the same email address.
260
takes_args = ["branch?"]
261
def run(self, branch=None):
262
from branchhistory import branch_history
263
return branch_history(branch)
265
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
266
cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
267
cmd_fix, cmd_branch_history]
269
command_decorators = []
271
command_decorators = []
273
import bzrlib.builtins
274
if not hasattr(bzrlib.builtins, "cmd_push"):
275
commands.append(push.cmd_push)
277
command_decorators.append(push.cmd_push)
279
from errors import NoPyBaz
282
commands.append(baz_import.cmd_baz_import_branch)
283
commands.append(baz_import.cmd_baz_import)
286
class cmd_baz_import_branch(bzrlib.commands.Command):
287
"""Disabled. (Requires PyBaz)"""
288
takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
289
takes_options = ['verbose', Option('max-count', type=int)]
290
def run(self, to_location=None, from_branch=None, fast=False,
291
max_count=None, verbose=False, dry_run=False,
292
reuse_history_list=[]):
293
print "This command is disabled. Please install PyBaz."
296
class cmd_baz_import(bzrlib.commands.Command):
297
"""Disabled. (Requires PyBaz)"""
298
takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
299
takes_options = ['verbose', Option('prefixes', type=str,
300
help="Prefixes of branches to import")]
301
def run(self, to_root_dir=None, from_archive=None, verbose=False,
302
reuse_history_list=[], prefixes=None):
303
print "This command is disabled. Please install PyBaz."
304
commands.extend((cmd_baz_import_branch, cmd_baz_import))
307
if hasattr(bzrlib.commands, 'register_command'):
308
for command in commands:
309
bzrlib.commands.register_command(command)
310
for command in command_decorators:
311
command._original_command = bzrlib.commands.register_command(
103
315
def test_suite():
104
317
from bzrlib.tests.TestUtil import TestLoader
106
return TestLoader().loadTestsFromModule(tests)
319
from doctest import DocTestSuite, ELLIPSIS
320
from unittest import TestSuite
325
result.addTest(DocTestSuite(bzrtools, optionflags=ELLIPSIS))
326
result.addTest(clean_tree.test_suite())
327
result.addTest(DocTestSuite(baz_import))
328
result.addTest(tests.test_suite())
329
result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
330
result.addTest(blackbox.test_suite())