mirror of https://github.com/garrytan/gstack.git
Merge 35e4aa53e9 into a3259400a3
This commit is contained in:
commit
b8ed8aa134
|
|
@ -124,8 +124,18 @@ function windowToDate(window: string): Date {
|
|||
export function normalizeRemoteUrl(url: string): string {
|
||||
let normalized = url.trim();
|
||||
|
||||
// SSH → HTTPS: git@github.com:user/repo → https://github.com/user/repo
|
||||
const sshMatch = normalized.match(/^(?:ssh:\/\/)?git@([^:]+):(.+)$/);
|
||||
// SSH URL → HTTPS: ssh://git@github.com/user/repo → https://github.com/user/repo
|
||||
try {
|
||||
const parsed = new URL(normalized);
|
||||
if (parsed.protocol === "ssh:" && parsed.username === "git" && parsed.pathname.length > 1) {
|
||||
normalized = `https://${parsed.host}${parsed.pathname}`;
|
||||
}
|
||||
} catch {
|
||||
// Not a URL-style remote; try scp-style below.
|
||||
}
|
||||
|
||||
// SCP-style SSH → HTTPS: git@github.com:user/repo → https://github.com/user/repo
|
||||
const sshMatch = normalized.match(/^git@([^:]+):(.+)$/);
|
||||
if (sshMatch) {
|
||||
normalized = `https://${sshMatch[1]}/${sshMatch[2]}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ describe("gstack-global-discover", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("converts URL-style SSH to HTTPS", () => {
|
||||
expect(normalizeRemoteUrl("ssh://git@github.com/user/repo.git")).toBe(
|
||||
"https://github.com/user/repo"
|
||||
);
|
||||
});
|
||||
|
||||
test("converts SSH without .git to HTTPS", () => {
|
||||
expect(normalizeRemoteUrl("git@github.com:user/repo")).toBe(
|
||||
"https://github.com/user/repo"
|
||||
|
|
@ -44,9 +50,11 @@ describe("gstack-global-discover", () => {
|
|||
|
||||
test("SSH and HTTPS for same repo normalize to same URL", () => {
|
||||
const ssh = normalizeRemoteUrl("git@github.com:garrytan/gstack.git");
|
||||
const sshUrl = normalizeRemoteUrl("ssh://git@github.com/garrytan/gstack.git");
|
||||
const https = normalizeRemoteUrl("https://github.com/garrytan/gstack.git");
|
||||
const httpsNoDotGit = normalizeRemoteUrl("https://github.com/garrytan/gstack");
|
||||
expect(ssh).toBe(https);
|
||||
expect(sshUrl).toBe(https);
|
||||
expect(https).toBe(httpsNoDotGit);
|
||||
});
|
||||
|
||||
|
|
@ -61,6 +69,12 @@ describe("gstack-global-discover", () => {
|
|||
"https://gitlab.com/org/project"
|
||||
);
|
||||
});
|
||||
|
||||
test("handles GitLab URL-style SSH URLs", () => {
|
||||
expect(normalizeRemoteUrl("ssh://git@gitlab.com/org/project.git")).toBe(
|
||||
"https://gitlab.com/org/project"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("CLI", () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue