@@ -146,7 +146,6 @@ export const store_original_file_states = async (
146146 return original_states
147147}
148148
149- // Helper function to extract content from patch for preview
150149export const extract_content_from_patch = (
151150 patch_content : string ,
152151 original_content : string
@@ -166,7 +165,6 @@ export const extract_content_from_patch = (
166165 }
167166}
168167
169- // Ensures all target files are closed before applying patches
170168async function close_files_in_all_editor_groups (
171169 file_paths : string [ ] ,
172170 workspace_path : string
@@ -209,7 +207,6 @@ async function close_files_in_all_editor_groups(
209207 return [ ...new Map ( closed_files . map ( ( item ) => [ item . fsPath , item ] ) ) . values ( ) ]
210208}
211209
212- // Reopens files that were closed before patch application
213210async function reopen_closed_files ( closed_files : vscode . Uri [ ] ) : Promise < void > {
214211 for ( const uri of closed_files ) {
215212 try {
@@ -225,7 +222,6 @@ async function reopen_closed_files(closed_files: vscode.Uri[]): Promise<void> {
225222 }
226223}
227224
228- // Opens, formats, and saves a list of files.
229225async function process_modified_files (
230226 file_paths : string [ ] ,
231227 workspace_path : string
@@ -464,11 +460,15 @@ export const apply_git_patch = async (
464460 workspace_path
465461 )
466462
467- await vscode . workspace . fs . writeFile (
468- vscode . Uri . file ( temp_file ) ,
469- Buffer . from ( patch_content )
470- )
471- await new Promise ( ( r ) => setTimeout ( r , 100 ) )
463+ // Write patch file and ensure it's synced to disk before git apply reads it
464+ const patch_buffer = Buffer . from ( patch_content )
465+ const fd = await fs . promises . open ( temp_file , 'w' )
466+ try {
467+ await fd . write ( patch_buffer )
468+ await fd . sync ( ) // Ensure data is flushed to disk
469+ } finally {
470+ await fd . close ( )
471+ }
472472
473473 let last_error : any = null
474474 let success = false
@@ -547,7 +547,6 @@ export const apply_git_patch = async (
547547 }
548548 }
549549
550- // Cleanup and return
551550 if ( success ) {
552551 await process_modified_files ( file_paths , workspace_path )
553552 await reopen_closed_files ( closed_files )
0 commit comments