@@ -75,6 +75,10 @@ const textDecoder = new TextDecoder('utf8');
75
75
const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' ;
76
76
77
77
export const GitErrors = {
78
+ noRemoteReference : / u n a b l e t o d e l e t e ' .+ ?' : r e m o t e r e f d o e s n o t e x i s t / i,
79
+ invalidBranchName : / f a t a l : ' .+ ?' i s n o t a v a l i d b r a n c h n a m e / i,
80
+ branchAlreadyExists : / f a t a l : A b r a n c h n a m e d ' .+ ?' a l r e a d y e x i s t s / i,
81
+ branchNotFullyMerged : / e r r o r : T h e b r a n c h ' .+ ?' i s n o t f u l l y m e r g e d / i,
78
82
badRevision : / b a d r e v i s i o n ' ( .* ?) ' / i,
79
83
cantLockRef : / c a n n o t l o c k r e f | u n a b l e t o u p d a t e l o c a l r e f / i,
80
84
changesWouldBeOverwritten : / Y o u r l o c a l c h a n g e s t o t h e f o l l o w i n g f i l e s w o u l d b e o v e r w r i t t e n / i,
@@ -523,7 +527,34 @@ export class Git {
523
527
}
524
528
525
529
async branch ( repoPath : string , ...args : string [ ] ) : Promise < void > {
526
- return this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
530
+ try {
531
+ await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
532
+ } catch ( ex ) {
533
+ 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 ;
555
+ }
556
+ throw new BranchError ( reason , ex ) ;
557
+ }
527
558
}
528
559
529
560
branch__set_upstream ( repoPath : string , branch : string , remote : string , remoteBranch : string ) {
0 commit comments