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