дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-30 06:12:33 +02:00
fix(vfs): reload ignore rules after git init on Windows
A watcher that started outside a repository caches, per directory, that no `.git` encloses it. After `git init` the explicit reload invalidated that cache from `/`, which is no ancestor of `C:\...`, so on Windows the stale entries stayed and `.git/info/exclude` / `.gitignore` entries written right after were not applied to listings until a file event arrived. Invalidate from the watch root's topmost ancestor instead. Also stop opening a directory as a plain file in the Python library index test: Windows refuses that without backup semantics; the mtime bump is only needed for coarse Unix file system clocks.
Цей коміт міститься в:
1 джерело
04e68f6a12
коміт
645895e3bf
3 files changed
+30
-3
No files matched your search
@@ -421,8 +421,10 @@ mod tests {
|
||||
// `pip install`: a new top-level entry changes the folder's modification time.
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
write(dir.path(), "newpkg/__init__.py", "def installed_later(): pass\n");
|
||||
let file = fs::File::open(dir.path()).unwrap();
|
||||
file.set_modified(SystemTime::now() + Duration::from_secs(5)).ok();
|
||||
// Coarse file system clocks may not move within the test; push it forward. Windows can't
|
||||
// open a directory as a plain file (it needs backup semantics), and NTFS keeps fine times.
|
||||
#[cfg(unix)]
|
||||
fs::File::open(dir.path()).unwrap().set_modified(SystemTime::now() + Duration::from_secs(5)).ok();
|
||||
let second = libraries.index(&roots, &syntax, &cancel).unwrap();
|
||||
assert!(!Arc::ptr_eq(&first, &second));
|
||||
assert_eq!(candidates(&second, "installed_later"), ["from newpkg import installed_later"]);
|
||||
|
||||
@@ -142,7 +142,11 @@ impl Watcher {
|
||||
/// Explicit refresh for writes to Git common metadata outside the watched root.
|
||||
pub fn reload_ignore_rules(&self) {
|
||||
self.rules.reload_repo_level();
|
||||
self.rules.invalidate_tree(self.rules.repo_root().unwrap_or(Path::new("/")));
|
||||
// Outside a repository, everything cached up to the filesystem root may have probed for a
|
||||
// `.git` that now exists (`git init`). `/` is no ancestor of `C:\…` on Windows, so take
|
||||
// the watch root's own topmost ancestor.
|
||||
let top = self.root.ancestors().last().unwrap_or(&self.root);
|
||||
self.rules.invalidate_tree(self.rules.repo_root().unwrap_or(top));
|
||||
}
|
||||
|
||||
/// The watched directory (canonical).
|
||||
|
||||
@@ -350,6 +350,27 @@ fn watcher_read_dir_reuses_its_ignore_rules() {
|
||||
assert!(watcher.read_dir(&other, &[]).unwrap().iter().all(|e| !e.ignored));
|
||||
}
|
||||
|
||||
/// A repository made after the watch started (`git init` in an open project) and the ignore
|
||||
/// entries written into it are seen by the next listing once the rules are reloaded.
|
||||
#[test]
|
||||
fn watcher_read_dir_sees_a_repository_made_after_it_started() {
|
||||
let (_t, r) = root();
|
||||
write(&r.join("shared.ignore-me"), "x");
|
||||
write(&r.join("private.ignore-me"), "x");
|
||||
let sink: SharedSink = Arc::new(|_| {});
|
||||
let watcher = Watcher::start(&r, vec![], sink, Box::new(|_| {})).unwrap();
|
||||
assert_eq!(watcher.repo_root(), None);
|
||||
// Listed once before `git init`: the rules remember that no repository encloses the folder.
|
||||
assert!(watcher.read_dir(&r, &[]).unwrap().iter().all(|e| !e.ignored));
|
||||
write(&r.join(".git/HEAD"), "ref: refs/heads/main\n");
|
||||
write(&r.join(".gitignore"), "/shared.ignore-me\n");
|
||||
write(&r.join(".git/info/exclude"), "/private.ignore-me\n");
|
||||
watcher.reload_ignore_rules();
|
||||
let ignored: BTreeSet<String> =
|
||||
watcher.read_dir(&r, &[]).unwrap().into_iter().filter(|e| e.ignored).map(|e| e.name).collect();
|
||||
assert_eq!(ignored, BTreeSet::from(["private.ignore-me".to_string(), "shared.ignore-me".to_string()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn watcher_reports_changes() {
|
||||
let (_t, r) = root();
|
||||
|
||||
Reference in new issue
Заблокувати користувача