Fix restore --staged for certain vfs ops#846
Open
tyrielv wants to merge 1 commit intomicrosoft:vfs-2.53.0from
Open
Fix restore --staged for certain vfs ops#846tyrielv wants to merge 1 commit intomicrosoft:vfs-2.53.0from
restore --staged for certain vfs ops#846tyrielv wants to merge 1 commit intomicrosoft:vfs-2.53.0from
Conversation
When using virtualfilesystem, Running git restore --staged after git cherry-pick -n or git reset --soft would result in an incorrect state - the modified files would still have their modified contents, but git would no longer recognize them as being modified; and the added files would be deleted from disk instead of just unstaged. See microsoft/VFSForGit#1855 for more details. This commit fixes these issues with two changes: Add a new flag to the index state structure, vfs_check_added_entries_for_clear_skip_worktree. This flag is set during cherry-pick -n before calculating the new index state, and causes newly added entries to have their SKIP_WORKTREE bit cleared. This ensures that newly added files are added to both the index and the worktree in the next step. Otherwise, sparse-checkout would prevent them from being added to the worktree. Set the existing flag updated_skipworktree on the index when running a checkout index (aka restore --staged) operation. These operations already will clear SKIP_WORKTREE bits for modified files, but without this flag set the virtualfilesystem hook notification does not indicate that they changed, causing the VFS to not update its state correctly.
37b6a50 to
716bf8d
Compare
dscho
reviewed
Mar 16, 2026
Member
dscho
left a comment
There was a problem hiding this comment.
I have to admit that I'm certain that I fail to understand the deep detail here, why VFS has to be special-cased (and, say, Scalar-based checkouts are fine).
Do you think that there may be an easy way to test this in a new test case? That might jog my brain to understand what bug is fixed here.
| */ | ||
| if ((select_mask & CE_ADDED) | ||
| && (clear_mask & CE_SKIP_WORKTREE) | ||
| && istate->vfs_check_added_entries_for_clear_skip_worktree) { |
Member
There was a problem hiding this comment.
How about moving the istate->vfs_... condition to the front, so that non-VFS scenarios are affected minimally?
| rollback_lock_file(&index_lock); | ||
| return clean; | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
Let's leave that empty line there.
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.
When using virtualfilesystem, Running git restore --staged after git cherry-pick -n or git reset --soft would result in an incorrect state - the modified files would still have their modified contents, but git would no longer recognize them as being modified; and the added files would be deleted from disk instead of just unstaged.
See microsoft/VFSForGit#1855 for more details.
This commit fixes these issues with two changes:
Add a new flag to the index state structure, vfs_check_added_entries_for_clear_skip_worktree. This flag is set during cherry-pick -n before calculating the new index state, and causes newly added entries to have their SKIP_WORKTREE bit cleared. This ensures that newly added files are added to both the index and the worktree in the next step. Otherwise, sparse-checkout would prevent them from being added to the worktree.
Set the existing flag updated_skipworktree on the index when running a checkout index (aka restore --staged) operation. These operations already will clear SKIP_WORKTREE bits for modified files, but without this flag set the virtualfilesystem hook notification does not indicate that they changed, causing the VFS to not update its state correctly.
Thanks for taking the time to contribute to Git!
This fork contains changes specific to monorepo scenarios. If you are an
external contributor, then please detail your reason for submitting to
this fork:
GVFS Protocol.