@@ -20,6 +20,8 @@ import {
2020 PullErrorReason ,
2121 PushError ,
2222 PushErrorReason ,
23+ ResetError ,
24+ ResetErrorReason ,
2325 StashPushError ,
2426 StashPushErrorReason ,
2527 TagError ,
@@ -105,6 +107,11 @@ export const GitErrors = {
105107 tagNotFound : / t a g .* n o t f o u n d / i,
106108 invalidTagName : / i n v a l i d t a g n a m e / i,
107109 remoteRejected : / r e j e c t e d b e c a u s e t h e r e m o t e c o n t a i n s w o r k / i,
110+ unmergedChanges : / e r r o r : \s * y o u n e e d t o r e s o l v e y o u r c u r r e n t i n d e x f i r s t / i,
111+ ambiguousArgument : / f a t a l : \s * a m b i g u o u s a r g u m e n t [ ' " ] .+ [ ' " ] : u n k n o w n r e v i s i o n o r p a t h n o t i n t h e w o r k i n g t r e e / i,
112+ entryNotUpToDate : / e r r o r : \s * E n t r y [ ' " ] .+ [ ' " ] n o t u p t o d a t e \. C a n n o t m e r g e \. / i,
113+ changesWouldBeOverwritten : / e r r o r : \s * 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,
114+ refLocked : / f a t a l : \s * c a n n o t l o c k r e f [ ' " ] .+ [ ' " ] : u n a b l e t o c r e a t e f i l e / i,
108115} ;
109116
110117const GitWarnings = {
@@ -173,6 +180,14 @@ const tagErrorAndReason: [RegExp, TagErrorReason][] = [
173180 [ GitErrors . remoteRejected , TagErrorReason . RemoteRejected ] ,
174181] ;
175182
183+ const resetErrorAndReason = [
184+ [ unmergedChanges , ResetErrorReason . UnmergedChanges ] ,
185+ [ ambiguousArgument , ResetErrorReason . AmbiguousArgument ] ,
186+ [ entryNotUpToDate , ResetErrorReason . EntryNotUpToDate ] ,
187+ [ changesWouldBeOverwritten , ResetErrorReason . LocalChangesWouldBeOverwritten ] ,
188+ [ refLocked , ResetErrorReason . RefLocked ] ,
189+ ] ;
190+
176191export class Git {
177192 /** Map of running git commands -- avoids running duplicate overlaping commands */
178193 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -1584,8 +1599,19 @@ export class Git {
15841599 return this . git < string > ( { cwd : repoPath } , 'remote' , 'get-url' , remote ) ;
15851600 }
15861601
1587- reset ( repoPath : string | undefined , pathspecs : string [ ] ) {
1588- return this . git < string > ( { cwd : repoPath } , 'reset' , '-q' , '--' , ...pathspecs ) ;
1602+ reset ( repoPath : string , pathspecs : string [ ] , ...args : string [ ] ) {
1603+ try {
1604+ return this . git < string > ( { cwd : repoPath } , 'reset' , '-q' , ...args , '--' , ...pathspecs ) ;
1605+ } catch ( ex ) {
1606+ const msg : string = ex ?. toString ( ) ?? '' ;
1607+ for ( const [ error , reason ] of resetErrorAndReason ) {
1608+ if ( error . test ( msg ) ) {
1609+ throw new ResetError ( reason , ex ) ;
1610+ }
1611+ }
1612+
1613+ throw new ResetError ( ResetErrorReason . Other , ex ) ;
1614+ }
15891615 }
15901616
15911617 async rev_list (
0 commit comments