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.
This commit is contained in:
Paul Gauthier 2023-05-12 23:00:48 -07:00
parent 4eed5a1b90
commit a711debd1d

View file

@ -410,8 +410,10 @@ class Coder:
self.abs_fnames.add(full_path) self.abs_fnames.add(full_path)
# TODO: check if it's already in the repo # Check if the file is already in the repo
if self.repo and self.io.confirm_ask(f"Add {path} to git?"): 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) self.repo.git.add(full_path)
edited.add(path) edited.add(path)