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

Function lsTreeWith

packages/computer/src/git/reads.ts:399–422  ·  view source on GitHub ↗
(opts: LsTreeWithDeps)

Source from the content-addressed store, hash-verified

397}
398
399export async function lsTreeWith(opts: LsTreeWithDeps): Promise<TreeEntryView[]> {
400 const dir = opts.dir ?? "/";
401 try {
402 const oid = await opts.git.resolveRef({ fs: opts.fs, dir, ref: opts.ref });
403 const { tree } = await opts.git.readTree({
404 fs: opts.fs,
405 dir,
406 oid,
407 filepath: opts.path,
408 cache: opts.cache,
409 });
410 return tree.map((e) => ({
411 mode: e.mode,
412 path: e.path,
413 oid: e.oid,
414 type: (e.type ?? inferType(e.mode)) as TreeEntryView["type"],
415 }));
416 } catch (cause) {
417 if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause });
418 throw new GitError("ELSTREEFAIL", `git ls-tree failed: ${errorMessage(cause)}`, {
419 cause,
420 });
421 }
422}
423
424function inferType(mode: string): "blob" | "tree" | "commit" {
425 if (mode.startsWith("04")) return "tree";

Callers 2

lsTreeFunction · 0.85
reads.test.tsFile · 0.85

Calls 5

inferTypeFunction · 0.85
isNotARepositoryCauseFunction · 0.85
readTreeMethod · 0.80
errorMessageFunction · 0.70
resolveRefMethod · 0.65

Tested by

no test coverage detected