From 0ba60d8a4460206708dce42db9539e2900251cf7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 20 Apr 2026 17:49:25 +0200 Subject: [PATCH] worktree: Fix `.git` modified events not being correctly filtered out (#54329) Release Notes: - N/A or Added/Fixed/Improved ... Co-authored by: Cole Miller --- crates/fs/src/fs.rs | 10 ++++++++-- crates/worktree/src/worktree.rs | 14 +++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index e44f557646239da5dd84354e364422cf16e14233..fa42c436f1b9beb4a17a63a61eeeb02b7e889569 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -1889,7 +1889,10 @@ impl FakeFs { drop(repo_state); if emit_git_event { - state.emit_event([(dot_git, Some(PathEventKind::Changed))]); + state.emit_event([( + dot_git.join("fake_git_repo_event"), + Some(PathEventKind::Changed), + )]); } Ok(result) @@ -1944,7 +1947,10 @@ impl FakeFs { if emit_git_event { drop(repo_state); - state.emit_event([(canonical_path, Some(PathEventKind::Changed))]); + state.emit_event([( + canonical_path.join("fake_git_repo_event"), + Some(PathEventKind::Changed), + )]); } Ok(result) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 990ed4fd54c0d2935c0dddf9d42fb632dbae15d5..8d66c375a24168e82af11e3eac022366fe288f1c 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3295,7 +3295,7 @@ impl BackgroundScannerState { } } -async fn is_git_dir(path: &Path, fs: &dyn Fs) -> bool { +async fn is_dot_git(path: &Path, fs: &dyn Fs) -> bool { if let Some(file_name) = path.file_name() && file_name == DOT_GIT { @@ -4291,7 +4291,7 @@ impl BackgroundScanner { let mut dot_git_paths = None; for ancestor in abs_path.as_path().ancestors() { - if is_git_dir(ancestor, self.fs.as_ref()).await { + if is_dot_git(ancestor, self.fs.as_ref()).await { let path_in_git_dir = abs_path .as_path() .strip_prefix(ancestor) @@ -4312,15 +4312,7 @@ impl BackgroundScanner { let is_dot_git_changed = { path_in_git_dir == Path::new("") && event.kind == Some(PathEventKind::Changed) - && abs_path - .strip_prefix(root_canonical_path) - .ok() - .and_then(|it| RelPath::new(it, PathStyle::local()).ok()) - .is_some_and(|it| { - snapshot - .entry_for_path(&it) - .is_some_and(|entry| entry.kind == EntryKind::Dir) - }) + && self.fs.is_dir(abs_path.as_path()).await }; let condition = skipped_files_in_dot_git.iter().any(|skipped| { OsStr::new(skipped) == path_in_git_dir.as_path().as_os_str()