fix: handle edge case when next line after HEAD is missing

This commit is contained in:
Nikolay Sedelnikov 2024-08-30 16:21:56 +02:00 committed by Nikolay Sedelnikov (aider)
parent e8e1bd556f
commit 976d2bfd87
No known key found for this signature in database
GPG key ID: BA786963302B556C

View file

@ -442,9 +442,8 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
# Check for SEARCH/REPLACE blocks
if line.strip() == HEAD:
try:
# if next line after HEAD is DIVIDER, it's a new file
next_line = lines[i + 1]
if next_line.strip() == DIVIDER:
# if next line after HEAD exists and is DIVIDER, it's a new file
if i + 1 < len(lines) and lines[i + 1].strip() == DIVIDER:
filename = find_filename(lines[max(0, i - 3) : i], fence, None)
else:
filename = find_filename(