mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
refac
This commit is contained in:
parent
0f5264b196
commit
08764215c3
2 changed files with 34 additions and 31 deletions
|
@ -717,6 +717,35 @@ class Coder:
|
||||||
def get_addable_relative_files(self):
|
def get_addable_relative_files(self):
|
||||||
return set(self.get_all_relative_files()) - set(self.get_inchat_relative_files())
|
return set(self.get_all_relative_files()) - set(self.get_inchat_relative_files())
|
||||||
|
|
||||||
|
def allowed_to_edit(self, path):
|
||||||
|
full_path = os.path.abspath(os.path.join(self.root, path))
|
||||||
|
|
||||||
|
if full_path in self.abs_fnames:
|
||||||
|
return full_path
|
||||||
|
|
||||||
|
if not Path(full_path).exists():
|
||||||
|
question = f"Allow creation of new file {path}?" # noqa: E501
|
||||||
|
else:
|
||||||
|
question = f"Allow edits to {path} which was not previously provided?" # noqa: E501
|
||||||
|
if not self.io.confirm_ask(question):
|
||||||
|
self.io.tool_error(f"Skipping edit to {path}")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not Path(full_path).exists():
|
||||||
|
Path(full_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
Path(full_path).touch()
|
||||||
|
|
||||||
|
self.abs_fnames.add(full_path)
|
||||||
|
|
||||||
|
# Check if the file is already in the repo
|
||||||
|
if self.repo:
|
||||||
|
tracked_files = set(self.repo.git.ls_files().splitlines())
|
||||||
|
relative_fname = self.get_rel_fname(full_path)
|
||||||
|
if relative_fname not in tracked_files and self.io.confirm_ask(f"Add {path} to git?"):
|
||||||
|
self.repo.git.add(full_path)
|
||||||
|
|
||||||
|
return full_path
|
||||||
|
|
||||||
def apply_updates(self):
|
def apply_updates(self):
|
||||||
try:
|
try:
|
||||||
edited = self.update_files()
|
edited = self.update_files()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import math
|
import math
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -24,38 +23,13 @@ class EditBlockCoder(Coder):
|
||||||
|
|
||||||
edited = set()
|
edited = set()
|
||||||
for path, original, updated in edits:
|
for path, original, updated in edits:
|
||||||
full_path = os.path.abspath(os.path.join(self.root, path))
|
full_path = self.allowed_to_edit(path)
|
||||||
|
if not full_path:
|
||||||
if full_path not in self.abs_fnames:
|
continue
|
||||||
if not Path(full_path).exists():
|
|
||||||
question = f"Allow creation of new file {path}?" # noqa: E501
|
|
||||||
else:
|
|
||||||
question = (
|
|
||||||
f"Allow edits to {path} which was not previously provided?" # noqa: E501
|
|
||||||
)
|
|
||||||
if not self.io.confirm_ask(question):
|
|
||||||
self.io.tool_error(f"Skipping edit to {path}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not Path(full_path).exists():
|
|
||||||
Path(full_path).parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
Path(full_path).touch()
|
|
||||||
|
|
||||||
self.abs_fnames.add(full_path)
|
|
||||||
|
|
||||||
# Check if the file is already in the repo
|
|
||||||
if self.repo:
|
|
||||||
tracked_files = set(self.repo.git.ls_files().splitlines())
|
|
||||||
relative_fname = self.get_rel_fname(full_path)
|
|
||||||
if relative_fname not in tracked_files and self.io.confirm_ask(
|
|
||||||
f"Add {path} to git?"
|
|
||||||
):
|
|
||||||
self.repo.git.add(full_path)
|
|
||||||
|
|
||||||
if do_replace(full_path, original, updated, self.dry_run):
|
if do_replace(full_path, original, updated, self.dry_run):
|
||||||
edited.add(path)
|
edited.add(path)
|
||||||
else:
|
continue
|
||||||
self.io.tool_error(f"Failed to apply edit to {path}")
|
self.io.tool_error(f"Failed to apply edit to {path}")
|
||||||
|
|
||||||
return edited
|
return edited
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue