Loading...
Loading...
Compare original and translation side by side
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)GIT_DIR != GIT_COMMONundefinedGIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)GIT_DIR != GIT_COMMONundefined
**如果 `GIT_DIR != GIT_COMMON`(且不是 submodule):** 你已经在一个 linked worktree 内。跳到步骤 3(项目设置)。**不要**再创建一个 worktree。
按分支状态报告:
- 在某个分支上:"已经在隔离工作区 `<path>`,分支 `<name>`。"
- 分离 HEAD:"已经在隔离工作区 `<path>`(分离 HEAD,由外部管理)。完成时需要创建分支。"
**如果 `GIT_DIR == GIT_COMMON`(或在 submodule 内):** 你在一个普通的仓库检出里。
用户是否已经在你的 instructions 里表明过 worktree 偏好?如果没有,创建 worktree 之前先征求同意:
> "你希望我搭一个隔离的 worktree 吗?它能保护你当前分支不被改动。"
如果用户已声明过偏好,直接遵循,不再询问。如果用户拒绝同意,原地工作并跳到步骤 3。
**If `GIT_DIR != GIT_COMMON` (and not in a submodule):** You're already inside a linked worktree. Skip to Step 3 (Project Setup). **Do NOT** create another worktree.
Report based on branch status:
- On a branch: "Already in isolated workspace `<path>`, branch `<name>`."
- Detached HEAD: "Already in isolated workspace `<path>` (detached HEAD, managed externally). Need to create a branch when done."
**If `GIT_DIR == GIT_COMMON` (or in a submodule):** You're in a normal repo checkout.
Has the user already indicated a worktree preference in your instructions? If not, ask for consent before creating a worktree:
> "Would you like me to set up an isolated worktree? It protects your current branch from being modified."
If the user has stated a preference, follow it directly without asking. If the user declines consent, work in place and skip to Step 3.EnterWorktreeWorktreeCreate/worktree--worktreegit worktree addEnterWorktreeWorktreeCreate/worktree--worktreegit worktree addls -d .worktrees 2>/dev/null # 首选(隐藏目录)
ls -d worktrees 2>/dev/null # 备选.worktreesproject=$(basename "$(git rev-parse --show-toplevel)")
ls -d ~/.config/superpowers/worktrees/$project 2>/dev/null.worktrees/ls -d .worktrees 2>/dev/null # Preferred (hidden directory)
ls -d worktrees 2>/dev/null # Alternative.worktreesproject=$(basename "$(git rev-parse --show-toplevel)")
ls -d ~/.config/superpowers/worktrees/$project 2>/dev/null.worktrees/git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null~/.config/superpowers/worktrees/git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null~/.config/superpowers/worktrees/project=$(basename "$(git rev-parse --show-toplevel)")project=$(basename "$(git rev-parse --show-toplevel)")
**沙盒回退:** 如果 `git worktree add` 因权限错误(沙盒拒绝)失败,告诉用户沙盒阻止了 worktree 创建,你将在当前目录原地工作。然后原地运行 setup 和基线测试。
**Sandbox Fallback:** If `git worktree add` fails due to permission errors (sandbox denial), inform the user that the sandbox prevented worktree creation, and you will work in the current directory. Then run setup and baseline tests in place.undefinedundefinedundefinedundefinedundefinedundefined
**如果测试失败:** 报告失败,询问是继续还是排查。
**如果测试通过:** 报告就绪。
**If tests fail:** Report the failure and ask whether to continue or troubleshoot.
**If tests pass:** Report readiness.工作树已就绪:<full-path>
测试通过(<N> 个测试,0 个失败)
准备实现 <feature-name>Worktree ready: <full-path>
Tests passed (<N> tests, 0 failures)
Ready to implement <feature-name>| 情况 | 操作 |
|---|---|
| 已在 linked worktree 内 | 跳过创建(步骤 0) |
| 在 submodule 内 | 按普通仓库处理(步骤 0 守卫) |
| 有原生 worktree 工具 | 用它(步骤 1a) |
| 没有原生工具 | git worktree 回退(步骤 1b) |
| 用它(验证已忽略) |
| 用它(验证已忽略) |
| 两者都存在 | 用 |
| 都不存在 | 检查 instructions 文件,再默认 |
| 全局路径存在 | 用它(向后兼容) |
| 目录未被忽略 | 添加到 .gitignore + 提交 |
| 创建时权限错误 | 沙盒回退,原地工作 |
| 基线测试失败 | 报告失败 + 询问 |
| 无 package.json/Cargo.toml | 跳过依赖安装 |
| Scenario | Action |
|---|---|
| Already in linked worktree | Skip creation (Step 0) |
| Inside a submodule | Treat as normal repo (Step 0 guard) |
| Native worktree tools available | Use them (Step 1a) |
| No native tools | Use git worktree fallback (Step 1b) |
| Use it (verify ignored) |
| Use it (verify ignored) |
| Both exist | Use |
| Neither exists | Check instructions file, then default to |
| Global path exists | Use it (backward compatibility) |
| Directory not ignored | Add to .gitignore + commit |
| Permission error during creation | Sandbox fallback, work in place |
| Baseline tests fail | Report failure + ask |
| No package.json/Cargo.toml | Skip dependency installation |
git worktree addgit worktree addgit check-ignoregit check-ignoreEnterWorktreegit worktree addgit worktree addEnterWorktree