mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-05 04:05:04 +00:00
![]() # 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 ``` |
||
---|---|---|
.. | ||
coders | ||
__init__.py | ||
commands.py | ||
diffs.py | ||
dump.py | ||
io.py | ||
main.py | ||
models.py | ||
prompts.py | ||
repo.py | ||
repomap.py | ||
sendchat.py | ||
utils.py | ||
versioncheck.py |