From acb850758a8b5ce458eaff83bacb9b28c2eb4ce8 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 18 Nov 2026 23:30:30 +0800 Subject: [PATCH] feat(vcs): option to detect changes with the Git command line (#4350) Encryption or file protection layers can make the file metadata gitoxide reads differ from what the system git sees, so unchanged files showed as modified while git status was clean. The new Git setting "Detect changes with the Git command line" (vcs.git.cliStatus, off by default) reads the full working-tree status with git status, the same reader the partial refresh already used. Closes #4124 --- crates/ide-core/src/workflow_settings.rs | 4 ++++ crates/ide-host/src/ops/vcs.rs | 2 ++ crates/ide-host/src/project.rs | 1 + crates/ide-vcs/src/lib.rs | 7 +++++++ crates/ide-vcs/src/repo.rs | 1 + crates/ide-vcs/src/status.rs | 12 ++++++++---- crates/ide-vcs/tests/repo.rs | 22 ++++++++++++++++++++++ src/bindings.ts | 5 +++++ src/features/settings/pages/vcs.tsx | 6 ++++++ src/platform/locales/text/en.json | 4 +++- src/platform/locales/text/zh.json | 4 +++- src/platform/workflowSettings.ts | 3 +++ 12 files changed, 65 insertions(+), 6 deletions(-) diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index 8919bc11f..6422c6486 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -77,6 +77,9 @@ pub struct GitSettings { /// The non-modal Commit tool window works on the index: Staged / Unstaged groups, /// stage and unstage instead of inclusion checkboxes, and no change lists. pub staging_area: bool, + /// Scan the working tree with `git status` (for file systems whose metadata only + /// the system git reads correctly) instead of in process. + pub cli_status: bool, } impl Default for GitSettings { @@ -101,6 +104,7 @@ impl Default for GitSettings { push_dialog_only_protected: false, combine_stash_and_shelf: false, staging_area: false, + cli_status: false, } } } diff --git a/crates/ide-host/src/ops/vcs.rs b/crates/ide-host/src/ops/vcs.rs index d28f9eefa..2130ff193 100644 --- a/crates/ide-host/src/ops/vcs.rs +++ b/crates/ide-host/src/ops/vcs.rs @@ -18,6 +18,7 @@ pub async fn vcs_status(host: &Host, window: &str) -> IdeResult> } for r in repos.all() { r.set_ignored_names(settings.ignored_names()); + r.set_cli_status(settings.vcs.git.cli_status); } repos.status() }) @@ -40,6 +41,7 @@ pub async fn vcs_status_paths(host: &Host, window: &str, paths: Vec, ignored: std::sync::RwLock, + /// Working-tree status from `git status` instead of gitoxide. + cli_status: std::sync::atomic::AtomicBool, log_index: std::sync::Mutex, log_signatures: std::sync::Mutex>, } @@ -794,6 +796,11 @@ impl Repo { let _scope = crate::ExecutionScope::enter(self.execution_allowed.load(std::sync::atomic::Ordering::Acquire)); *self.ignored.write().unwrap_or_else(|p| p.into_inner()) = names; } + /// Read the working-tree status with `git status` rather than in process: for file systems + /// (encryption or protection layers) whose metadata only the system git reads correctly. + pub fn set_cli_status(&self, on: bool) { + self.cli_status.store(on, std::sync::atomic::Ordering::Release); + } /// Staged (HEAD↔index) and unstaged (index↔worktree, incl. untracked) changes, /// sorted by path. Conflicted files report `unstaged: Conflicted` and no staged kind. pub fn status(&self) -> IdeResult> { diff --git a/crates/ide-vcs/src/repo.rs b/crates/ide-vcs/src/repo.rs index 66dedfd5f..e587ec2fe 100644 --- a/crates/ide-vcs/src/repo.rs +++ b/crates/ide-vcs/src/repo.rs @@ -76,6 +76,7 @@ pub(crate) fn discover(path: &Path) -> IdeResult> { git_dir, inner: std::sync::Mutex::new(cache), ignored: Default::default(), + cli_status: Default::default(), log_index: Default::default(), log_signatures: Default::default(), })) diff --git a/crates/ide-vcs/src/status.rs b/crates/ide-vcs/src/status.rs index 33793f656..d427a7af6 100644 --- a/crates/ide-vcs/src/status.rs +++ b/crates/ide-vcs/src/status.rs @@ -20,10 +20,14 @@ pub(crate) fn status(r: &Repo) -> IdeResult> { let ignored = r.ignored.read().unwrap_or_else(|p| p.into_inner()).clone(); // gitoxide stops at the first IO error (a directory it may not read), where git warns // and lists the rest: git answers then. - let (map, conflicts) = gix_status(r, &ignored).or_else(|e| { - tracing::debug!("status via gitoxide failed, asking git: {}", e.message); - cli_status(r, &ignored) - })?; + let (map, conflicts) = if r.cli_status.load(std::sync::atomic::Ordering::Acquire) { + cli_status(r, &ignored)? + } else { + gix_status(r, &ignored).or_else(|e| { + tracing::debug!("status via gitoxide failed, asking git: {}", e.message); + cli_status(r, &ignored) + })? + }; Ok(collect(r, &ignored, map, conflicts)) } diff --git a/crates/ide-vcs/tests/repo.rs b/crates/ide-vcs/tests/repo.rs index 2042c2099..a3170b499 100644 --- a/crates/ide-vcs/tests/repo.rs +++ b/crates/ide-vcs/tests/repo.rs @@ -2266,3 +2266,25 @@ fn sets_the_commit_identity_in_the_repository() { let blank = repo.set_user_identity("Ada", " ", false).unwrap_err(); assert_eq!(blank.kind, ErrorKind::InvalidInput); } + +#[test] +fn status_from_the_git_command_line_matches_the_in_process_one() { + let fx = Fixture::new(); + fx.write("a.txt", "a\n"); + fx.write("staged.txt", "a\n"); + fx.write("gone.txt", "a\n"); + fx.commit_all("base"); + fx.write("a.txt", "b\n"); + fx.write("staged.txt", "b\n"); + fx.git(&["add", "staged.txt"]); + std::fs::remove_file(fx.path("gone.txt")).unwrap(); + fx.write("dir/new.txt", "n\n"); + let repo = fx.repo(); + repo.set_ignored_names(ide_core::settings::Settings::default().ignored_names()); + let show = |s: Vec| s.into_iter().map(|f| (f.rel_path, f.staged, f.unstaged)).collect::>(); + let in_process = show(repo.status().unwrap()); + repo.set_cli_status(true); + let from_git = show(repo.status().unwrap()); + assert_eq!(from_git, in_process); + assert_eq!(from_git.len(), 4, "{from_git:#?}"); +} diff --git a/src/bindings.ts b/src/bindings.ts index 347404c81..cad4a245f 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -6279,6 +6279,11 @@ export type GitSettings = { * stage and unstage instead of inclusion checkboxes, and no change lists. */ stagingArea?: boolean, + /** + * Scan the working tree with `git status` (for file systems whose metadata only + * the system git reads correctly) instead of in process. + */ + cliStatus?: boolean, }; export type GoBuildTags = { diff --git a/src/features/settings/pages/vcs.tsx b/src/features/settings/pages/vcs.tsx index a7cfb9487..67bd02a08 100644 --- a/src/features/settings/pages/vcs.tsx +++ b/src/features/settings/pages/vcs.tsx @@ -556,6 +556,12 @@ export const VCS_PAGES: PageSpec[] = [ key: "vcs.git.showBranchInProjectView", label: "Show branch and incoming/outgoing commits in the Project view", }, + { + kind: "toggle", + key: "vcs.git.cliStatus", + label: "Detect changes with the Git command line", + hint: "Slower, but matches git status where encryption or file protection software makes files look modified.", + }, ], }, { diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index f5662ac6f..d0780cee6 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2513,5 +2513,7 @@ "Git user.name and user.email properties are not defined in 1 root": "Git user.name and user.email properties are not defined in 1 root", "Git user.name and user.email properties are not defined in {n} roots": "Git user.name and user.email properties are not defined in {n} roots", "E-mail:": "E-mail:", - "Set properties globally": "Set properties globally" + "Set properties globally": "Set properties globally", + "Detect changes with the Git command line": "Detect changes with the Git command line", + "Slower, but matches git status where encryption or file protection software makes files look modified.": "Slower, but matches git status where encryption or file protection software makes files look modified." } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index fc05e037f..d497bdc5f 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -8887,5 +8887,7 @@ "Git user.name and user.email properties are not defined in 1 root": "1 个根中未定义 Git user.name 和 user.email 属性", "Git user.name and user.email properties are not defined in {n} roots": "{n} 个根中未定义 Git user.name 和 user.email 属性", "E-mail:": "电子邮件:", - "Set properties globally": "全局设置属性" + "Set properties globally": "全局设置属性", + "Detect changes with the Git command line": "使用 Git 命令行检测更改", + "Slower, but matches git status where encryption or file protection software makes files look modified.": "速度较慢,但在加密或文件保护软件导致文件被误判为已修改时,结果与 git status 一致。" } diff --git a/src/platform/workflowSettings.ts b/src/platform/workflowSettings.ts index c662c27ab..40cb3101e 100644 --- a/src/platform/workflowSettings.ts +++ b/src/platform/workflowSettings.ts @@ -38,6 +38,7 @@ export interface GitSettingsValid { pushDialogOnlyProtected: boolean; combineStashAndShelf: boolean; stagingArea: boolean; + cliStatus: boolean; } export interface CommitSettingsValid { @@ -258,6 +259,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = { pushDialogOnlyProtected: false, combineStashAndShelf: false, stagingArea: false, + cliStatus: false, }, commit: { nonModal: true, @@ -418,6 +420,7 @@ export function validateVcs(raw: unknown): VcsSettingsValid { pushDialogOnlyProtected: bool(g.pushDialogOnlyProtected, d.git.pushDialogOnlyProtected), combineStashAndShelf: bool(g.combineStashAndShelf, d.git.combineStashAndShelf), stagingArea: bool(g.stagingArea, d.git.stagingArea), + cliStatus: bool(g.cliStatus, d.git.cliStatus), }, commit: { nonModal: bool(c.nonModal, d.commit.nonModal),