Skip to content
Closed
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
6 changes: 4 additions & 2 deletions lib/gstack-memory-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ export function canonicalizeRemote(url: string | null | undefined): string {
// strip user@ prefix on URL-style remotes
s = s.replace(/^[^@\/]+@/, "");
}
// strip trailing slash(es) first, so a URL written with a trailing slash
// still matches the `.git$` suffix below (e.g. ".../repo.git/" must
// canonicalize to ".../repo", not ".../repo.git").
s = s.replace(/\/+$/, "");
// strip trailing .git
s = s.replace(/\.git$/i, "");
// strip trailing slash
s = s.replace(/\/+$/, "");
// collapse multiple slashes (after path normalization)
s = s.replace(/\/{2,}/g, "/");
return s.toLowerCase();
Expand Down
15 changes: 15 additions & 0 deletions test/gstack-memory-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ describe("canonicalizeRemote", () => {
it("collapses redundant slashes", () => {
expect(canonicalizeRemote("https://github.com//foo//bar")).toBe("github.com/foo/bar");
});

it("strips .git even when the URL has a trailing slash", () => {
// A remote configured with both a .git suffix and a trailing slash must
// canonicalize to the same key as one without — otherwise the same repo
// gets two dedup/source-id keys across machines.
expect(canonicalizeRemote("https://github.com/garrytan/gstack.git/")).toBe("github.com/garrytan/gstack");
expect(canonicalizeRemote("git@github.com:garrytan/gstack.git/")).toBe("github.com/garrytan/gstack");
expect(canonicalizeRemote("https://github.com/foo/bar.git///")).toBe("github.com/foo/bar");
});

it("produces the same key with or without a trailing slash", () => {
expect(canonicalizeRemote("https://github.com/garrytan/gstack.git/")).toBe(
canonicalizeRemote("https://github.com/garrytan/gstack.git")
);
});
});

// ── secretScanFile ─────────────────────────────────────────────────────────
Expand Down
Loading