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 stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit.utils import *
23 from stgit import stack, git
25 help = 'Pop one or more patches from the stack'
26 usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
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
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
34 the push operations may fail because of conflicts (push --undo would
35 revert the last push operation)."""
38 opt('-a', '--all', action = 'store_true',
39 short = 'Pop all the applied patches'),
40 opt('-n', '--number', type = 'int',
41 short = 'Pop the specified number of patches'),
42 opt('-k', '--keep', action = 'store_true',
43 short = 'Keep the local changes')]
45 directory = DirectoryGotoToplevel()
47 def func(parser, options, args):
48 """Pop the topmost patch from the stack
51 check_head_top_equal(crt_series)
56 applied = crt_series.get_applied()
58 raise CmdException, 'No patches applied'
63 # reverse it twice to also work with negative or bigger than
65 patches = applied[::-1][:options.number][::-1]
67 patches = [applied[-1]]
69 patches = parse_patches(args, applied, ordered = True)
72 raise CmdException, 'No patches to pop'
74 # pop to the most distant popped patch
75 topop = applied[applied.index(patches[0]):]
76 # push those not in the popped range
77 topush = [p for p in topop if p not in patches]
79 if options.keep and topush:
80 raise CmdException, 'Cannot pop arbitrary patches with --keep'
83 pop_patches(crt_series, topop, options.keep)
85 push_patches(crt_series, topush)
87 print_crt_patch(crt_series)