From 0cd5f5b812ee3fd39bfe5db9d96244c4a10b9a52 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 16:57:49 -0700 Subject: [PATCH] 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. --- aider/coder.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index 9e0e08493..5856e5072 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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)