Repository navigation
docs(skills): worktree 路径改为基于仓库根的绝对路径 (#336) - #341
Open
Casper-Mars wants to merge 2 commits into
Open
Casper-Mars wants to merge 2 commits into
Casper-Mars wants to merge 2 commits into
Conversation
added 2 commits
November 4, 2026 06:28
原因:git-worktree 把 base 硬编码为 main,默认分支是 master/trunk 的仓库 要么选错(陈旧 main)要么选不到(无 main);两处各自表述也必然漂移。 改动: - git-branch 新增 ## Base 段作为唯一事实源:documented base → origin/HEAD → 用户指定 → main 兜底,每级先用 git rev-parse --verify --quiet 校验 ref - 给出可执行片段 ref_exists / resolve_base - git-worktree base 段改为引用 git-branch 规则,片段逐字节复制; 创建时 origin/<base> 优先、其次本地 <base>;解析失败列候选、提示 --base <branch>、非零退出,禁止静默按不存在的 main 继续 验证:fixture A(master 默认分支 + origin/HEAD + 无 main)worktree HEAD == origin/master;陈旧 main 不误选;无可用 base 非零退出;两文件片段 diff 为空; .github 两个 unittest 目录 533 + 14 条全绿
原因:SKILL 把路径写成相对 `.worktrees/<branch-name>`,在 monorepo 子目录 (如 packages/app)调用时会建到 `<subdir>/.worktrees/`:根目录 ignore 覆盖不到, 产生未跟踪的嵌套 worktree,且报告里的 `cd .worktrees/...` 指引失效。 改动: - 新增 ## Repository root 段:先 `git rev-parse --show-toplevel` 取根, 非仓库内明确报错并非零退出,不回落到相对路径 - Naming / Create 的目标改为绝对路径 "$repo_root/.worktrees/<branch-name>" - 边界:目标已存在不覆盖并非零退出;`git check-ignore -q` 只提示不改 .gitignore - Report 段 cd 指引改为 `cd "$repo_root/.worktrees/<branch-name>"` 验证:fixture B(packages/app 内执行)根目录建出 worktree、 子目录无 .worktrees、git status --porcelain 为空、worktree HEAD == origin/main、 cd 指引可用;非仓库内报错退出;重复创建拒绝覆盖;未忽略时只警告
This branch has not been deployed
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.
Fixes #336
Summary
git-worktree的 SKILL 把目标写成相对路径.worktrees/<branch-name>,既没要求先确认在仓库根,也没用git rev-parse --show-toplevel构造路径。在 monorepo 子目录(如packages/app)调用会建到<subdir>/.worktrees/:根目录的 ignore 规则覆盖不到,形成未跟踪的嵌套 worktree,且报告里的cd .worktrees/<branch-name>指引失效。## Repository root段:先repo_root=$(git rev-parse --show-toplevel),失败时明确报错并非零退出,不回落到相对路径;Naming/Create的目标改为绝对路径"$repo_root/.worktrees/<branch-name>",mkdir -p "$(dirname "$target")";git check-ignore -q "$target"未命中时只提示用户在根.gitignore补.worktrees/,本 skill 不自行改.gitignore;Report段cd指引改为cd "$repo_root/.worktrees/<branch-name>",并注明「可在仓库内任意子目录调用」;Testing
fixture B:monorepo(
main+ 远端origin/main+ 根.gitignore含.worktrees/),在packages/app子目录里执行;测试片段全部从 SKILL.md 现场抽取后顺序执行(占位符<branch-name>替换为feat/demo-336)。仓库回归(
python:3.12-slim+ git,Python 3.12.16,与 CI 同版本):Risk
.agents/skills会被install.sh整目录同步到目标仓库,措辞即安装指引;feature/AICF-1(已含 bug: git-worktree 在默认分支不是 main 的目标仓库中会选错或选不到 base #335 的7a909ca),在 docs(skills): 统一 git-branch / git-worktree 的 base 解析 (#335) #340 合并前,本 PR 的 diff 会同时显示 bug: git-worktree 在默认分支不是 main 的目标仓库中会选错或选不到 base #335 的提交;建议先合 docs(skills): 统一 git-branch / git-worktree 的 base 解析 (#335) #340 再合本 PR,届时 diff 自动收缩为仅 bug: 从仓库子目录调用 git-worktree 会把 worktree 创建到错误目录 #336 的改动,不会产生同文件冲突;How to revert
Revert 本 PR 的 merge commit;无数据、配置或安装脚本迁移。