mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 08:14:59 +00:00
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:
parent
22736b63d0
commit
5d8ed278aa
1 changed files with 15 additions and 1 deletions
|
@ -242,7 +242,21 @@ class GitRepo:
|
|||
res = Path(self.root) / path
|
||||
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):
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue