@@ -246,9 +246,37 @@ static int git_tag_config(const char *var, const char *value)
246246 return git_default_config (var , value );
247247}
248248
249+ static void write_tag_body (int fd , const unsigned char * sha1 )
250+ {
251+ unsigned long size ;
252+ enum object_type type ;
253+ char * buf , * sp , * eob ;
254+ size_t len ;
255+
256+ buf = read_sha1_file (sha1 , & type , & size );
257+ if (!buf )
258+ return ;
259+ /* skip header */
260+ sp = strstr (buf , "\n\n" );
261+
262+ if (!sp || !size || type != OBJ_TAG ) {
263+ free (buf );
264+ return ;
265+ }
266+ sp += 2 ; /* skip the 2 LFs */
267+ eob = strstr (sp , "\n" PGP_SIGNATURE "\n" );
268+ if (eob )
269+ len = eob - sp ;
270+ else
271+ len = buf + size - sp ;
272+ write_or_die (fd , sp , len );
273+
274+ free (buf );
275+ }
276+
249277static void create_tag (const unsigned char * object , const char * tag ,
250278 struct strbuf * buf , int message , int sign ,
251- unsigned char * result )
279+ unsigned char * prev , unsigned char * result )
252280{
253281 enum object_type type ;
254282 char header_buf [1024 ];
@@ -281,7 +309,11 @@ static void create_tag(const unsigned char *object, const char *tag,
281309 if (fd < 0 )
282310 die ("could not create file '%s': %s" ,
283311 path , strerror (errno ));
284- write_or_die (fd , tag_template , strlen (tag_template ));
312+
313+ if (!is_null_sha1 (prev ))
314+ write_tag_body (fd , prev );
315+ else
316+ write_or_die (fd , tag_template , strlen (tag_template ));
285317 close (fd );
286318
287319 launch_editor (path , buf );
@@ -418,7 +450,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
418450 die ("tag '%s' already exists" , tag );
419451
420452 if (annotate )
421- create_tag (object , tag , & buf , message , sign , object );
453+ create_tag (object , tag , & buf , message , sign , prev , object );
422454
423455 lock = lock_any_ref_for_update (ref , prev , 0 );
424456 if (!lock )
0 commit comments