git: Fix .git directory being removed from watcher when excluded via file_scan_exclusions - #57895
Conversation
|
I think this PR fixes the immediate bug, but the shape of the bug is more like a design issue because the watcher ownership is implicit. Currently zed/crates/worktree/src/worktree.rs Lines 4857 to 4894 in 8734d01 The repository-specific watches are added here: zed/crates/worktree/src/worktree.rs Lines 3271 to 3301 in 8734d01 But zed/crates/worktree/src/worktree.rs Lines 3156 to 3220 in 8734d01 This matters because So the same path can effectively be watched for two reasons:
The current fix special-cases git repository paths, which is probably fine for this PR. My point (and concern) is that this coupling is easy to miss, so if we later add another metadata directory with similar behavior, for example If zed decides to integrate something like But given that currently the only exception is git, I don't think this refactoring is needed for now to fix this bug. |
|
@AlvaroParker Thanks for the PR, and for the thorough analysis of the issue! This seems like a good fix. We just merged a related change in #58692 that split up "remove from snapshot" from "remove watcher", so if you merge main you should be able to use that to unconditionally remove from the snapshot and then conditionally remove the watcher in the "newly excluded" case. Once that's done, happy to merge this! |
804848c to
0d64584
Compare
|
@cole-miller sorry for the ping :) I did a rebase and updated the fix to be more inline to what has been done on #58692 Let me know what you think! |
…a `file_scan_exclusions` (zed-industries#57895) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#57888 Commit `1c7166dccc0ce3c5bee06e61c40813c0bd33173a` introduced the bug on zed-industries#50412 . This change modified the `remove_path` function to also remove the path from the watcher: https://github.com/zed-industries/zed/blob/9d532abd422e5e00ba7bb48ffbcb343ae0bf2be2/crates/worktree/src/worktree.rs#L3218-L3220 And when a user modified the global setting and doesn't include `.git` in it, like: ```jsonc // ~/.config/zed/settings.json { "file_scan_exclusions": ["foo"] } ``` But then includes it on their local project settings: ```jsonc // ~/my/local/project/.zed/settings.json { "file_scan_exclusions": ["**/.git"] } ``` It causes zed to stop watching for changes on `.git` Release Notes: - Fixed bug where zed stopped watching change on `.git` directory if it was added to the project local `file_scan_exclusions`
Self-Review Checklist:
Closes #57888
Commit
c19cc4c51e0f64eec42168943050f2deeccaa076introduced the bug on #50412 . This change modified theremove_pathfunction to also remove the path from the watcher:zed/crates/worktree/src/worktree.rs
Lines 3218 to 3220 in f0341c9
And when a user modified the global setting and doesn't include
.gitin it, like:But then includes it on their local project settings:
It causes zed to stop watching for changes on
.gitRelease Notes:
.gitdirectory if it was added to the project localfile_scan_exclusions