@@ -1251,77 +1251,51 @@ export class LocalGitProvider implements GitProvider, Disposable {
12511251 }
12521252
12531253 @log ( )
1254- async deleteBranches (
1254+ async deleteBranch (
12551255 repoPath : string ,
1256- branches : GitBranchReference [ ] ,
1256+ branch : GitBranchReference ,
12571257 options : { force ?: boolean ; remote ?: boolean } ,
12581258 ) : Promise < void > {
1259- const localBranches = branches . filter ( ( b : GitBranchReference ) => ! b . remote ) ;
1260- if ( localBranches . length !== 0 ) {
1261- const args = [ '--delete' ] ;
1262- if ( options . force ) {
1263- args . push ( '--force' ) ;
1264- }
1265-
1266- if ( options . remote ) {
1267- const trackingBranches = localBranches . filter ( b => b . upstream != null ) ;
1268- if ( trackingBranches . length !== 0 ) {
1269- const branchesByOrigin = groupByMap ( trackingBranches , b =>
1270- getRemoteNameFromBranchName ( b . upstream ! . name ) ,
1271- ) ;
1272-
1273- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1274- const remoteCommitByBranch : Map < string , string > = { } ;
1275- branches . forEach ( async b => {
1276- remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ b . ref } ` , {
1277- maxResults : 1 ,
1278- } ) ;
1279- remoteCommitByBranch [ b . ref ] = remoteCommit ;
1280- } ) ;
1259+ if ( branch . remote ) {
1260+ return this . git . push ( repoPath , {
1261+ delete : {
1262+ remote : getRemoteNameFromBranchName ( branch . name ) ,
1263+ branch : branch . remote ? getBranchNameWithoutRemote ( branch . name ) : branch . name ,
1264+ } ,
1265+ } ) ;
1266+ }
12811267
1282- await this . git . branch (
1283- repoPath ,
1284- '--delete' ,
1285- '--remotes' ,
1286- ...branches . map ( ( b : GitBranchReference ) => `${ remote } /${ b . ref } ` ) ,
1287- ) ;
1268+ const args = [ '--delete' ] ;
1269+ if ( options . force ) {
1270+ args . push ( '--force' ) ;
1271+ }
12881272
1289- try {
1290- await this . git . branch ( repoPath , ...args , ...branches . map ( ( b : GitBranchReference ) => b . ref ) ) ;
1291- await this . git . push ( repoPath , {
1292- delete : {
1293- remote : remote ,
1294- branches : branches . map ( b => getBranchNameWithoutRemote ( b . upstream ! . name ) ) ,
1295- } ,
1296- } ) ;
1297- } catch ( ex ) {
1298- // If it fails, restore the remote branches
1299- remoteCommitByBranch . forEach ( async ( branch , commit ) => {
1300- await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch } ` , commit ) ;
1301- await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1302- } ) ;
1303- throw ex ;
1304- }
1305- }
1306- }
1307- }
1273+ if ( ! options . remote || ! branch . upstream ) {
1274+ return this . git . branch ( repoPath , ...args , branch . ref ) ;
13081275 }
13091276
1310- const remoteBranches = branches . filter ( ( b : GitBranchReference ) => b . remote ) ;
1311- if ( remoteBranches . length !== 0 ) {
1312- const branchesByOrigin = groupByMap ( remoteBranches , b => getRemoteNameFromBranchName ( b . name ) ) ;
1277+ const remote = getRemoteNameFromBranchName ( branch . upstream . name ) ;
1278+ remoteCommit = await this . git . rev_list ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , {
1279+ maxResults : 1 ,
1280+ } ) ;
13131281
1314- for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1315- await this . git . push ( repoPath , {
1316- delete : {
1317- remote : remote ,
1318- branches : branches . map ( ( b : GitBranchReference ) =>
1319- b . remote ? getBranchNameWithoutRemote ( b . name ) : b . name ,
1320- ) ,
1321- } ,
1322- } ) ;
1323- }
1282+ await this . git . branch ( repoPath , '--delete' , '--remotes' , `${ remote } /${ branch . ref } ` ) ;
1283+
1284+ try {
1285+ await this . git . branch ( repoPath , ...args , branch . ref ) ;
1286+ } catch ( ex ) {
1287+ // If it fails, restore the remote branch
1288+ await this . git . update_ref ( repoPath , `refs/remotes/${ remote } /${ branch . ref } ` , commit ) ;
1289+ await this . git . branch__set_upstream ( repoPath , branch , remote , branch ) ;
1290+ throw ex ;
13241291 }
1292+
1293+ await this . git . push ( repoPath , {
1294+ delete : {
1295+ remote : remote ,
1296+ branch : getBranchNameWithoutRemote ( branch . upstream . name ) ,
1297+ } ,
1298+ } ) ;
13251299 }
13261300
13271301 @log ( )
0 commit comments