Skip to content

Commit afb81d3

Browse files
authored
Merge pull request #143 from carsakiller/addon-versioning
Addon versioning
2 parents 8aebfa9 + 2eddd49 commit afb81d3

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

client/src/addon_manager/commands/setVersion.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export default async (
1515
try {
1616
if (message.data.version === "Latest") {
1717
await addon.update();
18-
19-
const defaultBranch = await addon.getDefaultBranch();
20-
await addon.checkout(defaultBranch);
21-
await addon.pull();
2218
} else {
2319
await addon.checkout(message.data.version);
2420
}

client/src/addon_manager/models/addon.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ export class Addon {
6060
await this.getEnabled();
6161

6262
if (this.#installed) {
63-
tags = (await moduleGit.tags(["--sort=-taggerdate"])).all;
63+
tags = (
64+
await moduleGit.tags([
65+
"--sort=-taggerdate",
66+
"--merged",
67+
`origin/${await this.getDefaultBranch()}`,
68+
])
69+
).all;
6470

6571
const currentTag = await moduleGit
6672
.raw(["describe", "--tags", "--exact-match"])
6773
.catch((err) => {
68-
localLogger.warn(err);
6974
return null;
7075
});
7176
const commitsBehindLatest = await moduleGit.raw([
@@ -82,7 +87,9 @@ export class Addon {
8287
currentVersion = await moduleGit
8388
.revparse(["--short", "HEAD"])
8489
.catch((err) => {
85-
localLogger.warn(err);
90+
localLogger.warn(
91+
`Failed to get current hash for ${this.name}: ${err}`
92+
);
8693
return null;
8794
});
8895
}
@@ -126,8 +133,20 @@ export class Addon {
126133
}
127134

128135
public async getDefaultBranch() {
129-
const modulePath = vscode.Uri.joinPath(this.uri, "module");
136+
// Get branch from .gitmodules if specified
137+
const targetBranch = await git.raw(
138+
"config",
139+
"-f",
140+
".gitmodules",
141+
"--get",
142+
`submodule.addons/${this.name}/module.branch`
143+
);
144+
if (targetBranch) {
145+
return targetBranch;
146+
}
130147

148+
// Fetch default branch from remote
149+
const modulePath = vscode.Uri.joinPath(this.uri, "module");
131150
const result = (await git
132151
.cwd({ path: modulePath.fsPath, root: false })
133152
.remote(["show", "origin"])) as string;
@@ -179,9 +198,10 @@ export class Addon {
179198
);
180199

181200
const moduleURI = vscode.Uri.joinPath(this.uri, "module");
182-
this.#installed =
183-
(await filesystem.exists(moduleURI)) &&
184-
((await filesystem.readDirectory(moduleURI, { recursive: false }))?.length ?? 0) > 0;
201+
202+
const exists = await filesystem.exists(moduleURI);
203+
const empty = await filesystem.empty(moduleURI);
204+
this.#installed = exists && !empty;
185205

186206
return folderStates;
187207
}

client/src/addon_manager/services/filesystem.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ namespace filesystem {
5555
const bytes = await vscode.workspace.fs.readFile(uri);
5656
const str = bytes.toString();
5757

58-
localLogger.debug(`Read "${uri.path}"`);
59-
6058
return str;
6159
}
6260

0 commit comments

Comments
 (0)