aider/aider
Paul Gauthier 89542d2139 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
```
2023-07-24 13:43:05 -03:00
..
coders bugfix 2023-07-22 09:47:54 -03:00
__init__.py set version to 0.10.0-dev 2023-07-22 09:02:19 -03:00
commands.py Merge branch 'main' into refactor-repo 2023-07-23 10:23:38 -03:00
diffs.py use utf-8 2023-07-05 20:51:35 -07:00
dump.py isort 2023-05-28 22:47:38 -07:00
io.py Added hint to Use --encoding to set the unicode encoding. 2023-07-17 08:19:21 -03:00
main.py Merge branch 'main' into refactor-repo 2023-07-22 09:42:39 -03:00
models.py Disabled general availability of gpt-4 (it's rolling out, not 100% available yet) 2023-07-08 05:57:56 -07:00
prompts.py refactor Editors 2023-06-20 16:26:00 -07:00
repo.py aider: Handle the case where the repository has never had any commits by using index.diff(None) to get the staged files. 2023-07-24 13:43:05 -03:00
repomap.py Anchor the cache to the project root 2023-07-13 14:01:07 -07:00
sendchat.py aider.repo.simple_send_with_retries 2023-07-21 16:20:27 -03:00
utils.py Adopt safe_abs_path 2023-07-07 17:17:33 -07:00
versioncheck.py cleanup 2023-07-20 09:49:40 -03:00