Merge branch 'stable'
[stgit] / stgit / commands / push.py
1
2 __copyright__ = """
3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
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 stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit.utils import *
23 from stgit.out import *
24 from stgit import argparse, stack, git
25
26 help = 'Push one or more patches onto the stack'
27 kind = 'stack'
28 usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
29 description = """
30 Push one or more patches (defaulting to the first unapplied one) onto
31 the stack. The 'push' operation allows patch reordering by commuting
32 them with the three-way merge algorithm. If there are conflicts while
33 pushing a patch, those conflicts are written to the work tree, and the
34 command halts. Conflicts raised during the push operation have to be
35 fixed and the 'resolved' command run (alternatively, you may undo the
36 conflicting push with 'stg undo').
37
38 The command also notifies when the patch becomes empty (fully merged
39 upstream) or is modified (three-way merged) by the 'push' operation."""
40
41 args = [argparse.patch_range(argparse.unapplied_patches)]
42 options = [
43 opt('-a', '--all', action = 'store_true',
44 short = 'Push all the unapplied patches'),
45 opt('-n', '--number', type = 'int',
46 short = 'Push the specified number of patches'),
47 opt('--reverse', action = 'store_true',
48 short = 'Push the patches in reverse order'),
49 opt('-m', '--merged', action = 'store_true',
50 short = 'Check for patches merged upstream')]
51
52 directory = DirectoryGotoToplevel(log = True)
53
54 def func(parser, options, args):
55 """Pushes the given patch or all onto the series
56 """
57
58 check_local_changes()
59 check_conflicts()
60 check_head_top_equal(crt_series)
61
62 unapplied = crt_series.get_unapplied()
63 if not unapplied:
64 raise CmdException, 'No more patches to push'
65
66 if options.number:
67 patches = unapplied[:options.number]
68 elif options.all:
69 patches = unapplied
70 elif len(args) == 0:
71 patches = [unapplied[0]]
72 else:
73 patches = parse_patches(args, unapplied)
74
75 if patches == []:
76 raise CmdException, 'No patches to push'
77
78 if options.reverse:
79 patches.reverse()
80
81 push_patches(crt_series, patches, options.merged)
82
83 print_crt_patch(crt_series)