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

@@ -160,6 +160,63 @@ quicommit profile stats
quicommit profile token
```
### Git Credential Helper
QuiCommit can act as a Git credential helper to securely store and retrieve
Personal Access Tokens (PATs) via the system keyring. The `credential` command
is hidden from `--help` because it is invoked automatically by Git, not by end
users.
#### Setup
Register QuiCommit as a credential helper for Git:
```bash
# Use the default QuiCommit config
git config --global credential.helper quicommit
# Or specify a custom config file
git config --global credential.helper "quicommit --config /path/to/config.toml"
```
You can also limit the helper to a specific host:
```bash
git config --global credential.https://github.com.helper quicommit
```
#### How It Works
When Git needs credentials (e.g. pushing to a remote), it calls the helper
following the [gitcredentials protocol](https://git-scm.com/docs/gitcredentials):
1. **`get`** — Git asks QuiCommit for a stored PAT matching the requested host.
QuiCommit searches all configured profiles in the keyring and returns the
PAT (plus username) if found.
2. **`store`** — After a successful authentication (e.g. you entered a PAT in
the Git prompt), Git asks QuiCommit to save it. The PAT is stored in the
system keyring, bound to the matching profile.
3. **`erase`** — Git asks QuiCommit to delete a stored PAT for the given host.
Host names are mapped to canonical service names (`github.com``github`,
`gitlab.com``gitlab`, `bitbucket.org``bitbucket`, etc.). Unknown hosts
are used as-is.
#### Removing Stored Credentials
To remove a stored PAT, you can either use Git's built-in mechanism:
```bash
echo "protocol=https
host=github.com" | git credential reject
```
Or remove it via the profile token management command:
```bash
quicommit profile token
```
### Configure LLM
```bash
@@ -239,6 +296,7 @@ quicommit config reset --force
| `quicommit changelog` | `cl` | Generate changelog |
| `quicommit profile` | `p` | Manage Git profiles |
| `quicommit config` | `cfg` | Manage settings |
| `quicommit credential` | — | Git credential helper (hidden, invoked by Git) |
### Commit Options