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