@@ -194,6 +194,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
194194
195195struct create_tag_options {
196196 unsigned int message_given :1 ;
197+ unsigned int use_editor :1 ;
197198 unsigned int sign ;
198199 enum {
199200 CLEANUP_NONE ,
@@ -224,7 +225,7 @@ static void create_tag(const struct object_id *object, const char *tag,
224225 tag ,
225226 git_committer_info (IDENT_STRICT ));
226227
227- if (!opt -> message_given ) {
228+ if (!opt -> message_given || opt -> use_editor ) {
228229 int fd ;
229230
230231 /* write the template message before editing: */
@@ -233,7 +234,10 @@ static void create_tag(const struct object_id *object, const char *tag,
233234 if (fd < 0 )
234235 die_errno (_ ("could not create file '%s'" ), path );
235236
236- if (!is_null_oid (prev )) {
237+ if (opt -> message_given ) {
238+ write_or_die (fd , buf -> buf , buf -> len );
239+ strbuf_reset (buf );
240+ } else if (!is_null_oid (prev )) {
237241 write_tag_body (fd , prev );
238242 } else {
239243 struct strbuf buf = STRBUF_INIT ;
@@ -372,6 +376,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
372376 static struct ref_sorting * sorting = NULL , * * sorting_tail = & sorting ;
373377 struct ref_format format = REF_FORMAT_INIT ;
374378 int icase = 0 ;
379+ int edit_flag = 0 ;
375380 struct option options [] = {
376381 OPT_CMDMODE ('l' , "list" , & cmdmode , N_ ("list tag names" ), 'l' ),
377382 { OPTION_INTEGER , 'n' , NULL , & filter .lines , N_ ("n" ),
@@ -386,6 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
386391 OPT_CALLBACK ('m' , "message" , & msg , N_ ("message" ),
387392 N_ ("tag message" ), parse_msg_arg ),
388393 OPT_FILENAME ('F' , "file" , & msgfile , N_ ("read message from file" )),
394+ OPT_BOOL ('e' , "edit" , & edit_flag , N_ ("force edit of tag message" )),
389395 OPT_BOOL ('s' , "sign" , & opt .sign , N_ ("annotated and GPG-signed tag" )),
390396 OPT_STRING (0 , "cleanup" , & cleanup_arg , N_ ("mode" ),
391397 N_ ("how to strip spaces and #comments from message" )),
@@ -524,6 +530,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
524530 die (_ ("tag '%s' already exists" ), tag );
525531
526532 opt .message_given = msg .given || msgfile ;
533+ opt .use_editor = edit_flag ;
527534
528535 if (!cleanup_arg || !strcmp (cleanup_arg , "strip" ))
529536 opt .cleanup_mode = CLEANUP_ALL ;
0 commit comments