From 94ebfaabdce2b07c9da3f5cbc96a8956c4552f58 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Sun, 19 Apr 2026 06:49:24 +0800 Subject: [PATCH] fix(process): apply C.UTF-8 locale across platforms for child processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously LANG/LC_ALL were only set on Windows, so git stderr was localized on macOS/Linux and substring checks for English messages (e.g. 'unknown revision or path not in the working tree') silently failed — empty-repo/missing-branch cases surfaced as red error banners in the Git log panel instead of rendering as empty lists. --- src-tauri/src/process.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/process.rs b/src-tauri/src/process.rs index e58bfd8..2353723 100644 --- a/src-tauri/src/process.rs +++ b/src-tauri/src/process.rs @@ -13,9 +13,8 @@ pub fn configure_std_command(command: &mut Command) -> &mut Command { { use std::os::windows::process::CommandExt; command.creation_flags(CREATE_NO_WINDOW); - set_utf8_env(command); } - + set_utf8_env(command); command } @@ -34,41 +33,38 @@ pub fn configure_tokio_command( #[cfg(windows)] { command.creation_flags(CREATE_NO_WINDOW); - set_utf8_env(command); } - + set_utf8_env(command); command } -/// Hint child processes to produce UTF-8 output on Windows. +/// Force child processes to emit English, UTF-8 output. /// -/// Sets environment variables recognised by common runtimes (Python, MSYS2/Git -/// Bash, .NET console apps). Not all programs honour these, but they cover the -/// most frequent sources of mojibake in practice. -#[cfg(windows)] +/// Why: downstream code classifies errors by substring-matching English +/// git/coreutils stderr (e.g. "unknown revision or path not in the working +/// tree"). Without pinning the locale, those matches silently fail under +/// non-English system locales and legitimate empty-repo cases bubble up as +/// red error banners. fn set_utf8_env(command: &mut C) { // Python command.env("PYTHONUTF8", "1"); command.env("PYTHONIOENCODING", "utf-8"); - // MSYS2 / Git-for-Windows / POSIX-layer tools + // POSIX locale — honored by git, coreutils, MSYS2/Git-for-Windows. command.env("LANG", "C.UTF-8"); command.env("LC_ALL", "C.UTF-8"); } /// Abstraction over the `.env()` method shared by std and tokio Command types. -#[cfg(windows)] trait SetEnv { fn env(&mut self, key: &str, val: &str) -> &mut Self; } -#[cfg(windows)] impl SetEnv for Command { fn env(&mut self, key: &str, val: &str) -> &mut Self { Command::env(self, key, val) } } -#[cfg(windows)] impl SetEnv for tokio::process::Command { fn env(&mut self, key: &str, val: &str) -> &mut Self { tokio::process::Command::env(self, key, val)