fix(git): don't log an error when status is requested for a deleted directory

getStatus() screamed 'Failed to get Git status' and rethrew for a directory
that no longer exists — a benign case hit when PR-status resolution touches a
worktree that was deleted while still being watched. Treat a missing directory
like a non-repo: skip the error log (callers already handle/​swallow it).
This commit is contained in:
Bohdan Triapitsyn
2026-06-29 01:53:47 +03:00
parent 130ec9949b
commit f45089ccce
+14 -1
View File
@@ -824,6 +824,19 @@ const isNotGitRepositoryError = (error) => {
return /not a git repository/i.test(text);
};
// A directory that no longer exists (e.g. a worktree deleted while something
// was still polling its status) is an expected, benign condition — not a fault
// to scream about. simple-git throws "Cannot use simple-git on a directory that
// does not exist"; the underlying fs errors are ENOENT/ENOTDIR.
const isMissingDirectoryError = (error) => {
const code = error?.code;
if (code === 'ENOENT' || code === 'ENOTDIR') {
return true;
}
const text = parseGitErrorText(error);
return /directory that does not exist|does not exist|no such file or directory/i.test(text);
};
const runGitCommand = async (cwd, args) => {
try {
const { stdout, stderr } = await execFileAsync(getGitBinary(), args, {
@@ -2184,7 +2197,7 @@ export async function getStatus(directory, options = {}) {
rebaseInProgress,
};
} catch (error) {
if (!isNotGitRepositoryError(error)) {
if (!isNotGitRepositoryError(error) && !isMissingDirectoryError(error)) {
console.error('Failed to get Git status:', error);
}
throw error;