Skip to content

fix(project): use "/" as global project worktree when git has no commits#23220

Open
sim590 wants to merge 11 commits intoanomalyco:devfrom
sim590:fix/global-worktree-corruption
Open

fix(project): use "/" as global project worktree when git has no commits#23220
sim590 wants to merge 11 commits intoanomalyco:devfrom
sim590:fix/global-worktree-corruption

Conversation

@sim590
Copy link
Copy Markdown

@sim590 sim590 commented Apr 18, 2026

Issue for this PR

Fixes #23221
Related: #21230

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When fromDirectory() encounters a Git repository with no commits (git rev-list --max-parents=0 HEAD fails), it correctly falls back to ProjectID.global but sets worktree to the current directory (sandbox) instead of "/".

This causes the Phase 2 upsert to overwrite the global project's worktree in the database with a directory-specific path. The global project should always have worktree="/" by definition — the specific directory is already captured in sandbox and added to the sandboxes list.

The corruption is transient: it resolves the next time fromDirectory() is called from a non-git directory (which resets worktree back to "/"). The practical impact is limited, but the metadata should remain consistent regardless.

The fix is a one-line change in project.ts (line 234): worktree: sandboxworktree: "/".

How did you verify your code works?

  • Wrote a reproduction script that calls fromDirectory() on a non-git directory (creates global project with worktree="/"), then calls fromDirectory() on a git init directory without commits, and checks the database. Before the fix, worktree is overwritten with the directory path. After the fix, it stays "/".
  • Added a new test case (git init without commits must not overwrite global worktree) that encodes this scenario.
  • Updated two existing tests that expected worktree: tmp.path to expect worktree: "/" for the no-commits fallback.
  • All 49 project tests pass.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global project worktree is transiently overwritten after git init without commits

2 participants