(opts: LsTreeWithDeps)
| 397 | } |
| 398 | |
| 399 | export 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 | |
| 424 | function inferType(mode: string): "blob" | "tree" | "commit" { |
| 425 | if (mode.startsWith("04")) return "tree"; |
no test coverage detected