Skip to content

Commit

Permalink
chore: allow multiple tags
Browse files Browse the repository at this point in the history
  • Loading branch information
florianow committed Mar 12, 2024
1 parent abb2340 commit fdedd85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/api/git/GitCliFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const result = await this.processRunner.run([
"git",
Expand All @@ -34,6 +30,14 @@ export class GitCliFacade {
return result.stdout.trim();
}

async getTags(repoDir: string): Promise<string> {
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,
Expand Down
31 changes: 17 additions & 14 deletions src/model/CollieHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,30 @@ 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) {
collieHubVersion = await this.git.getLatestTag(hubCacheDir);
await this.git.checkout(hubCacheDir, collieHubVersion);
this.config.setProperty("colliehubVersion", collieHubVersion!);
}
try {
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);
const allTags = await this.git.getTags(hubCacheGitDir);
if (!allTags.includes(latestTag)) {
throw new Error(
`version tag dont exist, possible are ${allTags} not exist`,
);
}
await this.git.checkout(hubCacheDir, collieHubVersion);
} 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;
}
Expand Down

0 comments on commit fdedd85

Please sign in to comment.