Skip to content

Commit 6b2591b

Browse files
fix(source-control): a query or fragment after .git keeps the repository identity (pingdotgg#34857)
1 parent 0b6f482 commit 6b2591b

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎packages/shared/src/git.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ describe("normalizeGitRemoteUrl", () => {
2727
expect(normalizeGitRemoteUrl("ssh://[email protected]/T3Tools/T3Code")).toBe(
2828
"github.com/t3tools/t3code",
2929
);
30+
expect(normalizeGitRemoteUrl("https://github.com/T3Tools/T3Code.git?view=compact")).toBe(
31+
"github.com/t3tools/t3code",
32+
);
33+
expect(normalizeGitRemoteUrl("https://github.com/T3Tools/T3Code.git#section")).toBe(
34+
"github.com/t3tools/t3code",
35+
);
36+
expect(normalizeGitRemoteUrl("ssh://[email protected]/owner/repo.git.git")).toBe(
37+
normalizeGitRemoteUrl("[email protected]:owner/repo.git.git"),
38+
);
3039
});
3140

3241
it("preserves nested group paths for providers like GitLab", () => {

‎packages/shared/src/git.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ export function parseGitRemoteRepository(
141141

142142
if (/^(?:ssh|https?|git):\/\//i.test(normalized)) {
143143
try {
144-
const url = new URL(normalized);
145-
const repositorySegments = url.pathname.split("/").filter((segment) => segment.length > 0);
144+
// Parse the raw remote: `.git` may sit before a query or fragment, so strip it from the path once.
145+
const url = new URL(value.trim().toLowerCase());
146+
const repositorySegments = url.pathname
147+
.replace(/\/+$/, "")
148+
.replace(/\.git$/, "")
149+
.split("/")
150+
.filter((segment) => segment.length > 0);
146151
if (url.hostname && repositorySegments.length > 1) {
147152
return { host: url.hostname, path: repositorySegments.join("/") };
148153
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ it.each([
1919
["github.com:T3Tools/t3code.git", "T3Tools/t3code"],
2020
["gitlab.com:T3Tools/platform/t3code", "T3Tools/platform/t3code"],
2121
["https://github.com/T3Tools/t3code.git", "T3Tools/t3code"],
22+
["https://github.com/T3Tools/t3code.git?view=compact", "T3Tools/t3code"],
23+
["https://github.com/T3Tools/t3code.git#section", "T3Tools/t3code"],
2224
["C:/repos/t3code", null],
2325
])("reads the repository path of %s", (remoteUrl, expected) => {
2426
assert.strictEqual(repositoryPathFromRemoteUrl(remoteUrl), expected);

‎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)