fix(import): defer git import to module-level to prevent startup crash when git executable missing (#971)

This commit is contained in:
Will Miao
2026-06-11 21:47:55 +08:00
parent 46cbcf94c8
commit 84e9fe2dfb

View File

@@ -1,7 +1,6 @@
import os import os
import logging import logging
import toml import toml
import git
import zipfile import zipfile
import shutil import shutil
import tempfile import tempfile
@@ -357,6 +356,15 @@ class UpdateRoutes:
Returns: Returns:
tuple: (success, new_version) tuple: (success, new_version)
""" """
try:
import git
except ImportError:
logger.error(
"GitPython is not available: the git executable was not found in PATH. "
"Install git or set $GIT_PYTHON_GIT_EXECUTABLE to the git binary path."
)
return False, ""
try: try:
# Open the Git repository # Open the Git repository
repo = git.Repo(plugin_root) repo = git.Repo(plugin_root)
@@ -453,6 +461,7 @@ class UpdateRoutes:
if not os.path.exists(os.path.join(plugin_root, '.git')): if not os.path.exists(os.path.join(plugin_root, '.git')):
return git_info return git_info
import git
repo = git.Repo(plugin_root) repo = git.Repo(plugin_root)
commit = repo.head.commit commit = repo.head.commit
git_info['commit_hash'] = commit.hexsha git_info['commit_hash'] = commit.hexsha