diff --git a/src/api/git/GitCliFacade.ts b/src/api/git/GitCliFacade.ts index 361f238..3dbee31 100644 --- a/src/api/git/GitCliFacade.ts +++ b/src/api/git/GitCliFacade.ts @@ -20,10 +20,6 @@ export class GitCliFacade { await this.processRunner.run(["git", "clone", repoUrl, destDir]); } - async pull(repoDir: string) { - await this.processRunner.run(["git", "pull"], { cwd: repoDir }); - } - async getLatestTag(repoDir: string): Promise { const result = await this.processRunner.run([ "git", @@ -34,6 +30,14 @@ export class GitCliFacade { return result.stdout.trim(); } + async getTags(repoDir: string): Promise { + const result = await this.processRunner.run([ + "git", + "tag", + ], { cwd: repoDir }); + return result.stdout.trim(); + } + async checkout(repoDir: string, tagValue: string) { await this.processRunner.run(["git", "checkout", tagValue], { cwd: repoDir, diff --git a/src/model/CollieHub.ts b/src/model/CollieHub.ts index 1f6d6e5..7968bf3 100644 --- a/src/model/CollieHub.ts +++ b/src/model/CollieHub.ts @@ -56,27 +56,29 @@ export class CollieHub { ".git", ); const hasAlreadyCloned = await this.git.isRepo(hubCacheGitDir); - const collieHubVersion = this.config.getProperty("colliehubVersion"); + let collieHubVersion = this.config.getProperty("colliehubVersion"); if (!hasAlreadyCloned) { await this.git.clone(hubCacheDir, this.url); - } + } if (!collieHubVersion) { - const latestTag = await this.git.getLatestTag(hubCacheDir); - await this.git.checkout(hubCacheDir, latestTag); - this.config.setProperty("colliehubVersion", latestTag); - } else if (collieHubVersion !== undefined) { - try { - const latestTag = await this.git.getLatestTag(hubCacheDir); - if (latestTag !== collieHubVersion) { - throw new Error(`version tag ${collieHubVersion} not exist`); - } - } catch (error) { - this.logger.error(`${error}`); - Deno.exit(1); - } + collieHubVersion = await this.git.getLatestTag(hubCacheDir); await this.git.checkout(hubCacheDir, collieHubVersion); + this.config.setProperty("colliehubVersion", collieHubVersion!); + } + try { + const allTags = await this.git.getTags(hubCacheGitDir); + if (!allTags.includes(collieHubVersion)) { + throw new Error( + `version tag does not exist, possible are: ${allTags.split("\n")}`, + ); + } + } catch (error) { + this.logger.error(`${error}`); + Deno.exit(1); } + //collie-hub version is set by the if block + await this.git.checkout(hubCacheDir, collieHubVersion!); return hubCacheDir; }