From fdc81afb3fd7b3c19abbcd16ee03ed2cb8d029fc Mon Sep 17 00:00:00 2001 From: mijauexe Date: Thu, 3 Apr 2025 15:29:45 +0200 Subject: [PATCH] Make parsing old and new file contents more robust This will handle creating new files and deleting files with proper positive and negative diffs --- core/cli/helpers.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/cli/helpers.py b/core/cli/helpers.py index b23457241b..1015f8ad97 100644 --- a/core/cli/helpers.py +++ b/core/cli/helpers.py @@ -531,18 +531,16 @@ async def load_convo( current_file = await sm.get_file_for_project(state.id, path) prev_file = await sm.get_file_for_project(prev_state.id, path) - if not current_file or not prev_file: - continue + old_content = prev_file.content.content if prev_file and prev_file.content else "" + new_content = current_file.content.content if current_file and current_file.content else "" file["diff"] = get_line_changes( - old_content=prev_file.content.content if prev_file else "", - new_content=current_file.content.content, + old_content=old_content, + new_content=new_content, ) - file["old_content"] = prev_file.content.content if prev_file else "" - file["new_content"] = current_file.content.content + file["old_content"] = old_content + file["new_content"] = new_content - # hack that works fine because state.steps.completed is false until file is updated, but - # if we don't do this, we would have to compare to previous state which is complicated if file["diff"] != (0, 0): files.append(file)