Commit | Line | Data |
---|---|---|
fcee87cf CM |
1 | |
2 | __copyright__ = """ | |
3 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
4 | ||
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. | |
8 | ||
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. | |
13 | ||
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 | |
17 | """ | |
18 | ||
19 | import sys, os | |
20 | from optparse import OptionParser, make_option | |
21 | ||
22 | from stgit.commands.common import * | |
23 | from stgit.utils import * | |
24 | from stgit import stack, git | |
25 | ||
26 | ||
87bcf96e KH |
27 | help = 'delete patches' |
28 | usage = """%prog [options] <patch1> [<patch2>] [<patch3>..<patch4>] | |
26aab5b0 | 29 | |
87bcf96e KH |
30 | Delete the patches passed as arguments. If an applied patch is to be |
31 | deleted, all other patches applied on top of it must be deleted too, | |
32 | and they must be explicitly specified, since this command will not try | |
33 | to delete a patch unless you explicitly ask it to. If any applied | |
34 | patches are deleted, they are popped from the stack. | |
35 | ||
36 | Note that the 'delete' operation is irreversible.""" | |
fcee87cf | 37 | |
7354d694 PBG |
38 | options = [make_option('-b', '--branch', |
39 | help = 'use BRANCH instead of the default one')] | |
fcee87cf CM |
40 | |
41 | def func(parser, options, args): | |
87bcf96e KH |
42 | """Deletes one or more patches.""" |
43 | applied_patches = crt_series.get_applied() | |
44 | unapplied_patches = crt_series.get_unapplied() | |
45 | all_patches = applied_patches + unapplied_patches | |
46 | ||
47 | if args: | |
48 | patches = parse_patches(args, all_patches) | |
49 | else: | |
50 | parser.error('No patches specified') | |
51 | ||
52 | applied = {} | |
53 | unapplied = {} | |
54 | for patch in patches: | |
55 | if patch in unapplied_patches: | |
56 | unapplied[patch] = None | |
57 | else: | |
58 | applied[patch] = None | |
fcee87cf | 59 | |
87bcf96e KH |
60 | while crt_series.get_current() in applied: |
61 | patch = crt_series.get_current() | |
fcee87cf CM |
62 | check_local_changes() |
63 | check_conflicts() | |
64 | check_head_top_equal() | |
87bcf96e KH |
65 | crt_series.delete_patch(patch) |
66 | del applied[patch] | |
67 | print 'Patch "%s" successfully deleted' % patch | |
68 | ||
69 | for patch in unapplied.iterkeys(): | |
70 | crt_series.delete_patch(patch) | |
71 | print 'Patch "%s" successfully deleted' % patch | |
72 | ||
73 | if applied: | |
74 | print 'Error: failed to delete %s' % ', '.join(applied.iterkeys()) | |
fcee87cf | 75 | |
87bcf96e KH |
76 | failed = len(applied) |
77 | if failed: | |
78 | raise CmdException, 'Failed to delete %d patches' % failed | |
7354d694 PBG |
79 | |
80 | if not options.branch: | |
81 | print_crt_patch() |