fix(core): preserve external files during snapshot restore - #46947
Open
kitlangton wants to merge 1 commit into
Open
fix(core): preserve external files during snapshot restore#46947kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
Plan ancestor restoration before descendant deletion and keep missing paths beneath restored non-directory entries away from filesystem removal. Validate canonical parents for remaining deletions while leaving present entries to native Git checkout. Handle historical ignore queries beneath restored symlinks so Session Undo and Redo finish without manual repair. Cover external-file preservation, repeated and reversed restoration, mixed trees, typed failures, and unchanged user index state.
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.
Why
Undoing a change from a symlink to a directory can delete a file outside the project. Restore currently follows the input map's order: it can restore the parent symlink, then follow that link while removing an old child path.
What Changes
The user's Git index remains unchanged.
Restore Planning
Reuse the entry type already returned by
git ls-tree, then process ancestors before descendants. An absent child beneath a restored file, symlink, or removed ancestor has no project-owned file to delete. Other deletions check the canonical parent against the canonical worktree before touching the filesystem. Present entries continue to use Git's native checkout behavior.The real Session Undo/Redo regression also exposes Git's rejection of historical paths beneath a restored symlink during ignore checking. Snapshot comparison retries those paths using the first symlink ancestor's ignore status. Normal checks keep their existing path, and genuine Git errors still propagate.
Scope
Local snapshot restore safety and the corresponding Session Undo/Redo round trip only. This does not restore the deferred session-movement feature, change snapshot IDs, add cross-store retention, or change a public API. It does not introduce a general filesystem sandbox or new coordination with external filesystem writers.
Verification
1e4e9c5d85with an external-file sentinel in an isolated temporary directory.ffa2db8dcf, including Linux and Windows unit tests and typechecking.