@@ -74,6 +74,10 @@ const textDecoder = new TextDecoder('utf8');
74
74
const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' ;
75
75
76
76
export const GitErrors = {
77
+ 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,
78
+ 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,
79
+ 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,
80
+ 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,
77
81
badRevision : / b a d r e v i s i o n ' ( .* ?) ' / i,
78
82
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,
79
83
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,
@@ -510,7 +514,34 @@ export class Git {
510
514
}
511
515
512
516
async branch ( repoPath : string , ...args : string [ ] ) : Promise < void > {
513
- return this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
517
+ try {
518
+ await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
519
+ } catch ( ex ) {
520
+ 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 ;
542
+ }
543
+ throw new BranchError ( reason , ex ) ;
544
+ }
514
545
}
515
546
516
547
branch__set_upstream ( repoPath : string , branch : string , remote : string , remoteBranch : string ) {
0 commit comments