GeezerVison is showing github.com — fix(client-runtime): local repository clone folders keep # and ? in t… · patroza/t3code@4732927
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/client-runtime/src/operations
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/operations/projects.test.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -143,6 +143,11 @@ describe("add project shared logic", () => { |
143 | 143 | expect(getCloneDirectoryName("C:\\src\\repo.git")).toBe("repo"); |
144 | 144 | |
145 | 145 | expect(getCloneDirectoryName(" https://github.com/owner/repo.git ")).toBe("repo"); |
| 146 | + expect(getCloneDirectoryName("/srv/git/firmware#2.git")).toBe("firmware#2"); |
| 147 | + expect(getCloneDirectoryName("~/git/what?.git")).toBe("what?"); |
| 148 | + expect(getCloneDirectoryName("../firmware#2.git")).toBe("firmware#2"); |
| 149 | + expect(getCloneDirectoryName("C:\\src\\firmware#2.git")).toBe("firmware#2"); |
| 150 | + expect(getCloneDirectoryName("github.com:owner/repo.git?ref=main")).toBe("repo"); |
146 | 151 | }); |
147 | 152 |
|
148 | 153 | it("lays clone folders out like ghq only when asked, and only when the URL is safe", () => { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/operations/projects.ts +11-2Lines changed: 11 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,12 @@ import type { |
12 | 12 | } from "@t3tools/contracts"; |
13 | 13 | import { SourceControlProviderKind } from "@t3tools/contracts"; |
14 | 14 | import { cloneUrlRepositoryPath } from "@t3tools/shared/cloneUrl"; |
15 | | -import { isAbsolutePath, isExplicitRelativePath, newProjectFolderName } from "@t3tools/shared/path"; |
| 15 | +import { |
| 16 | + isAbsolutePath, |
| 17 | + isExplicitRelativePath, |
| 18 | + isHostPath, |
| 19 | + newProjectFolderName, |
| 20 | +} from "@t3tools/shared/path"; |
16 | 21 | import * as Arr from "effect/Array"; |
17 | 22 | import * as Option from "effect/Option"; |
18 | 23 | import * as Order from "effect/Order"; |
@@ -234,7 +239,11 @@ export function getAddProjectInitialQuery(baseDirectory: string | null | undefin |
234 | 239 | } |
235 | 240 |
|
236 | 241 | export function getCloneDirectoryName(repositoryOrRemoteUrl: string | null | undefined): string { |
237 | | - const withoutQuery = (repositoryOrRemoteUrl ?? "").split(/[?#]/)[0]?.trim() ?? ""; |
| 242 | + const trimmed = (repositoryOrRemoteUrl ?? "").trim(); |
| 243 | + // A local path keeps `#` and `?` in its name; in a URL they start a query or fragment. |
| 244 | + const isLocalPath = |
| 245 | + !trimmed.includes("://") && (isHostPath(trimmed) || isExplicitRelativePath(trimmed)); |
| 246 | + const withoutQuery = isLocalPath ? trimmed : (trimmed.split(/[?#]/)[0] ?? ""); |
238 | 247 | const schemeIndex = withoutQuery.indexOf("://"); |
239 | 248 | const hasHost = schemeIndex >= 0 || /^[^/\\:]+@[^/\\:]+:/.test(withoutQuery); |
240 | 249 | const pathPart = schemeIndex >= 0 ? withoutQuery.slice(schemeIndex + "://".length) : withoutQuery; |
|