2 Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3 Modified by Catalin Marinas
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
21 from stgit.argparse import opt
22 from stgit.commands import common
23 from stgit.lib import transaction
24 from stgit import argparse
26 help = 'Push patches to the top, even if applied'
31 Push a patch or a range of patches to the top even if applied. The
32 necessary pop and push operations will be performed to accomplish
33 this. The '--series' option can be used to rearrange the (top) patches
34 as specified by the given series file (or the standard input)."""
36 args = [argparse.patch_range(argparse.applied_patches,
37 argparse.unapplied_patches)]
39 opt('-s', '--series', metavar = 'FILE',
40 short = 'Rearrange according to the series FILE')
41 ] + argparse.keep_option()
43 directory = common.DirectoryHasRepositoryLib()
45 def func(parser, options, args):
46 """Reorder patches to make the named patch the topmost one.
48 if options.series and args:
49 parser.error('<patches> cannot be used with --series')
50 elif not options.series and not args:
51 parser.error('incorrect number of arguments')
53 stack = directory.repository.current_stack
56 if options.series == '-':
59 f = file(options.series)
63 patch = re.sub('#.*$', '', line).strip()
67 patches = common.parse_patches(args, stack.patchorder.all)
70 raise common.CmdException('No patches to float')
72 applied = [p for p in stack.patchorder.applied if p not in patches] + \
74 unapplied = [p for p in stack.patchorder.unapplied if not p in patches]
76 iw = stack.repository.default_iw
77 clean_iw = (not options.keep and iw) or None
78 trans = transaction.StackTransaction(stack, 'sink',
79 check_clean_iw = clean_iw)
82 trans.reorder_patches(applied, unapplied, iw = iw)
83 except transaction.TransactionHalted: