SuperAPI AI 工具集

finishing-a-development-branch

编程与开发

查看项目

更新于 10-16 06:09

技能介绍

用途

该技能用于开发工作的收尾阶段:当实现已完成、所有测试通过时,帮助使用者决定如何整合这次开发成果。它通过给出结构化的选项并执行所选的工作流,来引导开发工作的完成。

主要能力

  • 在给出选项前验证测试是否通过。
  • 确定当前分支的基线分支。
  • 呈现四个固定的收尾选项,避免开放式提问带来的歧义。
  • 按所选选项执行对应的 git / gh 操作。
  • 在适用的情况下清理 worktree。

核心原则为:验证测试 → 呈现选项 → 执行选择 → 清理。

技能开始时应声明:「I'm using the finishing-a-development-branch skill to complete this work.」

使用方式

第 1 步:验证测试

在呈现选项之前,先运行项目的测试套件验证测试通过:

# Run project's test suite
npm test / cargo test / pytest / go test ./...

如果测试失败,提示必须修复后才能完成,并展示失败信息;在测试通过之前不能进行合并或创建 PR,此时停止,不进入第 2 步。

如果测试通过,继续第 2 步。

第 2 步:确定基线分支

# Try common base branches
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

或询问:「This branch split from main - is that correct?」

第 3 步:呈现选项

恰好呈现以下 4 个选项:

Implementation complete. What would you like to do?

1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work

Which option?

不添加额外解释,保持选项简洁。

第 4 步:执行所选选项

选项 1:本地合并

# Switch to base branch
git checkout <base-branch>

# Pull latest
git pull

# Merge feature branch
git merge <feature-branch>

# Verify tests on merged result
<test command>

# If tests pass
git branch -d <feature-branch>

然后执行第 5 步(清理 worktree)。

选项 2:推送并创建 PR

# Push branch
git push -u origin <feature-branch>

# Create PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>

## Test Plan
- [ ] <verification steps>
EOF
)"

然后执行第 5 步(清理 worktree)。

选项 3:保持现状

报告:「Keeping branch . Worktree preserved at .」,不清理 worktree。

选项 4:丢弃

先确认:

This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>

Type 'discard' to confirm.

等待精确确认。若确认:

git checkout <base-branch>
git branch -D <feature-branch>

然后执行第 5 步(清理 worktree)。

第 5 步:清理 worktree

对于选项 1、2、4,检查是否处于 worktree 中:

git worktree list | grep $(git branch --show-current)

如果是,则:

git worktree remove <worktree-path>

对于选项 3,保留 worktree。

快速参考

选项 合并 推送 保留 Worktree 清理分支
1. 本地合并 ✓ - - ✓
2. 创建 PR - ✓ ✓ -
3. 保持现状 - - ✓ -
4. 丢弃 - - - ✓(强制)

常见错误

  • 跳过测试验证:会导致合并破损代码、创建失败的 PR;修复方式是始终在提供选项前验证测试。
  • 开放式提问:「What should I do next?」会产生歧义;修复方式是恰好呈现 4 个结构化选项。
  • 自动清理 worktree:在可能仍需要它时(选项 2、3)移除 worktree;修复方式是仅对选项 1 和 4 进行清理。
  • 丢弃时无确认:可能误删工作;修复方式是要求输入 discard 确认。

红线

绝不:在测试失败时继续;未在结果上验证测试就合并;未经确认就删除工作;未经明确请求就强制推送。

始终:在提供选项前验证测试;恰好呈现 4 个选项;对选项 4 获取输入的确认;仅对选项 1 和 4 清理 worktree。

集成

被以下调用:

  • subagent-driven-development(第 7 步)—— 所有任务完成后
  • executing-plans(第 5 步)—— 所有批次完成后

与以下配对:

  • using-git-worktrees —— 清理由该技能创建的 worktree