From 5d8ed278aace8d4580883794193afa23f7d75248 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 18 May 2024 18:13:08 -0700 Subject: [PATCH] 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 ``` --- aider/repo.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/aider/repo.py b/aider/repo.py index 4538c16a3..0133d15dc 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -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