fix(snapshot): make /redo targeted to only restore files from reverted turn#15611
fix(snapshot): make /redo targeted to only restore files from reverted turn#15611Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Conversation
…erted turn /redo used checkout-index -a -f which writes every file from the snapshot, updating modification timestamps on unchanged files and triggering editor reload prompts. Store the file list from patches during /undo, pass it through to /redo, and use per-file checkout (same pattern as revert) when a file list is available. Falls back to blanket restore for backward compatibility.
|
I've tested this code and confirm it appeared to fix the bug I encountered and created the Issue for in a limited new test session. However, when I went into an older session and used redo, the bug persisted and changed all files in project to todays date. |
|
Did some further testing. Code is fine, but testing environment was the problem. Tested this fix locally. Works as expected in new sessions — /undo then /redo correctly preserves file timestamps on untouched files. One edge case worth noting: if /undo was performed on older code (before this fix), the revert record stored in the session won't have the files field. When /redo runs with the new code, it hits the backward-compat fallback and does the old blanket checkout-index -a -f, reproducing the original bug. This is by design — the fix requires both /undo and /redo to run on the new code. Once the old revert is cleared (by redoing and undoing again with the new code), subsequent /redo operations work correctly. Not a bug — just a one-time edge case for sessions with pre-fix revert state. |
|
Hi — just a gentle bump on this. Happy to make any changes if needed! |
Issue for this PR
Closes #15391
Type of change
What does this PR do?
/redo(unrevert) was usingcheckout-index -a -fwhich writes every tracked file from the snapshot tree, updating mtimes on all files — even those untouched by the reverted turn. This triggers editor reload prompts and confuses file watchers.The fix stores the file list collected from patches during
/undointosession.revert.files, then passes it torestore()during/redo. When a file list is present,restore()does per-filegit checkout <hash> -- <file>(the same patternrevert()already uses) with thels-treefallback for files that were created and need deletion. When no file list is available (backward compat), it falls back to the existing blanket restore.Three files changed:
session/index.ts— added optionalfilesfield to the revert schemasession/revert.ts— collect unique file paths from patches, pass them through unrevertsnapshot/index.ts—restore()accepts optional file list for targeted checkoutHow did you verify your code works?
Read through the existing
revert()function to confirm the targeted checkout pattern is identical. The newrestore()path mirrorsrevert()exactly — same git flags, samels-treefallback, samefs.unlinkcleanup.Checklist