Add --sign and --ack options to "stg import"
[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 *
5e888f30 24from stgit.out import *
fcee87cf
CM
25from stgit import stack, git
26from stgit.config import config
27
28
29help = 'generate a new commit for the current patch'
026c0689 30usage = """%prog [options] [<files...>]
26aab5b0
CM
31
32Include the latest tree changes in the current patch. This command
33generates a new GIT commit object with the patch details, the previous
34one no longer being visible. The patch attributes like author,
35committer and description can be changed with the command line
36options. The '--force' option is useful when a commit object was
37created with a different tool but the changes need to be included in
38the current patch."""
fcee87cf
CM
39
40options = [make_option('-f', '--force',
41 help = 'force the refresh even if HEAD and '\
42 'top differ',
43 action = 'store_true'),
44 make_option('-e', '--edit',
45 help = 'invoke an editor for the patch '\
46 'description',
47 action = 'store_true'),
6ad48e48
PBG
48 make_option('-s', '--showpatch',
49 help = 'show the patch content in the editor buffer',
50 action = 'store_true'),
6ee70d6b
CM
51 make_option('--update',
52 help = 'only update the current patch files',
53 action = 'store_true'),
f80bef49
CM
54 make_option('--undo',
55 help = 'revert the commit generated by the last refresh',
56 action = 'store_true'),
fcee87cf
CM
57 make_option('-m', '--message',
58 help = 'use MESSAGE as the patch ' \
59 'description'),
eff17c6b
CM
60 make_option('-a', '--annotate', metavar = 'NOTE',
61 help = 'annotate the patch log entry'),
62 make_option('--author', metavar = '"NAME <EMAIL>"',
19cd0a8f 63 help = 'use "NAME <EMAIL>" as the author details'),
fcee87cf
CM
64 make_option('--authname',
65 help = 'use AUTHNAME as the author name'),
66 make_option('--authemail',
67 help = 'use AUTHEMAIL as the author e-mail'),
68 make_option('--authdate',
69 help = 'use AUTHDATE as the author date'),
70 make_option('--commname',
71 help = 'use COMMNAME as the committer name'),
72 make_option('--commemail',
73 help = 'use COMMEMAIL as the committer ' \
c40c3500 74 'e-mail'),
42fc7623 75 make_option('-p', '--patch',
130df01a
KH
76 help = 'refresh (applied) PATCH instead of the top one')
77 ] + make_sign_options()
fcee87cf
CM
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 85 if options.patch:
6ee70d6b 86 if args or options.update:
42fc7623
YD
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
14c88aa0 109 files = [path for (stat,path) in git.tree_status(verbose = True)]
6ee70d6b
CM
110 if args:
111 files = [f for f in files if f in args]
112
113 if files or not crt_series.head_top_equal() \
fcee87cf
CM
114 or options.edit or options.message \
115 or options.authname or options.authemail or options.authdate \
130df01a 116 or options.commname or options.commemail or options.sign_str:
42fc7623
YD
117
118 if options.patch:
119 applied = crt_series.get_applied()
120 between = applied[:applied.index(patch):-1]
121 pop_patches(between, keep = True)
6ee70d6b
CM
122 elif options.update:
123 rev1 = git_id('//bottom')
124 rev2 = git_id('//top')
125 patch_files = git.barefiles(rev1, rev2).split('\n')
126 files = [f for f in files if f in patch_files]
127 if not files:
128 out.info('No modified files for updating patch "%s"' % patch)
129 return
42fc7623 130
27ac2b7e 131 out.start('Refreshing patch "%s"' % patch)
fcee87cf
CM
132
133 if autoresolved == 'yes':
134 resolved_all()
6ee70d6b 135 crt_series.refresh_patch(files = files,
026c0689 136 message = options.message,
fcee87cf 137 edit = options.edit,
6ad48e48 138 show_patch = options.showpatch,
fcee87cf
CM
139 author_name = options.authname,
140 author_email = options.authemail,
141 author_date = options.authdate,
142 committer_name = options.commname,
f80bef49 143 committer_email = options.commemail,
130df01a 144 backup = True, sign_str = options.sign_str,
eff17c6b 145 notes = options.annotate)
fcee87cf 146
dc4e5946 147 if crt_series.empty_patch(patch):
27ac2b7e 148 out.done('empty patch')
dc4e5946 149 else:
27ac2b7e 150 out.done()
7c53fcf5 151
42fc7623
YD
152 if options.patch:
153 between.reverse()
154 push_patches(between)
ea7634bb
CM
155 elif options.annotate:
156 # only annotate the top log entry as there is no need to
157 # refresh the patch and generate a full commit
158 crt_series.log_patch(crt_series.get_patch(patch), None,
159 notes = options.annotate)
fcee87cf 160 else:
27ac2b7e 161 out.info('Patch "%s" is already up to date' % patch)