fix(opencode): preserve subdirectory for worktree workspaces#26098
Open
JGoP-L wants to merge 1 commit intoanomalyco:devfrom
Open
fix(opencode): preserve subdirectory for worktree workspaces#26098JGoP-L wants to merge 1 commit intoanomalyco:devfrom
JGoP-L wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found. |
f814fb5 to
404dca0
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes workspace creation for Git worktrees when OpenCode is launched from a repository subdirectory (e.g. monorepo app folder), ensuring the created workspace opens at the corresponding subdirectory inside the new worktree while still managing the worktree lifecycle at the real worktree root.
Changes:
- Add a regression test that creates a real Git repo with a nested
apps/webproject and verifies a worktree workspace targets the matching nested directory. - Extend the worktree creation flow to distinguish between the worktree root (
directory) and the workspace target path (target) and bootstrap/load using the target. - Persist the worktree root in
workspace.extra.rootonly when it differs from the workspace directory, and use it for correct removal.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/opencode/test/server/httpapi-workspace.test.ts | Adds an end-to-end regression test for creating a worktree workspace from a Git subdirectory and verifying the resulting workspace directory. |
| packages/opencode/src/worktree/index.ts | Introduces optional target to bootstrap/load and run start scripts from the intended workspace subdirectory. |
| packages/opencode/src/control-plane/adapters/worktree.ts | Computes subdirectory-relative targets during configure, stores the worktree root in extra.root when needed, and uses root vs target appropriately for create/remove. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26002
Type of change
What does this PR do?
Worktree workspaces currently lose the opened subdirectory when opencode is started from inside a git repo subfolder.
For example, if opencode is opened from:
/repo/apps/webcreating a worktree workspace stores the workspace directory as the new worktree root instead of:
<new-worktree>/apps/webThis PR keeps those two paths separate:
git worktree addand removalextra.rootonly when it differs from the target directoryThat keeps monorepo workspaces opening in the same nested project while preserving the existing worktree lifecycle behavior.
I also added a regression test that creates a real git repo with
apps/web, creates a worktree workspace from that subdirectory, and verifies the workspace target points to the matching subdirectory in the new worktree.How did you verify your code works?
I first reproduced the bug with a failing test in
test/server/httpapi-workspace.test.ts.Then I applied the fix and ran:
bun test test/server/httpapi-workspace.test.tsbun test test/project/worktree.test.ts test/control-plane/workspace.test.tsbun typecheckgit diff --checkResults:
9 pass, 0 failfor workspace HTTP API tests41 pass, 0 failfor worktree/control-plane workspace testsbun typecheckcompleted successfullygit diff --checkcompleted successfullyScreenshots / recordings
N/A. This is workspace path behavior and does not change UI.
Checklist