fix(gsd): suppress misleading warnings for expected ENOENT/EISDIR conditions

Skip ENOENT warnings in clearProjectRootStateFiles and untracked file
cleanup since missing files are expected. Check if .git is a directory
before attempting readFileSync in resolveGitDir to avoid EISDIR warning
in normal (non-worktree) repos.

Fixes #3597

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tibsfox 2026-04-06 18:23:54 -07:00
parent b4c6229360
commit f93123cdbb
2 changed files with 13 additions and 6 deletions

View file

@ -188,8 +188,10 @@ function clearProjectRootStateFiles(basePath: string, milestoneId: string): void
try {
unlinkSync(file);
} catch (err) {
/* non-fatal — file may not exist */
logWarning("worktree", `file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
// ENOENT is expected — file may not exist (#3597)
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
logWarning("worktree", `file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
}
}
}
@ -218,8 +220,11 @@ function clearProjectRootStateFiles(basePath: string, milestoneId: string): void
try {
unlinkSync(join(basePath, f));
} catch (err) {
/* non-fatal */
logWarning("worktree", `untracked file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
// ENOENT/EISDIR are expected for already-removed or directory entries (#3597)
const code = (err as NodeJS.ErrnoException).code;
if (code !== "ENOENT" && code !== "EISDIR") {
logWarning("worktree", `untracked file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
}
}
}
}

View file

@ -89,7 +89,9 @@ function normalizePathForComparison(path: string): string {
*/
export function resolveGitDir(basePath: string): string {
const gitPath = join(basePath, ".git");
if (!existsSync(gitPath)) return join(basePath, ".git");
if (!existsSync(gitPath)) return gitPath;
// In a normal repo .git is a directory — skip the file read (#3597)
if (lstatSync(gitPath).isDirectory()) return gitPath;
try {
const content = readFileSync(gitPath, "utf-8").trim();
if (content.startsWith("gitdir: ")) {
@ -98,7 +100,7 @@ export function resolveGitDir(basePath: string): string {
} catch (e) {
logWarning("worktree", `.git file read failed: ${(e as Error).message}`);
}
return join(basePath, ".git");
return gitPath;
}
export function worktreesDir(basePath: string): string {