fix(coding-agent/utils): handled EISDIR and ENOTDIR errors during ref resolution

- Update `shouldRetry` to treat `EISDIR` and `ENOTDIR` as terminal errors, preventing unnecessary retries when encountering Git reference directory conflicts.
- Add a test suite to verify graceful resolution of branches in scenarios where a packed ref conflicts with a directory path in the filesystem.
This commit is contained in:
can1357
2026-06-21 07:36:25 +02:00
parent 07c910210b
commit c5cf47aa7f
2 changed files with 73 additions and 2 deletions
+3 -2
View File
@@ -1,7 +1,7 @@
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { $which, hasFsCode, isEnoent, Snowflake } from "@oh-my-pi/pi-utils";
import { $which, hasFsCode, isEisdir, isEnoent, isEnotdir, Snowflake } from "@oh-my-pi/pi-utils";
import {
parseDiffHunks as parseCommitDiffHunks,
parseFileDiffs,
@@ -376,7 +376,8 @@ async function writeTempPatch(content: string): Promise<string> {
type EntryType = "directory" | "file";
function shouldRetry(err: unknown, n: number) {
if (isEnoent(err) || hasFsCode(err, "ENFILE") || hasFsCode(err, "EMFILE")) return false;
if (isEnoent(err) || isEisdir(err) || isEnotdir(err) || hasFsCode(err, "ENFILE") || hasFsCode(err, "EMFILE"))
return false;
if (hasFsCode(err, "EINTR")) return n < EINTR_MAX_RETRIES;
if (n > EINTR_MAX_RETRIES) throw err;
throw err;