Commit | Line | Data |
---|---|---|
fcee87cf CM |
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 optparse import OptionParser, make_option | |
21 | ||
22 | from stgit.commands.common import * | |
23 | from stgit.utils import * | |
5e888f30 | 24 | from stgit.out import * |
fcee87cf CM |
25 | from stgit import stack, git |
26 | ||
27 | ||
6b1e0111 CM |
28 | help = 'push one or more patches onto of the stack' |
29 | usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>] | |
26aab5b0 | 30 | |
6b1e0111 CM |
31 | Push one or more patches (defaulting to the first unapplied one) onto |
32 | the stack. The 'push' operation allows patch reordering by commuting | |
33 | them with the three-way merge algorithm. If the result of the 'push' | |
34 | operation is not acceptable or if there are too many conflicts, the | |
35 | '--undo' option can be used to revert the last pushed patch. Conflicts | |
36 | raised during the push operation have to be fixed and the 'resolved' | |
37 | command run. | |
26aab5b0 | 38 | |
718a5e51 CM |
39 | The command also notifies when the patch becomes empty (fully merged |
40 | upstream) or is modified (three-way merged) by the 'push' operation.""" | |
fcee87cf | 41 | |
89d889f4 | 42 | directory = DirectoryGotoToplevel() |
fcee87cf CM |
43 | options = [make_option('-a', '--all', |
44 | help = 'push all the unapplied patches', | |
45 | action = 'store_true'), | |
46 | make_option('-n', '--number', type = 'int', | |
47 | help = 'push the specified number of patches'), | |
fcee87cf CM |
48 | make_option('--reverse', |
49 | help = 'push the patches in reverse order', | |
50 | action = 'store_true'), | |
1777d8cd CM |
51 | make_option('-m', '--merged', |
52 | help = 'check for patches merged upstream', | |
53 | action = 'store_true'), | |
fcee87cf | 54 | make_option('--undo', |
6b1e0111 | 55 | help = 'undo the last patch pushing', |
fcee87cf CM |
56 | action = 'store_true')] |
57 | ||
58 | ||
59 | def func(parser, options, args): | |
60 | """Pushes the given patch or all onto the series | |
61 | """ | |
bca12bd1 | 62 | |
fcee87cf CM |
63 | # If --undo is passed, do the work and exit |
64 | if options.undo: | |
65 | patch = crt_series.get_current() | |
66 | if not patch: | |
67 | raise CmdException, 'No patch to undo' | |
68 | ||
27ac2b7e | 69 | out.start('Undoing push of "%s"' % patch) |
53f76663 | 70 | resolved_all() |
a5bbc44d | 71 | if crt_series.undo_push(): |
27ac2b7e | 72 | out.done() |
a5bbc44d | 73 | else: |
27ac2b7e | 74 | out.done('patch unchanged') |
6972fd6b | 75 | print_crt_patch(crt_series) |
fcee87cf CM |
76 | |
77 | return | |
78 | ||
53f76663 CM |
79 | check_local_changes() |
80 | check_conflicts() | |
6972fd6b | 81 | check_head_top_equal(crt_series) |
53f76663 | 82 | |
fcee87cf CM |
83 | unapplied = crt_series.get_unapplied() |
84 | if not unapplied: | |
85 | raise CmdException, 'No more patches to push' | |
86 | ||
6b1e0111 | 87 | if options.number: |
fcee87cf CM |
88 | patches = unapplied[:options.number] |
89 | elif options.all: | |
90 | patches = unapplied | |
91 | elif len(args) == 0: | |
92 | patches = [unapplied[0]] | |
fcee87cf | 93 | else: |
6b1e0111 | 94 | patches = parse_patches(args, unapplied) |
fcee87cf CM |
95 | |
96 | if patches == []: | |
97 | raise CmdException, 'No patches to push' | |
98 | ||
99 | if options.reverse: | |
100 | patches.reverse() | |
101 | ||
6972fd6b | 102 | push_patches(crt_series, patches, options.merged) |
fcee87cf | 103 | |
6972fd6b | 104 | print_crt_patch(crt_series) |