aider: Checked if there were any commits in the repo before trying to diff.

# Context:
USER: have get_dirty_files_and_diffs check if there are any commits in the repo before trying to diff
ASSISTANT: To check if there are any commits in the repo before trying to diff, we can use `len(repo.heads)` to get the number of branches in the repo. If there are no branches, it means there are no commits. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
=======
    if len(repo.heads) > 0:
        these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
    else:
        these_diffs = ""
>>>>>>> UPDATED
```

This will prevent the `git diff` command from running if there are no commits in the repo.
This commit is contained in:
Paul Gauthier 2023-05-11 16:57:49 -07:00
parent e6f88394f5
commit 0cd5f5b812

View file

@ -465,7 +465,10 @@ class Coder:
for fname in file_list:
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
if self.pretty:
these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
if len(repo.heads) > 0:
these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
else:
these_diffs = ""
else:
these_diffs = repo.git.diff("HEAD", relative_fname)