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 | from stgit.config import config | |
26 | ||
27 | ||
28 | help = 'generate a new commit for the current patch' | |
026c0689 | 29 | usage = """%prog [options] [<files...>] |
26aab5b0 CM |
30 | |
31 | Include the latest tree changes in the current patch. This command | |
32 | generates a new GIT commit object with the patch details, the previous | |
33 | one no longer being visible. The patch attributes like author, | |
34 | committer and description can be changed with the command line | |
35 | options. The '--force' option is useful when a commit object was | |
36 | created with a different tool but the changes need to be included in | |
37 | the current patch.""" | |
fcee87cf CM |
38 | |
39 | options = [make_option('-f', '--force', | |
40 | help = 'force the refresh even if HEAD and '\ | |
41 | 'top differ', | |
42 | action = 'store_true'), | |
43 | make_option('-e', '--edit', | |
44 | help = 'invoke an editor for the patch '\ | |
45 | 'description', | |
46 | action = 'store_true'), | |
6ad48e48 PBG |
47 | make_option('-s', '--showpatch', |
48 | help = 'show the patch content in the editor buffer', | |
49 | action = 'store_true'), | |
6ee70d6b CM |
50 | make_option('--update', |
51 | help = 'only update the current patch files', | |
52 | action = 'store_true'), | |
f80bef49 CM |
53 | make_option('--undo', |
54 | help = 'revert the commit generated by the last refresh', | |
55 | action = 'store_true'), | |
fcee87cf CM |
56 | make_option('-m', '--message', |
57 | help = 'use MESSAGE as the patch ' \ | |
58 | 'description'), | |
eff17c6b CM |
59 | make_option('-a', '--annotate', metavar = 'NOTE', |
60 | help = 'annotate the patch log entry'), | |
61 | make_option('--author', metavar = '"NAME <EMAIL>"', | |
19cd0a8f | 62 | help = 'use "NAME <EMAIL>" as the author details'), |
fcee87cf CM |
63 | make_option('--authname', |
64 | help = 'use AUTHNAME as the author name'), | |
65 | make_option('--authemail', | |
66 | help = 'use AUTHEMAIL as the author e-mail'), | |
67 | make_option('--authdate', | |
68 | help = 'use AUTHDATE as the author date'), | |
69 | make_option('--commname', | |
70 | help = 'use COMMNAME as the committer name'), | |
71 | make_option('--commemail', | |
72 | help = 'use COMMEMAIL as the committer ' \ | |
c40c3500 | 73 | 'e-mail'), |
42fc7623 YD |
74 | make_option('-p', '--patch', |
75 | help = 'refresh (applied) PATCH instead of the top one'), | |
c40c3500 CM |
76 | make_option('--sign', |
77 | help = 'add Signed-off-by line', | |
78 | action = 'store_true'), | |
79 | make_option('--ack', | |
80 | help = 'add Acked-by line', | |
81 | action = 'store_true')] | |
fcee87cf CM |
82 | |
83 | ||
84 | def func(parser, options, args): | |
c73e63b7 | 85 | autoresolved = config.get('stgit.autoresolved') |
fcee87cf CM |
86 | |
87 | if autoresolved != 'yes': | |
88 | check_conflicts() | |
89 | ||
42fc7623 | 90 | if options.patch: |
6ee70d6b | 91 | if args or options.update: |
42fc7623 YD |
92 | raise CmdException, \ |
93 | 'Only full refresh is available with the --patch option' | |
94 | patch = options.patch | |
95 | if not crt_series.patch_applied(patch): | |
96 | raise CmdException, 'Patches "%s" not applied' % patch | |
97 | else: | |
98 | patch = crt_series.get_current() | |
99 | if not patch: | |
100 | raise CmdException, 'No patches applied' | |
fcee87cf CM |
101 | |
102 | if not options.force: | |
103 | check_head_top_equal() | |
104 | ||
f80bef49 | 105 | if options.undo: |
27ac2b7e | 106 | out.start('Undoing the refresh of "%s"' % patch) |
f80bef49 | 107 | crt_series.undo_refresh() |
27ac2b7e | 108 | out.done() |
f80bef49 CM |
109 | return |
110 | ||
19cd0a8f CM |
111 | if options.author: |
112 | options.authname, options.authemail = name_email(options.author) | |
113 | ||
c40c3500 CM |
114 | if options.sign: |
115 | sign_str = 'Signed-off-by' | |
bc7ba6e9 YD |
116 | if options.ack: |
117 | raise CmdException, '--ack and --sign were both specified' | |
c40c3500 CM |
118 | elif options.ack: |
119 | sign_str = 'Acked-by' | |
120 | else: | |
121 | sign_str = None | |
122 | ||
6ee70d6b CM |
123 | files = [x[1] for x in git.tree_status(verbose = True)] |
124 | if args: | |
125 | files = [f for f in files if f in args] | |
126 | ||
127 | if files or not crt_series.head_top_equal() \ | |
fcee87cf CM |
128 | or options.edit or options.message \ |
129 | or options.authname or options.authemail or options.authdate \ | |
c40c3500 | 130 | or options.commname or options.commemail \ |
eff17c6b | 131 | or options.sign or options.ack or options.annotate: |
42fc7623 YD |
132 | |
133 | if options.patch: | |
134 | applied = crt_series.get_applied() | |
135 | between = applied[:applied.index(patch):-1] | |
136 | pop_patches(between, keep = True) | |
6ee70d6b CM |
137 | elif options.update: |
138 | rev1 = git_id('//bottom') | |
139 | rev2 = git_id('//top') | |
140 | patch_files = git.barefiles(rev1, rev2).split('\n') | |
141 | files = [f for f in files if f in patch_files] | |
142 | if not files: | |
143 | out.info('No modified files for updating patch "%s"' % patch) | |
144 | return | |
42fc7623 | 145 | |
27ac2b7e | 146 | out.start('Refreshing patch "%s"' % patch) |
fcee87cf CM |
147 | |
148 | if autoresolved == 'yes': | |
149 | resolved_all() | |
6ee70d6b | 150 | crt_series.refresh_patch(files = files, |
026c0689 | 151 | message = options.message, |
fcee87cf | 152 | edit = options.edit, |
6ad48e48 | 153 | show_patch = options.showpatch, |
fcee87cf CM |
154 | author_name = options.authname, |
155 | author_email = options.authemail, | |
156 | author_date = options.authdate, | |
157 | committer_name = options.commname, | |
f80bef49 | 158 | committer_email = options.commemail, |
eff17c6b CM |
159 | backup = True, sign_str = sign_str, |
160 | notes = options.annotate) | |
fcee87cf | 161 | |
dc4e5946 | 162 | if crt_series.empty_patch(patch): |
27ac2b7e | 163 | out.done('empty patch') |
dc4e5946 | 164 | else: |
27ac2b7e | 165 | out.done() |
7c53fcf5 | 166 | |
42fc7623 YD |
167 | if options.patch: |
168 | between.reverse() | |
169 | push_patches(between) | |
fcee87cf | 170 | else: |
27ac2b7e | 171 | out.info('Patch "%s" is already up to date' % patch) |