From b2ca2c2eb13645ea197194d3255a0ba7d8f7dad0 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Sun, 19 Apr 2026 06:53:20 +0800 Subject: [PATCH] refactor(git-error): drop locale-specific not-a-repo patterns Child processes now have LANG/LC_ALL pinned to C.UTF-8 on every platform, so git stderr is always English when it leaks past the typed not_a_git_repository preflight. The 8 non-English regex fallbacks were dead code; keep only the English pattern as a belt-and-suspenders fallback for un-preflighted commands. --- src/i18n/git-error-patterns.ts | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/i18n/git-error-patterns.ts b/src/i18n/git-error-patterns.ts index 118d712..3087ad7 100644 --- a/src/i18n/git-error-patterns.ts +++ b/src/i18n/git-error-patterns.ts @@ -1,29 +1,16 @@ /** - * Locale-independent patterns that identify a "not a git repository" error - * from the raw stderr of a failed git invocation. + * Fallback pattern that identifies a "not a git repository" error from the + * raw stderr of a failed git invocation. * - * Git translates its error messages via gettext based on the **system** - * LC_MESSAGES locale, which may differ from the user's browser locale. - * Detection therefore needs patterns for every language git might emit on - * the server, not just the one the UI is localized into. + * The primary detection path is the typed `not_a_git_repository` error code + * returned by backend commands wrapped with a filesystem preflight check + * (see `src-tauri/src/git_repo.rs::ensure_git_repo`). This pattern only + * applies when an un-preflighted command leaks raw stderr to the client. * - * These patterns are a belt-and-suspenders fallback. The primary detection - * path is the typed `not_a_git_repository` error code returned by backend - * commands wrapped with a filesystem preflight check (see - * `src-tauri/src/commands/folders.rs::ensure_git_repo`). Patterns only apply - * when an un-preflighted command leaks raw stderr to the client. - * - * Locales covered match git's own gettext translations. Arabic falls back to - * English in upstream git (no ar translation), so no separate pattern. + * Only the English form is needed: `src-tauri/src/process.rs` pins + * `LANG=C.UTF-8` / `LC_ALL=C.UTF-8` on every spawned child process, so git + * stderr is always English regardless of the system locale. */ export const NOT_A_GIT_REPO_PATTERNS: readonly RegExp[] = [ - /not a git repository/i, // en - /不是\s*git\s*仓库/i, // zh-CN - /不是\s*git\s*儲存庫/i, // zh-TW - /git\s*リポジトリではありません/i, // ja - /git\s*저장소가\s*아닙니다/i, // ko - /kein\s*git[-\s]*repository/i, // de - /pas\s*(?:un|dans\s*un)\s*d[ée]p[oô]t\s*git/i, // fr - /no\s*es\s*un\s*repositorio\s*git/i, // es - /n[ãa]o\s*[ée]\s*um\s*reposit[oó]rio\s*git/i, // pt + /not a git repository/i, ]