mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
handle multiple udiffs inside a single fenced block
This commit is contained in:
parent
bd1c8b625d
commit
d5f4ba2278
2 changed files with 62 additions and 1 deletions
|
@ -307,7 +307,7 @@ def apply_partial_hunk(content, preceding_context, changes, following_context):
|
||||||
|
|
||||||
|
|
||||||
def find_diffs(content):
|
def find_diffs(content):
|
||||||
# We can always use triple-quotes, because all the udiff content
|
# We can always fence with triple-quotes, because all the udiff content
|
||||||
# is prefixed with +/-/space.
|
# is prefixed with +/-/space.
|
||||||
|
|
||||||
if not content.endswith("\n"):
|
if not content.endswith("\n"):
|
||||||
|
@ -356,6 +356,20 @@ def process_fenced_block(lines, start_line_num):
|
||||||
hunk.append(line)
|
hunk.append(line)
|
||||||
if len(line) < 2:
|
if len(line) < 2:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if line.startswith("+++ ") and hunk[-2].startswith("--- "):
|
||||||
|
if hunk[-3] == "\n":
|
||||||
|
hunk = hunk[:-3]
|
||||||
|
else:
|
||||||
|
hunk = hunk[:-2]
|
||||||
|
|
||||||
|
edits.append((fname, hunk))
|
||||||
|
hunk = []
|
||||||
|
keeper = False
|
||||||
|
|
||||||
|
fname = line[4:].strip()
|
||||||
|
continue
|
||||||
|
|
||||||
op = line[0]
|
op = line[0]
|
||||||
if op in "-+":
|
if op in "-+":
|
||||||
keeper = True
|
keeper = True
|
||||||
|
@ -369,6 +383,7 @@ def process_fenced_block(lines, start_line_num):
|
||||||
hunk = hunk[:-1]
|
hunk = hunk[:-1]
|
||||||
edits.append((fname, hunk))
|
edits.append((fname, hunk))
|
||||||
hunk = []
|
hunk = []
|
||||||
|
keeper = False
|
||||||
|
|
||||||
return line_num + 1, edits
|
return line_num + 1, edits
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,52 @@ Some text...
|
||||||
self.assertEqual(edit[0], "dir name with spaces/file.txt")
|
self.assertEqual(edit[0], "dir name with spaces/file.txt")
|
||||||
self.assertEqual(edit[1], ["-Original\n", "+Modified\n"])
|
self.assertEqual(edit[1], ["-Original\n", "+Modified\n"])
|
||||||
|
|
||||||
|
def test_find_multi_diffs(self):
|
||||||
|
content = """
|
||||||
|
To implement the `--check-update` option, I will make the following changes:
|
||||||
|
|
||||||
|
1. Add the `--check-update` argument to the argument parser in `aider/main.py`.
|
||||||
|
2. Modify the `check_version` function in `aider/versioncheck.py` to return a boolean indicating whether an update is available.
|
||||||
|
3. Use the returned value from `check_version` in `aider/main.py` to set the exit status code when `--check-update` is used.
|
||||||
|
|
||||||
|
Here are the diffs for those changes:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- aider/versioncheck.py
|
||||||
|
+++ aider/versioncheck.py
|
||||||
|
@@ ... @@
|
||||||
|
except Exception as err:
|
||||||
|
print_cmd(f"Error checking pypi for new version: {err}")
|
||||||
|
+ return False
|
||||||
|
|
||||||
|
--- aider/main.py
|
||||||
|
+++ aider/main.py
|
||||||
|
@@ ... @@
|
||||||
|
other_group.add_argument(
|
||||||
|
"--version",
|
||||||
|
action="version",
|
||||||
|
version=f"%(prog)s {__version__}",
|
||||||
|
help="Show the version number and exit",
|
||||||
|
)
|
||||||
|
+ other_group.add_argument(
|
||||||
|
+ "--check-update",
|
||||||
|
+ action="store_true",
|
||||||
|
+ help="Check for updates and return status in the exit code",
|
||||||
|
+ default=False,
|
||||||
|
+ )
|
||||||
|
other_group.add_argument(
|
||||||
|
"--apply",
|
||||||
|
metavar="FILE",
|
||||||
|
```
|
||||||
|
|
||||||
|
These changes will add the `--check-update` option to the command-line interface and use the `check_version` function to determine if an update is available, exiting with status code `0` if no update is available and `1` if an update is available.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
|
edits = find_diffs(content)
|
||||||
|
dump(edits)
|
||||||
|
self.assertEqual(len(edits), 2)
|
||||||
|
self.assertEqual(len(edits[0][1]), 3)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue