chiark / gitweb /
2a18ebceb20bced0b52c980bda63f428bb140ba5
[stgit] / stgit / commands / sink.py
1
2 __copyright__ = """
3 Copyright (C) 2007, Yann Dirson <ydirson@altern.org>
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
19 import sys, os
20 from optparse import OptionParser, make_option
21
22 from stgit.commands.common import *
23 from stgit.utils import *
24 from stgit import stack, git
25
26
27 help = 'send patches deeper down the stack'
28 usage = """%prog [-t <target patch>] [-n] [<patches>]
29
30 Pop all patches (or all patches including <target patch>), then
31 push the specified <patches> (the current patch by default), and
32 then push back into place the formerly-applied patches (unless -n
33 is also given)."""
34
35 options = [make_option('-n', '--nopush',
36                        help = 'do not push the patches back after sinking',
37                        action = 'store_true'),
38            make_option('-t', '--to', metavar = 'TARGET',
39                        help = 'sink patches below TARGET patch')]
40
41 def func(parser, options, args):
42     """Sink patches down the stack.
43     """
44
45     check_local_changes()
46     check_conflicts()
47     check_head_top_equal()
48
49     oldapplied = crt_series.get_applied()
50     unapplied = crt_series.get_unapplied()
51     all = unapplied + oldapplied
52
53     if options.to and not options.to in oldapplied:
54         raise CmdException('Cannot sink below %s, since it is not applied'
55                            % options.to)
56
57     if len(args) > 0:
58         patches = parse_patches(args, all)
59     else:
60         patches = [ crt_series.get_current() ]
61
62     crt_series.pop_patch(options.to or oldapplied[0])
63     push_patches(patches)
64
65     if not options.nopush:
66         newapplied = crt_series.get_applied()
67         def not_reapplied_yet(p):
68             return not p in newapplied
69         push_patches(filter(not_reapplied_yet, oldapplied))