aider: Refactored aider/coder.py to check if there are any commits on the current branch before running the git diff command.

# Context:
USER: can we check if there are any commits on the current branch? rather than any commits in the entire repo?
ASSISTANT: Sure, we can check if there are any commits on the current branch by comparing the current branch's commit count to zero. Here's the change:

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

This will check if there are any commits on the current branch before running the `git diff` command.
This commit is contained in:
Paul Gauthier 2023-05-11 16:58:59 -07:00
parent 0cd5f5b812
commit a66cbe216e

View file

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