@@ -171,6 +171,15 @@ function getStdinUniqueKey(): number {
171171type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
172172export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
173173
174+ const branchErrorAndReason = [
175+ [ GitErrors . noRemoteReference , BranchErrorReason . NoRemoteReference ] ,
176+ [ GitErrors . invalidBranchName , BranchErrorReason . InvalidBranchName ] ,
177+ [ GitErrors . branchAlreadyExists , BranchErrorReason . BranchAlreadyExists ] ,
178+ [ GitErrors . branchNotFullyMerged , BranchErrorReason . BranchNotFullyMerged ] ,
179+ [ GitErrors . branchNotYetBorn , BranchErrorReason . BranchNotYetBorn ] ,
180+ [ GitErrors . branchFastForwardRejected , BranchErrorReason . BranchFastForwardRejected ] ,
181+ ] ;
182+
174183const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
175184 [ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
176185 [ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
@@ -531,29 +540,12 @@ export class Git {
531540 await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
532541 } catch ( ex ) {
533542 const msg : string = ex ?. toString ( ) ?? '' ;
534- let reason : BranchErrorReason = BranchErrorReason . Other ;
535- switch ( true ) {
536- case GitErrors . noRemoteReference . test ( msg ) || GitErrors . noRemoteReference . test ( ex . stderr ?? '' ) :
537- reason = BranchErrorReason . NoRemoteReference ;
538- break ;
539- case GitErrors . invalidBranchName . test ( msg ) || GitErrors . invalidBranchName . test ( ex . stderr ?? '' ) :
540- reason = BranchErrorReason . InvalidBranchName ;
541- break ;
542- case GitErrors . branchAlreadyExists . test ( msg ) || GitErrors . branchAlreadyExists . test ( ex . stderr ?? '' ) :
543- reason = BranchErrorReason . BranchAlreadyExists ;
544- break ;
545- case GitErrors . branchNotFullyMerged . test ( msg ) || GitErrors . branchNotFullyMerged . test ( ex . stderr ?? '' ) :
546- reason = BranchErrorReason . BranchNotFullyMerged ;
547- break ;
548- case GitErrors . branchNotYetBorn . test ( msg ) || GitErrors . branchNotYetBorn . test ( ex . stderr ?? '' ) :
549- reason = BranchErrorReason . BranchNotYetBorn ;
550- break ;
551- case GitErrors . branchFastForwardRejected . test ( msg ) ||
552- GitErrors . branchFastForwardRejected . test ( ex . stderr ?? '' ) :
553- reason = BranchErrorReason . BranchFastForwardRejected ;
554- break ;
543+ for ( const [ error , reason ] of branchErrorAndReason ) {
544+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
545+ throw new BranchError ( reason , ex ) ;
546+ }
555547 }
556- throw new BranchError ( reason , ex ) ;
548+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
557549 }
558550 }
559551
@@ -1038,9 +1030,9 @@ export class Git {
10381030 } else {
10391031 params . push ( options . remote , options . branch ) ;
10401032 }
1041- } else if ( options . remote != null ) {
1033+ } else if ( options . remote ) {
10421034 params . push ( options . remote ) ;
1043- } else if ( options . delete != null ) {
1035+ } else if ( options . delete ) {
10441036 params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
10451037 }
10461038
0 commit comments