@@ -44,17 +44,57 @@ export class Addon {
4444
4545 /** Fetch addon info from `info.json` */
4646 public async fetchInfo ( ) {
47- const path = vscode . Uri . joinPath ( this . uri , INFO_FILENAME ) ;
48- const rawInfo = await filesystem . readFile ( path ) ;
47+ const infoFilePath = vscode . Uri . joinPath ( this . uri , INFO_FILENAME ) ;
48+ const modulePath = vscode . Uri . joinPath ( this . uri , "module" ) ;
49+
50+ const rawInfo = await filesystem . readFile ( infoFilePath ) ;
4951 const info = JSON . parse ( rawInfo ) as AddonInfo ;
5052
5153 this . #displayName = info . name ;
5254
55+ const moduleGit = git . cwd ( { path : modulePath . fsPath , root : false } ) ;
56+
57+ let currentVersion = null ;
58+ let tags = [ ] ;
59+
60+ await this . getEnabled ( ) ;
61+
62+ if ( this . #installed) {
63+ tags = ( await moduleGit . tags ( [ "--sort=-taggerdate" ] ) ) . all ;
64+
65+ const currentTag = await moduleGit
66+ . raw ( [ "describe" , "--tags" , "--exact-match" ] )
67+ . catch ( ( err ) => {
68+ localLogger . warn ( err ) ;
69+ return null ;
70+ } ) ;
71+ const commitsBehindLatest = await moduleGit . raw ( [
72+ "rev-list" ,
73+ `HEAD..origin/${ await this . getDefaultBranch ( ) } ` ,
74+ "--count" ,
75+ ] ) ;
76+
77+ if ( Number ( commitsBehindLatest ) < 1 ) {
78+ currentVersion = "Latest" ;
79+ } else if ( currentTag != "" ) {
80+ currentVersion = currentTag ;
81+ } else {
82+ currentVersion = await moduleGit
83+ . revparse ( [ "--short" , "HEAD" ] )
84+ . catch ( ( err ) => {
85+ localLogger . warn ( err ) ;
86+ return null ;
87+ } ) ;
88+ }
89+ }
90+
5391 return {
5492 name : info . name ,
5593 description : info . description ,
5694 size : info . size ,
5795 hasPlugin : info . hasPlugin ,
96+ tags : tags ,
97+ version : currentVersion ,
5898 } ;
5999 }
60100
@@ -85,6 +125,30 @@ export class Addon {
85125 . then ( ( message ) => localLogger . debug ( message ) ) ;
86126 }
87127
128+ public async getDefaultBranch ( ) {
129+ const modulePath = vscode . Uri . joinPath ( this . uri , "module" ) ;
130+
131+ const result = ( await git
132+ . cwd ( { path : modulePath . fsPath , root : false } )
133+ . remote ( [ "show" , "origin" ] ) ) as string ;
134+ const match = result . match ( / H E A D b r a n c h : ( \w + ) / ) ;
135+
136+ return match [ 1 ] ;
137+ }
138+
139+ public async pull ( ) {
140+ const modulePath = vscode . Uri . joinPath ( this . uri , "module" ) ;
141+
142+ return await git . cwd ( { path : modulePath . fsPath , root : false } ) . pull ( ) ;
143+ }
144+
145+ public async checkout ( obj : string ) {
146+ const modulePath = vscode . Uri . joinPath ( this . uri , "module" ) ;
147+ return git
148+ . cwd ( { path : modulePath . fsPath , root : false } )
149+ . checkout ( [ obj ] ) ;
150+ }
151+
88152 /** Check whether this addon is enabled, given an array of enabled library paths.
89153 * @param libraryPaths An array of paths from the `Lua.workspace.library` setting.
90154 */
@@ -254,7 +318,8 @@ export class Addon {
254318 public async toJSON ( ) {
255319 await this . getEnabled ( ) ;
256320
257- const { name, description, size, hasPlugin } = await this . fetchInfo ( ) ;
321+ const { name, description, size, hasPlugin, tags, version } =
322+ await this . fetchInfo ( ) ;
258323 const enabled = this . #enabled;
259324 const installTimestamp = ( await git . log ( ) ) . latest . date ;
260325 const hasUpdate = this . #hasUpdate;
@@ -270,6 +335,8 @@ export class Addon {
270335 hasUpdate,
271336 processing : this . #processing,
272337 installed : this . #installed,
338+ tags,
339+ version,
273340 } ;
274341 }
275342
0 commit comments