From 4e63254704fa99142fbf0fd83a445d2c4fa1c966 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 9 Sep 2024 13:40:56 -0700 Subject: [PATCH] refactor: Improve error handling in git repository checks --- aider/main.py | 24 ++++++++++++------------ aider/repo.py | 3 +++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/aider/main.py b/aider/main.py index 1610d0bc7..5b0ab6dfa 100644 --- a/aider/main.py +++ b/aider/main.py @@ -302,23 +302,23 @@ def sanity_check_repo(repo, io): try: repo.get_tracked_files() - return True + if not repo.git_repo_error: + return True + error_msg = str(repo.git_repo_error) except ANY_GIT_ERROR as exc: error_msg = str(exc) - if "version in (1, 2)" in error_msg: - io.tool_error("Aider only works with git repos with version number 1 or 2.") - io.tool_output( - "You may be able to convert your repo: git update-index --index-version=2" - ) - io.tool_output("Or run aider --no-git to proceed without using git.") - io.tool_output("https://github.com/paul-gauthier/aider/issues/211") - return False - - io.tool_error("Unable to read git repository, it may be corrupt?") - io.tool_output(error_msg) + if "version in (1, 2)" in error_msg: + io.tool_error("Aider only works with git repos with version number 1 or 2.") + io.tool_output("You may be able to convert your repo: git update-index --index-version=2") + io.tool_output("Or run aider --no-git to proceed without using git.") + io.tool_output("https://github.com/paul-gauthier/aider/issues/211") return False + io.tool_error("Unable to read git repository, it may be corrupt?") + io.tool_output(error_msg) + return False + def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False): report_uncaught_exceptions() diff --git a/aider/repo.py b/aider/repo.py index ca6c0102f..7416c4d40 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -21,6 +21,7 @@ class GitRepo: aider_ignore_last_check = 0 subtree_only = False ignore_file_cache = {} + git_repo_error = None def __init__( self, @@ -258,6 +259,7 @@ class GitRepo: except ValueError: commit = None except ANY_GIT_ERROR as err: + self.git_repo_error = err self.io.tool_error(f"Unable to list files in git repo: {err}") self.io.tool_output("Is your git repo corrupted?") return [] @@ -272,6 +274,7 @@ class GitRepo: if blob.type == "blob": # blob is a file files.add(blob.path) except ANY_GIT_ERROR as err: + self.git_repo_error = err self.io.tool_error(f"Unable to list files in git repo: {err}") self.io.tool_output("Is your git repo corrupted?") return []