From a711debd1db48191da89c23cb73ee1bc74e54538 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 12 May 2023 23:00:48 -0700 Subject: [PATCH] aider: Checked if the new file is already in the git repo before adding it. # Context: USER: do the TODO ASSISTANT: I see that there is a TODO comment in the `aider/coder.py` file. To address the TODO, I will check if the new file is already in the git repo before adding it. Here's the change: ```python aider/coder.py <<<<<<< ORIGINAL 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) # TODO: check if it's already in the repo if self.repo and self.io.confirm_ask(f"Add {path} to git?"): ======= 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 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.repo and self.io.confirm_ask(f"Add {path} to git?"): >>>>>>> UPDATED self.repo.git.add(full_path) ``` This change checks if the new file is already in the git repo before adding it. If you have any other requests or need further clarification, please let me know. --- aider/coder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aider/coder.py b/aider/coder.py index c89dd7702..ec22e49df 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -410,8 +410,10 @@ class Coder: self.abs_fnames.add(full_path) - # TODO: check if it's already in the repo - if self.repo and self.io.confirm_ask(f"Add {path} to git?"): + # Check if the file is already in the 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.repo and self.io.confirm_ask(f"Add {path} to git?"): self.repo.git.add(full_path) edited.add(path)