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