X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/87bcf96e1932268c3bb67c99bde6c8e897ec9fdf..2153b8f56dfa10936ca934a68a364dacdf161117:/stgit/commands/delete.py?ds=sidebyside diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index 6f12a15..515f4b7 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -39,7 +39,8 @@ options = [make_option('-b', '--branch', help = 'use BRANCH instead of the default one')] def func(parser, options, args): - """Deletes one or more patches.""" + """Deletes one or more patches. + """ applied_patches = crt_series.get_applied() unapplied_patches = crt_series.get_unapplied() all_patches = applied_patches + unapplied_patches @@ -49,33 +50,31 @@ def func(parser, options, args): else: parser.error('No patches specified') - applied = {} - unapplied = {} - for patch in patches: - if patch in unapplied_patches: - unapplied[patch] = None + applied = [] + + # find the applied patches to be deleted. We can only delete + # consecutive patches in the applied range + for patch in applied_patches[::-1]: + if patch in patches: + applied.append(patch) + patches.remove(patch) else: - applied[patch] = None + break + + # any applied patches to be deleted but not in consecutive order? + for patch in patches: + if patch in applied_patches: + raise CmdException, 'Cannot delete the applied patch "%s"' % patch - while crt_series.get_current() in applied: - patch = crt_series.get_current() + if applied and not options.branch: 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(): + # delete the patches + for patch in applied + patches: 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 - if not options.branch: print_crt_patch()