Skip to content

Commit be7cb30

Browse files
committed
Add explicit literal directory watch syntax
1 parent 2c112c1 commit be7cb30

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ workflow = "rust"
6363

6464
- Table name: the watch-group name.
6565
- `paths`: glob patterns evaluated relative to `root`.
66+
Use a trailing `/` for a literal directory target that should be
67+
watched recursively even before it exists.
6668
- `workflow`: workflow to run when a matching file changes. If omitted,
6769
the watch-group name is used as the workflow name.
6870

src/config.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl CompiledWatchTarget {
307307
if pattern_is_literal(pattern) {
308308
return Self {
309309
path: root.join(prefix),
310-
recursive: false,
310+
recursive: pattern.ends_with('/'),
311311
};
312312
}
313313

@@ -1362,6 +1362,27 @@ mod tests {
13621362
);
13631363
}
13641364

1365+
#[test]
1366+
fn compiled_watch_targets_keep_literal_directory_targets_recursive() {
1367+
let mut config = base_config();
1368+
config.root = PathBuf::from("/tmp/example");
1369+
config.watch.insert(
1370+
"content".into(),
1371+
WatchGroup {
1372+
paths: vec!["content/".into()],
1373+
workflow: Some("content".into()),
1374+
},
1375+
);
1376+
1377+
assert_eq!(
1378+
config.compiled_watch_targets(),
1379+
vec![CompiledWatchTarget {
1380+
path: PathBuf::from("/tmp/example/content"),
1381+
recursive: true,
1382+
}]
1383+
);
1384+
}
1385+
13651386
#[test]
13661387
fn config_detects_notify_reload_in_nested_workflow() {
13671388
let mut config = base_config();

src/engine.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,9 @@ fn resolve_watch_registrations(
572572
.parent()
573573
.ok_or_else(|| anyhow!("watch target '{}' has no parent", target.path.display()))?;
574574
if immediate_parent.exists() {
575-
let recursive = target.path.extension().is_none();
576575
return Ok(vec![CompiledWatchTarget {
577576
path: immediate_parent.to_path_buf(),
578-
recursive,
577+
recursive: false,
579578
}]);
580579
}
581580

@@ -781,14 +780,14 @@ mod tests {
781780
}
782781

783782
#[test]
784-
fn resolve_watch_registration_uses_recursive_parent_for_missing_directory_like_target() {
783+
fn resolve_watch_registration_uses_recursive_parent_for_missing_explicit_directory_target() {
785784
let dir = tempdir().expect("tempdir");
786785
let target = dir.path().join("content");
787786

788787
let registrations = resolve_watch_registrations(
789788
&CompiledWatchTarget {
790789
path: target,
791-
recursive: false,
790+
recursive: true,
792791
},
793792
WatcherKind::Native,
794793
)

0 commit comments

Comments
 (0)