X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/26aab5b04fa4ba13f48948de73e497cf0a315ad1..87bcf96e1932268c3bb67c99bde6c8e897ec9fdf:/stgit/commands/delete.py diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index 01bea62..6f12a15 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -24,28 +24,58 @@ from stgit.utils import * from stgit import stack, git -help = 'remove the topmost or any unapplied patch' -usage = """%prog [options] +help = 'delete patches' +usage = """%prog [options] [] [..] -Delete the patch passed as argument. The patch to be deleted can only -be part of the unapplied list or be the topmost one, in the latter -case the command also popping it from the stack. Note that the -'delete' operation is irreversible.""" +Delete the patches passed as arguments. If an applied patch is to be +deleted, all other patches applied on top of it must be deleted too, +and they must be explicitly specified, since this command will not try +to delete a patch unless you explicitly ask it to. If any applied +patches are deleted, they are popped from the stack. -options = [] +Note that the 'delete' operation is irreversible.""" +options = [make_option('-b', '--branch', + help = 'use BRANCH instead of the default one')] def func(parser, options, args): - """Deletes a patch - """ - if len(args) != 1: - parser.error('incorrect number of arguments') + """Deletes one or more patches.""" + applied_patches = crt_series.get_applied() + unapplied_patches = crt_series.get_unapplied() + all_patches = applied_patches + unapplied_patches - if args[0] == crt_series.get_current(): + if args: + patches = parse_patches(args, all_patches) + else: + parser.error('No patches specified') + + applied = {} + unapplied = {} + for patch in patches: + if patch in unapplied_patches: + unapplied[patch] = None + else: + applied[patch] = None + + while crt_series.get_current() in applied: + patch = crt_series.get_current() check_local_changes() check_conflicts() check_head_top_equal() + crt_series.delete_patch(patch) + del applied[patch] + print 'Patch "%s" successfully deleted' % patch + + for patch in unapplied.iterkeys(): + crt_series.delete_patch(patch) + print 'Patch "%s" successfully deleted' % patch + + if applied: + print 'Error: failed to delete %s' % ', '.join(applied.iterkeys()) + + failed = len(applied) + if failed: + raise CmdException, 'Failed to delete %d patches' % failed - crt_series.delete_patch(args[0]) - print 'Patch "%s" successfully deleted' % args[0] - print_crt_patch() + if not options.branch: + print_crt_patch()