MCPcopy Create free account
hub / github.com/cloudflare/computer / repoNameFromUrl

Function repoNameFromUrl

packages/computer/src/git/cli.ts:2322–2338  ·  view source on GitHub ↗

* Derive the default clone directory name from a repository URL, * mirroring real git: take the last non-empty path segment and * strip a trailing `.git`. Returns `undefined` when no usable * name can be extracted (e.g. the URL ends in a bare host or a * slash), so the caller can demand an expli

(url: string)

Source from the content-addressed store, hash-verified

2320 * slash), so the caller can demand an explicit destination.
2321 */
2322function repoNameFromUrl(url: string): string | undefined {
2323 // Trim a query/fragment and trailing slashes before splitting.
2324 let s = url.split(/[?#]/, 1)[0];
2325 while (s.endsWith("/")) s = s.slice(0, -1);
2326 // Drop the scheme + authority so a host with no path doesn't
2327 // yield the host name as a repo name.
2328 const schemeEnd = s.indexOf("://");
2329 const afterScheme = schemeEnd === -1 ? s : s.slice(schemeEnd + 3);
2330 const firstSlash = afterScheme.indexOf("/");
2331 if (firstSlash === -1) return undefined;
2332 const path = afterScheme.slice(firstSlash + 1);
2333 const segment = path.split("/").pop();
2334 if (segment === undefined || segment === "") return undefined;
2335 const name = segment.endsWith(".git") ? segment.slice(0, -4) : segment;
2336 if (name === "" || name === "." || name === "..") return undefined;
2337 return name;
2338}
2339
2340/** True when `ref` carries a `gitrevisions(7)` ancestry suffix. */
2341function hasRevisionSuffix(ref: string): boolean {

Callers 1

runCloneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected