Skip to content

Commit 7da3065

Browse files
fix(source-control): a query or fragment after .git keeps the repository identity
The .git suffix was only stripped at the end of the whole remote string, so https://github.com/owner/repo.git?view=compact kept it and was identified as owner/repo.git. Strip it from the parsed URL path, and drop the query and fragment of URL remotes before reading the repository path. Fixes #34807 AI-assisted; verified with the tests and tools listed above.
1 parent 146c03e commit 7da3065

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/shared/src/git.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ export function parseGitRemoteRepository(
142142
if (/^(?:ssh|https?|git):\/\//i.test(normalized)) {
143143
try {
144144
const url = new URL(normalized);
145-
const repositorySegments = url.pathname.split("/").filter((segment) => segment.length > 0);
145+
const repositorySegments = url.pathname
146+
.replace(/\/+$/, "")
147+
.replace(/\.git$/, "")
148+
.split("/")
149+
.filter((segment) => segment.length > 0);
146150
if (url.hostname && repositorySegments.length > 1) {
147151
return { host: url.hostname, path: repositorySegments.join("/") };
148152
}

‎packages/source-control-core/src/server/SourceControlProvider.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export function sourceControlRefFromInput(input: {
100100
}
101101

102102
export function repositoryPathFromRemoteUrl(url: string | null): string | null {
103-
const trimmed = url?.trim() ?? "";
103+
const remote = url?.trim() ?? "";
104+
const trimmed = /^(?:ssh|https?|git):\/\//iu.test(remote) ? remote.split(/[?#]/u, 1)[0]! : remote;
104105
if (trimmed.length === 0) {
105106
return null;
106107
}

0 commit comments

Comments
 (0)