(opts: HashObjectWithDeps)
| 66 | } |
| 67 | |
| 68 | export async function hashObjectWith(opts: HashObjectWithDeps): Promise<string> { |
| 69 | const dir = opts.dir ?? "/"; |
| 70 | // hashBlob is pure (no fs) and gives us the oid without |
| 71 | // writing. When the caller asks for write, hand the bytes to |
| 72 | // writeBlob so the object lands in the store. The two paths |
| 73 | // produce identical oids for the same input, so the typed |
| 74 | // surface returns just the oid in both cases. |
| 75 | const bytes = |
| 76 | typeof opts.content === "string" ? new TextEncoder().encode(opts.content) : opts.content; |
| 77 | try { |
| 78 | if (opts.write) { |
| 79 | return await opts.git.writeBlob({ fs: opts.fs, dir, blob: bytes }); |
| 80 | } |
| 81 | const { oid } = await opts.git.hashBlob({ object: bytes }); |
| 82 | return oid; |
| 83 | } catch (cause) { |
| 84 | if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause }); |
| 85 | throw new GitError("EHASHFAIL", `git hash-object failed: ${errorMessage(cause)}`, { |
| 86 | cause, |
| 87 | }); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // --------------------------------------------------------------- |
| 92 | // catFile |
no test coverage detected