@@ -298,7 +298,7 @@ static int add_known_remote(struct remote *remote, void *cb_data)
298
298
299
299
struct branches_for_remote {
300
300
struct remote * remote ;
301
- struct string_list * branches ;
301
+ struct string_list * branches , * skipped ;
302
302
struct known_remotes * keep ;
303
303
};
304
304
@@ -323,6 +323,16 @@ static int add_branch_for_removal(const char *refname,
323
323
return 0 ;
324
324
}
325
325
326
+ /* don't delete non-remote refs */
327
+ if (prefixcmp (refname , "refs/remotes" )) {
328
+ /* advise user how to delete local branches */
329
+ if (!prefixcmp (refname , "refs/heads/" ))
330
+ string_list_append (abbrev_branch (refname ),
331
+ branches -> skipped );
332
+ /* silently skip over other non-remote refs */
333
+ return 0 ;
334
+ }
335
+
326
336
/* make sure that symrefs are deleted */
327
337
if (flags & REF_ISSYMREF )
328
338
return unlink (git_path ("%s" , refname ));
@@ -542,8 +552,11 @@ static int rm(int argc, const char **argv)
542
552
struct strbuf buf = STRBUF_INIT ;
543
553
struct known_remotes known_remotes = { NULL , NULL };
544
554
struct string_list branches = { NULL , 0 , 0 , 1 };
545
- struct branches_for_remote cb_data = { NULL , & branches , & known_remotes };
546
- int i ;
555
+ struct string_list skipped = { NULL , 0 , 0 , 1 };
556
+ struct branches_for_remote cb_data = {
557
+ NULL , & branches , & skipped , & known_remotes
558
+ };
559
+ int i , result ;
547
560
548
561
if (argc != 2 )
549
562
usage_with_options (builtin_remote_usage , options );
@@ -583,14 +596,26 @@ static int rm(int argc, const char **argv)
583
596
* refs, which are invalidated when deleting a branch.
584
597
*/
585
598
cb_data .remote = remote ;
586
- i = for_each_ref (add_branch_for_removal , & cb_data );
599
+ result = for_each_ref (add_branch_for_removal , & cb_data );
587
600
strbuf_release (& buf );
588
601
589
- if (!i )
590
- i = remove_branches (& branches );
602
+ if (!result )
603
+ result = remove_branches (& branches );
591
604
string_list_clear (& branches , 1 );
592
605
593
- return i ;
606
+ if (skipped .nr ) {
607
+ fprintf (stderr , skipped .nr == 1 ?
608
+ "Note: A non-remote branch was not removed; "
609
+ "to delete it, use:\n" :
610
+ "Note: Non-remote branches were not removed; "
611
+ "to delete them, use:\n" );
612
+ for (i = 0 ; i < skipped .nr ; i ++ )
613
+ fprintf (stderr , " git branch -d %s\n" ,
614
+ skipped .items [i ].string );
615
+ }
616
+ string_list_clear (& skipped , 0 );
617
+
618
+ return result ;
594
619
}
595
620
596
621
static void show_list (const char * title , struct string_list * list ,
0 commit comments