fix(reference-source): distinguish Git API probes from failed reads

This commit is contained in:
N0zoM1z0
2026-10-10 16:59:30 +00:00
parent 3b66532e26
commit 87b7bf8db1
3 changed files with 81 additions and 16 deletions
+18 -2
View File
@@ -53,9 +53,25 @@ const resolveSourceHead = async (
...fs.promises,
// isomorphic-git treats every read failure as absence. Preserve real
// failures so a readable packed ref cannot hide an unreadable loose ref.
readFile: async (path: string) => {
readFile: async (path?: string, options?: unknown) => {
// isomorphic-git probes promise support with readFile() before reading
// metadata. Its rejected probe must not count as a failed file read.
if (path === undefined)
throw new TypeError("Git metadata path is required");
try {
return await readRegularFile(path, { signal });
const bytes = await readRegularFile(path, { signal });
const encoding =
typeof options === "string"
? options
: typeof options === "object" &&
options !== null &&
"encoding" in options
? options.encoding
: undefined;
if (encoding === undefined || encoding === null) return bytes;
if (typeof encoding !== "string" || !Buffer.isEncoding(encoding))
throw new TypeError("Unsupported Git metadata text encoding");
return bytes.toString(encoding);
} catch (cause: unknown) {
if (errorCode(cause) !== "ENOENT") failedRead ??= { cause };
throw cause;