@@ -749,15 +749,23 @@ static int mv(int argc, const char **argv)
749
749
750
750
static int remove_branches (struct string_list * branches )
751
751
{
752
+ const char * * branch_names ;
752
753
int i , result = 0 ;
754
+
755
+ branch_names = xmalloc (branches -> nr * sizeof (* branch_names ));
756
+ for (i = 0 ; i < branches -> nr ; i ++ )
757
+ branch_names [i ] = branches -> items [i ].string ;
758
+ result |= repack_without_refs (branch_names , branches -> nr );
759
+ free (branch_names );
760
+
753
761
for (i = 0 ; i < branches -> nr ; i ++ ) {
754
762
struct string_list_item * item = branches -> items + i ;
755
763
const char * refname = item -> string ;
756
- unsigned char * sha1 = item -> util ;
757
764
758
- if (delete_ref (refname , sha1 , 0 ))
765
+ if (delete_ref (refname , NULL , 0 ))
759
766
result |= error (_ ("Could not remove branch %s" ), refname );
760
767
}
768
+
761
769
return result ;
762
770
}
763
771
@@ -789,10 +797,6 @@ static int rm(int argc, const char **argv)
789
797
known_remotes .to_delete = remote ;
790
798
for_each_remote (add_known_remote , & known_remotes );
791
799
792
- strbuf_addf (& buf , "remote.%s" , remote -> name );
793
- if (git_config_rename_section (buf .buf , NULL ) < 1 )
794
- return error (_ ("Could not remove config section '%s'" ), buf .buf );
795
-
796
800
read_branches ();
797
801
for (i = 0 ; i < branch_list .nr ; i ++ ) {
798
802
struct string_list_item * item = branch_list .items + i ;
@@ -837,6 +841,12 @@ static int rm(int argc, const char **argv)
837
841
}
838
842
string_list_clear (& skipped , 0 );
839
843
844
+ if (!result ) {
845
+ strbuf_addf (& buf , "remote.%s" , remote -> name );
846
+ if (git_config_rename_section (buf .buf , NULL ) < 1 )
847
+ return error (_ ("Could not remove config section '%s'" ), buf .buf );
848
+ }
849
+
840
850
return result ;
841
851
}
842
852
@@ -1303,6 +1313,8 @@ static int prune_remote(const char *remote, int dry_run)
1303
1313
{
1304
1314
int result = 0 , i ;
1305
1315
struct ref_states states ;
1316
+ struct string_list delete_refs_list = STRING_LIST_INIT_NODUP ;
1317
+ const char * * delete_refs ;
1306
1318
const char * dangling_msg = dry_run
1307
1319
? _ (" %s will become dangling!" )
1308
1320
: _ (" %s has become dangling!" );
@@ -1316,11 +1328,20 @@ static int prune_remote(const char *remote, int dry_run)
1316
1328
states .remote -> url_nr
1317
1329
? states .remote -> url [0 ]
1318
1330
: _ ("(no URL)" ));
1331
+
1332
+ delete_refs = xmalloc (states .stale .nr * sizeof (* delete_refs ));
1333
+ for (i = 0 ; i < states .stale .nr ; i ++ )
1334
+ delete_refs [i ] = states .stale .items [i ].util ;
1335
+ if (!dry_run )
1336
+ result |= repack_without_refs (delete_refs , states .stale .nr );
1337
+ free (delete_refs );
1319
1338
}
1320
1339
1321
1340
for (i = 0 ; i < states .stale .nr ; i ++ ) {
1322
1341
const char * refname = states .stale .items [i ].util ;
1323
1342
1343
+ string_list_insert (& delete_refs_list , refname );
1344
+
1324
1345
if (!dry_run )
1325
1346
result |= delete_ref (refname , NULL , 0 );
1326
1347
@@ -1330,9 +1351,11 @@ static int prune_remote(const char *remote, int dry_run)
1330
1351
else
1331
1352
printf_ln (_ (" * [pruned] %s" ),
1332
1353
abbrev_ref (refname , "refs/remotes/" ));
1333
- warn_dangling_symref (stdout , dangling_msg , refname );
1334
1354
}
1335
1355
1356
+ warn_dangling_symrefs (stdout , dangling_msg , & delete_refs_list );
1357
+ string_list_clear (& delete_refs_list , 0 );
1358
+
1336
1359
free_remote_ref_states (& states );
1337
1360
return result ;
1338
1361
}
0 commit comments