From fe44d0b334c27b677f0504d6c1dbba6ab4970fce Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 29 Oct 2025 05:40:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=8Egit=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=AE=89=E8=A3=85=E5=BA=94=E7=94=A8=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=AE=8C=E6=95=B4=E5=A4=8D=E5=88=B6=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jingrow/jingrow/utils/app_installer.py | 29 ++++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/jingrow/jingrow/utils/app_installer.py b/apps/jingrow/jingrow/utils/app_installer.py index bcb1ec3..c0faf63 100644 --- a/apps/jingrow/jingrow/utils/app_installer.py +++ b/apps/jingrow/jingrow/utils/app_installer.py @@ -80,14 +80,23 @@ def analyze_package(temp_dir: str) -> Dict[str, Any]: if not root_items: return {'success': False, 'error': '目录为空'} - # 对于 git clone 的目录,跳过 .git,进入仓库名目录 - # 找到一个不是 .git 的目录作为 root_dir + # 对于 git clone 的目录,跳过 .git,检查是否为应用根目录 + # 统计非 .git 的目录数量 + non_git_dirs = [item for item in root_items if os.path.isdir(os.path.join(temp_dir, item)) and item != '.git'] + + # 检查是否包含 .git 目录(说明是 Git 仓库) + is_git_repo = '.git' in root_items + root_dir = temp_dir - for item in root_items: - item_path = os.path.join(temp_dir, item) - if os.path.isdir(item_path) and item != '.git': - root_dir = item_path - break + + # 如果只有一个目录且是 Git 仓库,通常是 Git 仓库克隆后的结构,需要进入 + # 如果有多个目录,说明已经是应用根目录 + if len(non_git_dirs) == 1 and is_git_repo: + root_dir = os.path.join(temp_dir, non_git_dirs[0]) + # 如果多个目录但有 .git,说明 Git 仓库根目录就是应用根目录(典型开发结构) + elif len(non_git_dirs) > 1 and is_git_repo: + # 不进入子目录,直接使用 temp_dir 作为 root_dir + root_dir = temp_dir package_info = { 'app_name': os.path.basename(root_dir), @@ -101,7 +110,7 @@ def analyze_package(temp_dir: str) -> Dict[str, Any]: } # 检查配置文件 - if os.path.exists(os.path.join(root_dir, 'setup.py')): + if os.path.exists(os.path.join(root_dir, 'hooks.py')): package_info['has_backend'] = True if os.path.exists(os.path.join(root_dir, 'package.json')): @@ -167,9 +176,9 @@ def install_files(temp_dir: str, app_name: str, package_info: Dict[str, Any]) -> # 获取根目录(analyze_package 已经找到正确的根目录) root_dir = package_info.get('root_dir', temp_dir) - # 直接复制整个包结构(不检查内层目录,因为导出时就包含了完整结构) + # 直接复制整个包结构(只跳过系统生成的文件) for item in os.listdir(root_dir): - if item in ['__pycache__', '.git', '.DS_Store']: + if item in ['__pycache__', '.DS_Store']: continue src = os.path.join(root_dir, item)