@@ -125,9 +125,7 @@ export async function extract_diff_patches(
125125
126126export function extract_file_paths_from_patch ( patch_content : string ) : string [ ] {
127127 const file_paths : string [ ] = [ ]
128- // Normalize line endings to LF
129- const normalized_content = patch_content . replace ( / \r \n / g, '\n' )
130- const lines = normalized_content . split ( '\n' )
128+ const lines = patch_content . split ( '\n' )
131129
132130 for ( const line of lines ) {
133131 // Look for lines starting with +++ b/ which indicate target files in git patches
@@ -302,19 +300,12 @@ export async function apply_git_patch(
302300 let closed_files : vscode . Uri [ ] = [ ]
303301
304302 try {
305- // Normalize line endings to LF for git
306- const normalized_patch_content = patch_content . replace ( / \r \n / g, '\n' )
307-
308- // Extract file paths from the patch
309- const file_paths = extract_file_paths_from_patch ( normalized_patch_content )
310-
311- // Store original file states before applying patch
303+ const file_paths = extract_file_paths_from_patch ( patch_content )
312304 const original_states = await store_original_file_states (
313- normalized_patch_content ,
305+ patch_content ,
314306 workspace_path
315307 )
316308
317- // Close all files before applying patch to prevent conflicts
318309 closed_files = await close_files_in_all_editor_groups (
319310 file_paths ,
320311 workspace_path
@@ -324,14 +315,13 @@ export async function apply_git_patch(
324315 const temp_file = path . join ( workspace_path , '.tmp_patch' )
325316 await vscode . workspace . fs . writeFile (
326317 vscode . Uri . file ( temp_file ) ,
327- Buffer . from ( normalized_patch_content )
318+ Buffer . from ( patch_content )
328319 )
329320
330321 // Apply the patch
331322 try {
323+ let used_fallback = false
332324 try {
333- // Attempt to apply the patch using git
334- // Add the --ignore-whitespace flag to handle whitespace differences on Windows
335325 await execAsync (
336326 'git apply --whitespace=fix --ignore-whitespace ' + temp_file ,
337327 {
@@ -349,11 +339,15 @@ export async function apply_git_patch(
349339 if ( ( await process_diff_patch ( file_path_safe , temp_file ) ) == false ) {
350340 throw new Error ( 'Failed to apply diff patch for all methods' )
351341 }
342+
343+ used_fallback = true
352344 }
353345
354346 Logger . log ( {
355347 function_name : 'apply_git_patch' ,
356- message : 'Patch applied successfully' ,
348+ message : `Patch applied successfully${
349+ used_fallback ? ' using fallback' : ''
350+ } `,
357351 data : { workspace_path }
358352 } )
359353
0 commit comments