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