chiark / gitweb /
Infrastructure for current directory handling
[stgit] / stgit / commands / delete.py
CommitLineData
fcee87cf
CM
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 *
5e888f30 24from stgit.out import *
fcee87cf
CM
25from stgit import stack, git
26
27
87bcf96e
KH
28help = 'delete patches'
29usage = """%prog [options] <patch1> [<patch2>] [<patch3>..<patch4>]
26aab5b0 30
87bcf96e
KH
31Delete the patches passed as arguments. If an applied patch is to be
32deleted, all other patches applied on top of it must be deleted too,
33and they must be explicitly specified, since this command will not try
34to delete a patch unless you explicitly ask it to. If any applied
35patches are deleted, they are popped from the stack.
36
37Note that the 'delete' operation is irreversible."""
fcee87cf 38
6dd8fafa 39directory = DirectoryHasRepository()
7354d694
PBG
40options = [make_option('-b', '--branch',
41 help = 'use BRANCH instead of the default one')]
fcee87cf
CM
42
43def func(parser, options, args):
2153b8f5
CM
44 """Deletes one or more patches.
45 """
87bcf96e
KH
46 applied_patches = crt_series.get_applied()
47 unapplied_patches = crt_series.get_unapplied()
48 all_patches = applied_patches + unapplied_patches
49
50 if args:
ceba3178 51 patches = parse_patches(args, all_patches, len(applied_patches))
87bcf96e
KH
52 else:
53 parser.error('No patches specified')
54
2153b8f5
CM
55 applied = []
56
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]:
60 if patch in patches:
61 applied.append(patch)
62 patches.remove(patch)
87bcf96e 63 else:
2153b8f5
CM
64 break
65
66 # any applied patches to be deleted but not in consecutive order?
67 for patch in patches:
68 if patch in applied_patches:
69 raise CmdException, 'Cannot delete the applied patch "%s"' % patch
fcee87cf 70
2153b8f5 71 if applied and not options.branch:
fcee87cf
CM
72 check_local_changes()
73 check_conflicts()
74 check_head_top_equal()
87bcf96e 75
2153b8f5
CM
76 # delete the patches
77 for patch in applied + patches:
87bcf96e 78 crt_series.delete_patch(patch)
27ac2b7e 79 out.info('Patch "%s" successfully deleted' % patch)
87bcf96e 80
7354d694
PBG
81 if not options.branch:
82 print_crt_patch()