Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-from optparse import make_option
-
+from stgit.argparse import opt
from stgit.commands import common
from stgit.lib import transaction
+from stgit import argparse
-help = 'delete patches'
-usage = """%prog [options] <patch1> [<patch2>] [<patch3>..<patch4>]
-
-Delete the patches passed as arguments.
+help = 'Delete patches'
+kind = 'patch'
+usage = ['[options] <patch1> [<patch2>] [<patch3>..<patch4>]']
+description = """
+Delete the patches passed as arguments."""
-Note that the 'delete' operation is irreversible."""
+args = [argparse.patch_range(argparse.applied_patches,
+ argparse.unapplied_patches)]
+options = [
+ opt('--spill', action = 'store_true',
+ short = 'Spill patch contents to worktree and index', long = """
+ Delete the patches, but do not touch the index and worktree.
+ This only works with applied patches at the top of the stack.
+ The effect is to "spill" the patch contents into the index and
+ worktree. This can be useful e.g. if you want to split a patch
+ into several smaller pieces."""),
+ opt('-b', '--branch', args = [argparse.stg_branches],
+ short = 'Use BRANCH instead of the default branch')]
directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-b', '--branch',
- help = 'use BRANCH instead of the default one')]
def func(parser, options, args):
"""Delete one or more patches."""
else:
iw = stack.repository.default_iw
if args:
- patches = set(common.parse_patches(args, list(stack.patchorder.all)))
+ patches = set(common.parse_patches(args, list(stack.patchorder.all),
+ len(stack.patchorder.applied)))
else:
parser.error('No patches specified')
+
+ if options.spill:
+ if set(stack.patchorder.applied[-len(patches):]) != patches:
+ parser.error('Can only spill topmost applied patches')
+ iw = None # don't touch index+worktree
+
def allow_conflicts(trans):
# Allow conflicts if the topmost patch stays the same.
if stack.patchorder.applied: