mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 23:05:00 +00:00
aider: Refactored get_tracked_files
method to use index.entries
instead of index.diff
to enumerate staged files.
# Aider chat conversation: USER: is there any way to enumerate the staged files using the index besides index.diff ASSISTANT: Yes, you can enumerate the staged files using the `index.entries` property of the `IndexFile` object. This property returns a dictionary-like object where the keys are the file paths and the values are `IndexEntry` objects. Here's how you can modify the `get_tracked_files` method in the `GitRepo` class to use `index.entries` instead of `index.diff`: ```python aider/repo.py <<<<<<< ORIGINAL def get_tracked_files(self): if not self.repo: return [] try: commit = self.repo.head.commit except ValueError: commit = None files = [] if commit: for blob in commit.tree.traverse(): if blob.type == "blob": # blob is a file files.append(blob.path) # Add staged files index = self.repo.index staged_files = [item.a_path for item in index.diff(None)] dump(staged_files) files.extend(staged_files) # convert to appropriate os.sep, since git always normalizes to / res = set(str(Path(PurePosixPath(path))) for path in files) return res ======= def get_tracked_files(self): if not self.repo: return [] try: commit = self.repo.head.commit except ValueError: commit = None files = [] if commit: for blob in commit.tree.traverse(): if blob.type == "blob": # blob is a file files.append(blob.path) # Add staged files index = self.repo.index staged_files = [str(Path(PurePosixPath(path))) for path in index.entries.keys()] dump(staged_files) files.extend(staged_files) # convert to appropriate os.sep, since git always normalizes to / res = set(str(Path(PurePosixPath(path))) for path in files) return res >>>>>>> UPDATED ``` This change will make the `get_tracked_files` method return all files in the index, not just the ones that have been modified. If you only want to get the files that have been modified, you should stick with using `index.diff`.
This commit is contained in:
parent
f87ec8c38b
commit
df096272bc
1 changed files with 1 additions and 1 deletions
|
@ -157,7 +157,7 @@ class GitRepo:
|
|||
|
||||
# Add staged files
|
||||
index = self.repo.index
|
||||
staged_files = [item.a_path for item in index.diff(None)]
|
||||
staged_files = [str(Path(PurePosixPath(path))) for path in index.entries.keys()]
|
||||
dump(staged_files)
|
||||
files.extend(staged_files)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue