@@ -1234,11 +1234,60 @@ export class LocalGitProvider implements GitProvider, Disposable {
12341234 @log ( )
12351235 async branch ( repoPath : string , options : GitBranchOptions ) : Promise < void > {
12361236 if ( options ?. create != null ) {
1237- return this . git . branch ( repoPath , options . create . name , options . create . startRef ) ;
1237+ const { name, startRef } = options . create ;
1238+ return this . git . branch ( repoPath , name , startRef ) ;
12381239 }
12391240
12401241 if ( options ?. rename != null ) {
1241- return this . git . branch ( repoPath , '-m' , options . rename . old , options . rename . new ) ;
1242+ const { old : oldName , new : newName } = options . rename ;
1243+ return this . git . branch ( repoPath , '-m' , oldName , newName ) ;
1244+ }
1245+
1246+ if ( options ?. delete != null ) {
1247+ const { force : forceOpt = false , remote : remoteOpt = false , branches } = options . delete ;
1248+ const localBranches = branches . filter ( ( b : GitBranchReference ) => ! b . remote ) ;
1249+ if ( localBranches . length !== 0 ) {
1250+ const args = [ '--delete' ] ;
1251+ if ( forceOpt ) {
1252+ args . push ( '--force' ) ;
1253+ }
1254+
1255+ void this . git . branch ( repoPath , ...args , ...branches . map ( ( b : GitBranchReference ) => b . ref ) ) ;
1256+
1257+ if ( remoteOpt ) {
1258+ const trackingBranches = localBranches . filter ( b => b . upstream != null ) ;
1259+ if ( trackingBranches . length !== 0 ) {
1260+ const branchesByOrigin = groupByMap ( trackingBranches , b =>
1261+ getRemoteNameFromBranchName ( b . upstream ! . name ) ,
1262+ ) ;
1263+
1264+ for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1265+ void this . git . push ( repoPath , {
1266+ delete : {
1267+ remote : remote ,
1268+ branches : branches . map ( b => getBranchNameWithoutRemote ( b . upstream ! . name ) ) ,
1269+ } ,
1270+ } ) ;
1271+ }
1272+ }
1273+ }
1274+ }
1275+
1276+ const remoteBranches = branches . filter ( ( b : GitBranchReference ) => b . remote ) ;
1277+ if ( remoteBranches . length !== 0 ) {
1278+ const branchesByOrigin = groupByMap ( remoteBranches , b => getRemoteNameFromBranchName ( b . name ) ) ;
1279+
1280+ for ( const [ remote , branches ] of branchesByOrigin . entries ( ) ) {
1281+ void this . git . push ( repoPath , {
1282+ delete : {
1283+ remote : remote ,
1284+ branches : branches . map ( ( b : GitBranchReference ) =>
1285+ b . remote ? getBranchNameWithoutRemote ( b . name ) : b . name ,
1286+ ) ,
1287+ } ,
1288+ } ) ;
1289+ }
1290+ }
12421291 }
12431292
12441293 throw new Error ( 'Invalid branch options' ) ;
0 commit comments