From 84e9fe2dfb7e42bb8fc06e73af5fbe8e48a71a57 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Thu, 11 Jun 2026 21:47:55 +0800 Subject: [PATCH] fix(import): defer git import to module-level to prevent startup crash when git executable missing (#971) --- py/routes/update_routes.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/py/routes/update_routes.py b/py/routes/update_routes.py index 14dc6c95..c9e423e9 100644 --- a/py/routes/update_routes.py +++ b/py/routes/update_routes.py @@ -1,7 +1,6 @@ import os import logging import toml -import git import zipfile import shutil import tempfile @@ -357,6 +356,15 @@ class UpdateRoutes: Returns: 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: # Open the Git repository repo = git.Repo(plugin_root) @@ -453,6 +461,7 @@ class UpdateRoutes: if not os.path.exists(os.path.join(plugin_root, '.git')): return git_info + import git repo = git.Repo(plugin_root) commit = repo.head.commit git_info['commit_hash'] = commit.hexsha