`file.watcher.updated` events never fire in git repositories with no commits
Description
The file.watcher.updated event never fires in git repositories that have been initialized but have no commits yet. The FileWatcher silently fails to initialize because the project is incorrectly assigned projectID=global instead of being recognized as a git project.
This affects:
- Plugins listening for
file.watcher.updatedevents - Any functionality dependent on file system watching Root cause analysis: When OpenCode detects a git repository:
-
git rev-parsesucceeds (.gitdirectory exists) - But for repos with no commits, the project is created with
projectID=globalinstead of a proper git project hash - In
FileWatcher.init(), there's an early return check:if (Instance.project.vcs !== "git") return {}; - Since
projectID=globalprojects don't havevcs: "git", the watcher never initializes - No logs are emitted - the failure is completely silent
OpenCode version
1.0.119
Steps to reproduce
- Create a new git repository without any commits:
mkdir test-repo && cd test-repo git init echo "test" > file.txt git add file.txt # Don't commit! - Run opencode with logging:
opencode run --print-logs --log-level INFO "add 1 to main.txt" - Observe the logs:
- You'll see
projectID=globalin session creation - No
service=file.watcherlogs appear at all - No
file.watcher.updatedevents are published
- You'll see
- Compare with a repo that has commits - the watcher initializes properly with logs like:
INFO service=file.watcher init INFO service=file.watcher platform=linux backend=inotify watcher backend
Screenshot and/or share link
No response
Operating System
NixOS (Linux)
Terminal
vscode
We do this intentionally because if you are running opencode in your root dir we dont wanna file watch everything that'd be crazy
But we need to fix for this case:
But for repos with no commits, the project is created with projectID=global instead of a proper git project hash
fixed in next release: https://github.com/sst/opencode/commit/767a81f9308c451dbe68451da1623baa255745e9