Skip to content

Commit c918e6f

Browse files
only21milclaude
andcommitted
fix(github): strip only one .git suffix from a URL selector
The selector-level strip ran before URL parsing and the pathname strip ran again after it, so https://github.com/acme/web.git.git lost both suffixes. Strip from the pathname for URLs and from the selector string only for bare and host-qualified forms, so every form drops exactly one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d36fc13 commit c918e6f

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ describe("selectGitHubBaseRepository", () => {
7777

7878
describe("parseGitHubRepositorySelector", () => {
7979
it("drops a clone URL's .git suffix wherever the selector ends", () => {
80-
for (const [selector, host] of [
81-
["https://github.com/acme/web.git", "github.com"],
82-
["https://github.com/acme/web.git/", "github.com"],
83-
["https://github.com/acme/web.git?tab=readme", "github.com"],
84-
["acme/web.git/", "github.com"],
85-
["ghe.example.com/acme/web.git/", "ghe.example.com"],
80+
for (const [selector, host, name] of [
81+
["https://github.com/acme/web.git", "github.com", "web"],
82+
["https://github.com/acme/web.git/", "github.com", "web"],
83+
["https://github.com/acme/web.git?tab=readme", "github.com", "web"],
84+
["https://github.com/acme/web.git.git", "github.com", "web.git"],
85+
["https://github.com/acme/web.git.git/", "github.com", "web.git"],
86+
["acme/web.git/", "github.com", "web"],
87+
["ghe.example.com/acme/web.git/", "ghe.example.com", "web"],
8688
] as const) {
8789
assert.deepStrictEqual(parseGitHubRepositorySelector(selector, "github.com"), {
8890
host,
8991
owner: "acme",
90-
name: "web",
92+
name,
9193
});
9294
}
9395
});

‎packages/source-control-github/src/server/gitHubRepositoryResolution.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function parseGitHubRepositorySelector(
114114
): GitHubRepositoryLocator | null {
115115
// Like gh, a clone URL's `.git` comes off the path, before any trailing slash, query or fragment.
116116
const withoutGitSuffix = (path: string) => path.replace(/\.git\/*$/i, "");
117-
const trimmed = withoutGitSuffix(selector.trim());
117+
const trimmed = selector.trim();
118118
if (/^https?:\/\//i.test(trimmed)) {
119119
try {
120120
const url = new URL(trimmed);
@@ -126,7 +126,7 @@ export function parseGitHubRepositorySelector(
126126
return null;
127127
}
128128
}
129-
const parts = trimmed.split("/").filter(Boolean);
129+
const parts = withoutGitSuffix(trimmed).split("/").filter(Boolean);
130130
if (parts.length === 2) return { host: defaultHost, owner: parts[0]!, name: parts[1]! };
131131
if (parts.length === 3)
132132
return { host: parts[0]!.toLowerCase(), owner: parts[1]!, name: parts[2]! };

0 commit comments

Comments
 (0)