fix(snapshot): run git from worktree, not launch directory#27737
Open
danfry1 wants to merge 2 commits into
Open
fix(snapshot): run git from worktree, not launch directory#27737danfry1 wants to merge 2 commits into
danfry1 wants to merge 2 commits into
Conversation
When opencode is launched from a subdirectory of a git worktree, state.directory points at the subdirectory while git is told the worktree via --work-tree. Pathspecs from ls-files came back worktree-relative but were then passed to subsequent git invocations with cwd=subdir, so git tried to resolve src/foo.txt under subdir/src/ and the snapshot silently failed. Use state.worktree consistently for cwd and path joins in this file so operations are anchored to the same root as --work-tree. Fixes anomalyco#27688
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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 #27688
Type of change
What does this PR do?
Snapshot git operations ran with cwd set to the directory opencode was launched from (
state.directory), while--git-dir/--work-treealready pointed at the repo root. When those two are different (running from a subdirectory of the worktree),ls-filesreturned worktree-relative pathspecs that were then fed back intogit addwith cwd=subdir, so git tried to resolvesrc/foo.txtundersubdir/src/foo.txtand the snapshot silently failed.This switches the remaining git calls and the related
path.jointo usestate.worktree, matching whatrestore/revert/excludes/diffalready do. It also drops the now-unusedstate.directoryfield.How did you verify your code works?
8 new regression tests in
test/snapshot/snapshot.test.tsuseprovideInstance(subdir)sodirectory != worktree. They cover patch, diff/diffFull, gitignore, drop of staged-then-later-ignored files, large-file skip, restore, and a linked worktree (.git file rather than directory) launched from a subdir. I confirmed each one fails against the pre-fix source.bun test test/snapshot/snapshot.test.tsfrompackages/opencode: 60 pass / 1 skip / 0 failbun typecheckfrompackages/opencodeManual repro before the fix: init a git repo,
cd subdir && opencode ., edit a file, look forpathspec ... did not matchin the snapshot warnings.Screenshots / recordings
N/A (not a UI change).
Checklist