fix(snapshot): reverting in a session can wipe out other files that have changed#7774
Open
ryanwyler wants to merge 1 commit intoanomalyco:devfrom
Open
fix(snapshot): reverting in a session can wipe out other files that have changed#7774ryanwyler wants to merge 1 commit intoanomalyco:devfrom
ryanwyler wants to merge 1 commit intoanomalyco:devfrom
Conversation
When running opencode from a subdirectory, the snapshot system would restore stale files from other directories during unrevert. This happened because: 1. The snapshot index is shared across all sessions in a project 2. git add . from a subdirectory only updates that subdirectory's entries 3. restore() used checkout-index -a which restores ALL files in the index 4. diff() used cwd(Instance.worktree) showing diffs for unrelated directories Fix by scoping both restore() and diff() to Instance.directory: - restore() now lists files under the session directory prefix and only restores those specific files - diff() now uses cwd(Instance.directory) so the path spec is relative to the session directory
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
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.
Summary
Fixes #7775
Fixes a bug where running opencode from a subdirectory and clicking "undo revert" would overwrite files in other directories with stale versions from weeks ago.
Problem
When running opencode from a subdirectory (e.g.,
project/frontend/), the unrevert operation would restore stale versions of files in other directories (e.g.,project/backend/). This happened because:git add .from a subdirectory only updates that subdirectory's entries in the indexrestore()usedcheckout-index -awhich restores ALL files in the indexdiff()usedcwd(Instance.worktree)showing diffs for unrelated directoriesSolution
Scope both
restore()anddiff()toInstance.directory:restore()now lists files under the session directory prefix usingls-treeand only restores those specific filesdiff()now usescwd(Instance.directory)so the-- .path spec is relative to the session directorySteps to Reproduce
backend/, make a change, then exit:frontend/, make a change, revert, then unrevert:Testing
Bug History
Traced the origin of this bug through git history:
11d042be2isomorphic-gitwith per-session snapshots284c01018checkout-index -a -ff993541e0The original per-session implementation was safe because each session had its own isolated snapshot directory. The bug was introduced when refactoring to shell git commands (
checkout-index -arestores all files regardless of cwd), and became a real problem when snapshots became shared per-project (stale entries from other sessions persist in the shared index).