This commit is contained in:
Paul Gauthier 2023-06-24 14:57:40 -07:00
parent 81b1916c6a
commit d8294cab44

View file

@ -1,4 +1,3 @@
import os
from pathlib import Path from pathlib import Path
from aider import diffs from aider import diffs
@ -38,11 +37,10 @@ class WholeFileCoder(Coder):
if line.startswith("```"): if line.startswith("```"):
if fname: if fname:
# ending an existing block # ending an existing block
full_path = os.path.abspath(os.path.join(self.root, fname)) full_path = (Path(self.root) / fname).absolute()
if mode == "diff": if mode == "diff" and full_path.exists():
with open(full_path, "r") as f: orig_lines = full_path.readlines()
orig_lines = f.readlines()
show_diff = diffs.diff_partial_update( show_diff = diffs.diff_partial_update(
orig_lines, orig_lines,
@ -55,7 +53,7 @@ class WholeFileCoder(Coder):
edited.add(fname) edited.add(fname)
if not self.dry_run: if not self.dry_run:
new_lines = "".join(new_lines) new_lines = "".join(new_lines)
Path(full_path).write_text(new_lines) full_path.write_text(new_lines)
fname = None fname = None
new_lines = [] new_lines = []
@ -78,11 +76,10 @@ class WholeFileCoder(Coder):
if mode == "diff": if mode == "diff":
if fname: if fname:
# ending an existing block # ending an existing block
full_path = os.path.abspath(os.path.join(self.root, fname)) full_path = (Path(self.root) / fname).absolute()
if mode == "diff": if mode == "diff" and full_path.exists():
with open(full_path, "r") as f: orig_lines = full_path.readlines()
orig_lines = f.readlines()
show_diff = diffs.diff_partial_update( show_diff = diffs.diff_partial_update(
orig_lines, orig_lines,