106
93
strip_help="""Strip the smallest prefix containing num leading slashes from \
107
94
each file name found in the patch file."""
108
95
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
109
Option.OPTIONS['bzrdiff'] = Option('bzrdiff',type=None,
110
help="""Handle extra bzr tags""")
111
96
class cmd_patch(bzrlib.commands.Command):
112
"""Apply a named patch to the current tree. <BZRTOOLS>
97
"""Apply a named patch to the current tree.
114
99
takes_args = ['filename?']
115
takes_options = ['strip','bzrdiff']
116
def run(self, filename=None, strip=-1, bzrdiff=0):
100
takes_options = ['strip']
101
def run(self, filename=None, strip=0):
117
102
from patch import patch
118
from bzrlib.workingtree import WorkingTree
119
wt = WorkingTree.open_containing('.')[0]
121
if bzrdiff: strip = 0
103
from bzrlib.branch import Branch
104
b = Branch.open_containing('.')[0]
105
return patch(b, filename, strip)
124
return patch(wt, filename, strip, legacy= not bzrdiff)
126
108
class cmd_shelve(bzrlib.commands.Command):
127
"""Temporarily set aside some changes from the current tree. <BZRTOOLS>
129
Shelve allows you to temporarily put changes you've made "on the shelf",
130
ie. out of the way, until a later time when you can bring them back from
131
the shelf with the 'unshelve' command.
133
Shelve is intended to help separate several sets of text changes that have
134
been inappropriately mingled. If you just want to get rid of all changes
135
(text and otherwise) and you don't need to restore them later, use revert.
136
If you want to shelve all text changes at once, use shelve --all.
138
By default shelve asks you what you want to shelve, press '?' at the
139
prompt to get help. To shelve everything run shelve --all.
141
You can put multiple items on the shelf, each time you run unshelve the
142
most recently shelved changes will be reinstated.
144
If filenames are specified, only the changes to those files will be
145
shelved, other files will be left untouched.
147
If a revision is specified, changes since that revision will be shelved.
109
"""Temporarily remove some changes from the current tree.
110
Use 'unshelve' to restore these changes.
112
If filenames are specified, only changes to those files will be unshelved.
113
If a revision is specified, all changes since that revision will may be
150
116
takes_args = ['file*']
151
takes_options = ['message', 'revision',
152
Option('all', help='Shelve all changes without prompting')]
117
takes_options = ['all', 'message', 'revision']
154
118
def run(self, all=False, file_list=None, message=None, revision=None):
119
if file_list is not None and len(file_list) > 0:
120
branchdir = file_list[0]
155
124
if revision is not None and revision:
156
125
if len(revision) == 1:
157
126
revision = revision[0]
159
raise CommandError("shelve only accepts a single revision "
128
raise BzrCommandError("shelve only accepts a single revision "
162
source = BzrPatchSource(revision, file_list)
163
s = Shelf(source.base)
164
s.shelve(source, all, message)
167
class cmd_shelf(bzrlib.commands.Command):
168
"""Perform various operations on your shelved patches. See also shelve.
171
list (ls) List the patches on the current shelf.
172
delete (del) <patch> Delete a patch from the current shelf.
173
switch <shelf> Switch to the named shelf, create it if necessary.
174
show <patch> Show the contents of the specified patch.
175
upgrade Upgrade old format shelves.
177
takes_args = ['subcommand', 'args*']
179
def run(self, subcommand, args_list):
182
source = BzrPatchSource()
183
s = Shelf(source.base)
185
if subcommand == 'ls' or subcommand == 'list':
186
self.__check_no_args(args_list, "shelf list takes no arguments!")
188
elif subcommand == 'delete' or subcommand == 'del':
189
self.__check_one_arg(args_list, "shelf delete takes one argument!")
190
s.delete(args_list[0])
191
elif subcommand == 'switch':
192
self.__check_one_arg(args_list, "shelf switch takes one argument!")
193
s = Shelf(source.base, args_list[0])
195
elif subcommand == 'show':
196
self.__check_one_arg(args_list, "shelf show takes one argument!")
197
s.display(args_list[0])
198
elif subcommand == 'upgrade':
199
self.__check_no_args(args_list, "shelf upgrade takes no arguments!")
202
print subcommand, args_list
203
print >>sys.stderr, "Unknown shelf subcommand '%s'" % subcommand
205
def __check_one_arg(self, args, msg):
206
if args is None or len(args) != 1:
207
raise CommandError(msg)
209
def __check_no_args(self, args, msg):
211
raise CommandError(msg)
132
return s.shelve(all, message, revision, file_list)
214
135
class cmd_unshelve(bzrlib.commands.Command):
215
"""Restore the most recently shelved changes to current tree. <BZRTOOLS>
216
See 'shelve' for more information.
136
"""Restore previously-shelved changes to the current tree.
219
Option('all', help='Unshelve all changes without prompting'),
220
Option('force', help='Force unshelving even if errors occur'),
222
def run(self, all=False, force=False):
223
source = BzrPatchSource()
224
s = Shelf(source.base)
225
s.unshelve(source, all, force)
229
143
class cmd_shell(bzrlib.commands.Command):
230
"""Begin an interactive shell tailored for bzr. <BZRTOOLS>
231
Bzr commands can be used without typing bzr first, and will be run natively
232
when possible. Tab completion is tailored for bzr. The shell prompt shows
233
the branch nick, revno, and path.
235
If it encounters any moderately complicated shell command, it will punt to
240
bzr bzrtools:287/> status
243
bzr bzrtools:287/> status --[TAB][TAB]
244
--all --help --revision --show-ids
245
bzr bzrtools:287/> status --
249
146
return shell.run_shell()
251
class cmd_branch_history(bzrlib.commands.Command):
253
Display the development history of a branch <BZRTOOLS>.
255
Each different committer or branch nick is considered a different line of
256
development. Committers are treated as the same if they have the same
257
name, or if they have the same email address.
259
takes_args = ["branch?"]
260
def run(self, branch=None):
261
from branchhistory import branch_history
262
return branch_history(branch)
265
class cmd_zap(bzrlib.commands.Command):
267
Remove a checkout, if it can be done safely. <BZRTOOLS>
269
This command will remove a checkout without losing data. That means
270
it only removes checkouts,
272
takes_args = ["checkout"]
273
def run(self, checkout):
278
commands = [cmd_shelve, cmd_unshelve, cmd_shelf, cmd_clean_tree,
279
cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch, cmd_shell,
280
cmd_branch_history, cmd_zap]
148
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
149
cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix]
283
151
command_decorators = []
286
153
import bzrlib.builtins
154
if not hasattr(bzrlib.builtins, "cmd_annotate"):
155
commands.append(annotate.cmd_annotate)
287
156
if not hasattr(bzrlib.builtins, "cmd_push"):
288
157
commands.append(push.cmd_push)
292
161
from errors import NoPyBaz
294
163
import baz_import
295
commands.append(baz_import.cmd_baz_import_branch)
296
164
commands.append(baz_import.cmd_baz_import)
299
class cmd_baz_import_branch(bzrlib.commands.Command):
300
"""Disabled. (Requires PyBaz) <BZRTOOLS>"""
301
takes_args = ['to_location?', 'from_branch?', 'reuse_history*']
302
takes_options = ['verbose', Option('max-count', type=int)]
303
def run(self, to_location=None, from_branch=None, fast=False,
304
max_count=None, verbose=False, dry_run=False,
305
reuse_history_list=[]):
167
class cmd_baz_import(bzrlib.commands.Command):
168
"""Disabled. (Requires PyBaz)"""
169
takes_args = ['to_root_dir?', 'from_archive?']
170
takes_options = ['verbose']
171
def run(self, to_root_dir=None, from_archive=None, verbose=False):
306
172
print "This command is disabled. Please install PyBaz."
309
class cmd_baz_import(bzrlib.commands.Command):
310
"""Disabled. (Requires PyBaz) <BZRTOOLS>"""
311
takes_args = ['to_root_dir?', 'from_archive?', 'reuse_history*']
312
takes_options = ['verbose', Option('prefixes', type=str,
313
help="Prefixes of branches to import")]
314
def run(self, to_root_dir=None, from_archive=None, verbose=False,
315
reuse_history_list=[], prefixes=None):
316
print "This command is disabled. Please install PyBaz."
317
commands.extend((cmd_baz_import_branch, cmd_baz_import))
173
commands.append(cmd_baz_import)
320
176
if hasattr(bzrlib.commands, 'register_command'):