@@ -20,6 +20,8 @@ import {
2020 PullErrorReason ,
2121 PushError ,
2222 PushErrorReason ,
23+ ResetError ,
24+ ResetErrorReason ,
2325 StashPushError ,
2426 StashPushErrorReason ,
2527 WorkspaceUntrustedError ,
@@ -100,6 +102,11 @@ export const GitErrors = {
100102 tagConflict : / ! \[ r e j e c t e d \] .* \( w o u l d c l o b b e r e x i s t i n g t a g \) / m,
101103 unmergedFiles : / i s n o t p o s s i b l e b e c a u s e y o u h a v e u n m e r g e d f i l e s / i,
102104 unstagedChanges : / Y o u h a v e u n s t a g e d c h a n g e s / i,
105+ 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,
106+ 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,
107+ 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,
108+ 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,
109+ 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,
103110} ;
104111
105112const GitWarnings = {
@@ -160,6 +167,14 @@ function getStdinUniqueKey(): number {
160167type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
161168export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
162169
170+ const resetErrorAndReason = [
171+ [ unmergedChanges , ResetErrorReason . UnmergedChanges ] ,
172+ [ ambiguousArgument , ResetErrorReason . AmbiguousArgument ] ,
173+ [ entryNotUpToDate , ResetErrorReason . EntryNotUpToDate ] ,
174+ [ changesWouldBeOverwritten , ResetErrorReason . LocalChangesWouldBeOverwritten ] ,
175+ [ refLocked , ResetErrorReason . RefLocked ] ,
176+ ] ;
177+
163178export class Git {
164179 /** Map of running git commands -- avoids running duplicate overlaping commands */
165180 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -1571,8 +1586,19 @@ export class Git {
15711586 return this . git < string > ( { cwd : repoPath } , 'remote' , 'get-url' , remote ) ;
15721587 }
15731588
1574- reset ( repoPath : string | undefined , pathspecs : string [ ] ) {
1575- return this . git < string > ( { cwd : repoPath } , 'reset' , '-q' , '--' , ...pathspecs ) ;
1589+ reset ( repoPath : string , pathspecs : string [ ] , ...args : string [ ] ) {
1590+ try {
1591+ return this . git < string > ( { cwd : repoPath } , 'reset' , '-q' , ...args , '--' , ...pathspecs ) ;
1592+ } catch ( ex ) {
1593+ const msg : string = ex ?. toString ( ) ?? '' ;
1594+ for ( const [ error , reason ] of resetErrorAndReason ) {
1595+ if ( error . test ( msg ) ) {
1596+ throw new ResetError ( reason , ex ) ;
1597+ }
1598+ }
1599+
1600+ throw new ResetError ( ResetErrorReason . Other , ex ) ;
1601+ }
15761602 }
15771603
15781604 async rev_list (
0 commit comments