@@ -282,10 +282,18 @@ def get_changed_files(self):
282282 raise Exception (f"Failed to get PR files: { resp .status_code } " )
283283 changed = []
284284 for fd in resp .json ():
285- if fd ['status' ] in ['added' ,'modified' ]:
286- fn = fd ['filename' ]
285+ status = fd ['status' ]
286+ fn = fd ['filename' ]
287+ # Skip deleted/removed files - they don't exist in PR head
288+ if status in ['removed' , 'deleted' ]:
289+ logger .info (f"Skipping deleted file: { fn } " )
290+ continue
291+ # For added, modified, or renamed files, use the new filename
292+ if status in ['added' , 'modified' , 'renamed' ]:
287293 if not fn .startswith ('.' ) or fn == '.copyrightconfig' :
288294 changed .append (fn )
295+ else :
296+ logger .warning (f"Unknown file status '{ status } ' for { fn } " )
289297 logger .info (f"Changed files: { len (changed )} " )
290298 return changed
291299 except Exception as e :
@@ -308,10 +316,19 @@ def download_files(self, file_paths):
308316 clone_res = subprocess .run (['git' ,'clone' ,'--depth' ,'1' ,'--branch' , self .pr_data ['base' ]['ref' ], auth_clone_url , base_clone_dir ], capture_output = True , text = True , timeout = 60 )
309317 if clone_res .returncode != 0 :
310318 raise Exception (f"Git clone failed: { clone_res .stderr } " )
311- apply_res = subprocess .run (['git' ,'apply' ,'--3way' ,'--ignore-whitespace' , diff_path ], cwd = base_clone_dir , capture_output = True , text = True , timeout = 30 )
319+ # First try normal apply for new files, then 3way for modifications
320+ normal_apply_res = subprocess .run (['git' ,'apply' ,'--ignore-whitespace' , diff_path ], cwd = base_clone_dir , capture_output = True , text = True , timeout = 30 )
321+ if normal_apply_res .returncode != 0 :
322+ logger .info (f"Normal git apply failed, trying --3way: { normal_apply_res .stderr [:200 ]} " )
323+ threeway_apply_res = subprocess .run (['git' ,'apply' ,'--3way' ,'--ignore-whitespace' , diff_path ], cwd = base_clone_dir , capture_output = True , text = True , timeout = 30 )
324+ apply_res = threeway_apply_res
325+ else :
326+ apply_res = normal_apply_res
312327 stderr_lower = apply_res .stderr .lower ()
313328 applied_some = stderr_lower .count ('applied patch' ) + stderr_lower .count ('cleanly' )
314329 self .diff_applied = apply_res .returncode == 0 or applied_some > 0
330+ if apply_res .returncode != 0 :
331+ logger .warning (f"Git apply stderr: { apply_res .stderr [:500 ]} " )
315332 downloaded = []
316333 diff_content = diff_resp .text
317334 for fp in file_paths :
@@ -325,7 +342,7 @@ def download_files(self, file_paths):
325342 else :
326343 self .files_from_base .append (fp )
327344 else :
328- logger .warning (f"File not found: { fp } " )
345+ logger .warning (f"File not found after diff apply : { fp } " )
329346 return downloaded
330347 except Exception as e :
331348 logger .error (f"download_files error: { e } " )
0 commit comments