File tree Expand file tree Collapse file tree
apps/editor/src/commands/apply-chat-response-command/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -546,13 +546,36 @@ export const apply_git_patch = async (
546546 await reopen_closed_files ( closed_files )
547547 await vscode . workspace . fs . delete ( vscode . Uri . file ( temp_file ) )
548548
549- if ( original_states && applied_content && file_paths . length > 0 ) {
550- const processed_path = file_paths [ 0 ]
551- const state = original_states . find (
552- ( s ) => s . file_path === processed_path
553- )
554- if ( state ) {
555- state . proposed_content = applied_content
549+ if ( original_states ) {
550+ for ( const state of original_states ) {
551+ if ( state . proposed_content !== undefined ) {
552+ continue
553+ }
554+
555+ if (
556+ applied_content &&
557+ file_paths . length > 0 &&
558+ state . file_path == file_paths [ 0 ]
559+ ) {
560+ state . proposed_content = applied_content
561+ continue
562+ }
563+
564+ const safe_path = create_safe_path ( workspace_path , state . file_path )
565+ if ( safe_path && fs . existsSync ( safe_path ) ) {
566+ try {
567+ const content = fs . readFileSync ( safe_path , 'utf8' )
568+ state . proposed_content = content
569+ } catch ( error ) {
570+ Logger . warn ( {
571+ function_name : 'apply_git_patch' ,
572+ message : 'Failed to read proposed content from disk' ,
573+ data : { file_path : state . file_path , error }
574+ } )
575+ }
576+ } else if ( state . file_state === 'deleted' ) {
577+ state . proposed_content = ''
578+ }
556579 }
557580 }
558581
You can’t perform that action at this time.
0 commit comments