@@ -517,29 +517,19 @@ export class Git {
517517 await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
518518 } catch ( ex ) {
519519 const msg : string = ex ?. toString ( ) ?? '' ;
520- let reason : BranchErrorReason = BranchErrorReason . Other ;
521- switch ( true ) {
522- case GitErrors . noRemoteReference . test ( msg ) || GitErrors . noRemoteReference . test ( ex . stderr ?? '' ) :
523- reason = BranchErrorReason . NoRemoteReference ;
524- break ;
525- case GitErrors . invalidBranchName . test ( msg ) || GitErrors . invalidBranchName . test ( ex . stderr ?? '' ) :
526- reason = BranchErrorReason . InvalidBranchName ;
527- break ;
528- case GitErrors . branchAlreadyExists . test ( msg ) || GitErrors . branchAlreadyExists . test ( ex . stderr ?? '' ) :
529- reason = BranchErrorReason . BranchAlreadyExists ;
530- break ;
531- case GitErrors . branchNotFullyMerged . test ( msg ) || GitErrors . branchNotFullyMerged . test ( ex . stderr ?? '' ) :
532- reason = BranchErrorReason . BranchNotFullyMerged ;
533- break ;
534- case GitErrors . branchNotYetBorn . test ( msg ) || GitErrors . branchNotYetBorn . test ( ex . stderr ?? '' ) :
535- reason = BranchErrorReason . BranchNotYetBorn ;
536- break ;
537- case GitErrors . branchFastForwardRejected . test ( msg ) ||
538- GitErrors . branchFastForwardRejected . test ( ex . stderr ?? '' ) :
539- reason = BranchErrorReason . BranchFastForwardRejected ;
540- break ;
520+ for ( const [ error , reason ] of [
521+ [ GitErrors . noRemoteReference , BranchErrorReason . NoRemoteReference ] ,
522+ [ GitErrors . invalidBranchName , BranchErrorReason . InvalidBranchName ] ,
523+ [ GitErrors . branchAlreadyExists , BranchErrorReason . BranchAlreadyExists ] ,
524+ [ GitErrors . branchNotFullyMerged , BranchErrorReason . BranchNotFullyMerged ] ,
525+ [ GitErrors . branchNotYetBorn , BranchErrorReason . BranchNotYetBorn ] ,
526+ [ GitErrors . branchFastForwardRejected , BranchErrorReason . BranchFastForwardRejected ] ,
527+ ] ) {
528+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
529+ throw new BranchError ( reason , ex ) ;
530+ }
541531 }
542- throw new BranchError ( reason , ex ) ;
532+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
543533 }
544534 }
545535
@@ -1024,9 +1014,9 @@ export class Git {
10241014 } else {
10251015 params . push ( options . remote , options . branch ) ;
10261016 }
1027- } else if ( options . remote != null ) {
1017+ } else if ( options . remote ) {
10281018 params . push ( options . remote ) ;
1029- } else if ( options . delete != null ) {
1019+ } else if ( options . delete ) {
10301020 params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
10311021 }
10321022
0 commit comments