From 597d19dbfee842042f9dd514582101433e791615 Mon Sep 17 00:00:00 2001 From: Image Date: Thu, 25 Dec 2025 16:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(git)=EF=BC=9A=E5=B0=86SSH?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E5=AF=86=E9=92=A5=E6=A3=80=E6=9F=A5=E4=BB=8E?= =?UTF-8?q?no=E6=94=B9=E4=B8=BAyes=E4=BB=A5=E5=A2=9E=E5=BC=BA=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=80=A7=20=E2=9C=A8=20feat(git)=EF=BC=9A=E6=94=B9?= =?UTF-8?q?=E8=BF=9BSSH=20URL=E6=A3=80=E6=B5=8B=E5=92=8C=E5=88=86=E6=94=AF?= =?UTF-8?q?=E5=85=8B=E9=9A=86=E9=80=BB=E8=BE=91=20=F0=9F=93=9D=20docs(fron?= =?UTF-8?q?tend)=EF=BC=9A=E6=9B=B4=E6=96=B0SSH=E5=85=AC=E9=92=A5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=B4=E6=98=8E=EF=BC=8C=E7=A7=BB=E9=99=A4CodeUp?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/endpoints/agent_tasks.py | 4 ++-- backend/app/services/git_ssh_service.py | 14 +++++++++----- frontend/src/pages/Account.tsx | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/app/api/v1/endpoints/agent_tasks.py b/backend/app/api/v1/endpoints/agent_tasks.py index 3a3964a..a9052f6 100644 --- a/backend/app/api/v1/endpoints/agent_tasks.py +++ b/backend/app/api/v1/endpoints/agent_tasks.py @@ -2319,7 +2319,7 @@ async def _get_project_root( await emit(f"🔄 正在获取仓库: {repo_url}") # 检测是否为SSH URL(SSH链接不支持ZIP下载) - is_ssh_url = repo_url.startswith('git@') + is_ssh_url = GitSSHOperations.is_ssh_url(repo_url) # 解析仓库 URL 获取 owner/repo parsed = urlparse(repo_url) @@ -2602,7 +2602,7 @@ async def _get_project_root( async def run_default_ssh_clone(): return await asyncio.to_thread( GitSSHOperations.clone_repo_with_ssh, - repo_url, ssh_private_key, base_path, "" # 空字符串表示使用默认分支 + repo_url, ssh_private_key, base_path, branch ) clone_task = asyncio.create_task(run_default_ssh_clone()) diff --git a/backend/app/services/git_ssh_service.py b/backend/app/services/git_ssh_service.py index 99c542a..cd26dcc 100644 --- a/backend/app/services/git_ssh_service.py +++ b/backend/app/services/git_ssh_service.py @@ -229,7 +229,7 @@ class GitSSHOperations: return url.startswith('git@') or url.startswith('ssh://') @staticmethod - def clone_repo_with_ssh(repo_url: str, private_key: str, target_dir: str, branch: str = "main") -> Dict[str, any]: + def clone_repo_with_ssh(repo_url: str, private_key: str, target_dir: str, branch: str = None) -> Dict[str, any]: """ 使用SSH密钥克隆Git仓库 @@ -260,7 +260,7 @@ class GitSSHOperations: ssh_cmd_parts = [ 'ssh', '-i', key_file, - '-o', 'StrictHostKeyChecking=no', + '-o', 'StrictHostKeyChecking=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'PreferredAuthentications=publickey', '-o', 'IdentitiesOnly=yes' # 只使用指定的密钥,不使用系统默认密钥 @@ -270,7 +270,11 @@ class GitSSHOperations: print(f"[Git Clone] Using DeepAudit SSH key only: {key_file}") # 执行git clone - cmd = ['git', 'clone', '--depth', '1', '--branch', branch, repo_url, target_dir] + cmd = ['git', 'clone', '--depth', '1'] + if branch: # 只有明确指定分支时才添加 + cmd.extend(['--branch', branch]) + cmd.extend([repo_url, target_dir]) + result = subprocess.run( cmd, env=env, @@ -414,7 +418,7 @@ class GitSSHOperations: cmd = [ 'ssh', '-i', key_file, - '-o', 'StrictHostKeyChecking=no', + '-o', 'StrictHostKeyChecking=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'ConnectTimeout=10', '-o', 'PreferredAuthentications=publickey', @@ -444,7 +448,7 @@ class GitSSHOperations: 'output': f'提示:服务器显示Anonymous表示公钥未添加到Git服务或未关联到您的账户。\n请在Git服务的设置中添加SSH公钥。\n\n原始输出:\n{output}' } - # 检查是否认证成功(必须有用户名,不能是Anonymous) + # 检查是否认证成功 success_indicators = [ ('successfully authenticated', True), # GitHub ('hi ', True), # GitHub: "Hi username!" diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index cf15b63..b223cdc 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -487,7 +487,7 @@ export default function Account() { )}

- 请将此公钥添加到 GitHubGitLabCodeUp 账户 + 请将此公钥添加到 GitHubGitLab 账户