mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-27 15:55:00 +00:00
refactor: Improve error handling in git repository checks
This commit is contained in:
parent
3cd6790d9a
commit
4e63254704
2 changed files with 15 additions and 12 deletions
|
@ -302,23 +302,23 @@ def sanity_check_repo(repo, io):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo.get_tracked_files()
|
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:
|
except ANY_GIT_ERROR as exc:
|
||||||
error_msg = str(exc)
|
error_msg = str(exc)
|
||||||
|
|
||||||
if "version in (1, 2)" in 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_error("Aider only works with git repos with version number 1 or 2.")
|
||||||
io.tool_output(
|
io.tool_output("You may be able to convert your repo: git update-index --index-version=2")
|
||||||
"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")
|
||||||
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
|
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):
|
def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False):
|
||||||
report_uncaught_exceptions()
|
report_uncaught_exceptions()
|
||||||
|
|
|
@ -21,6 +21,7 @@ class GitRepo:
|
||||||
aider_ignore_last_check = 0
|
aider_ignore_last_check = 0
|
||||||
subtree_only = False
|
subtree_only = False
|
||||||
ignore_file_cache = {}
|
ignore_file_cache = {}
|
||||||
|
git_repo_error = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -258,6 +259,7 @@ class GitRepo:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
commit = None
|
commit = None
|
||||||
except ANY_GIT_ERROR as err:
|
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_error(f"Unable to list files in git repo: {err}")
|
||||||
self.io.tool_output("Is your git repo corrupted?")
|
self.io.tool_output("Is your git repo corrupted?")
|
||||||
return []
|
return []
|
||||||
|
@ -272,6 +274,7 @@ class GitRepo:
|
||||||
if blob.type == "blob": # blob is a file
|
if blob.type == "blob": # blob is a file
|
||||||
files.add(blob.path)
|
files.add(blob.path)
|
||||||
except ANY_GIT_ERROR as err:
|
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_error(f"Unable to list files in git repo: {err}")
|
||||||
self.io.tool_output("Is your git repo corrupted?")
|
self.io.tool_output("Is your git repo corrupted?")
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue