@@ -166,6 +166,15 @@ function getStdinUniqueKey(): number {
166166type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
167167export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
168168
169+ const branchErrorAndReason = [
170+ [ GitErrors . noRemoteReference , BranchErrorReason . NoRemoteReference ] ,
171+ [ GitErrors . invalidBranchName , BranchErrorReason . InvalidBranchName ] ,
172+ [ GitErrors . branchAlreadyExists , BranchErrorReason . BranchAlreadyExists ] ,
173+ [ GitErrors . branchNotFullyMerged , BranchErrorReason . BranchNotFullyMerged ] ,
174+ [ GitErrors . branchNotYetBorn , BranchErrorReason . BranchNotYetBorn ] ,
175+ [ GitErrors . branchFastForwardRejected , BranchErrorReason . BranchFastForwardRejected ] ,
176+ ] ;
177+
169178export class Git {
170179 /** Map of running git commands -- avoids running duplicate overlaping commands */
171180 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -518,29 +527,12 @@ export class Git {
518527 await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
519528 } catch ( ex ) {
520529 const msg : string = ex ?. toString ( ) ?? '' ;
521- let reason : BranchErrorReason = BranchErrorReason . Other ;
522- switch ( true ) {
523- case GitErrors . noRemoteReference . test ( msg ) || GitErrors . noRemoteReference . test ( ex . stderr ?? '' ) :
524- reason = BranchErrorReason . NoRemoteReference ;
525- break ;
526- case GitErrors . invalidBranchName . test ( msg ) || GitErrors . invalidBranchName . test ( ex . stderr ?? '' ) :
527- reason = BranchErrorReason . InvalidBranchName ;
528- break ;
529- case GitErrors . branchAlreadyExists . test ( msg ) || GitErrors . branchAlreadyExists . test ( ex . stderr ?? '' ) :
530- reason = BranchErrorReason . BranchAlreadyExists ;
531- break ;
532- case GitErrors . branchNotFullyMerged . test ( msg ) || GitErrors . branchNotFullyMerged . test ( ex . stderr ?? '' ) :
533- reason = BranchErrorReason . BranchNotFullyMerged ;
534- break ;
535- case GitErrors . branchNotYetBorn . test ( msg ) || GitErrors . branchNotYetBorn . test ( ex . stderr ?? '' ) :
536- reason = BranchErrorReason . BranchNotYetBorn ;
537- break ;
538- case GitErrors . branchFastForwardRejected . test ( msg ) ||
539- GitErrors . branchFastForwardRejected . test ( ex . stderr ?? '' ) :
540- reason = BranchErrorReason . BranchFastForwardRejected ;
541- break ;
530+ for ( const [ error , reason ] of branchErrorAndReason ) {
531+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
532+ throw new BranchError ( reason , ex ) ;
533+ }
542534 }
543- throw new BranchError ( reason , ex ) ;
535+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
544536 }
545537 }
546538
@@ -1025,9 +1017,9 @@ export class Git {
10251017 } else {
10261018 params . push ( options . remote , options . branch ) ;
10271019 }
1028- } else if ( options . remote != null ) {
1020+ } else if ( options . remote ) {
10291021 params . push ( options . remote ) ;
1030- } else if ( options . delete != null ) {
1022+ } else if ( options . delete ) {
10311023 params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
10321024 }
10331025
0 commit comments