@@ -7,15 +7,15 @@ class GitError extends AbstractError {
77}
88
99export class Git {
10- async git ( args : string [ ] ) {
10+ async git ( args : string [ ] ) : Promise < string > {
1111 const { stdout, stderr } = await exec ( 'git' , args ) ;
1212
1313 if ( stderr ) throw stderr ;
1414
1515 return stdout ;
1616 }
1717
18- async userName ( ) {
18+ async userName ( ) : Promise < string > {
1919 try {
2020 return ( await this . git ( [ 'config' , '--get' , 'user.name' ] ) ) . trim ( ) ;
2121 } catch ( error ) {
@@ -25,15 +25,15 @@ export class Git {
2525 }
2626 }
2727
28- async latestTag ( ) {
28+ async latestTag ( ) : Promise < string | null > {
2929 try {
3030 return ( await this . git ( [ 'describe' , '--tags' , '--abbrev=0' ] ) ) . trim ( ) ;
3131 } catch {
3232 return null ;
3333 }
3434 }
3535
36- async tags ( ) {
36+ async tags ( ) : Promise < string [ ] > {
3737 try {
3838 return ( await this . git ( [ 'tag' , '-l' ] ) )
3939 . trim ( )
@@ -47,17 +47,17 @@ export class Git {
4747 }
4848 }
4949
50- async previousTag ( tag : string ) {
50+ async previousTag ( tag : string ) : Promise < string | null > {
5151 try {
5252 const tags = await this . tags ( ) ;
5353
54- return tags . at ( tags . findIndex ( ( t ) => t === tag ) - 1 ) ;
54+ return tags . at ( tags . findIndex ( ( t ) => t === tag ) - 1 ) ?? null ;
5555 } catch {
5656 return null ;
5757 }
5858 }
5959
60- async dryFetch ( ) {
60+ async dryFetch ( ) : Promise < string > {
6161 try {
6262 return await this . git ( [ 'fetch' , '--dry-run' ] ) ;
6363 } catch ( error ) {
@@ -67,7 +67,7 @@ export class Git {
6767 }
6868 }
6969
70- async fetch ( ) {
70+ async fetch ( ) : Promise < boolean > {
7171 try {
7272 await this . git ( [ 'fetch' ] ) ;
7373
@@ -79,7 +79,7 @@ export class Git {
7979 }
8080 }
8181
82- async pull ( ) {
82+ async pull ( ) : Promise < boolean > {
8383 try {
8484 await this . git ( [ 'pull' ] ) ;
8585
@@ -91,9 +91,9 @@ export class Git {
9191 }
9292 }
9393
94- async revisionDiffsCount ( ) {
94+ async revisionDiffsCount ( ) : Promise < number > {
9595 try {
96- return await Number . parseInt (
96+ return Number . parseInt (
9797 await this . git ( [ 'rev-list' , '@{u}...HEAD' , '--count' , '--left-only' ] ) ,
9898 ) ;
9999 } catch ( error ) {
@@ -104,7 +104,7 @@ export class Git {
104104 }
105105 }
106106
107- async status ( ) {
107+ async status ( ) : Promise < string > {
108108 try {
109109 return ( await this . git ( [ 'status' , '--porcelain' ] ) ) . trim ( ) ;
110110 } catch ( error ) {
@@ -114,7 +114,10 @@ export class Git {
114114 }
115115 }
116116
117- async commits ( leftRev : string , rightRev : string ) {
117+ async commits (
118+ leftRev : string ,
119+ rightRev : string ,
120+ ) : Promise < { id : string ; message : string } [ ] > {
118121 try {
119122 const logs = await this . git ( [
120123 'log' ,
@@ -137,17 +140,17 @@ export class Git {
137140 }
138141 }
139142
140- async version ( ) {
143+ async version ( ) : Promise < string > {
141144 try {
142- return ( await this . git ( [ '--version' ] ) ) . trim ( ) . match ( / \d + \. \d + \. \d + / ) ?. [ 0 ] ;
145+ return ` ${ ( await this . git ( [ '--version' ] ) ) . trim ( ) . match ( / \d + \. \d + \. \d + / ) ?. [ 0 ] } ` ;
143146 } catch ( error ) {
144147 throw new GitError ( 'Failed to run `git --version`' , {
145148 cause : error ,
146149 } ) ;
147150 }
148151 }
149152
150- async branch ( ) {
153+ async branch ( ) : Promise < string > {
151154 try {
152155 return ( await this . git ( [ 'rev-parse' , '--abbrev-ref' , 'HEAD' ] ) ) . trim ( ) ;
153156 } catch ( error ) {
@@ -157,7 +160,7 @@ export class Git {
157160 }
158161 }
159162
160- async switch ( branch : string ) {
163+ async switch ( branch : string ) : Promise < boolean > {
161164 try {
162165 await this . git ( [ 'switch' , branch ] ) ;
163166
@@ -169,7 +172,7 @@ export class Git {
169172 }
170173 }
171174
172- async checkTagExist ( tag : string ) {
175+ async checkTagExist ( tag : string ) : Promise < boolean > {
173176 try {
174177 return (
175178 (
@@ -186,7 +189,7 @@ export class Git {
186189 }
187190 }
188191
189- async deleteTag ( tag : string ) {
192+ async deleteTag ( tag : string ) : Promise < boolean > {
190193 try {
191194 await this . git ( [ 'tag' , '--delete' , tag ] ) ;
192195
@@ -198,7 +201,7 @@ export class Git {
198201 }
199202 }
200203
201- async stageAll ( ) {
204+ async stageAll ( ) : Promise < boolean > {
202205 try {
203206 await this . git ( [ 'add' , '.' ] ) ;
204207
@@ -210,7 +213,7 @@ export class Git {
210213 }
211214 }
212215
213- async stash ( ) {
216+ async stash ( ) : Promise < boolean > {
214217 try {
215218 await this . git ( [ 'stash' ] ) ;
216219
@@ -222,7 +225,7 @@ export class Git {
222225 }
223226 }
224227
225- async popStash ( ) {
228+ async popStash ( ) : Promise < boolean > {
226229 try {
227230 await this . git ( [ 'stash' , 'pop' ] ) ;
228231
@@ -234,7 +237,7 @@ export class Git {
234237 }
235238 }
236239
237- async stage ( file : string ) {
240+ async stage ( file : string ) : Promise < boolean > {
238241 try {
239242 await this . git ( [ 'add' , file ] ) ;
240243
@@ -246,7 +249,7 @@ export class Git {
246249 }
247250 }
248251
249- async reset ( rev ?: string , option ?: string ) {
252+ async reset ( rev ?: string , option ?: string ) : Promise < boolean > {
250253 const args = [ 'reset' , rev , option ] . filter ( ( v ) => v ) as string [ ] ;
251254
252255 try {
@@ -260,7 +263,7 @@ export class Git {
260263 }
261264 }
262265
263- async latestCommit ( ) {
266+ async latestCommit ( ) : Promise < string > {
264267 try {
265268 return ( await this . git ( [ 'rev-parse' , 'HEAD' ] ) ) . trim ( ) ;
266269 } catch ( error ) {
@@ -270,7 +273,7 @@ export class Git {
270273 }
271274 }
272275
273- async firstCommit ( ) {
276+ async firstCommit ( ) : Promise < string > {
274277 try {
275278 return ( await this . git ( [ 'rev-list' , '--max-parents=0' , 'HEAD' ] ) ) . trim ( ) ;
276279 } catch ( error ) {
@@ -280,7 +283,7 @@ export class Git {
280283 }
281284 }
282285
283- async commit ( message : string ) {
286+ async commit ( message : string ) : Promise < string > {
284287 try {
285288 await this . git ( [ 'commit' , '-m' , message ] ) ;
286289
@@ -292,7 +295,7 @@ export class Git {
292295 }
293296 }
294297
295- async repository ( ) {
298+ async repository ( ) : Promise < string > {
296299 try {
297300 return ( await this . git ( [ 'remote' , 'get-url' , 'origin' ] ) ) . trim ( ) ;
298301 } catch ( error ) {
@@ -302,7 +305,7 @@ export class Git {
302305 }
303306 }
304307
305- async createTag ( tag : string , commitRev ?: string ) {
308+ async createTag ( tag : string , commitRev ?: string ) : Promise < boolean > {
306309 const args = [ 'tag' , tag , commitRev ] . filter ( ( v ) => v ) as string [ ] ;
307310
308311 try {
@@ -316,7 +319,7 @@ export class Git {
316319 }
317320 }
318321
319- async push ( options ?: string ) {
322+ async push ( options ?: string ) : Promise < boolean > {
320323 const args = [ 'push' , options ] . filter ( ( v ) => v ) as string [ ] ;
321324
322325 try {
0 commit comments