3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 from optparse
import OptionParser
, make_option
22 from stgit
.commands
.common
import *
23 from stgit
.utils
import *
24 from stgit
.out
import *
25 from stgit
import stack
, git
28 help = 'delete patches'
29 usage
= """%prog [options] <patch1> [<patch2>] [<patch3>..<patch4>]
31 Delete the patches passed as arguments. If an applied patch is to be
32 deleted, all other patches applied on top of it must be deleted too,
33 and they must be explicitly specified, since this command will not try
34 to delete a patch unless you explicitly ask it to. If any applied
35 patches are deleted, they are popped from the stack.
37 Note that the 'delete' operation is irreversible."""
39 directory
= DirectoryGotoToplevel()
40 options
= [make_option('-b', '--branch',
41 help = 'use BRANCH instead of the default one')]
43 def func(parser
, options
, args
):
44 """Deletes one or more patches.
46 applied_patches
= crt_series
.get_applied()
47 unapplied_patches
= crt_series
.get_unapplied()
48 all_patches
= applied_patches
+ unapplied_patches
51 patches
= parse_patches(args
, all_patches
, len(applied_patches
))
53 parser
.error('No patches specified')
57 # find the applied patches to be deleted. We can only delete
58 # consecutive patches in the applied range
59 for patch
in applied_patches
[::-1]:
66 # any applied patches to be deleted but not in consecutive order?
68 if patch
in applied_patches
:
69 raise CmdException
, 'Cannot delete the applied patch "%s"' % patch
71 if applied
and not options
.branch
:
74 check_head_top_equal(crt_series
)
77 for patch
in applied
+ patches
:
78 crt_series
.delete_patch(patch
)
79 out
.info('Patch "%s" successfully deleted' % patch
)
81 if not options
.branch
:
82 print_crt_patch(crt_series
)