mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
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:
parent
e6f88394f5
commit
0cd5f5b812
1 changed files with 4 additions and 1 deletions
|
@ -465,7 +465,10 @@ class Coder:
|
||||||
for fname in file_list:
|
for fname in file_list:
|
||||||
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
|
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
|
||||||
if self.pretty:
|
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:
|
else:
|
||||||
these_diffs = repo.git.diff("HEAD", relative_fname)
|
these_diffs = repo.git.diff("HEAD", relative_fname)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue