@@ -166,6 +166,15 @@ function getStdinUniqueKey(): number {
166
166
type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
167
167
export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
168
168
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
+
169
178
export class Git {
170
179
/** Map of running git commands -- avoids running duplicate overlaping commands */
171
180
private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -518,29 +527,12 @@ export class Git {
518
527
await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
519
528
} catch ( ex ) {
520
529
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
+ }
542
534
}
543
- throw new BranchError ( reason , ex ) ;
535
+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
544
536
}
545
537
}
546
538
@@ -1025,9 +1017,9 @@ export class Git {
1025
1017
} else {
1026
1018
params . push ( options . remote , options . branch ) ;
1027
1019
}
1028
- } else if ( options . remote != null ) {
1020
+ } else if ( options . remote ) {
1029
1021
params . push ( options . remote ) ;
1030
- } else if ( options . delete != null ) {
1022
+ } else if ( options . delete ) {
1031
1023
params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
1032
1024
}
1033
1025
0 commit comments