fix(snapshot): fix revert not restoring files due to absolute path issue#8631
fix(snapshot): fix revert not restoring files due to absolute path issue#8631Twisted928 wants to merge 5 commits intoanomalyco:devfrom
Conversation
Root cause: Snapshot.patch() returns absolute paths in files array, but git checkout expects paths relative to worktree, causing checkout to fail silently and files not being restored. Changes: - Convert absolute paths to relative using path.relative() - Add safety guards: worktree escape check, empty path check - Normalize path separators for Windows compatibility - Add fs.mkdir() before fs.writeFile() in git show fallback - Add 13 test cases covering the fix and edge cases Fixes TUI Revert not actually reverting file changes in workspace.
|
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. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
I tested this fix locally and can confirm it works correctly. The revert feature now properly restores files as expected. Would appreciate seeing this merged soon. 👍 |
Based on PR anomalyco#8631 by @Twisted928, this adds 8 additional test scenarios: - Unicode/Chinese character filenames (skipped - reveals bug) - Emoji filenames (skipped - reveals bug) - Symlink handling - Large file handling (1MB) - Binary file handling - Concurrent operations - Empty file handling - Restore to empty state Co-authored-by: Twisted <46923858+Twisted928@users.noreply.github.com>
|
@rekram1-node review pr plz |
Root cause: Snapshot.patch() returns absolute paths in files array, but git checkout expects paths relative to worktree, causing checkout to fail silently and files not being restored. Changes: - Convert absolute paths to relative using path.relative() - Add safety guards: worktree escape check, empty path check - Normalize path separators for Windows compatibility - Add fs.mkdir() before fs.writeFile() in git show fallback - Add 13 test cases covering the fix and edge cases Fixes TUI Revert not actually reverting file changes in workspace. Based on PR anomalyco#8631 by Twisted928
Root cause: Snapshot.patch() returns absolute paths in files array, but git checkout expects paths relative to worktree, causing checkout to fail silently and files not being restored. Changes: - Convert absolute paths to relative using path.relative() - Add safety guards: worktree escape check, empty path check - Normalize path separators for Windows compatibility - Add fs.mkdir() before fs.writeFile() in git show fallback - Add 13 test cases covering the fix and edge cases Fixes TUI Revert not actually reverting file changes in workspace. Based on PR anomalyco#8631 by Twisted928
|
/review |
|
lgtm |
|
I think this all makes sense, will review more tmr |
Root cause: Snapshot.patch() returns absolute paths in files array, but git checkout expects paths relative to worktree, causing checkout to fail silently and files not being restored. Changes: - Convert absolute paths to relative using path.relative() - Add safety guards: worktree escape check, empty path check - Normalize path separators for Windows compatibility - Add fs.mkdir() before fs.writeFile() in git show fallback - Add 13 test cases covering the fix and edge cases Fixes TUI Revert not actually reverting file changes in workspace. Based on PR anomalyco#8631 by Twisted928
|
Looks like a test is failing now? ENOENT: no such file or directory, open '/tmp/opencode-test-9o219frjhtu/文件.txt' (fail) unicode filenames modification and restore [68.14ms] |
| }) | ||
| }) | ||
|
|
||
| test("revert restores modified file content correctly", async () => { |
There was a problem hiding this comment.
These tests don't really test anything it seems?
They still pass with the old code
Root cause: Snapshot.patch() returns absolute paths in files array, but git checkout expects paths relative to worktree, causing checkout to fail silently and files not being restored. Changes: - Convert absolute paths to relative using path.relative() - Add safety guards: worktree escape check, empty path check - Normalize path separators for Windows compatibility - Add fs.mkdir() before fs.writeFile() in git show fallback - Add 13 test cases covering the fix and edge cases Fixes TUI Revert not actually reverting file changes in workspace. Based on PR anomalyco#8631 by Twisted928
00637c0 to
71e0ba2
Compare
f802701 to
f1ae801
Compare
…ript - Add list of upstream PRs (anomalyco#5547, anomalyco#8631, anomalyco#9658, anomalyco#10796) that are open but merged in this fork - Update sync script to check if these PRs are merged in upstream before rebasing, preventing duplicate commits
…ript - Add list of upstream PRs (anomalyco#5547, anomalyco#8631, anomalyco#9658, anomalyco#10796) that are open but merged in this fork - Update sync script to check if these PRs are merged in upstream before rebasing, preventing duplicate commits
…ript - Add list of upstream PRs (anomalyco#5547, anomalyco#8631, anomalyco#9658, anomalyco#10796) that are open but merged in this fork - Update sync script to check if these PRs are merged in upstream before rebasing, preventing duplicate commits
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Fixes #8098
Summary
Fix TUI Revert feature not actually reverting file changes in workspace.
Root Cause
Snapshot.patch()returns absolute paths in thefilesarray, butgit checkoutexpects paths relative to the worktree. This caused checkout to fail silently, leaving files unchanged while the session state showed them as "reverted".Changes
Core Fix (
packages/opencode/src/snapshot/index.ts)path.relative(Instance.worktree, file)gitPathfor all git commandsSafety Guards
Filesystem.contains()+path.isAbsolute()checkrelativePath === ""\→/) for git pathspecfs.mkdir()beforefs.writeFile()in git show fallbackTests (
packages/opencode/test/snapshot/snapshot.test.ts)Added 13 new test cases:
patch returns absolute paths and revert handles them correctlyrevert restores modified file content correctlyrevert handles deeply nested files with absolute pathsrevert handles files with spaces in namesrevert handles multiple sequential patches correctlyrevert with patches array containing multiple itemsrevert deletes file created after snapshotrevert restores deleted filepatch files relative path computation is correctrevert works when process cwd differs from worktreerevert skips files outside worktreerevert skips patch with empty relativePathrevert creates parent directory when using fallbackTesting