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
This commit is contained in:
l0ng-ai
2026-11-18 23:30:30 +08:00
committed by GitHub
parent 6bf69cfb2a
commit acb850758a
12 changed files with 65 additions and 6 deletions
+4
View File
@@ -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,
}
}
}
+2
View File
@@ -18,6 +18,7 @@ pub async fn vcs_status(host: &Host, window: &str) -> IdeResult<Vec<FileStatus>>
}
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<std::path::P
}
for r in repos.all() {
r.set_ignored_names(settings.ignored_names());
r.set_cli_status(settings.vcs.git.cli_status);
}
repos.status_paths(&paths)
})
+1
View File
@@ -1076,6 +1076,7 @@ impl Project {
apply_git_executable(&settings);
}
repo.set_ignored_names(settings.ignored_names());
repo.set_cli_status(settings.vcs.git.cli_status);
f(repo)
}
+7
View File
@@ -768,6 +768,8 @@ pub struct Repo {
git_dir: PathBuf,
inner: std::sync::Mutex<repo::Cache>,
ignored: std::sync::RwLock<IgnoredNames>,
/// Working-tree status from `git status` instead of gitoxide.
cli_status: std::sync::atomic::AtomicBool,
log_index: std::sync::Mutex<log_index::LogIndex>,
log_signatures: std::sync::Mutex<std::collections::HashMap<String, LogDetails>>,
}
@@ -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<Vec<FileStatus>> {
+1
View File
@@ -76,6 +76,7 @@ pub(crate) fn discover(path: &Path) -> IdeResult<Option<Repo>> {
git_dir,
inner: std::sync::Mutex::new(cache),
ignored: Default::default(),
cli_status: Default::default(),
log_index: Default::default(),
log_signatures: Default::default(),
}))
+8 -4
View File
@@ -20,10 +20,14 @@ pub(crate) fn status(r: &Repo) -> IdeResult<Vec<FileStatus>> {
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))
}
+22
View File
@@ -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<FileStatus>| s.into_iter().map(|f| (f.rel_path, f.staged, f.unstaged)).collect::<Vec<_>>();
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:#?}");
}
+5
View File
@@ -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 = {
+6
View File
@@ -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.",
},
],
},
{
+3 -1
View File
@@ -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."
}
+3 -1
View File
@@ -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 一致。"
}
+3
View File
@@ -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),