@@ -74,6 +74,10 @@ const textDecoder = new TextDecoder('utf8');
7474const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' ;
7575
7676export 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,
7781 badRevision : / b a d r e v i s i o n ' ( .* ?) ' / i,
7882 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,
7983 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,
@@ -509,7 +513,34 @@ export class Git {
509513 }
510514
511515 async branch ( repoPath : string , ...args : string [ ] ) : Promise < void > {
512- return this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
516+ try {
517+ await this . git < string > ( { cwd : repoPath } , 'branch' , ...args ) ;
518+ } catch ( ex ) {
519+ 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 ;
541+ }
542+ throw new BranchError ( reason , ex ) ;
543+ }
513544 }
514545
515546 branch__set_upstream ( repoPath : string , branch : string , remote : string , remoteBranch : string ) {
0 commit comments