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