Trigger doesn't output events for root directory
- Dominant language
- C++
- Stars
- 13.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Description
I'm developing a trigger that is meant to `rsync` directory changes as responsively as possible while still being correct. The trigger invokes my shell script which wraps an `rsync` invocation. It's best for performance if I pass only changed directory names to `rsync`, instead of file names and directory names. This isn't currently possible, though, because Watchman triggers seem to never give root directory changes as output to the triggered command.
## Environment
- OS: macOS 10.14.4
- Watchman version: repro with both latest `master` (commit `7bce6e959b`) and release `4.9.0`
- Watcher: FSEvents
## Repro
In one terminal, run:
```
watchman shutdown-server && watchman -f --logfile=/dev/stdout --log-level=2
```
In another, run:
```
./trigger.sh
./test.sh
```
Observe the output in the first terminal (ignore anything related to the creation of the `subdir` directory).
The `test.sh` script creates two files like
```
.
├── file_in_root
└── subdir
└── file_in_subdir
```
You should see that upon `test.sh`'s creation of `./file_in_root` and `./subdir/file_in_subdir` that only the following events are printed:
```
[
{"exists": true, "type": "d", "name": "subdir"},
{"exists": true, "type": "f", "name": "file_in_root"},
{"exists": true, "type": "f", "name": "subdir/file_in_subdir"}
]
```
I would expect something like this hypothetical fourth event for the root directory to also be printed:
```
{"exists": true, "type": "d", "name": "."}
```
Since events for the root directory like this aren't printed out, I have to work around it with this irksome addition to my trigger expression:
```
["anyof",
["type", "d"],
["allof",
["type", "f"],
["not", ["pcre", ".*/.*", "wholename"]],
]
]
]
```
It would be great if Watchman would just print out the root directory change events to avoid this.
### Repro scripts
`test.sh`:
```
#!/bin/bash
mkdir -p subdir
sleep 2 # wait for dir creation to clear
touch file_in_root
touch subdir/file_in_subdir
sleep 2 # wait for test creations to clear, then clean-up
rm -rf file_in_root subdir
```
`trigger.sh`:
```
#!/bin/bash
watchman watch-project .
watchman -n -j <<-EOT
["trigger", "$(pwd -P)", {
"name": "watchman_bug2",
"command": ["$(pwd -P)/triggered_script.sh"],
"expression": ["exists"],
"append_files": false,
"stdin": [
"name",
"exists",
"type"
]
}]
EOT
```
`triggered_script.sh`:
```
#!/bin/bash
while read line
do
echo "$line"
done
```
Contributor guide
Assessment
This issue has not been assessed yet.