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 optparse
import OptionParser
, make_option
22 from stgit
.commands
.common
import *
23 from stgit
.utils
import *
24 from stgit
import stack
, git
27 help = 'push a patch on top of the series'
28 usage
= '%prog [options] [<name>]'
30 options
= [make_option('-a', '--all',
31 help = 'push all the unapplied patches',
32 action
= 'store_true'),
33 make_option('-n', '--number', type = 'int',
34 help = 'push the specified number of patches'),
35 make_option('-t', '--to', metavar
= 'PATCH1[:PATCH2]',
36 help = 'push all patches to PATCH1 or between '
38 make_option('--reverse',
39 help = 'push the patches in reverse order',
40 action
= 'store_true'),
42 help = 'undo the last push operation',
43 action
= 'store_true')]
46 def func(parser
, options
, args
):
47 """Pushes the given patch or all onto the series
49 # If --undo is passed, do the work and exit
51 patch
= crt_series
.get_current()
53 raise CmdException
, 'No patch to undo'
55 print 'Undoing the "%s" push...' % patch
,
58 crt_series
.undo_push()
66 check_head_top_equal()
68 unapplied
= crt_series
.get_unapplied()
70 raise CmdException
, 'No more patches to push'
73 boundaries
= options
.to
.split(':')
74 if len(boundaries
) == 1:
75 if boundaries
[0] not in unapplied
:
76 raise CmdException
, 'Patch "%s" not unapplied' % boundaries
[0]
77 patches
= unapplied
[:unapplied
.index(boundaries
[0])+1]
78 elif len(boundaries
) == 2:
79 if boundaries
[0] not in unapplied
:
80 raise CmdException
, 'Patch "%s" not unapplied' % boundaries
[0]
81 if boundaries
[1] not in unapplied
:
82 raise CmdException
, 'Patch "%s" not unapplied' % boundaries
[1]
83 lb
= unapplied
.index(boundaries
[0])
84 hb
= unapplied
.index(boundaries
[1])
86 raise CmdException
, 'Patch "%s" after "%s"' \
87 %
(boundaries
[0], boundaries
[1])
88 patches
= unapplied
[lb
:hb
+1]
90 raise CmdException
, 'incorrect parameters to "--to"'
92 patches
= unapplied
[:options
.number
]
96 patches
= [unapplied
[0]]
100 parser
.error('incorrect number of arguments')
103 raise CmdException
, 'No patches to push'
109 print 'Pushing patch "%s"...' % p
,
112 crt_series
.push_patch(p
)
114 if crt_series
.empty_patch(p
):
115 print 'done (empty patch)'