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

Function repoRootWith

packages/computer/src/git/reads.ts:288–305  ·  view source on GitHub ↗
(opts: RepoRootWithDeps)

Source from the content-addressed store, hash-verified

286 * finding a `.git`.
287 */
288export async function repoRootWith(opts: RepoRootWithDeps): Promise<string> {
289 const start = normalizeAbsolute(opts.dir ?? "/");
290 const fs = opts.fs as StatFsClient;
291 let current = start;
292 while (true) {
293 const gitPath = current === "/" ? "/.git" : `${current}/.git`;
294 try {
295 await fs.promises.stat(gitPath);
296 return current;
297 } catch {
298 // Not here; climb one level.
299 }
300 if (current === "/") break;
301 const slash = current.lastIndexOf("/");
302 current = slash <= 0 ? "/" : current.slice(0, slash);
303 }
304 throw new NotARepositoryError(start);
305}
306
307function normalizeAbsolute(p: string): string {
308 // Collapse a trailing slash (except the root) so the parent

Callers 2

repoRootFunction · 0.85
reads.test.tsFile · 0.85

Calls 2

normalizeAbsoluteFunction · 0.70
statMethod · 0.65

Tested by

no test coverage detected