#!/usr/bin/env python3 # -*- coding: utf-8 -*- """通过Git命令尝试创建远程仓库""" import subprocess import sys # Git配置 GIT_SERVER = "git.alicorns.co.jp" GIT_USER = "aitest" REPONAME = "office-file-handler" print("=== 尝试通过Git操作创建远程仓库 ===") print(f"Git服务器: {GIT_SERVER}") print(f"用户: {GIT_USER}") print(f"仓库名: {REPONAME}") print() # 方法1: 尝试通过SSH创建裸仓库 print("方法1: 通过SSH创建裸仓库") ssh_command = f'ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 {GIT_USER}@{GIT_SERVER} "mkdir -p /git/{REPONAME}.git && cd /git/{REPONAME}.git && git init --bare"' print(f"命令: {ssh_command}") try: result = subprocess.run(ssh_command, shell=True, capture_output=True, text=True, timeout=30) print("输出:", result.stdout) print("错误:", result.stderr) if result.returncode == 0: print("✓ SSH创建成功!") else: print(f"SSH创建失败,返回码: {result.returncode}") except subprocess.TimeoutExpired: print("✗ SSH连接超时") except Exception as e: print(f"✗ SSH错误: {e}") print() # 方法2: 尝试通过git命令查看服务器信息 print("方法2: 检查Git服务器信息") try: result = subprocess.run(["git", "ls-remote", f"https://{GIT_USER}@{GIT_SERVER}/test.git"], capture_output=True, text=True, timeout=10) print("ls-remote输出:", result.stdout) print("ls-remote错误:", result.stderr) except Exception as e: print(f"✗ ls-remote错误: {e}") print() print("如果无法自动创建,请在Git服务器Web界面上手动创建仓库:") print(f"1. 访问 https://{GIT_SERVER}/") print(f"2. 创建仓库: {REPONAME}") print("3. 然后使用git push命令推送代码")