From d45b7ae752d1e10ac0ec8f3f17b504457bab45d8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 22:59:02 -0700 Subject: [PATCH] handle filenames above the triple quotes --- aider/utils.py | 6 ++++-- tests/test_utils.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 397f38483..42f0195a1 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -174,9 +174,11 @@ def find_original_update_blocks(content): processed.append(cur) # original_marker - filename = processed[-2].splitlines()[-1] + filename = processed[-2].splitlines()[-1].strip() if not len(filename) or "`" in filename: - raise ValueError(f"Bad/missing filename: {filename}") + filename = processed[-2].splitlines()[-2].strip() + if not len(filename) or "`" in filename: + raise ValueError(f"Bad/missing filename. It should go right above {ORIGINAL}") original_text = pieces.pop() processed.append(original_text) diff --git a/tests/test_utils.py b/tests/test_utils.py index f7c06b329..c065c5e51 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -54,6 +54,25 @@ Tooooo >>>>>>> UPDATED ``` +Hope you like it! +""" + + edits = list(utils.find_original_update_blocks(edit)) + self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")]) + + def test_find_original_update_blocks_quote_below_filename(self): + edit = """ +Here's the change: + +foo.txt +```text +<<<<<<< ORIGINAL +Two +======= +Tooooo +>>>>>>> UPDATED +``` + Hope you like it! """