@@ -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' ;
@@ -100,6 +101,10 @@ export const GitErrors = {
100101 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,
101102 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,
102103 unstagedChanges : / Y o u h a v e u n s t a g e d c h a n g e s / i,
104+ tagAlreadyExists : / t a g .* a l r e a d y e x i s t s / i,
105+ tagNotFound : / t a g .* n o t f o u n d / i,
106+ invalidTagName : / i n v a l i d t a g n a m e / i,
107+ 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,
103108} ;
104109
105110const GitWarnings = {
@@ -160,6 +165,14 @@ function getStdinUniqueKey(): number {
160165type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly : true } ;
161166export type PushForceOptions = { withLease : true ; ifIncludes ?: boolean } | { withLease : false ; ifIncludes ?: never } ;
162167
168+ const tagErrorAndReason : [ RegExp , TagErrorReason ] [ ] = [
169+ [ GitErrors . tagAlreadyExists , TagErrorReason . TagAlreadyExists ] ,
170+ [ GitErrors . tagNotFound , TagErrorReason . TagNotFound ] ,
171+ [ GitErrors . invalidTagName , TagErrorReason . InvalidTagName ] ,
172+ [ GitErrors . permissionDenied , TagErrorReason . PermissionDenied ] ,
173+ [ GitErrors . remoteRejected , TagErrorReason . RemoteRejected ] ,
174+ ] ;
175+
163176export class Git {
164177 /** Map of running git commands -- avoids running duplicate overlaping commands */
165178 private readonly pendingCommands = new Map < string , Promise < string | Buffer > > ( ) ;
@@ -2078,8 +2091,19 @@ export class Git {
20782091 return this . git < string > ( { cwd : repoPath } , 'symbolic-ref' , '--short' , ref ) ;
20792092 }
20802093
2081- tag ( repoPath : string ) {
2082- return this . git < string > ( { cwd : repoPath } , 'tag' , '-l' , `--format=${ parseGitTagsDefaultFormat } ` ) ;
2094+ async tag ( repoPath : string , ...args : string [ ] ) {
2095+ try {
2096+ const output = await this . git < string > ( { cwd : repoPath } , 'tag' , ...args ) ;
2097+ return output ;
2098+ } catch ( ex ) {
2099+ const msg : string = ex ?. toString ( ) ?? '' ;
2100+ for ( const [ error , reason ] of tagErrorAndReason ) {
2101+ if ( error . test ( msg ) || error . test ( ex . stderr ?? '' ) ) {
2102+ throw new TagError ( reason , ex ) ;
2103+ }
2104+ }
2105+ throw new TagError ( TagErrorReason . Other , ex ) ;
2106+ }
20832107 }
20842108
20852109 worktree__add (
0 commit comments