From 4558f9db55e636adb8b4edbc89fb2e373f595c77 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:55:43 -0500 Subject: [PATCH 1/6] Test that deleting a glob-named file under a gitignored directory leaves the index --- packages/rust/tests/config_gitignore_watch.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/rust/tests/config_gitignore_watch.rs b/packages/rust/tests/config_gitignore_watch.rs index 12ccdeac7..eb4f0805f 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:?}"); +} From e9cd01bfb2bc323f14756e99fe6258d2a45cc577 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:02:11 -0500 Subject: [PATCH 2/6] Exempt a glob-spelled gitignored path in the live event filter as the scan does --- .../2026-11-18-live-filter-glob-exemption.md | 1 + .../2026-11-18-live-filter-glob-exemption.md | 21 +++++ packages/rust/src/lib.rs | 4 +- packages/rust/src/scanner.rs | 85 +++++++++++++++---- 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 packages/rust/changelog.d/2026-11-18-live-filter-glob-exemption.md create mode 100644 packages/rust/migrations.d/2026-11-18-live-filter-glob-exemption.md 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 000000000..93ac8262f --- /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 000000000..e9efc161c --- /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 c0a095685..2299efe9c 100644 --- a/packages/rust/src/lib.rs +++ b/packages/rust/src/lib.rs @@ -1366,9 +1366,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 6eb26a3a3..2d675b184 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] From ae9514b9869d02c8c58d4950952baa209d8ae0f8 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:07:24 -0500 Subject: [PATCH 3/6] e2e attestation for bot/1774-live-filter-exemption-1118 --- .../bot-1774-live-filter-exemption-1118.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json 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 000000000..2dbcb89c0 --- /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": 1795057644, + "exit_code": 0, + "commit": "e9cd01bfb2bc323f14756e99fe6258d2a45cc577", + "branch": "bot/1774-live-filter-exemption-1118" +} From 5c4c4ca91f01e5d981c6efe865eee6bdaf7ae556 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:08:46 -0500 Subject: [PATCH 4/6] e2e attestation for bot/1774-live-filter-exemption-1118 --- .../bot-1774-live-filter-exemption-1118.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json 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 000000000..985bdccd5 --- /dev/null +++ b/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json @@ -0,0 +1,7 @@ +{ + "command": "pnpm test:e2e", + "ran_at": 1795057726, + "exit_code": 0, + "commit": "ae9514b9869d02c8c58d4950952baa209d8ae0f8", + "branch": "bot/1774-live-filter-exemption-1118" +} From 6bb438a3639cbae0b45bf4687d281a0b6030ade3 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Fri, 20 Nov 2026 14:16:23 -0500 Subject: [PATCH 5/6] e2e attestation for bot/1774-live-filter-exemption-1118 --- .../e2e-attestations/bot-1774-live-filter-exemption-1118.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 2dbcb89c0..3954caf5f 100644 --- a/packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json +++ b/packages/python/e2e-attestations/bot-1774-live-filter-exemption-1118.json @@ -1,7 +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": 1795057644, + "ran_at": 1795202183, "exit_code": 0, - "commit": "e9cd01bfb2bc323f14756e99fe6258d2a45cc577", + "commit": "e260bf503e8b380a21e5d48590a3405f165a8951", "branch": "bot/1774-live-filter-exemption-1118" } From cda4adce6e7ac34ac73d2f3ad642323d1a00eddb Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Fri, 20 Nov 2026 14:17:10 -0500 Subject: [PATCH 6/6] e2e attestation for bot/1774-live-filter-exemption-1118 --- .../e2e-attestations/bot-1774-live-filter-exemption-1118.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 985bdccd5..0e15c3ec4 100644 --- a/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json +++ b/packages/ts/e2e-attestations/bot-1774-live-filter-exemption-1118.json @@ -1,7 +1,7 @@ { "command": "pnpm test:e2e", - "ran_at": 1795057726, + "ran_at": 1795202230, "exit_code": 0, - "commit": "ae9514b9869d02c8c58d4950952baa209d8ae0f8", + "commit": "6bb438a3639cbae0b45bf4687d281a0b6030ade3", "branch": "bot/1774-live-filter-exemption-1118" }