@@ -165,6 +165,15 @@ function getStdinUniqueKey(): number {
165165type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
166166export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
167167
168+ const branchErrorAndReason = [
169+ [ GitErrors . noRemoteReference , BranchErrorReason . NoRemoteReference ] ,
170+ [ GitErrors . invalidBranchName , BranchErrorReason . InvalidBranchName ] ,
171+ [ GitErrors . branchAlreadyExists , BranchErrorReason . BranchAlreadyExists ] ,
172+ [ GitErrors . branchNotFullyMerged , BranchErrorReason . BranchNotFullyMerged ] ,
173+ [ GitErrors . branchNotYetBorn , BranchErrorReason . BranchNotYetBorn ] ,
174+ [ GitErrors . branchFastForwardRejected , BranchErrorReason . BranchFastForwardRejected ] ,
175+ ] ;
176+
168177export class Git {
169178 /** Map of running git commands -- avoids running duplicate overlaping commands */
170179 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -517,29 +526,12 @@ export class Git {
517526 await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
518527 } catch ( ex ) {
519528 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 ;
529+ for ( const [ error , reason ] of branchErrorAndReason ) {
530+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
531+ throw new BranchError ( reason , ex ) ;
532+ }
541533 }
542- throw new BranchError ( reason , ex ) ;
534+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
543535 }
544536 }
545537
@@ -1024,9 +1016,9 @@ export class Git {
10241016 } else {
10251017 params . push ( options . remote , options . branch ) ;
10261018 }
1027- } else if ( options . remote != null ) {
1019+ } else if ( options . remote ) {
10281020 params . push ( options . remote ) ;
1029- } else if ( options . delete != null ) {
1021+ } else if ( options . delete ) {
10301022 params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
10311023 }
10321024
0 commit comments