@@ -15,6 +15,7 @@ static const char * const push_usage[] = {
15
15
};
16
16
17
17
static int thin ;
18
+ static int deleterefs ;
18
19
static const char * receivepack ;
19
20
20
21
static const char * * refspec ;
@@ -39,11 +40,24 @@ static void set_refspecs(const char **refs, int nr)
39
40
if (nr <= ++ i )
40
41
die ("tag shorthand without <tag>" );
41
42
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
+ }
44
50
strcat (tag , refs [i ]);
45
51
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" );
47
61
add_refspec (ref );
48
62
}
49
63
}
@@ -196,6 +210,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
196
210
OPT_BIT ( 0 , "all" , & flags , "push all refs" , TRANSPORT_PUSH_ALL ),
197
211
OPT_BIT ( 0 , "mirror" , & flags , "mirror all refs" ,
198
212
(TRANSPORT_PUSH_MIRROR |TRANSPORT_PUSH_FORCE )),
213
+ OPT_BOOLEAN ( 0 , "delete" , & deleterefs , "delete refs" ),
199
214
OPT_BOOLEAN ( 0 , "tags" , & tags , "push tags (can't be used with --all or --mirror)" ),
200
215
OPT_BIT ('n' , "dry-run" , & flags , "dry run" , TRANSPORT_PUSH_DRY_RUN ),
201
216
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)
209
224
git_config (git_default_config , NULL );
210
225
argc = parse_options (argc , argv , prefix , options , push_usage , 0 );
211
226
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
+
212
232
if (tags )
213
233
add_refspec ("refs/tags/*" );
214
234
0 commit comments