Describe the bug
When fromDirectory() encounters a directory with git init but no commits, it correctly falls back to ProjectID.global but sets worktree to the current directory instead of "/". The Phase 2 upsert then overwrites the global project's worktree in the database.
The global project should always have worktree="/" by definition.
Steps to reproduce
- Open opencode in a directory without
.git (e.g., ~) — global project created with worktree="/"
- Run
git init (without committing) in a different directory
- Open opencode in that directory — global project's
worktree in the database is overwritten with the directory path
Expected behavior
The global project's worktree should remain "/" regardless of which directory triggers the ProjectID.global fallback.
Actual behavior
The global project's worktree is transiently overwritten with the directory path. It self-corrects the next time fromDirectory() is called from a non-git directory.
Impact
Limited — the corruption is transient and self-correcting. This is primarily a metadata consistency issue.
Environment
- opencode version: v1.4.7+
- OS: Linux
Describe the bug
When
fromDirectory()encounters a directory withgit initbut no commits, it correctly falls back toProjectID.globalbut setsworktreeto the current directory instead of"/". The Phase 2 upsert then overwrites the global project'sworktreein the database.The global project should always have
worktree="/"by definition.Steps to reproduce
.git(e.g.,~) — global project created withworktree="/"git init(without committing) in a different directoryworktreein the database is overwritten with the directory pathExpected behavior
The global project's
worktreeshould remain"/"regardless of which directory triggers theProjectID.globalfallback.Actual behavior
The global project's
worktreeis transiently overwritten with the directory path. It self-corrects the next timefromDirectory()is called from a non-git directory.Impact
Limited — the corruption is transient and self-correcting. This is primarily a metadata consistency issue.
Environment