mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
fix: Handle missing git module gracefully
This commit is contained in:
parent
65555b5dd0
commit
f62ef34715
4 changed files with 36 additions and 11 deletions
|
@ -3,7 +3,11 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import git
|
||||
except ImportError:
|
||||
git = None
|
||||
|
||||
from diff_match_patch import diff_match_patch
|
||||
from tqdm import tqdm
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@ import webbrowser
|
|||
from dataclasses import fields
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import git
|
||||
except ImportError:
|
||||
git = None
|
||||
|
||||
import importlib_resources
|
||||
from dotenv import load_dotenv
|
||||
from prompt_toolkit.enums import EditingMode
|
||||
|
@ -93,6 +97,9 @@ def make_new_repo(git_root, io):
|
|||
|
||||
|
||||
def setup_git(git_root, io):
|
||||
if git is None:
|
||||
return
|
||||
|
||||
try:
|
||||
cwd = Path.cwd()
|
||||
except OSError:
|
||||
|
@ -410,7 +417,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
|||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
|
||||
if force_git_root:
|
||||
if git is None:
|
||||
git_root = None
|
||||
elif force_git_root:
|
||||
git_root = force_git_root
|
||||
else:
|
||||
git_root = get_git_root()
|
||||
|
@ -451,6 +460,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
|||
|
||||
args, unknown = parser.parse_known_args(argv)
|
||||
|
||||
if git is None:
|
||||
args.git = False
|
||||
|
||||
# Load the .env file specified in the arguments
|
||||
loaded_dotenvs = load_dotenv_files(git_root, args.env_file, args.encoding)
|
||||
|
||||
|
@ -646,7 +658,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
|||
# We can't know the git repo for sure until after parsing the args.
|
||||
# If we guessed wrong, reparse because that changes things like
|
||||
# the location of the config.yml and history files.
|
||||
if args.git and not force_git_root:
|
||||
if args.git and not force_git_root and git is not None:
|
||||
right_repo_root = guessed_wrong_repo(io, git_root, fnames, git_dname)
|
||||
if right_repo_root:
|
||||
analytics.event("exit", reason="Recursing with correct repo")
|
||||
|
|
|
@ -2,7 +2,17 @@ import os
|
|||
import time
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
try:
|
||||
import git
|
||||
|
||||
ANY_GIT_ERROR = [
|
||||
git.exc.ODBError,
|
||||
git.exc.GitError,
|
||||
]
|
||||
except ImportError:
|
||||
git = None
|
||||
ANY_GIT_ERROR = []
|
||||
|
||||
import pathspec
|
||||
|
||||
from aider import prompts, utils
|
||||
|
@ -10,15 +20,14 @@ from aider.sendchat import simple_send_with_retries
|
|||
|
||||
from .dump import dump # noqa: F401
|
||||
|
||||
ANY_GIT_ERROR = (
|
||||
git.exc.ODBError,
|
||||
git.exc.GitError,
|
||||
ANY_GIT_ERROR += [
|
||||
OSError,
|
||||
IndexError,
|
||||
BufferError,
|
||||
TypeError,
|
||||
ValueError,
|
||||
)
|
||||
]
|
||||
ANY_GIT_ERROR = tuple(ANY_GIT_ERROR)
|
||||
|
||||
|
||||
class GitRepo:
|
||||
|
|
|
@ -8,8 +8,6 @@ import tempfile
|
|||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import git
|
||||
|
||||
from aider.dump import dump # noqa: F401
|
||||
|
||||
IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp", ".pdf"}
|
||||
|
@ -73,6 +71,8 @@ class GitTemporaryDirectory(ChdirTemporaryDirectory):
|
|||
|
||||
|
||||
def make_repo(path=None):
|
||||
import git
|
||||
|
||||
if not path:
|
||||
path = "."
|
||||
repo = git.Repo.init(path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue