Skip to content

Global project worktree is transiently overwritten after git init without commits #23221

@sim590

Description

@sim590

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

  1. Open opencode in a directory without .git (e.g., ~) — global project created with worktree="/"
  2. Run git init (without committing) in a different directory
  3. 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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions