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 | ||
1056440b CM |
19 | from stgit.commands import common |
20 | from stgit.lib import transaction | |
21 | from stgit import argparse | |
575bbdae | 22 | from stgit.argparse import opt |
fcee87cf | 23 | |
575bbdae | 24 | help = 'Pop one or more patches from the stack' |
33ff9cdd | 25 | kind = 'stack' |
575bbdae KH |
26 | usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]'] |
27 | description = """ | |
d1368d81 CM |
28 | Pop the topmost patch or a range of patches from the stack. The |
29 | command fails if there are conflicts or local changes (and --keep was | |
30 | not specified). | |
31 | ||
32 | A series of pop and push operations are performed so that only the | |
33 | patches passed on the command line are popped from the stack. Some of | |
625e8de7 | 34 | the push operations may fail because of conflicts ("stg undo" would |
d1368d81 | 35 | revert the last push operation).""" |
fcee87cf | 36 | |
6c8a90e1 | 37 | args = [argparse.patch_range(argparse.applied_patches)] |
575bbdae KH |
38 | options = [ |
39 | opt('-a', '--all', action = 'store_true', | |
40 | short = 'Pop all the applied patches'), | |
41 | opt('-n', '--number', type = 'int', | |
1056440b CM |
42 | short = 'Pop the specified number of patches') |
43 | ] + argparse.keep_option() | |
fcee87cf | 44 | |
1056440b | 45 | directory = common.DirectoryHasRepositoryLib() |
fcee87cf CM |
46 | |
47 | def func(parser, options, args): | |
1056440b CM |
48 | """Pop the given patches or the topmost one from the stack.""" |
49 | stack = directory.repository.current_stack | |
50 | iw = stack.repository.default_iw | |
51 | clean_iw = (not options.keep and iw) or None | |
52 | trans = transaction.StackTransaction(stack, 'pop', | |
53 | check_clean_iw = clean_iw) | |
e45af3d4 | 54 | |
1056440b CM |
55 | if not trans.applied: |
56 | raise common.CmdException('No patches applied') | |
fcee87cf | 57 | |
6b1e0111 | 58 | if options.all: |
1056440b | 59 | patches = trans.applied |
fcee87cf | 60 | elif options.number: |
d1368d81 CM |
61 | # reverse it twice to also work with negative or bigger than |
62 | # the length numbers | |
1056440b CM |
63 | patches = trans.applied[::-1][:options.number][::-1] |
64 | elif not args: | |
65 | patches = [trans.applied[-1]] | |
fcee87cf | 66 | else: |
1056440b | 67 | patches = common.parse_patches(args, trans.applied, ordered = True) |
fcee87cf | 68 | |
d1368d81 | 69 | if not patches: |
1056440b CM |
70 | raise common.CmdException('No patches to pop') |
71 | ||
72 | applied = [p for p in trans.applied if not p in set(patches)] | |
73 | unapplied = patches + trans.unapplied | |
74 | try: | |
75 | trans.reorder_patches(applied, unapplied, iw = iw) | |
76 | except transaction.TransactionException: | |
77 | pass | |
78 | return trans.run(iw) |