@@ -15,6 +15,7 @@ static const char * const push_usage[] = {
1515};
1616
1717static int thin ;
18+ static int deleterefs ;
1819static const char * receivepack ;
1920
2021static const char * * refspec ;
@@ -39,11 +40,24 @@ static void set_refspecs(const char **refs, int nr)
3940 if (nr <= ++ i )
4041 die ("tag shorthand without <tag>" );
4142 len = strlen (refs [i ]) + 11 ;
42- tag = xmalloc (len );
43- strcpy (tag , "refs/tags/" );
43+ if (deleterefs ) {
44+ tag = xmalloc (len + 1 );
45+ strcpy (tag , ":refs/tags/" );
46+ } else {
47+ tag = xmalloc (len );
48+ strcpy (tag , "refs/tags/" );
49+ }
4450 strcat (tag , refs [i ]);
4551 ref = tag ;
46- }
52+ } else if (deleterefs && !strchr (ref , ':' )) {
53+ char * delref ;
54+ int len = strlen (ref )+ 1 ;
55+ delref = xmalloc (len );
56+ strcpy (delref , ":" );
57+ strcat (delref , ref );
58+ ref = delref ;
59+ } else if (deleterefs )
60+ die ("--delete only accepts plain target ref names" );
4761 add_refspec (ref );
4862 }
4963}
@@ -196,6 +210,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
196210 OPT_BIT ( 0 , "all" , & flags , "push all refs" , TRANSPORT_PUSH_ALL ),
197211 OPT_BIT ( 0 , "mirror" , & flags , "mirror all refs" ,
198212 (TRANSPORT_PUSH_MIRROR |TRANSPORT_PUSH_FORCE )),
213+ OPT_BOOLEAN ( 0 , "delete" , & deleterefs , "delete refs" ),
199214 OPT_BOOLEAN ( 0 , "tags" , & tags , "push tags (can't be used with --all or --mirror)" ),
200215 OPT_BIT ('n' , "dry-run" , & flags , "dry run" , TRANSPORT_PUSH_DRY_RUN ),
201216 OPT_BIT ( 0 , "porcelain" , & flags , "machine-readable output" , TRANSPORT_PUSH_PORCELAIN ),
@@ -209,6 +224,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
209224 git_config (git_default_config , NULL );
210225 argc = parse_options (argc , argv , prefix , options , push_usage , 0 );
211226
227+ if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR ))))
228+ die ("--delete is incompatible with --all, --mirror and --tags" );
229+ if (deleterefs && argc < 2 )
230+ die ("--delete doesn't make sense without any refs" );
231+
212232 if (tags )
213233 add_refspec ("refs/tags/*" );
214234
0 commit comments