aider: Add get_dirty_files() method to return all dirty files staged or in the working directory.

# Aider chat conversation:

USER: add a get_dirty_files() method which returns all the files which are dirty (not committed) either staged or in the working dir.

ASSISTANT: To add the `get_dirty_files()` method, we need to:

1. Define the new method in the `GitRepo` class.
2. Implement the logic to return all dirty files, both staged and in the working directory.

Here is the *SEARCH/REPLACE* block:

aider/repo.py
```python
<<<<<<< SEARCH
    def is_dirty(self, path=None):
=======
    def get_dirty_files(self):
        """
        Returns a list of all files which are dirty (not committed), either staged or in the working directory.
        """
        dirty_files = set()

        # Get staged files
        staged_files = self.repo.git.diff('--name-only', '--cached').splitlines()
        dirty_files.update(staged_files)

        # Get unstaged files
        unstaged_files = self.repo.git.diff('--name-only').splitlines()
        dirty_files.update(unstaged_files)

        return list(dirty_files)

>>>>>>> REPLACE
```

aider/repo.py
```python
<<<<<<< SEARCH
        return self.repo.is_dirty(path=path)
=======
        return self.repo.is_dirty(path=path)
>>>>>>> REPLACE
```
This commit is contained in:
Paul Gauthier 2024-05-18 18:13:08 -07:00
parent 22736b63d0
commit 5d8ed278aa

View file

@ -242,7 +242,21 @@ class GitRepo:
res = Path(self.root) / path res = Path(self.root) / path
return utils.safe_abs_path(res) return utils.safe_abs_path(res)
def is_dirty(self, path=None): def get_dirty_files(self):
"""
Returns a list of all files which are dirty (not committed), either staged or in the working directory.
"""
dirty_files = set()
# Get staged files
staged_files = self.repo.git.diff('--name-only', '--cached').splitlines()
dirty_files.update(staged_files)
# Get unstaged files
unstaged_files = self.repo.git.diff('--name-only').splitlines()
dirty_files.update(unstaged_files)
return list(dirty_files)
if path and not self.path_in_repo(path): if path and not self.path_in_repo(path):
return True return True