@@ -753,6 +753,7 @@ static int do_recursive_merge(struct repository *r,
753753 int clean , show_output ;
754754 int i ;
755755 struct lock_file index_lock = LOCK_INIT ;
756+ int flags ;
756757
757758 if (repo_hold_locked_index (r , & index_lock , LOCK_REPORT_ON_ERROR ) < 0 )
758759 return -1 ;
@@ -787,15 +788,26 @@ static int do_recursive_merge(struct repository *r,
787788 * to be replace with the tree the index matched before we
788789 * started doing any picks.
789790 */
791+ if (opts -> no_commit && core_virtualfilesystem ) {
792+ /* When using the virtual file system, staged new files
793+ * should clear SKIP_WORKTREE because the virtual file
794+ * system only tracks files that are not modified in index.
795+ * Without this, `restore --staged` will delete the new files
796+ * from disk as well as from index.
797+ */
798+ o .repo -> index -> clear_skip_worktree_for_added_entries = 1 ;
799+ }
790800 merge_switch_to_result (& o , head_tree , & result , 1 , show_output );
801+ o .repo -> index -> clear_skip_worktree_for_added_entries = 0 ;
802+
791803 clean = result .clean ;
792804 if (clean < 0 ) {
793805 rollback_lock_file (& index_lock );
794806 return clean ;
795807 }
796808
797809 if (write_locked_index (r -> index , & index_lock ,
798- COMMIT_LOCK | SKIP_IF_UNCHANGED ))
810+ COMMIT_LOCK | SKIP_IF_UNCHANGED ) < 0 )
799811 /*
800812 * TRANSLATORS: %s will be "revert", "cherry-pick" or
801813 * "rebase".
0 commit comments