@@ -1272,77 +1272,51 @@ export class LocalGitProvider implements GitProvider, Disposable {
1272
1272
}
1273
1273
1274
1274
@log ( )
1275
- async deleteBranches (
1275
+ async deleteBranch (
1276
1276
repoPath : string ,
1277
- branches : GitBranchReference [ ] ,
1277
+ branch : GitBranchReference ,
1278
1278
options : { force ?: boolean ; remote ?: boolean } ,
1279
1279
) : Promise < void > {
1280
- const localBranches = branches . filter ( ( b : GitBranchReference ) => ! b . remote ) ;
1281
- if ( localBranches . length !== 0 ) {
1282
- const args = [ '--delete' ] ;
1283
- if ( options . force ) {
1284
- args . push ( '--force' ) ;
1285
- }
1286
-
1287
- if ( options . remote ) {
1288
- const trackingBranches = localBranches . filter ( b => b . upstream != null ) ;
1289
- if ( trackingBranches . length !== 0 ) {
1290
- const branchesByOrigin = groupByMap ( trackingBranches , b =>
1291
- getRemoteNameFromBranchName ( b . upstream ! . name ) ,
1292
- ) ;
1293
-
1294
- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1295
- const remoteCommitByBranch : Map < string , string > = { } ;
1296
- branches . forEach ( async b => {
1297
- remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ b . ref } ` , {
1298
- maxResults : 1 ,
1299
- } ) ;
1300
- remoteCommitByBranch [ b . ref ] = remoteCommit ;
1301
- } ) ;
1280
+ if ( branch . remote ) {
1281
+ return this . git . push ( repoPath , {
1282
+ delete : {
1283
+ remote : getRemoteNameFromBranchName ( branch . name ) ,
1284
+ branch : branch . remote ? getBranchNameWithoutRemote ( branch . name ) : branch . name ,
1285
+ } ,
1286
+ } ) ;
1287
+ }
1302
1288
1303
- await this . git . branch (
1304
- repoPath ,
1305
- '--delete' ,
1306
- '--remotes' ,
1307
- ...branches . map ( ( b : GitBranchReference ) => `${ remote } /${ b . ref } ` ) ,
1308
- ) ;
1289
+ const args = [ '--delete' ] ;
1290
+ if ( options . force ) {
1291
+ args . push ( '--force' ) ;
1292
+ }
1309
1293
1310
- try {
1311
- await this . git . branch ( repoPath , ...args , ...branches . map ( ( b : GitBranchReference ) => b . ref ) ) ;
1312
- await this . git . push ( repoPath , {
1313
- delete : {
1314
- remote : remote ,
1315
- branches : branches . map ( b => getBranchNameWithoutRemote ( b . upstream ! . name ) ) ,
1316
- } ,
1317
- } ) ;
1318
- } catch ( ex ) {
1319
- // If it fails, restore the remote branches
1320
- remoteCommitByBranch . forEach ( async ( branch , commit ) => {
1321
- await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch } ` , commit ) ;
1322
- await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1323
- } ) ;
1324
- throw ex ;
1325
- }
1326
- }
1327
- }
1328
- }
1294
+ if ( ! options . remote || ! branch . upstream ) {
1295
+ return this . git . branch ( repoPath , ...args , branch . ref ) ;
1329
1296
}
1330
1297
1331
- const remoteBranches = branches . filter ( ( b : GitBranchReference ) => b . remote ) ;
1332
- if ( remoteBranches . length !== 0 ) {
1333
- const branchesByOrigin = groupByMap ( remoteBranches , b => getRemoteNameFromBranchName ( b . name ) ) ;
1298
+ const remote = getRemoteNameFromBranchName ( branch . upstream . name ) ;
1299
+ remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , {
1300
+ maxResults : 1 ,
1301
+ } ) ;
1334
1302
1335
- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1336
- await this . git . push ( repoPath , {
1337
- delete : {
1338
- remote : remote ,
1339
- branches : branches . map ( ( b : GitBranchReference ) =>
1340
- b . remote ? getBranchNameWithoutRemote ( b . name ) : b . name ,
1341
- ) ,
1342
- } ,
1343
- } ) ;
1344
- }
1303
+ await this . git . branch ( repoPath , '--delete' , '--remotes' , `${ remote } /${ branch . ref } ` ) ;
1304
+
1305
+ try {
1306
+ await this . git . branch ( repoPath , ...args , branch . ref ) ;
1307
+ } catch ( ex ) {
1308
+ // If it fails, restore the remote branch
1309
+ await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , commit ) ;
1310
+ await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1311
+ throw ex ;
1345
1312
}
1313
+
1314
+ await this . git . push ( repoPath , {
1315
+ delete : {
1316
+ remote : remote ,
1317
+ branch : getBranchNameWithoutRemote ( branch . upstream . name ) ,
1318
+ } ,
1319
+ } ) ;
1346
1320
}
1347
1321
1348
1322
@log ( )
0 commit comments