@@ -25,19 +25,19 @@ import type {
2525 RebaseErrorReason ,
2626 ResetErrorReason ,
2727 RevertErrorReason ,
28+ StashApplyErrorReason ,
29+ StashPushErrorReason ,
2830 TagErrorReason ,
2931} from '../../../git/errors' ;
3032import {
3133 BlameIgnoreRevsFileBadRevisionError ,
3234 BlameIgnoreRevsFileError ,
33- BranchError ,
3435 CheckoutError ,
3536 FetchError ,
3637 PullError ,
3738 PushError ,
3839 ResetError ,
3940 StashPushError ,
40- TagError ,
4141 WorkspaceUntrustedError ,
4242} from '../../../git/errors' ;
4343import type { GitDir } from '../../../git/gitProvider' ;
@@ -123,6 +123,9 @@ export const GitErrors = {
123123 remoteAhead : / 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,
124124 remoteConnectionFailed : / C o u l d n o t r e a d f r o m r e m o t e r e p o s i t o r y / i,
125125 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,
126+ stashConflictingStagedAndUnstagedLines : / C a n n o t r e m o v e w o r k t r e e c h a n g e s / i,
127+ stashNothingToSave : / N o l o c a l c h a n g e s t o s a v e / i,
128+ stashSavedWorkingDirAndIndexState : / S a v e d w o r k i n g d i r e c t o r y a n d i n d e x s t a t e / i,
126129 tagAlreadyExists : / t a g .* a l r e a d y e x i s t s / i,
127130 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,
128131 tagNotFound : / t a g .* n o t f o u n d / i,
@@ -751,21 +754,6 @@ export class Git implements Disposable {
751754 }
752755 }
753756
754- async branch ( repoPath : string , ...args : string [ ] ) : Promise < GitResult < string > > {
755- const params = [ 'branch' , ...args ] ;
756- try {
757- const result = await this . exec ( { cwd : repoPath } , ...params ) ;
758- return result ;
759- } catch ( ex ) {
760- throw getGitCommandError (
761- 'branch' ,
762- ex ,
763- reason =>
764- new BranchError ( reason ?? 'other' , ex , undefined , undefined , { repoPath : repoPath , args : params } ) ,
765- ) ;
766- }
767- }
768-
769757 async branchOrTag__containsOrPointsAt (
770758 repoPath : string ,
771759 refs : string [ ] ,
@@ -1535,25 +1523,11 @@ export class Git implements Disposable {
15351523 }
15361524
15371525 try {
1538- const result = await this . exec ( { cwd : repoPath , stdin : stdin } , ...params ) ;
1539- if ( result . stdout . includes ( 'No local changes to save' ) ) {
1540- throw new StashPushError ( 'nothingToSave' , undefined , {
1541- repoPath : repoPath ,
1542- args : params ,
1543- } ) ;
1544- }
1526+ void ( await this . exec ( { cwd : repoPath , stdin : stdin } , ...params ) ) ;
15451527 } catch ( ex ) {
1546- if (
1547- ex instanceof GitError &&
1548- ex . stdout ?. includes ( 'Saved working directory and index state' ) &&
1549- ex . stderr ?. includes ( 'Cannot remove worktree changes' )
1550- ) {
1551- throw new StashPushError ( 'conflictingStagedAndUnstagedLines' , undefined , {
1552- repoPath : repoPath ,
1553- args : params ,
1554- } ) ;
1555- }
1556- throw ex ;
1528+ throw getGitCommandError ( 'stash-push' , ex , reason => {
1529+ return new StashPushError ( reason ?? 'other' , ex , { repoPath : repoPath , args : params } ) ;
1530+ } ) ;
15571531 }
15581532 }
15591533
@@ -1590,21 +1564,6 @@ export class Git implements Disposable {
15901564 return result ;
15911565 }
15921566
1593- async tag ( repoPath : string , ...args : string [ ] ) : Promise < GitResult < string > > {
1594- const params = [ 'tag' , ...args ] ;
1595- try {
1596- const result = await this . exec ( { cwd : repoPath } , ...params ) ;
1597- return result ;
1598- } catch ( ex ) {
1599- throw getGitCommandError (
1600- 'tag' ,
1601- ex ,
1602- reason =>
1603- new TagError ( reason ?? 'other' , ex , undefined , undefined , { repoPath : repoPath , args : params } ) ,
1604- ) ;
1605- }
1606- }
1607-
16081567 async readDotGitFile (
16091568 gitDir : GitDir ,
16101569 pathParts : string [ ] ,
@@ -1704,6 +1663,8 @@ type GitCommand =
17041663 | 'rebase'
17051664 | 'reset'
17061665 | 'revert'
1666+ | 'stash-apply'
1667+ | 'stash-push'
17071668 | 'tag' ;
17081669type GitCommandToReasonMap = {
17091670 branch : BranchErrorReason ;
@@ -1716,6 +1677,8 @@ type GitCommandToReasonMap = {
17161677 rebase : RebaseErrorReason ;
17171678 reset : ResetErrorReason ;
17181679 revert : RevertErrorReason ;
1680+ 'stash-apply' : StashApplyErrorReason ;
1681+ 'stash-push' : StashPushErrorReason ;
17191682 tag : TagErrorReason ;
17201683} ;
17211684
@@ -1825,6 +1788,15 @@ const errorToReasonMap = new Map<GitCommand, [RegExp, GitCommandToReasonMap[GitC
18251788 [ GitErrors . changesWouldBeOverwritten , 'wouldOverwriteChanges' ] ,
18261789 ] ,
18271790 ] ,
1791+ [ 'stash-apply' , [ [ GitErrors . changesWouldBeOverwritten , 'uncommittedChanges' ] ] ] ,
1792+ [
1793+ 'stash-push' ,
1794+ [
1795+ [ GitErrors . stashConflictingStagedAndUnstagedLines , 'conflictingStagedAndUnstagedLines' ] ,
1796+ [ GitErrors . stashNothingToSave , 'nothingToSave' ] ,
1797+ [ GitErrors . stashSavedWorkingDirAndIndexState , 'conflictingStagedAndUnstagedLines' ] ,
1798+ ] ,
1799+ ] ,
18281800 [
18291801 'tag' ,
18301802 [
0 commit comments