增加兼容性
This commit is contained in:
37
AGENTS.md
37
AGENTS.md
@@ -13,6 +13,7 @@ This document provides coding agents with essential information about the QuickG
|
||||
- Standard library only: `subprocess`, `os`, `datetime`, `sys`
|
||||
- Cross-platform support: Windows, Linux, macOS
|
||||
- ANSI escape codes for colorful console output
|
||||
- **SSH-only Git operations**: Supports GitHub and Gitea via SSH (no HTTPS support)
|
||||
|
||||
---
|
||||
|
||||
@@ -37,21 +38,32 @@ python mengya_git_manager.py
|
||||
|
||||
**No formal test suite exists yet.** Manual testing workflow:
|
||||
|
||||
1. **Test in a clean directory:**
|
||||
1. **Prerequisite: Configure SSH keys**
|
||||
```bash
|
||||
# Generate SSH key if needed
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||
|
||||
# Test SSH connection
|
||||
ssh -T git@github.com
|
||||
ssh -T git@git.shumengya.top -p 8022
|
||||
```
|
||||
|
||||
2. **Test in a clean directory:**
|
||||
```bash
|
||||
cd /path/to/test/directory
|
||||
python E:\SmyProjects\Python\脚本\萌芽一键Git管理\quickgit.py
|
||||
```
|
||||
|
||||
2. **Test each menu option:**
|
||||
3. **Test each menu option:**
|
||||
- Option 1: Initialize Git repo
|
||||
- Option 2: Commit and push (requires changes)
|
||||
- Option 3: Pull from remote
|
||||
- Option 4: View status
|
||||
- Option 5: Manage remotes
|
||||
- Option 6: Exit
|
||||
- Option 2: Commit changes to local (requires changes)
|
||||
- Option 3: Push to remote (requires SSH-configured remote)
|
||||
- Option 4: Pull from remote (requires SSH-configured remote)
|
||||
- Option 5: View status
|
||||
- Option 6: Manage remotes (add GitHub/Gitea via SSH)
|
||||
- Option 7: Exit
|
||||
|
||||
3. **Verify console output:**
|
||||
4. **Verify console output:**
|
||||
- Check colors render correctly
|
||||
- Ensure ASCII dividers align (60 chars wide)
|
||||
- No encoding errors with Chinese characters
|
||||
@@ -240,10 +252,17 @@ OutputFormatter.menu_item(1, "Option") # [1] Menu item
|
||||
|
||||
### SSH Configuration
|
||||
|
||||
**⚠️ IMPORTANT: This tool ONLY supports SSH connections. HTTPS is not supported.**
|
||||
|
||||
- **GitHub:** `git@github.com:shumengya/{repo}.git`
|
||||
- **Gitea:** `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
|
||||
All remote operations use SSH (no HTTPS).
|
||||
All remote operations (push, pull, fetch) use SSH. Do not use HTTPS URLs like `https://github.com/user/repo.git`.
|
||||
|
||||
**Prerequisites:**
|
||||
1. User must have SSH keys generated (`ssh-keygen`)
|
||||
2. Public key must be added to GitHub/Gitea account
|
||||
3. SSH connection must be tested and working
|
||||
|
||||
### Command Execution
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# GitHub SSH 连接问题诊断与解决方案
|
||||
|
||||
**⚠️ QuickGit 工具说明:** 本工具目前仅支持 SSH 方式连接远程仓库,不支持 HTTPS。本文档中提到的 HTTPS 方案仅适用于手动使用 `git` 命令行操作,不适用于 QuickGit 工具本身。
|
||||
|
||||
---
|
||||
|
||||
## 问题现象
|
||||
|
||||
```
|
||||
@@ -286,8 +290,8 @@ git remote -v
|
||||
### 步骤 6: 使用 QuickGit 推送
|
||||
|
||||
1. 启动 QuickGit
|
||||
2. 选择 `[2] 提交并推送更改`
|
||||
3. 选择推送到 `github`
|
||||
2. 选择 `[2] 提交更改到本地` - 提交到本地仓库
|
||||
3. 选择 `[3] 推送到远程仓库` - 推送到 `github`(通过 SSH)
|
||||
|
||||
---
|
||||
|
||||
@@ -311,9 +315,11 @@ git push -v github main
|
||||
|
||||
---
|
||||
|
||||
## 快速修复:改用 HTTPS
|
||||
## 快速修复:改用 HTTPS(仅适用于 git 命令行)
|
||||
|
||||
如果 SSH 问题难以解决,可以临时使用 HTTPS:
|
||||
**⚠️ 重要:** 以下 HTTPS 方案仅适用于手动使用 `git` 命令行操作,**QuickGit 工具本身不支持 HTTPS**。
|
||||
|
||||
如果 SSH 问题难以解决,可以临时使用命令行的 HTTPS 方式:
|
||||
|
||||
```bash
|
||||
# 修改远程仓库 URL
|
||||
@@ -333,18 +339,19 @@ git push github main
|
||||
3. 勾选 `repo` 权限
|
||||
4. 复制 Token(只显示一次)
|
||||
|
||||
**再次强调:** QuickGit 工具不支持 HTTPS 远程仓库,必须使用 SSH。如果需要使用 HTTPS,请直接使用 `git` 命令行工具。
|
||||
|
||||
---
|
||||
|
||||
## 总结
|
||||
|
||||
**推荐解决方案顺序:**
|
||||
**推荐解决方案顺序(用于 QuickGit):**
|
||||
|
||||
1. ✅ 生成 SSH 密钥
|
||||
2. ✅ 添加公钥到 GitHub
|
||||
3. ✅ 测试 SSH 连接
|
||||
4. ✅ 配置 SSH Agent(如果需要)
|
||||
5. ⚠️ 检查代理设置(如果在公司网络)
|
||||
6. 🔄 最后选择:使用 HTTPS 作为备用方案
|
||||
6. ⚠️ 使用 SSH over HTTPS(端口 443)作为备选
|
||||
|
||||
**最快的解决方法:**
|
||||
如果急需推送代码,先改用 HTTPS,之后再慢慢配置 SSH。
|
||||
**注意:** QuickGit 工具不支持 HTTPS 方式,必须解决 SSH 连接问题才能正常使用。如果实在无法配置 SSH,建议直接使用 `git` 命令行工具配合 HTTPS。
|
||||
|
||||
158
README.md
158
README.md
@@ -1,26 +1,31 @@
|
||||
# QuickGit - 萌芽一键Git管理工具
|
||||
|
||||
一个纯 Python 3.6+、零外部依赖的彩色 CLI 工具,用模块化方式把常用 Git 操作“一键化”,支持 Windows / Linux / macOS。
|
||||
一个纯 Python 3.6+、零外部依赖的彩色 CLI 工具,用模块化方式把常用 Git 操作"一键化",支持 Windows / Linux / macOS。
|
||||
|
||||
**⚠️ 重要说明:** 本工具目前仅支持通过 **SSH 方式**连接 GitHub 和 Gitea 远程仓库,不支持 HTTPS 方式。使用前请确保已配置 SSH 密钥。
|
||||
|
||||
## 1) 项目简介与核心卖点
|
||||
- 模块化架构,功能职责清晰,易扩展。
|
||||
- 无三方依赖,直接随 Python 运行。
|
||||
- 跨平台路径与编码适配,默认分支 `main`。
|
||||
- 彩色输出 + ASCII 分隔线,兼顾可读性与兼容性。
|
||||
- **SSH 优先策略**:仅支持 SSH 连接,更安全、更便捷。
|
||||
|
||||
## 2) 功能清单
|
||||
- [x] 灵活目录选择(启动时可管理任意仓库)
|
||||
- [x] 初始化仓库(创建分支、生成 `.gitignore`)
|
||||
- [x] 提交更改(提交到本地仓库)
|
||||
- [x] 推送更改(推送到远程仓库,支持多远程选择)
|
||||
- [x] 从远程拉取
|
||||
- [x] 远程仓库管理(GitHub / Gitea,SSH 优先)
|
||||
- [x] 推送更改(推送到远程仓库,支持多远程选择,**仅支持 SSH**)
|
||||
- [x] 从远程拉取(**仅支持 SSH**)
|
||||
- [x] 远程仓库管理(GitHub / Gitea / 自建 Git 服务器,**仅支持 SSH 方式**)
|
||||
- [x] **可配置 Gitea 服务器**(自定义主机地址和端口)
|
||||
- [x] **自建 Git 仓库支持**(GitLab、自建 Gitea、Gogs 等)
|
||||
- [x] 状态查看(工作区状态 + 最近提交)
|
||||
- [ ] 分支管理
|
||||
- [ ] 标签管理
|
||||
- [ ] 冲突解决辅助
|
||||
- [ ] 自定义配置文件
|
||||
- [ ] 批量处理多个仓库
|
||||
- [ ] HTTPS 支持(未来版本)
|
||||
|
||||
## 3) 项目结构
|
||||
```
|
||||
@@ -40,7 +45,33 @@ QuickGit/
|
||||
```
|
||||
|
||||
## 4) 快速开始
|
||||
前置要求:已安装 Git,Python 3.6+;已配置 SSH 密钥(推荐用 SSH 访问远程仓库)。
|
||||
|
||||
### 前置要求
|
||||
1. **必需**:已安装 Git 和 Python 3.6+
|
||||
2. **必需**:已配置 SSH 密钥并添加到 GitHub/Gitea 账户
|
||||
3. **推荐**:使用支持 ANSI 颜色的终端(Windows Terminal、PowerShell、iTerm2 等)
|
||||
|
||||
### SSH 密钥配置指南
|
||||
如果你还没有配置 SSH 密钥,请按以下步骤操作:
|
||||
|
||||
```bash
|
||||
# 1. 生成 SSH 密钥(如果还没有)
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||
|
||||
# 2. 查看公钥内容
|
||||
cat ~/.ssh/id_ed25519.pub # Linux/macOS
|
||||
type %USERPROFILE%\.ssh\id_ed25519.pub # Windows
|
||||
|
||||
# 3. 将公钥添加到远程仓库
|
||||
# - GitHub: Settings -> SSH and GPG keys -> New SSH key
|
||||
# - Gitea: 设置 -> SSH/GPG 密钥 -> 添加密钥
|
||||
|
||||
# 4. 测试连接
|
||||
ssh -T git@github.com # 测试 GitHub
|
||||
ssh -T git@git.shumengya.top -p 8022 # 测试 Gitea
|
||||
```
|
||||
|
||||
### 启动程序
|
||||
|
||||
**Windows**
|
||||
```bash
|
||||
@@ -73,13 +104,81 @@ python3 quickgit.py
|
||||
```
|
||||
|
||||
## 6) 常用操作示例
|
||||
- 初始化仓库:选择目录 → 选 1 → 自动创建 `.gitignore`(含前端/后端通用规则)并尝试首提。
|
||||
- 提交更改:选 2 → 查看更改 → 输入提交信息(留空自动填入时间戳)→ 提交到本地仓库。
|
||||
- 推送更改:选 3 → 选择远程(可多选)→ 推送到远程仓库。
|
||||
- 拉取更新:选 4 → 选择远程 → 拉取当前分支。
|
||||
- 远程管理:选 6 → 支持添加/删除远程;URL 模板
|
||||
- GitHub: `git@github.com:shumengya/{repo}.git`
|
||||
- Gitea : `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
|
||||
### 场景0: 选择工作目录
|
||||
- 启动时输入要管理的仓库路径
|
||||
- 支持绝对路径、相对路径、`~` 路径
|
||||
- 直接回车使用当前目录
|
||||
|
||||
### 场景1: 初始化新仓库
|
||||
1. 选择 [1] 初始化Git仓库
|
||||
2. 自动创建 `.gitignore`(含前端/后端通用规则)
|
||||
3. 自动创建 `main` 分支并进行首次提交
|
||||
4. 选择 [6] 管理远程仓库 → 添加 GitHub 或 Gitea 远程仓库(**仅 SSH**)
|
||||
|
||||
### 场景2: 日常提交工作流
|
||||
1. 选择 [2] 提交更改到本地
|
||||
- 查看更改的文件
|
||||
- 输入提交信息(留空自动填入时间戳)
|
||||
- 代码提交到本地仓库
|
||||
2. 选择 [3] 推送到远程仓库
|
||||
- 选择远程仓库(可多选)
|
||||
- 通过 SSH 推送到远程
|
||||
|
||||
### 场景3: 拉取远程更新
|
||||
1. 选择 [4] 从远程仓库拉取
|
||||
2. 选择远程仓库(单选)
|
||||
3. 通过 SSH 拉取当前分支的更新
|
||||
|
||||
### 场景4: 管理远程仓库
|
||||
|
||||
选择 [6] 管理远程仓库,提供以下功能:
|
||||
|
||||
#### 4.1 添加 GitHub 远程仓库
|
||||
SSH 格式:`git@github.com:shumengya/{repo}.git`
|
||||
|
||||
#### 4.2 添加 Gitea 远程仓库
|
||||
SSH 格式:`ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
|
||||
默认使用配置的 Gitea 服务器地址和端口,可通过"配置 Gitea 服务器"修改。
|
||||
|
||||
#### 4.3 添加自建 Git 仓库
|
||||
支持添加自定义 Git 服务器(GitLab、自建 Gitea、Gogs 等):
|
||||
1. 输入远程仓库名称(如:`gitlab`、`mygit`)
|
||||
2. 输入完整的 SSH URL
|
||||
3. 支持的 URL 格式示例:
|
||||
- `git@gitlab.com:user/repo.git`
|
||||
- `ssh://git@your-server.com:port/user/repo.git`
|
||||
|
||||
#### 4.4 配置 Gitea 服务器
|
||||
自定义 Gitea 服务器的主机地址和 SSH 端口:
|
||||
- 默认主机:`git.shumengya.top`
|
||||
- 默认端口:`8022`
|
||||
- 配置保存在:`~/.quickgit_config.json`
|
||||
|
||||
#### 4.5 其他功能
|
||||
- **查看所有远程仓库** - 显示已配置的远程仓库列表
|
||||
- **删除远程仓库** - 移除不需要的远程仓库
|
||||
|
||||
**⚠️ 注意:** 本工具不支持 HTTPS URL 格式(如 `https://github.com/user/repo.git`),仅支持 SSH 格式。
|
||||
|
||||
### 场景5: 配置文件
|
||||
|
||||
QuickGit 的配置文件保存在:`~/.quickgit_config.json`
|
||||
|
||||
**配置内容:**
|
||||
```json
|
||||
{
|
||||
"gitea_host": "git.shumengya.top",
|
||||
"gitea_port": "8022",
|
||||
"github_user": "shumengya",
|
||||
"default_branch": "main"
|
||||
}
|
||||
```
|
||||
|
||||
**修改方式:**
|
||||
- 通过菜单:[6] 管理远程仓库 → [5] 配置 Gitea 服务器
|
||||
- 或手动编辑配置文件(需重启工具生效)
|
||||
|
||||
## 7) 跨平台与终端要求
|
||||
- `run.bat` 自动设置 UTF-8;Windows 使用 `python` 命令。
|
||||
@@ -99,18 +198,41 @@ python3 quickgit.py
|
||||
- 默认分支 `main`;`.gitignore` 自动写入成功。
|
||||
|
||||
## 10) 常见问题 / 故障排查
|
||||
- 推送失败:确认 SSH 密钥已添加且远程地址正确。
|
||||
- 终端乱码:设置 UTF-8(Windows 可 `chcp 65001`;Linux/macOS 确保 `LANG/LC_ALL` 为 UTF-8)。
|
||||
- 颜色不显示:使用支持 ANSI 的终端(Windows Terminal/PowerShell 等)。
|
||||
- 找不到 `python3`:在 Linux/macOS 安装或创建软链接;Windows 使用 `python`。
|
||||
|
||||
### SSH 相关问题
|
||||
- **推送/拉取失败 "Permission denied (publickey)"**:
|
||||
- 确认 SSH 密钥已生成:`ls ~/.ssh/id_*.pub` (Linux/macOS) 或 `dir %USERPROFILE%\.ssh\id_*.pub` (Windows)
|
||||
- 确认公钥已添加到 GitHub/Gitea 账户
|
||||
- 测试 SSH 连接:`ssh -T git@github.com` 或 `ssh -T git@git.shumengya.top -p 8022`
|
||||
|
||||
- **"Could not resolve hostname"**:
|
||||
- 检查网络连接
|
||||
- 确认远程仓库地址格式正确(SSH 格式,非 HTTPS)
|
||||
|
||||
- **端口被防火墙拦截**:
|
||||
- GitHub 使用标准 SSH 端口 22
|
||||
- Gitea 使用自定义端口 8022,确保防火墙允许此端口
|
||||
|
||||
### 远程仓库相关
|
||||
- **不支持 HTTPS URL**:本工具仅支持 SSH 方式,如果你的远程仓库使用 HTTPS URL(如 `https://github.com/user/repo.git`),请手动改为 SSH 格式或使用 `git remote` 命令修改。
|
||||
|
||||
### 终端显示问题
|
||||
- **终端乱码**:设置 UTF-8(Windows 可 `chcp 65001`;Linux/macOS 确保 `LANG/LC_ALL` 为 UTF-8)。
|
||||
- **颜色不显示**:使用支持 ANSI 的终端(Windows Terminal/PowerShell 等)。
|
||||
- **找不到 `python3`**:在 Linux/macOS 安装或创建软链接;Windows 使用 `python`。
|
||||
|
||||
## 11) 路线图
|
||||
- [x] 模块化架构重构
|
||||
- [x] SSH 方式支持(GitHub + Gitea)
|
||||
- [x] 可配置 Gitea 服务器
|
||||
- [x] 自建 Git 仓库支持(GitLab、自建 Gitea 等)
|
||||
- [x] 配置文件持久化
|
||||
- [ ] HTTPS 方式支持
|
||||
- [ ] 分支管理
|
||||
- [ ] 标签管理
|
||||
- [ ] 冲突解决辅助
|
||||
- [ ] 自定义配置文件
|
||||
- [ ] 批量操作多个仓库
|
||||
- [ ] 更多 Git 托管平台支持(Bitbucket 等)
|
||||
|
||||
## 12) 许可证与作者
|
||||
- 许可证:MIT
|
||||
|
||||
@@ -2,16 +2,99 @@
|
||||
配置模块 - 存储项目配置信息
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
class Config:
|
||||
"""配置类"""
|
||||
|
||||
# Gitea服务器配置
|
||||
GITEA_HOST = "git.shumengya.top"
|
||||
GITEA_PORT = "8022"
|
||||
# 配置文件路径
|
||||
CONFIG_FILE = os.path.join(os.path.expanduser("~"), ".quickgit_config.json")
|
||||
|
||||
# GitHub配置
|
||||
GITHUB_USER = "shumengya"
|
||||
# 默认配置
|
||||
_defaults = {
|
||||
"gitea_host": "git.shumengya.top",
|
||||
"gitea_port": "8022",
|
||||
"github_user": "shumengya",
|
||||
"default_branch": "main"
|
||||
}
|
||||
|
||||
# 运行时配置(从文件加载或使用默认值)
|
||||
_config = None
|
||||
|
||||
@classmethod
|
||||
def _load_config(cls):
|
||||
"""加载配置文件"""
|
||||
if cls._config is not None:
|
||||
return
|
||||
|
||||
if os.path.exists(cls.CONFIG_FILE):
|
||||
try:
|
||||
with open(cls.CONFIG_FILE, 'r', encoding='utf-8') as f:
|
||||
cls._config = json.load(f)
|
||||
except Exception:
|
||||
cls._config = cls._defaults.copy()
|
||||
else:
|
||||
cls._config = cls._defaults.copy()
|
||||
|
||||
@classmethod
|
||||
def _save_config(cls):
|
||||
"""保存配置到文件"""
|
||||
cls._load_config()
|
||||
try:
|
||||
with open(cls.CONFIG_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(cls._config, f, indent=2, ensure_ascii=False)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def get(cls, key: str, default=None):
|
||||
"""获取配置项"""
|
||||
cls._load_config()
|
||||
return cls._config.get(key, default)
|
||||
|
||||
@classmethod
|
||||
def set(cls, key: str, value):
|
||||
"""设置配置项"""
|
||||
cls._load_config()
|
||||
cls._config[key] = value
|
||||
cls._save_config()
|
||||
|
||||
# 属性访问器(保持向后兼容)
|
||||
@property
|
||||
def GITEA_HOST(self) -> str:
|
||||
return self.get("gitea_host", self._defaults["gitea_host"])
|
||||
|
||||
@property
|
||||
def GITEA_PORT(self) -> str:
|
||||
return self.get("gitea_port", self._defaults["gitea_port"])
|
||||
|
||||
@property
|
||||
def GITHUB_USER(self) -> str:
|
||||
return self.get("github_user", self._defaults["github_user"])
|
||||
|
||||
@property
|
||||
def DEFAULT_BRANCH(self) -> str:
|
||||
return self.get("default_branch", self._defaults["default_branch"])
|
||||
|
||||
# 类方法访问器(用于类级别访问)
|
||||
@classmethod
|
||||
def get_gitea_host(cls) -> str:
|
||||
return cls.get("gitea_host", cls._defaults["gitea_host"])
|
||||
|
||||
@classmethod
|
||||
def get_gitea_port(cls) -> str:
|
||||
return cls.get("gitea_port", cls._defaults["gitea_port"])
|
||||
|
||||
@classmethod
|
||||
def get_github_user(cls) -> str:
|
||||
return cls.get("github_user", cls._defaults["github_user"])
|
||||
|
||||
@classmethod
|
||||
def get_default_branch(cls) -> str:
|
||||
return cls.get("default_branch", cls._defaults["default_branch"])
|
||||
|
||||
# Git配置
|
||||
DEFAULT_BRANCH = "main"
|
||||
|
||||
@@ -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("跳过远程仓库配置")
|
||||
|
||||
|
||||
@@ -208,13 +208,15 @@ class GitManagerUI:
|
||||
OutputFormatter.menu_item(1, "查看远程仓库")
|
||||
OutputFormatter.menu_item(2, "添加GitHub远程仓库")
|
||||
OutputFormatter.menu_item(3, "添加Gitea远程仓库")
|
||||
OutputFormatter.menu_item(4, "删除远程仓库")
|
||||
OutputFormatter.menu_item(5, "返回主菜单")
|
||||
OutputFormatter.menu_item(4, "添加自建Git仓库")
|
||||
OutputFormatter.menu_item(5, "配置Gitea服务器")
|
||||
OutputFormatter.menu_item(6, "删除远程仓库")
|
||||
OutputFormatter.menu_item(7, "返回主菜单")
|
||||
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
|
||||
|
||||
choice = InputValidator.get_choice(
|
||||
f"{Colors.BRIGHT_CYAN}>> 请选择 [1-5]: {Colors.ENDC}",
|
||||
range(1, 6)
|
||||
f"{Colors.BRIGHT_CYAN}>> 请选择 [1-7]: {Colors.ENDC}",
|
||||
range(1, 8)
|
||||
)
|
||||
|
||||
if choice == 1:
|
||||
@@ -224,8 +226,12 @@ class GitManagerUI:
|
||||
elif choice == 3:
|
||||
self.remote_mgr.add_gitea_remote()
|
||||
elif choice == 4:
|
||||
self.remote_mgr.remove_remote()
|
||||
self.remote_mgr.add_custom_remote()
|
||||
elif choice == 5:
|
||||
self.remote_mgr.configure_gitea_settings()
|
||||
elif choice == 6:
|
||||
self.remote_mgr.remove_remote()
|
||||
elif choice == 7:
|
||||
break
|
||||
|
||||
def run(self):
|
||||
|
||||
75
使用说明.md
75
使用说明.md
@@ -1,5 +1,25 @@
|
||||
# QuickGit 使用说明
|
||||
|
||||
**⚠️ 重要提示:本工具仅支持通过 SSH 方式连接 GitHub 和 Gitea 远程仓库,不支持 HTTPS。**
|
||||
|
||||
## 前置要求
|
||||
|
||||
### 必需配置 SSH 密钥
|
||||
1. 生成 SSH 密钥:
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||
```
|
||||
|
||||
2. 将公钥添加到 GitHub/Gitea:
|
||||
- GitHub: Settings → SSH and GPG keys → New SSH key
|
||||
- Gitea: 设置 → SSH/GPG 密钥 → 添加密钥
|
||||
|
||||
3. 测试连接:
|
||||
```bash
|
||||
ssh -T git@github.com
|
||||
ssh -T git@git.shumengya.top -p 8022
|
||||
```
|
||||
|
||||
## 已修复的问题
|
||||
|
||||
### 1. 添加文件失败问题
|
||||
@@ -54,22 +74,59 @@ Git状态: [已初始化]
|
||||
>> 主菜单
|
||||
------------------------------------------------------------
|
||||
[1] 初始化Git仓库
|
||||
[2] 提交并推送更改
|
||||
[3] 从远程仓库拉取
|
||||
[4] 查看仓库状态
|
||||
[5] 管理远程仓库
|
||||
[6] 退出程序
|
||||
[2] 提交更改到本地
|
||||
[3] 推送到远程仓库
|
||||
[4] 从远程仓库拉取
|
||||
[5] 查看仓库状态
|
||||
[6] 管理远程仓库
|
||||
[7] 退出程序
|
||||
------------------------------------------------------------
|
||||
>> 请输入选项 [1-6]:
|
||||
[*] 提交代码前建议先拉取最新代码,减少代码冲突
|
||||
[*] 使用SSH进行Git提交更方便快捷和安全
|
||||
------------------------------------------------------------
|
||||
>> 请输入选项 [1-7]:
|
||||
```
|
||||
|
||||
## 功能说明
|
||||
|
||||
所有功能均正常工作:
|
||||
- ✓ 初始化Git仓库
|
||||
- ✓ 提交并推送更改
|
||||
- ✓ 从远程仓库拉取
|
||||
- ✓ 提交更改到本地(不推送)
|
||||
- ✓ 推送到远程仓库(通过 SSH)
|
||||
- ✓ 从远程仓库拉取(通过 SSH)
|
||||
- ✓ 查看仓库状态
|
||||
- ✓ 管理远程仓库(GitHub/Gitea)
|
||||
- ✓ 管理远程仓库(GitHub/Gitea/自建 Git,仅 SSH)
|
||||
- ✓ 配置 Gitea 服务器(自定义主机和端口)
|
||||
- ✓ 添加自建 Git 仓库(GitLab、自建 Gitea、Gogs 等)
|
||||
|
||||
### 远程仓库管理菜单
|
||||
```
|
||||
[1] 查看远程仓库
|
||||
[2] 添加GitHub远程仓库
|
||||
[3] 添加Gitea远程仓库
|
||||
[4] 添加自建Git仓库 ← 新功能
|
||||
[5] 配置Gitea服务器 ← 新功能
|
||||
[6] 删除远程仓库
|
||||
[7] 返回主菜单
|
||||
```
|
||||
|
||||
### 远程仓库 URL 格式
|
||||
- **GitHub**: `git@github.com:shumengya/{repo}.git`
|
||||
- **Gitea**: `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
- 主机和端口可通过菜单配置
|
||||
- **自建 Git**: 支持自定义 SSH URL
|
||||
- GitLab: `git@gitlab.com:user/repo.git`
|
||||
- 自建服务器: `ssh://git@your-server.com:port/user/repo.git`
|
||||
|
||||
**注意**:不支持 HTTPS URL 格式(如 `https://github.com/user/repo.git`)
|
||||
|
||||
### 配置文件
|
||||
配置保存在:`~/.quickgit_config.json`
|
||||
|
||||
可配置项:
|
||||
- Gitea 主机地址
|
||||
- Gitea SSH 端口
|
||||
- GitHub 用户名
|
||||
- 默认分支名
|
||||
|
||||
界面美观、对齐完美、功能稳定!
|
||||
|
||||
Reference in New Issue
Block a user