Slightly modify the "publish" command description
[stgit] / stgit / commands / float.py
CommitLineData
d98a499c
RR
1__copyright__ = """
2Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3Modified by Catalin Marinas
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
cef5deb4 19import re
5a1bab1a 20import sys
575bbdae 21from stgit.argparse import opt
5a1bab1a
CM
22from stgit.commands import common
23from stgit.lib import transaction
24from stgit import argparse
d98a499c 25
575bbdae 26help = 'Push patches to the top, even if applied'
33ff9cdd 27kind = 'stack'
575bbdae
KH
28usage = ['<patches>',
29 '-s <series>']
30description = """
d98a499c
RR
31Push a patch or a range of patches to the top even if applied. The
32necessary pop and push operations will be performed to accomplish
1ab20f6c
CM
33this. The '--series' option can be used to rearrange the (top) patches
34as specified by the given series file (or the standard input)."""
d98a499c 35
6c8a90e1
KH
36args = [argparse.patch_range(argparse.applied_patches,
37 argparse.unapplied_patches)]
575bbdae 38options = [
5a1bab1a
CM
39 opt('-s', '--series', metavar = 'FILE',
40 short = 'Rearrange according to the series FILE')
41 ] + argparse.keep_option()
575bbdae 42
5a1bab1a 43directory = common.DirectoryHasRepositoryLib()
d98a499c
RR
44
45def func(parser, options, args):
5a1bab1a 46 """Reorder patches to make the named patch the topmost one.
d98a499c 47 """
5a1bab1a
CM
48 if options.series and args:
49 parser.error('<patches> cannot be used with --series')
50 elif not options.series and not args:
d98a499c
RR
51 parser.error('incorrect number of arguments')
52
5a1bab1a 53 stack = directory.repository.current_stack
d98a499c 54
1ab20f6c 55 if options.series:
5a1bab1a 56 if options.series == '-':
1ab20f6c 57 f = sys.stdin
5a1bab1a 58 else:
cef5deb4 59 f = file(options.series)
1ab20f6c
CM
60
61 patches = []
62 for line in f:
63 patch = re.sub('#.*$', '', line).strip()
64 if patch:
65 patches.append(patch)
66 else:
5a1bab1a
CM
67 patches = common.parse_patches(args, stack.patchorder.all)
68
69 if not patches:
70 raise common.CmdException('No patches to float')
71
72 applied = [p for p in stack.patchorder.applied if p not in patches] + \
73 patches
74 unapplied = [p for p in stack.patchorder.unapplied if not p in patches]
5a1bab1a
CM
75
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)
80
81 try:
d44708ef 82 trans.reorder_patches(applied, unapplied, iw = iw)
5a1bab1a
CM
83 except transaction.TransactionHalted:
84 pass
85 return trans.run(iw)