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