@@ -171,6 +171,15 @@ function getStdinUniqueKey(): number {
171
171
type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
172
172
export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
173
173
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
+
174
183
const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
175
184
[ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
176
185
[ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
@@ -531,29 +540,12 @@ export class Git {
531
540
await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
532
541
} catch ( ex ) {
533
542
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
+ }
555
547
}
556
- throw new BranchError ( reason , ex ) ;
548
+ throw new BranchError ( BranchErrorReason . Other , ex ) ;
557
549
}
558
550
}
559
551
@@ -1038,9 +1030,9 @@ export class Git {
1038
1030
} else {
1039
1031
params . push ( options . remote , options . branch ) ;
1040
1032
}
1041
- } else if ( options . remote != null ) {
1033
+ } else if ( options . remote ) {
1042
1034
params . push ( options . remote ) ;
1043
- } else if ( options . delete != null ) {
1035
+ } else if ( options . delete ) {
1044
1036
params . push ( '-d' , options . delete . remote , ...options . delete . branches ) ;
1045
1037
}
1046
1038
0 commit comments