@@ -22,6 +22,8 @@ import {
2222 PushErrorReason ,
2323 StashPushError ,
2424 StashPushErrorReason ,
25+ TagError ,
26+ TagErrorReason ,
2527 WorkspaceUntrustedError ,
2628} from '../../../git/errors' ;
2729import type { GitDir } from '../../../git/gitProvider' ;
@@ -32,7 +34,6 @@ import type { GitUser } from '../../../git/models/user';
3234import { parseGitBranchesDefaultFormat } from '../../../git/parsers/branchParser' ;
3335import { parseGitLogAllFormat , parseGitLogDefaultFormat } from '../../../git/parsers/logParser' ;
3436import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser' ;
35- import { parseGitTagsDefaultFormat } from '../../../git/parsers/tagParser' ;
3637import { splitAt } from '../../../system/array' ;
3738import { log } from '../../../system/decorators/log' ;
3839import { join } from '../../../system/iterable' ;
@@ -99,6 +100,10 @@ export const GitErrors = {
99100 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,
100101 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,
101102 unstagedChanges : / Y o u h a v e u n s t a g e d c h a n g e s / i,
103+ tagAlreadyExists : / t a g .* a l r e a d y e x i s t s / i,
104+ tagNotFound : / t a g .* n o t f o u n d / i,
105+ invalidTagName : / i n v a l i d t a g n a m e / i,
106+ 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,
102107} ;
103108
104109const GitWarnings = {
@@ -159,6 +164,14 @@ function getStdinUniqueKey(): number {
159164type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
160165export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
161166
167+ const tagErrorAndReason = [
168+ [ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
169+ [ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
170+ [ GitErrors . invalidTagName , TagErrorReason . InvalidTagName ] ,
171+ [ GitErrors . permissionDenied , TagErrorReason . PermissionDenied ] ,
172+ [ GitErrors . remoteRejected , TagErrorReason . RemoteRejected ] ,
173+ ] ;
174+
162175export class Git {
163176 /** Map of running git commands -- avoids running duplicate overlaping commands */
164177 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -2116,8 +2129,19 @@ export class Git {
21162129 return this . git < string > ( { cwd : repoPath } , 'symbolic-ref' , '--short' , ref ) ;
21172130 }
21182131
2119- tag ( repoPath : string ) {
2120- return this . git < string > ( { cwd : repoPath } , 'tag' , '-l' , `--format=${ parseGitTagsDefaultFormat } ` ) ;
2132+ async tag ( repoPath : string , ...args : string [ ] ) {
2133+ try {
2134+ const output = await this . git < string > ( { cwd : repoPath } , 'tag' , ...args ) ;
2135+ return output ;
2136+ } catch ( ex ) {
2137+ const msg : string = ex ?. toString ( ) ?? '' ;
2138+ for ( const [ error , reason ] of tagErrorAndReason ) {
2139+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
2140+ throw new TagError ( reason , ex ) ;
2141+ }
2142+ }
2143+ throw new TagError ( TagErrorReason . Other , ex ) ;
2144+ }
21212145 }
21222146
21232147 worktree__add (
0 commit comments