增加兼容性
This commit is contained in:
@@ -46,7 +46,8 @@ class RemoteManager:
|
||||
from .utils import Colors
|
||||
repo_name = InputValidator.get_input(f"{Colors.BRIGHT_CYAN}>> 请输入GitHub仓库名: {Colors.ENDC}")
|
||||
|
||||
remote_url = f"git@github.com:{Config.GITHUB_USER}/{repo_name}.git"
|
||||
github_user = Config.get_github_user()
|
||||
remote_url = f"git@github.com:{github_user}/{repo_name}.git"
|
||||
|
||||
return self._add_remote("github", remote_url)
|
||||
|
||||
@@ -68,10 +69,97 @@ class RemoteManager:
|
||||
if not repo_name:
|
||||
repo_name = InputValidator.get_input(f"{Colors.BRIGHT_CYAN}>> 请输入Gitea仓库名: {Colors.ENDC}")
|
||||
|
||||
remote_url = f"ssh://git@{Config.GITEA_HOST}:{Config.GITEA_PORT}/{user}/{repo_name}.git"
|
||||
gitea_host = Config.get_gitea_host()
|
||||
gitea_port = Config.get_gitea_port()
|
||||
remote_url = f"ssh://git@{gitea_host}:{gitea_port}/{user}/{repo_name}.git"
|
||||
|
||||
return self._add_remote("gitea", remote_url)
|
||||
|
||||
def add_custom_remote(self) -> bool:
|
||||
"""
|
||||
添加自建Git远程仓库
|
||||
|
||||
Returns:
|
||||
是否成功
|
||||
"""
|
||||
from .utils import Colors
|
||||
|
||||
print(f"\n{Colors.BRIGHT_MAGENTA}>> 添加自建Git仓库{Colors.ENDC}")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
OutputFormatter.tip("支持 GitLab、自建Gitea、Gogs 等 Git 服务器")
|
||||
OutputFormatter.tip("SSH URL 格式示例:")
|
||||
print(f"{Colors.WHITE} - git@gitlab.com:user/repo.git")
|
||||
print(f"{Colors.WHITE} - ssh://git@your-server.com:port/user/repo.git{Colors.ENDC}")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
|
||||
# 输入远程仓库名称
|
||||
remote_name = InputValidator.get_input(
|
||||
f"{Colors.BRIGHT_CYAN}>> 请输入远程仓库名称 (如: gitlab, mygit): {Colors.ENDC}"
|
||||
)
|
||||
|
||||
# 检查是否已存在
|
||||
remotes = self.get_remotes()
|
||||
if remote_name in remotes:
|
||||
OutputFormatter.warning(f"远程仓库 '{remote_name}' 已存在")
|
||||
if not InputValidator.confirm("是否覆盖?", default=False):
|
||||
return False
|
||||
self.executor.run(f"git remote remove {remote_name}", show_output=False)
|
||||
|
||||
# 输入SSH URL
|
||||
remote_url = InputValidator.get_input(
|
||||
f"{Colors.BRIGHT_CYAN}>> 请输入完整的SSH URL: {Colors.ENDC}"
|
||||
)
|
||||
|
||||
# 验证URL格式
|
||||
if not (remote_url.startswith("git@") or remote_url.startswith("ssh://")):
|
||||
OutputFormatter.error("无效的SSH URL格式,必须以 'git@' 或 'ssh://' 开头")
|
||||
return False
|
||||
|
||||
return self._add_remote(remote_name, remote_url)
|
||||
|
||||
def configure_gitea_settings(self):
|
||||
"""配置Gitea服务器设置"""
|
||||
from .utils import Colors
|
||||
|
||||
print(f"\n{Colors.BRIGHT_MAGENTA}>> 配置Gitea服务器{Colors.ENDC}")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
|
||||
# 显示当前配置
|
||||
current_host = Config.get_gitea_host()
|
||||
current_port = Config.get_gitea_port()
|
||||
|
||||
OutputFormatter.info(f"当前配置:")
|
||||
print(f"{Colors.WHITE} 主机: {current_host}{Colors.ENDC}")
|
||||
print(f"{Colors.WHITE} 端口: {current_port}{Colors.ENDC}")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
|
||||
# 询问是否修改
|
||||
if not InputValidator.confirm("是否修改Gitea服务器配置?", default=False):
|
||||
return
|
||||
|
||||
# 输入新的主机地址
|
||||
new_host = InputValidator.get_input(
|
||||
f"{Colors.BRIGHT_CYAN}>> 请输入Gitea主机地址 (回车保持 {current_host}): {Colors.ENDC}",
|
||||
allow_empty=True
|
||||
)
|
||||
|
||||
if new_host:
|
||||
Config.set("gitea_host", new_host)
|
||||
OutputFormatter.success(f"Gitea主机地址已更新为: {new_host}")
|
||||
|
||||
# 输入新的端口
|
||||
new_port = InputValidator.get_input(
|
||||
f"{Colors.BRIGHT_CYAN}>> 请输入SSH端口 (回车保持 {current_port}): {Colors.ENDC}",
|
||||
allow_empty=True
|
||||
)
|
||||
|
||||
if new_port:
|
||||
Config.set("gitea_port", new_port)
|
||||
OutputFormatter.success(f"Gitea SSH端口已更新为: {new_port}")
|
||||
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
OutputFormatter.tip("配置已保存,下次添加Gitea仓库时将使用新配置")
|
||||
|
||||
def _add_remote(self, name: str, url: str) -> bool:
|
||||
"""
|
||||
添加远程仓库
|
||||
@@ -150,7 +238,7 @@ class RemoteManager:
|
||||
|
||||
OutputFormatter.menu_item(1, "GitHub")
|
||||
OutputFormatter.menu_item(2, "Gitea")
|
||||
OutputFormatter.menu_item(3, "两者都配置")
|
||||
OutputFormatter.menu_item(3, "自建Git仓库")
|
||||
OutputFormatter.menu_item(4, "跳过")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
|
||||
@@ -164,8 +252,7 @@ class RemoteManager:
|
||||
elif choice == 2:
|
||||
self.add_gitea_remote()
|
||||
elif choice == 3:
|
||||
self.add_github_remote()
|
||||
self.add_gitea_remote()
|
||||
self.add_custom_remote()
|
||||
else:
|
||||
OutputFormatter.info("跳过远程仓库配置")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user