@@ -1286,77 +1286,51 @@ export class LocalGitProvider implements GitProvider, Disposable {
12861286 }
12871287
12881288 @log ( )
1289- async deleteBranches (
1289+ async deleteBranch (
12901290 repoPath : string ,
1291- branches : GitBranchReference [ ] ,
1291+ branch : GitBranchReference ,
12921292 options : { force ?: boolean ; remote ?: boolean } ,
12931293 ) : Promise < void > {
1294- const localBranches = branches . filter ( ( b : GitBranchReference ) => ! b . remote ) ;
1295- if ( localBranches . length !== 0 ) {
1296- const args = [ '--delete' ] ;
1297- if ( options . force ) {
1298- args . push ( '--force' ) ;
1299- }
1300-
1301- if ( options . remote ) {
1302- const trackingBranches = localBranches . filter ( b => b . upstream != null ) ;
1303- if ( trackingBranches . length !== 0 ) {
1304- const branchesByOrigin = groupByMap ( trackingBranches , b =>
1305- getRemoteNameFromBranchName ( b . upstream ! . name ) ,
1306- ) ;
1307-
1308- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1309- const remoteCommitByBranch : Map < string , string > = { } ;
1310- branches . forEach ( async b => {
1311- remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ b . ref } ` , {
1312- maxResults : 1 ,
1313- } ) ;
1314- remoteCommitByBranch [ b . ref ] = remoteCommit ;
1315- } ) ;
1294+ if ( branch . remote ) {
1295+ return this . git . push ( repoPath , {
1296+ delete : {
1297+ remote : getRemoteNameFromBranchName ( branch . name ) ,
1298+ branch : branch . remote ? getBranchNameWithoutRemote ( branch . name ) : branch . name ,
1299+ } ,
1300+ } ) ;
1301+ }
13161302
1317- await this . git . branch (
1318- repoPath ,
1319- '--delete' ,
1320- '--remotes' ,
1321- ...branches . map ( ( b : GitBranchReference ) => `${ remote } /${ b . ref } ` ) ,
1322- ) ;
1303+ const args = [ '--delete' ] ;
1304+ if ( options . force ) {
1305+ args . push ( '--force' ) ;
1306+ }
13231307
1324- try {
1325- await this . git . branch ( repoPath , ...args , ...branches . map ( ( b : GitBranchReference ) => b . ref ) ) ;
1326- await this . git . push ( repoPath , {
1327- delete : {
1328- remote : remote ,
1329- branches : branches . map ( b => getBranchNameWithoutRemote ( b . upstream ! . name ) ) ,
1330- } ,
1331- } ) ;
1332- } catch ( ex ) {
1333- // If it fails, restore the remote branches
1334- remoteCommitByBranch . forEach ( async ( branch , commit ) => {
1335- await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch } ` , commit ) ;
1336- await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1337- } ) ;
1338- throw ex ;
1339- }
1340- }
1341- }
1342- }
1308+ if ( ! options . remote || ! branch . upstream ) {
1309+ return this . git . branch ( repoPath , ...args , branch . ref ) ;
13431310 }
13441311
1345- const remoteBranches = branches . filter ( ( b : GitBranchReference ) => b . remote ) ;
1346- if ( remoteBranches . length !== 0 ) {
1347- const branchesByOrigin = groupByMap ( remoteBranches , b => getRemoteNameFromBranchName ( b . name ) ) ;
1312+ const remote = getRemoteNameFromBranchName ( branch . upstream . name ) ;
1313+ remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , {
1314+ maxResults : 1 ,
1315+ } ) ;
13481316
1349- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1350- await this . git . push ( repoPath , {
1351- delete : {
1352- remote : remote ,
1353- branches : branches . map ( ( b : GitBranchReference ) =>
1354- b . remote ? getBranchNameWithoutRemote ( b . name ) : b . name ,
1355- ) ,
1356- } ,
1357- } ) ;
1358- }
1317+ await this . git . branch ( repoPath , '--delete' , '--remotes' , `${ remote } /${ branch . ref } ` ) ;
1318+
1319+ try {
1320+ await this . git . branch ( repoPath , ...args , branch . ref ) ;
1321+ } catch ( ex ) {
1322+ // If it fails, restore the remote branch
1323+ await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , commit ) ;
1324+ await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1325+ throw ex ;
13591326 }
1327+
1328+ await this . git . push ( repoPath , {
1329+ delete : {
1330+ remote : remote ,
1331+ branch : getBranchNameWithoutRemote ( branch . upstream . name ) ,
1332+ } ,
1333+ } ) ;
13601334 }
13611335
13621336 @log ( )
0 commit comments