mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
fix: Handle new file creation in the same folder
This commit is contained in:
parent
301c4265b7
commit
e8e1bd556f
2 changed files with 46 additions and 1 deletions
|
@ -442,7 +442,15 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
|
||||||
# Check for SEARCH/REPLACE blocks
|
# Check for SEARCH/REPLACE blocks
|
||||||
if line.strip() == HEAD:
|
if line.strip() == HEAD:
|
||||||
try:
|
try:
|
||||||
filename = find_filename(lines[max(0, i - 3) : i], fence, valid_fnames)
|
# if next line after HEAD is DIVIDER, it's a new file
|
||||||
|
next_line = lines[i + 1]
|
||||||
|
if next_line.strip() == DIVIDER:
|
||||||
|
filename = find_filename(lines[max(0, i - 3) : i], fence, None)
|
||||||
|
else:
|
||||||
|
filename = find_filename(
|
||||||
|
lines[max(0, i - 3) : i], fence, valid_fnames
|
||||||
|
)
|
||||||
|
|
||||||
if not filename:
|
if not filename:
|
||||||
if current_filename:
|
if current_filename:
|
||||||
filename = current_filename
|
filename = current_filename
|
||||||
|
|
|
@ -456,6 +456,43 @@ Hope you like it!
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_new_file_created_in_same_folder(self):
|
||||||
|
edit = """
|
||||||
|
Here's the change:
|
||||||
|
|
||||||
|
path/to/a/file2.txt
|
||||||
|
```python
|
||||||
|
<<<<<<< SEARCH
|
||||||
|
=======
|
||||||
|
three
|
||||||
|
>>>>>>> REPLACE
|
||||||
|
```
|
||||||
|
|
||||||
|
another change
|
||||||
|
|
||||||
|
path/to/a/file1.txt
|
||||||
|
```python
|
||||||
|
<<<<<<< SEARCH
|
||||||
|
one
|
||||||
|
=======
|
||||||
|
two
|
||||||
|
>>>>>>> REPLACE
|
||||||
|
```
|
||||||
|
|
||||||
|
Hope you like it!
|
||||||
|
"""
|
||||||
|
|
||||||
|
edits = list(
|
||||||
|
eb.find_original_update_blocks(edit, valid_fnames=["path/to/a/file1.txt"])
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
edits,
|
||||||
|
[
|
||||||
|
("path/to/a/file2.txt", "", "three\n"),
|
||||||
|
("path/to/a/file1.txt", "one\n", "two\n"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue