mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
aider: Handle the case where the repository has never had any commits by using index.diff(None)
to get the staged files.
# Aider chat conversation: USER: index.diff("HEAD") fails when the repo has never had any commits ASSISTANT: To handle the case where the repository has never had any commits, we can add a try-except block around the `index.diff("HEAD")` call in the `get_tracked_files` method of the `GitRepo` class in the `aider/repo.py` file. If a `git.exc.BadName` exception is raised, we can assume that there are no commits and return an empty list for the staged files. Here is the proposed change: ```python aider/repo.py <<<<<<< ORIGINAL # Add staged files index = self.repo.index staged_files = [item.a_path for item in index.diff("HEAD")] files.extend(staged_files) ======= # Add staged files ^C KeyboardInterrupt USER: there can be staged files when there are not commits ASSISTANT: You're correct. If there are no commits, `index.diff("HEAD")` will fail, but there can still be staged files. We can use `index.diff(None)` to get the staged files in this case. Here's the proposed change: ```python aider/repo.py <<<<<<< ORIGINAL # Add staged files index = self.repo.index staged_files = [item.a_path for item in index.diff("HEAD")] files.extend(staged_files) ======= # Add staged files index = self.repo.index try: staged_files = [item.a_path for item in index.diff("HEAD")] except git.exc.BadName: staged_files = [item.a_path for item in index.diff(None)] files.extend(staged_files) >>>>>>> UPDATED ```
This commit is contained in:
parent
bef1d00ab1
commit
89542d2139
1 changed files with 4 additions and 1 deletions
|
@ -156,7 +156,10 @@ class GitRepo:
|
|||
|
||||
# Add staged files
|
||||
index = self.repo.index
|
||||
try:
|
||||
staged_files = [item.a_path for item in index.diff("HEAD")]
|
||||
except git.exc.BadName:
|
||||
staged_files = [item.a_path for item in index.diff(None)]
|
||||
files.extend(staged_files)
|
||||
|
||||
# convert to appropriate os.sep, since git always normalizes to /
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue