Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/git-url-tag-suffix-not-parsed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@generata/core": patch
---

fix: parse @ref suffix from git URLs in classifySpecifier
26 changes: 26 additions & 0 deletions packages/core/src/cli/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ describe("classifySpecifier", () => {
strictEqual(classifySpecifier("https://github.com/ben/repo.git").kind, "git-url");
strictEqual(classifySpecifier("git@github.com:ben/repo.git").kind, "git-url");
});

it("extracts @ref suffix from git URLs", () => {
const c = classifySpecifier("https://github.com/you/template.git@v2");
strictEqual(c.kind, "git-url");
if (c.kind === "git-url") {
strictEqual(c.url, "https://github.com/you/template.git");
strictEqual(c.ref, "v2");
}
});

it("leaves ref undefined for git URLs without @ref suffix", () => {
const c = classifySpecifier("https://github.com/ben/repo.git");
strictEqual(c.kind, "git-url");
if (c.kind === "git-url") {
strictEqual(c.ref, undefined);
}
});

it("extracts @ref from SSH-style git URLs", () => {
const c = classifySpecifier("git@github.com:you/template.git@v2");
strictEqual(c.kind, "git-url");
if (c.kind === "git-url") {
strictEqual(c.url, "git@github.com:you/template.git");
strictEqual(c.ref, "v2");
}
});
});

describe("resolveTemplate (local)", () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/cli/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const exec = promisify(execFile);
export type Specifier =
| { kind: "catalog"; alias: string }
| { kind: "github-short"; url: string }
| { kind: "git-url"; url: string }
| { kind: "git-url"; url: string; ref?: string }
| { kind: "local"; path: string };

export interface ResolvedTemplate {
Expand Down Expand Up @@ -39,8 +39,13 @@ export function classifySpecifier(spec: string): Specifier {
spec.startsWith("git@") ||
spec.startsWith("https://") ||
spec.startsWith("git+") ||
spec.endsWith(".git")
spec.endsWith(".git") ||
/\.git@[^@]+$/.test(spec)
) {
const parts = spec.split(/\.git@(.+)$/);
if (parts.length >= 2 && parts[1]) {
return { kind: "git-url", url: `${parts[0]}.git`, ref: parts[1] };
}
return { kind: "git-url", url: spec };
}
if (isAbsolute(spec) || spec.startsWith("./") || spec.startsWith("../")) {
Expand Down Expand Up @@ -76,7 +81,8 @@ export async function resolveTemplate(spec: string): Promise<ResolvedTemplate> {
}

if (classified.kind === "github-short" || classified.kind === "git-url") {
const cloned = await cloneToTemp(classified.url);
const ref = classified.kind === "git-url" ? classified.ref : undefined;
const cloned = await cloneToTemp(classified.url, ref);
assertHasManifest(cloned.dir, classified.url, cloned.cleanup);
return cloned;
}
Expand Down
Loading