feat: 新增 Git credential helper 协议支持,实现 get|store|erase 子命令

This commit is contained in:
2026-07-16 11:38:06 +08:00
parent b6bc091502
commit 19aff8a6c1
4 changed files with 134 additions and 3 deletions

View File

@@ -159,6 +159,58 @@ quicommit profile stats
quicommit profile token
```
### Git 凭据助手Credential Helper
QuiCommit 可以作为 Git 凭据助手通过系统密钥环安全地存储和读取个人访问令牌PAT
`credential` 命令在 `--help` 中是隐藏的,因为它由 Git 自动调用,无需用户手动执行。
#### 配置方法
将 QuiCommit 注册为 Git 凭据助手:
```bash
# 使用默认的 QuiCommit 配置
git config --global credential.helper quicommit
# 或指定自定义配置文件路径
git config --global credential.helper "quicommit --config /path/to/config.toml"
```
也可以仅对特定主机启用:
```bash
git config --global credential.https://github.com.helper quicommit
```
#### 工作原理
当 Git 需要凭据(例如推送到远程仓库)时,会按照
[gitcredentials 协议](https://git-scm.com/docs/gitcredentials) 调用助手:
1. **`get`** — Git 向 QuiCommit 请求与目标主机匹配的已存储 PAT。
QuiCommit 在所有已配置的 profile 中搜索密钥环,找到则返回 PAT及用户名
2. **`store`** — 认证成功后(例如你在 Git 提示中输入了 PATGit 要求
QuiCommit 保存该凭据。PAT 将存入系统密钥环,并与匹配的 profile 绑定。
3. **`erase`** — Git 要求 QuiCommit 删除指定主机的已存储 PAT。
主机名会被映射为规范化的服务名(`github.com``github``gitlab.com`
`gitlab``bitbucket.org``bitbucket` 等),未知主机则原样使用。
#### 删除已存储的凭据
可以通过 Git 内置机制删除已存储的 PAT
```bash
echo "protocol=https
host=github.com" | git credential reject
```
也可以通过 profile 令牌管理命令删除:
```bash
quicommit profile token
```
### LLM配置
```bash
@@ -238,6 +290,7 @@ quicommit config reset --force
| `quicommit changelog` | `cl` | 生成变更日志 |
| `quicommit profile` | `p` | 管理Git配置 |
| `quicommit config` | `cfg` | 管理应用配置 |
| `quicommit credential` | — | Git凭据助手隐藏由Git调用 |
### commit命令选项