Repository navigation
feat(worktree): 新增全局设置 worktreeRoot,可把新建 worktree 放到指定目录 - #3111
Merged
Merged
Conversation
botmux 新建 worktree 原来固定建在主仓库旁边,五处入口各自拼路径:普通与按分支 创建、强制话题 worktree、principal lane、多仓分组目录。系统盘小、另有数据盘的 机器上,worktree 会把系统盘堆满。 现在五处都改走 git-worktree 的 worktreeTargetPath:设了 BOTMUX_WORKTREE_ROOT 时建到该目录下,不设时行为不变。主仓库旁边已有同名目录时仍用旧位置,进行中的 会话和确定性目标(principal lane、强制话题 worktree)照常复用。 测试围栏清掉该变量,避免跑测试时往真实目录里建 worktree。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 21:02
- 去掉环境变量 BOTMUX_WORKTREE_ROOT,改为 ~/.botmux/config.json 的 worktreeRoot, Dashboard「通用设置 → Worktree」可改,保存时校验目录存在且可写 - 根目录下按主仓库所在路径分层,同名仓库不再冲突;已删除 worktree 的恢复 逐级去掉路径前缀查找主仓库,改过根目录也能恢复重建 - 根目录不存在或不是目录时退回主仓库旁边并告警,不在系统盘上重建路径; 根目录先解析软链 - reuseExisting 在目标路径找不到时按分支复用已有 worktree(仍做身份校验、 排除主仓库),复用旧位置时提交阶段持有它的锁 - 测试围栏清除 BOTMUX_GLOBAL_CONFIG_FILE Co-Authored-By: Claude Opus 5.5 <[email protected]>
…到 bun 腿
新增的 vi.mock('node:fs', async (importOriginal) => …) 命中 bun 腿选择器的
「工厂接收原模块参数」规则(bun 不传这个参数),整个文件因此被排除出 bun 腿,
158 个用例只剩 vitest 在跑。改成不带参数的工厂、在工厂里 require 原模块,
与 dashboard-bot-defaults-refresh-race.test.ts 的写法一致。
Co-Authored-By: Claude Opus 5.5 <[email protected]>
usableWorktreeRoot 只检查根目录存在且是目录。数据盘被重新挂成只读、或权限 变了之后,路径照样算到根目录下,git worktree add 前的 mkdir 直接报 EROFS / EACCES:自动 worktree 退回到在主仓库里开会话,/tw 和 principal lane 建不出来。 现在再要求根目录可写(与 Dashboard 保存时的校验一致),不可写时和目录不存在 走同一条退回:建在主仓库旁边,并告警一次。 新增 test/git-worktree-root-writable.test.ts:只读根目录退回旁边,恢复可写后 回到根目录下。文档与设置页说明同步写明「不存在或不可写」。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
这是自动评审的初步意见,最终以维护者审阅为准。 复审(head 合前需要处理的一项,已在分支上代修:
顺手修了一处同主题的小问题:
不阻断、建议后续跟进的几点:
以上四点已登记到 #3163。两个修复提交已另行复核通过,076687765 可合。 |
This was referenced Nov 8, 2026
|
🚀 Released in v3.59.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
新增全局设置
worktreeRoot。它写在~/.botmux/config.json,也可以在 Dashboard「通用设置 → Worktree → worktree 存放目录」里改。设置后,botmux 新建的 worktree 建到这个目录下;不设时行为不变,仍建在主仓库旁边。落点规则
src/services/git-worktree.ts新增worktreeTargetPath(repo, dirName):<主仓库父目录>/<dirName>,和原来相同。/root/iserver/botmux的 worktree 建成/data00/worktrees/root/iserver/botmux-wt-<slug>,不同位置的同名仓库不会落到同一个目录。mkdir -p在系统盘上重建出那条路径。原来有五处各自用
join(dirname(repo), …)拼 worktree 路径,现在都改用这个函数:createRepoWorktree的自动命名(wt/<slug>、wt/N)和显式分支resolveWorktreePathForBranch(话题指令头/repo wt <目标> <分支>预检用,必须和上一条一致)daemon.ts的forceTopicWorktreeTarget)core/principal-lane-worktree.ts)im/lark/card-handler.ts的multiWorktreeParentPath)设置改过之后
reuseExisting在算出的位置找不到时,会按分支在git worktree list里找已有的那个(git 一个分支只能检出在一个 worktree 里)。找到后照常做身份校验;如果找到的是主仓库本身,则不复用。resolveDeletedWorktreeOrigin)会逐级去掉路径前缀,直到旁边找到主仓库。这一步不读当前设置,所以建在旧根目录下的 worktree 也能恢复重建。设置项
global-config.ts:worktreeRoot只接受去掉首尾空白后的绝对路径,或以~/开头的路径;其他值读取时忽略。invalid_worktreeRoot,不写入;留空保存即清除。docs-site/docs/{zh,en}/global-settings.md。为什么
系统盘小、另挂大数据盘的机器上,worktree 会把系统盘堆满。在一台 1T 系统盘的开发机上实测:工作目录下登记的 597 个 worktree 里,552 个由 botmux 创建,其中近两周新建 477 个;同机的 5T 数据盘几乎是空的。git worktree 只共享对象库,工作区文件每个 worktree 各有一份,所以把 worktree 放到大盘上是最直接的办法。
做成全局设置而不是环境变量:每台机器只需配一次,能在 Dashboard 里看到和修改,不用改
.env再重启。影响面
services/git-worktree.ts、core/principal-lane-worktree.ts、im/lark/card-handler.ts、daemon.ts、global-config.ts、Dashboard 设置页与写入校验。只改了 worktree 路径的计算和复用查找,不涉及 CLI 适配器、PTY/tmux 后端和消息处理。.git本来就指向主仓库里的 git 目录(绝对路径),跨盘不影响;仓库选择器靠git worktree list列 worktree,照常能看到。/cleanup-wt、会话结束清理)按 worktree 路径调用git worktree remove,不依赖位置。BOTMUX_GLOBAL_CONFIG_FILE加进fenceHomeRootedEnv的精确路径清除名单(bun-shim-parity.test.ts同步)。这样在设了这个变量的 shell 里跑测试时,Dashboard 保存设置不会改写真实的全局配置。测试验证
新增用例:
test/git-worktree.test.ts的worktreeRoot setting组,用真实 git 仓库和临时全局配置:~开头test/global-config.test.ts:读取去空白的绝对 /~/路径;忽略相对路径和非字符串。test/settings-write-applier.test.ts:写入去空白的已存在目录;留空即清除;拒绝非字符串、相对路径、~other/…、不存在的路径、文件,以及不可写的目录,且都不写入。test/settings-worktree-root-ui.test.ts:按钮和回车都保存去空白后的值;可清空;提示显示已保存的值而不是草稿;未改动、只加了空白或只读时保存按钮禁用。变异复验:每条防护单独改回去,确认至少一条新用例变红。
未在 live daemon 上验证。需要时
bun run switch:here && bun run daemon:restart,在 Dashboard 设好目录后,在飞书里建一个 worktree 看落点。测试基于
f1ab179a3;与当前 master(250a30c88)合并无冲突。评审发现与处理
mkdir -p会在系统盘上重建出根目录路径,悄悄写回系统盘reuseExisting增加按分支查找realpath再使用BOTMUX_GLOBAL_CONFIG_FILE,在设了它的 shell 里跑测试会改写真实全局配置statSync遇到权限错误会抛出;不可写的目录也能保存EACCES)/sys/fs/cgroup作根目录,修前createRepoWorktree抛 EROFS,修后建在主仓库旁边;用例test/git-worktree-root-writable.test.tssettings-write-applier.test.ts的node:fsmock 工厂接收importOriginal,整个文件被排除出 bun 腿isDeferredFromBunLeg:master 为 false、改前为 true、改后为 false;改后bun test158 个用例通过require🤖 Generated with Claude Code