Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
85 changes: 70 additions & 15 deletions packages/rust/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
Expand Down Expand Up @@ -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]
Expand Down
26 changes: 26 additions & 0 deletions packages/rust/tests/config_gitignore_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"command": "pnpm test:e2e",
"ran_at": 1795202230,
"exit_code": 0,
"commit": "6bb438a3639cbae0b45bf4687d281a0b6030ade3",
"branch": "bot/1774-live-filter-exemption-1118"
}
Loading