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