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 * | |
24 | from stgit import stack, git | |
25 | ||
26 | ||
6b1e0111 CM |
27 | help = 'push one or more patches onto of the stack' |
28 | usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>] | |
26aab5b0 | 29 | |
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 CM |
40 | |
41 | options = [make_option('-a', '--all', | |
42 | help = 'push all the unapplied patches', | |
43 | action = 'store_true'), | |
44 | make_option('-n', '--number', type = 'int', | |
45 | help = 'push the specified number of patches'), | |
fcee87cf CM |
46 | make_option('--reverse', |
47 | help = 'push the patches in reverse order', | |
48 | action = 'store_true'), | |
1777d8cd CM |
49 | make_option('-m', '--merged', |
50 | help = 'check for patches merged upstream', | |
51 | action = 'store_true'), | |
fcee87cf | 52 | make_option('--undo', |
6b1e0111 | 53 | help = 'undo the last patch pushing', |
fcee87cf CM |
54 | action = 'store_true')] |
55 | ||
56 | ||
57 | def func(parser, options, args): | |
58 | """Pushes the given patch or all onto the series | |
59 | """ | |
bca12bd1 | 60 | |
fcee87cf CM |
61 | # If --undo is passed, do the work and exit |
62 | if options.undo: | |
63 | patch = crt_series.get_current() | |
64 | if not patch: | |
65 | raise CmdException, 'No patch to undo' | |
66 | ||
67 | print 'Undoing the "%s" push...' % patch, | |
68 | sys.stdout.flush() | |
69 | resolved_all() | |
a5bbc44d PBG |
70 | if crt_series.undo_push(): |
71 | print 'done' | |
72 | else: | |
73 | print 'done (patch unchanged)' | |
fcee87cf CM |
74 | print_crt_patch() |
75 | ||
76 | return | |
77 | ||
78 | check_local_changes() | |
79 | check_conflicts() | |
80 | check_head_top_equal() | |
81 | ||
82 | unapplied = crt_series.get_unapplied() | |
83 | if not unapplied: | |
84 | raise CmdException, 'No more patches to push' | |
85 | ||
6b1e0111 | 86 | if options.number: |
fcee87cf CM |
87 | patches = unapplied[:options.number] |
88 | elif options.all: | |
89 | patches = unapplied | |
90 | elif len(args) == 0: | |
91 | patches = [unapplied[0]] | |
fcee87cf | 92 | else: |
6b1e0111 | 93 | patches = parse_patches(args, unapplied) |
fcee87cf CM |
94 | |
95 | if patches == []: | |
96 | raise CmdException, 'No patches to push' | |
97 | ||
98 | if options.reverse: | |
99 | patches.reverse() | |
100 | ||
1777d8cd | 101 | push_patches(patches, options.merged) |
fcee87cf | 102 | |
fcee87cf | 103 | print_crt_patch() |