Description
Bug Description
When opening opencode in a git repository subdirectory (e.g., src/), the snapshot service fails to track files with the error:
WARN service=snapshot exitCode=128 stderr=warning: cannot open directory 'src/src/': No such file or directory
fatal error: pathspec 'src/date.txt' did not match any files
failed to add snapshot files
Root Cause
The issue was introduced in packages/opencode/src/snapshot/index.ts.
In the stage, drop, and ignore functions, cwd is set to state.directory (the directory where opencode was launched), but files paths are relative to state.worktree (git repository root).
When --work-tree points to the repository root but cwd points to a subdirectory, git cannot resolve the paths correctly.
Affected Code
In packages/opencode/src/snapshot/index.ts:
ignore function: cwd: state.directory should be cwd: state.worktree
drop function: cwd: state.directory should be cwd: state.worktree
stage function: cwd: state.directory should be cwd: state.worktree
Expected Behavior
Snapshot should work correctly regardless of which directory within a git repository opencode is launched from.
Plugins
No response
OpenCode version
v1.15.0
Steps to reproduce
- Initialize a git repository with some files
- Open opencode from a subdirectory (e.g.,
cd src && opencode)
- The snapshot service will fail with the error above
Screenshot and/or share link
No response
Operating System
RHEL 8
Terminal
iTerm2
Description
Bug Description
When opening opencode in a git repository subdirectory (e.g.,
src/), the snapshot service fails to track files with the error:WARN service=snapshot exitCode=128 stderr=warning: cannot open directory 'src/src/': No such file or directory
fatal error: pathspec 'src/date.txt' did not match any files
failed to add snapshot files
Root Cause
The issue was introduced in
packages/opencode/src/snapshot/index.ts.In the
stage,drop, andignorefunctions,cwdis set tostate.directory(the directory where opencode was launched), butfilespaths are relative tostate.worktree(git repository root).When
--work-treepoints to the repository root butcwdpoints to a subdirectory, git cannot resolve the paths correctly.Affected Code
In
packages/opencode/src/snapshot/index.ts:ignorefunction:cwd: state.directoryshould becwd: state.worktreedropfunction:cwd: state.directoryshould becwd: state.worktreestagefunction:cwd: state.directoryshould becwd: state.worktreeExpected Behavior
Snapshot should work correctly regardless of which directory within a git repository opencode is launched from.
Plugins
No response
OpenCode version
v1.15.0
Steps to reproduce
cd src && opencode)Screenshot and/or share link
No response
Operating System
RHEL 8
Terminal
iTerm2