Fix restore --staged for certain vfs ops#846
Fix restore --staged for certain vfs ops#846tyrielv wants to merge 1 commit intomicrosoft:vfs-2.53.0from
restore --staged for certain vfs ops#846Conversation
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
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) { |
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; | ||
| } | ||
|
|
There was a problem hiding this comment.
Let's leave that empty line there.
I've got a test case proposed for VFSForGit functional tests I'll look into what happens with Scalar in this same case. |
@dscho You're right, this does not appear to be handled entirely properly in Scalar either, though it's not as bad. For
If I were to expand the proposed fix to not isolate to virtual file system it would make Scalar break expectations, placing files outside the sparse checkout definition and possibly turning off skip-worktree despite the definition. I propose we set the expectation for Scalar on |
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.