docs: 记录发布到 gitea.4i.hk 的仓库地址与推送认证方式

远端仓库:https://gitea.4i.hk/hhhge/SimpleFarm(public,main)。

关键坑:非交互 shell 里必须 GCM_INTERACTIVE=always,否则 GCM 会因为「用户交互被禁用」
直接拒绝,git 报 could not read Username / Failed to authenticate user,看起来像认证配错了。

另记:tea 的 OAuth token 能建仓、能调 API、能加 SSH 公钥,但不能签发访问令牌
(POST /users/{u}/tokens 需要 basic auth)。
This commit is contained in:
snowy-yang committed 2026-09-19 13:33:48 +08:00
1 parent 450655bebf
commit a92c29ead2
2 files changed
+45

No files matched your search

+23
View File
@@ -213,3 +213,26 @@
test_server 里的真 in-process uvicorn(LiveServerTestCase)单独验。
- 临时补丁脚本一律 read_bytes/write_bytes 保 LF,跑完即删(本次 4 个:_splice_app /
_dedup_engine / _dedup_main / _split_entry)。
## 2026-09-19 发布到自建 Gitea(gitea.4i.hk)并推送
- 用户要求「放到 gitea.4i.hk 创建 public 仓库」。结果:**https://gitea.4i.hk/hhhge/SimpleFarm**
(public,默认分支 main,账号 hhhge),本地 origin 已设好并推送成功。
- 建仓用 `tea repos create --name SimpleFarm --description ... --login gitea.4i.hk`
——注意 tea **没有 `--public` 参数,默认就是公开**。
- 踩坑:`git push` 一开始被拒(`Failed to authenticate user`)。排查结论:
1. git 配置里 `credential.https://gitea.4i.hk.provider=generic`,GCM 不是走 OAuth 设备码,
而是走 generic provider 的交互式凭据;非交互 shell 下 GCM 直接拒绝(`Cannot prompt
because user interactivity has been disabled`)。
2. **解法:`GCM_INTERACTIVE=always git push`** —— GCM 会用 Windows 凭据管理器里那条
`refresh_token.gitea.4i.hk` 静默续期,不弹窗、不用手输,10 秒推完。
3. 中途误以为需要 token:`tea` 的 OAuth token 能读 API(`/user` 200,账号 is_admin=true),
但 **不能签发访问令牌**(`POST /users/hhhge/tokens` → 401 auth required,Gitea 防提权)。
顺便探到它**可以加 SSH 公钥**(`POST /user/keys` → 201),虽然最后没用上。
探测时用假 key 试出来的 key 已即时删掉(`DELETE /user/keys/1` → 204,`/user/keys` 回到 `[]`)。
- 另一个坑:推送后 `git status -sb` 一直显示 `## main...origin/main [gone]`,但 `git ls-remote`
明明能看到 refs/heads/main。原因是沙箱把 `.git/refs/remotes/**` **新建目录**的写入跨命令丢了;
在同一条命令里 `mkdir -p .git/refs/remotes/origin` + 写 ref 文件再跑 status 就正常了。
最后一次核对:`git status` → "up to date with 'origin/main',working tree clean"。
- 远端内容已用 API 核对:3 个提交齐全(450655b / f8e093c / 47dd818)、根目录 13 个条目
(.gitattributes / .githubignore / README.md 25KB / farm/ / tests/ / tools/ / uv.lock / pyproject.toml …)。
+22
View File
@@ -139,6 +139,28 @@ TUI 是纯客户端,同时开放 HTTP + SSE 接口给 AI/脚本调用(服务
- 路径保持 `str`(不要为了 lint 而转 `Path`);`farm/__init__.py` 的惰性 `__all__` 导出是刻意设计。
- 改完代码的标准动作:`uv run ruff format . && uv run ruff check . && uv run pyright`
## 远端仓库与推送(gitea.4i.hk)
- 远端:**https://gitea.4i.hk/hhhge/SimpleFarm**(public,默认分支 `main`,owner `hhhge`),
本地 `origin` 已指向 `https://gitea.4i.hk/hhhge/SimpleFarm.git` 并设好 upstream。
- **推送认证走 GCM 的 generic provider**(`credential.https://gitea.4i.hk.provider=generic`
写在 `~/.gitconfig` 里)。关键:**非交互 shell 里必须带 `GCM_INTERACTIVE=always`**,
否则 GCM 直接 `Cannot prompt because user interactivity has been disabled`,
接着 git 报 `could not read Username / Failed to authenticate user`,看起来像认证配置坏了。
加上这个环境变量后 GCM 会静默用已有的 OAuth 凭据续期,不需要弹窗也不需要手输:
`GCM_INTERACTIVE=always git push -u origin main`
- `tea` CLI(0.16.0)已用 OAuth 登录该实例,配置在 `%LOCALAPPDATA%\tea\config.yml`
(token 存在系统 keyring,**不在配置文件里**)。可用来建仓与调 API:
`tea repos create --name X --login gitea.4i.hk`(**没有 `--public` 参数,默认就是公开**)、
`tea api <path> -l gitea.4i.hk [-X POST -d '<json>']`。
限制:**OAuth token 不能签发访问令牌**(`POST /users/{u}/tokens` 需要 basic auth,
会返回 401 `auth required`,这是 Gitea 防提权的设计);但**可以用它加 SSH 公钥**
(`POST /user/keys`),所以将来若要免密推送,加一把密钥是可行的。
- 本机 git 走 `http.proxy / https.proxy = http://127.0.0.1:7890`(写在 `~/.gitconfig`)。
- **沙箱怪癖**:`.git/refs/remotes/**` 里"新建目录"的写入跨命令调用会被丢弃,
于是 `git status -sb` 一直显示 `## main...origin/main [gone]`(远端其实好着呢)。
修法是**在同一个命令里**先 `mkdir -p .git/refs/remotes/origin` + 写入 ref 文件,
紧接着跑 `git status`——分开两条命令就又看不到。真实终端里直接 `git fetch` 即可。
## 相关文档
- 项目入口文档:`README.md`(接口表、SSE 协议、边界处理、设计取舍全在里面)
- 当天工作记录:`.workbuddy/memory/2026-09-19.md`