From a66cbe216ee294ed00f5b7234705f887c1e74030 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 16:58:59 -0700 Subject: [PATCH] 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. --- aider/coder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index 5856e5072..84978c23e 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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 = ""