@@ -271,11 +271,10 @@ static const char message_advice_nested_tag[] =
271
271
static void create_tag (const struct object_id * object , const char * object_ref ,
272
272
const char * tag ,
273
273
struct strbuf * buf , struct create_tag_options * opt ,
274
- struct object_id * prev , struct object_id * result )
274
+ struct object_id * prev , struct object_id * result , char * path )
275
275
{
276
276
enum object_type type ;
277
277
struct strbuf header = STRBUF_INIT ;
278
- char * path = NULL ;
279
278
280
279
type = oid_object_info (the_repository , object , NULL );
281
280
if (type <= OBJ_NONE )
@@ -299,7 +298,6 @@ static void create_tag(const struct object_id *object, const char *object_ref,
299
298
int fd ;
300
299
301
300
/* write the template message before editing: */
302
- path = git_pathdup ("TAG_EDITMSG" );
303
301
fd = xopen (path , O_CREAT | O_TRUNC | O_WRONLY , 0600 );
304
302
305
303
if (opt -> message_given ) {
@@ -341,10 +339,6 @@ static void create_tag(const struct object_id *object, const char *object_ref,
341
339
path );
342
340
exit (128 );
343
341
}
344
- if (path ) {
345
- unlink_or_warn (path );
346
- free (path );
347
- }
348
342
}
349
343
350
344
static void create_reflog_msg (const struct object_id * oid , struct strbuf * sb )
@@ -495,6 +489,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
495
489
};
496
490
int ret = 0 ;
497
491
const char * only_in_list = NULL ;
492
+ char * path = NULL ;
498
493
499
494
setup_ref_filter_porcelain_msg ();
500
495
@@ -629,16 +624,27 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
629
624
if (create_tag_object ) {
630
625
if (force_sign_annotate && !annotate )
631
626
opt .sign = 1 ;
632
- create_tag (& object , object_ref , tag , & buf , & opt , & prev , & object );
627
+ path = git_pathdup ("TAG_EDITMSG" );
628
+ create_tag (& object , object_ref , tag , & buf , & opt , & prev , & object ,
629
+ path );
633
630
}
634
631
635
632
transaction = ref_transaction_begin (& err );
636
633
if (!transaction ||
637
634
ref_transaction_update (transaction , ref .buf , & object , & prev ,
638
635
create_reflog ? REF_FORCE_CREATE_REFLOG : 0 ,
639
636
reflog_msg .buf , & err ) ||
640
- ref_transaction_commit (transaction , & err ))
637
+ ref_transaction_commit (transaction , & err )) {
638
+ if (path )
639
+ fprintf (stderr ,
640
+ _ ("The tag message has been left in %s\n" ),
641
+ path );
641
642
die ("%s" , err .buf );
643
+ }
644
+ if (path ) {
645
+ unlink_or_warn (path );
646
+ free (path );
647
+ }
642
648
ref_transaction_free (transaction );
643
649
if (force && !is_null_oid (& prev ) && !oideq (& prev , & object ))
644
650
printf (_ ("Updated tag '%s' (was %s)\n" ), tag ,
0 commit comments