diff --git a/packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json b/packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json new file mode 100644 index 00000000..3954caf5 --- /dev/null +++ b/packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json @@ -0,0 +1,7 @@ +{ + "command": "uv run python -m pytest tests/e2e/watch_fault_test.py tests/e2e/fanout_test.py tests/e2e/fresh_declared_repros_test.py tests/e2e/glob_speed_gitignore_test.py tests/e2e/watch_speed_test.py -x -q", + "ran_at": 1795202183, + "exit_code": 0, + "commit": "e260bf503e8b380a21e5d48590a3405f165a8951", + "branch": "bot/1774-live-filter-exemption-1118" +} diff --git a/packages/rust/changelog.d/2026-11-18-live-filter-glob-exemption.md b/packages/rust/changelog.d/2026-11-18-live-filter-glob-exemption.md new file mode 100644 index 00000000..93ac8262 --- /dev/null +++ b/packages/rust/changelog.d/2026-11-18-live-filter-glob-exemption.md @@ -0,0 +1 @@ +**Fixed** A file under a gitignored directory that a table glob spells out with no wildcard is now kept current while watching, as the startup scan indexes it: deleting or editing it updates the index instead of leaving a stale row. diff --git a/packages/rust/migrations.d/2026-11-18-live-filter-glob-exemption.md b/packages/rust/migrations.d/2026-11-18-live-filter-glob-exemption.md new file mode 100644 index 00000000..e9efc161 --- /dev/null +++ b/packages/rust/migrations.d/2026-11-18-live-filter-glob-exemption.md @@ -0,0 +1,21 @@ +### The live watcher tracks glob-named files under gitignored directories + +#### Summary + +The live event filter now exempts a gitignored path a table glob spells out, as the startup scan does, so such a file's edits and deletion reach the index. Nothing breaks and no code changes are required. + +#### Required changes + +_None._ + +#### Deprecations removed + +_None._ + +#### Behavior changes without code changes + +With `.gitignore` listing `build/` and a table globbing `build/x.md`, deleting or editing `build/x.md` while watching now removes or updates its row; before, the row stayed as the startup scan left it. + +#### Verification + +In a git repo whose `.gitignore` lists `build/`, run `dirsql --watch` with one table globbing `build/x.md`, delete `build/x.md`, and see a delete event for it. diff --git a/packages/rust/src/lib.rs b/packages/rust/src/lib.rs index e2dbf604..a5d0a629 100644 --- a/packages/rust/src/lib.rs +++ b/packages/rust/src/lib.rs @@ -1367,9 +1367,11 @@ impl DirSQL { continue; } if group.matcher.respects_gitignore() - && scanner::is_gitignored_path( + && scanner::gitignore_drops( &abs_path, + &rel_path_buf, self.inner.fs.is_dir(&abs_path).unwrap_or(false), + &group.matcher, ) { continue; diff --git a/packages/rust/src/scanner.rs b/packages/rust/src/scanner.rs index 6eb26a3a..2d675b18 100644 --- a/packages/rust/src/scanner.rs +++ b/packages/rust/src/scanner.rs @@ -1255,18 +1255,33 @@ fn reaches_dir(rel_path: &Path, ignore: &TableMatcher) -> bool { }) && dirs_glob(ignore).is_none_or(|glob| glob_reaches_dir(glob, rel_path)) } -/// Whether a walk from `root` enters `dir`: [`reaches_dir`], and, under a -/// matcher honoring `.gitignore`, no directory on the way is one the -/// `.gitignore` files in force there ignore and no table glob spells. +/// Whether a walk from `root` enters `dir`: [`reaches_dir`], and +/// [`gitignore_drops`] does not drop it. pub(crate) fn enters_dir(root: &Path, dir: &Path, ignore: &TableMatcher) -> bool { let Ok(rel_path) = dir.strip_prefix(root) else { return false; }; - reaches_dir(rel_path, ignore) - && !(ignore.respects_gitignore() - && gitignore_hides(rel_path, dirs_glob(ignore), &|prefix| { - is_gitignored_dir(&root.join(prefix)) - })) + reaches_dir(rel_path, ignore) && !gitignore_drops(dir, rel_path, true, ignore) +} + +/// Whether a walk under a matcher honoring `.gitignore` drops `path`, reached +/// as `rel_path` from the walk's root: some entry on the way, `path` itself +/// included, is one the `.gitignore` files in force there ignore and no table +/// glob spells. +pub(crate) fn gitignore_drops( + path: &Path, + rel_path: &Path, + is_dir: bool, + ignore: &TableMatcher, +) -> bool { + let depth = rel_path.components().count(); + ignore.respects_gitignore() + && gitignore_hides(rel_path, dirs_glob(ignore), &|prefix| { + let below = depth - prefix.components().count(); + path.ancestors() + .nth(below) + .is_some_and(|entry| is_gitignored_entry(entry, is_dir || below > 0)) + }) } /// Whether some directory on the way to `rel_path`, itself included, is one @@ -1283,13 +1298,13 @@ fn gitignore_hides( }) } -/// Whether the `.gitignore` files in force in the directory holding `dir` -/// ignore it, as the walk judges an entry: only `dir` itself is matched, its +/// Whether the `.gitignore` files in force in the directory holding `path` +/// ignore it, as the walk judges an entry: only `path` itself is matched, its /// parents having been judged on the way. -fn is_gitignored_dir(dir: &Path) -> bool { - dir.parent() +fn is_gitignored_entry(path: &Path, is_dir: bool) -> bool { + path.parent() .and_then(|parent| enclosing_repo(parent, &holds_git)) - .is_some_and(|top| is_gitignored(&gitignores_above(dir, top, &Frame::load), dir, true)) + .is_some_and(|top| is_gitignored(&gitignores_above(path, top, &Frame::load), path, is_dir)) } /// Whether some component of `glob` can enter the directory at `rel_path`. @@ -1919,11 +1934,51 @@ mod tests { )); } + fn drops(root: &Path, rel: &str, is_dir: bool, matcher: &TableMatcher) -> bool { + gitignore_drops(&root.join(rel), Path::new(rel), is_dir, matcher) + } + + #[test] + fn gitignore_drops_a_file_below_a_gitignored_directory() { + let root = repo_ignoring_build(); + let matcher = TableMatcher::new(&[("**/*.md", "t")], &[]) + .unwrap() + .with_gitignore(true); + assert!(drops(root.path(), "build/x.md", false, &matcher)); + assert!(!drops(root.path(), "docs/x.md", false, &matcher)); + } + + #[test] + fn gitignore_drops_no_file_a_glob_spells_below_a_gitignored_directory() { + let root = repo_ignoring_build(); + let matcher = TableMatcher::new(&[("build/x.md", "t")], &[]) + .unwrap() + .with_gitignore(true); + assert!(!drops(root.path(), "build/x.md", false, &matcher)); + } + + #[test] + fn gitignore_drops_a_directory_only_pattern_for_a_directory_only() { + let root = repo_ignoring_build(); + let matcher = TableMatcher::new(&[("**", "t")], &[]) + .unwrap() + .with_gitignore(true); + assert!(drops(root.path(), "build", true, &matcher)); + assert!(!drops(root.path(), "build", false, &matcher)); + } + + #[test] + fn gitignore_drops_nothing_when_gitignore_is_off() { + let root = repo_ignoring_build(); + let matcher = TableMatcher::new(&[("**/*.md", "t")], &[]).unwrap(); + assert!(!drops(root.path(), "build/x.md", false, &matcher)); + } + #[test] - fn is_gitignored_dir_is_false_outside_any_repo() { + fn is_gitignored_entry_is_false_outside_any_repo() { let root = tempfile::tempdir().unwrap(); fs::write(root.path().join(".gitignore"), "build/\n").unwrap(); - assert!(!is_gitignored_dir(&root.path().join("build"))); + assert!(!is_gitignored_entry(&root.path().join("build"), true)); } #[test] diff --git a/packages/rust/tests/config_gitignore_watch.rs b/packages/rust/tests/config_gitignore_watch.rs index 12ccdeac..eb4f0805 100644 --- a/packages/rust/tests/config_gitignore_watch.rs +++ b/packages/rust/tests/config_gitignore_watch.rs @@ -47,3 +47,29 @@ fn a_gitignored_file_created_while_watching_is_not_indexed() { assert_eq!(names(&db), vec!["keep.md"], "events: {seen:?}"); } + +#[test] +fn a_file_a_glob_spells_under_a_gitignored_directory_leaves_the_index_when_deleted() { + let dir = TempDir::new().unwrap(); + fs::create_dir(dir.path().join(".git")).unwrap(); + fs::write(dir.path().join(".gitignore"), "build/\n").unwrap(); + fs::create_dir(dir.path().join("build")).unwrap(); + fs::write(dir.path().join("build/x.md"), "x").unwrap(); + let table = Table::new("t", "CREATE TABLE t (name TEXT)", "build/x.md", |path| { + let name = path.rsplit(['/', '\\']).next().unwrap().to_string(); + vec![HashMap::from([("name".into(), Value::Text(name))])] + }); + let db = DirSQL::new(dir.path(), vec![table]).unwrap(); + assert_eq!(names(&db), vec!["x.md"]); + thread::sleep(Duration::from_millis(250)); + + fs::remove_file(dir.path().join("build/x.md")).unwrap(); + + let deadline = Instant::now() + Duration::from_secs(5); + let mut seen = Vec::new(); + while Instant::now() < deadline && !seen.iter().any(|e| matches!(e, RowEvent::Delete { .. })) { + seen.extend(db.poll_events(Duration::from_millis(200)).unwrap()); + } + + assert!(names(&db).is_empty(), "events: {seen:?}"); +} diff --git a/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json b/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json new file mode 100644 index 00000000..0e15c3ec --- /dev/null +++ b/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json @@ -0,0 +1,7 @@ +{ + "command": "pnpm test:e2e", + "ran_at": 1795202230, + "exit_code": 0, + "commit": "6bb438a3639cbae0b45bf4687d281a0b6030ade3", + "branch": "bot/1774-live-filter-exemption-1118" +}