feat: grove new and grove rm CLI subcommands#24
Merged
Merged
Conversation
`grove new <branch>` creates a worktree, honouring base/path/remote/ existing/no-hooks flags. `-q` prints only the resulting path on stdout (logs on stderr) so it composes with `cd "$(grove new feat/foo -q)"`. `grove rm [branch]` removes a worktree — defaults to the one containing the cwd when no branch is given. Prompts for confirmation in a TTY, requires `-y` otherwise. `--dry-run`, `--force`, `--prune` and `--no-hooks` cover the remaining ergonomics. Extracts `plan_create_worktree` and adds `create_worktree_cli` / `remove_worktree_cli` that build a transient SharedState and stream logs to stdout, mirroring the existing `run_hooks_cli` pattern. `plan_*_worktree_*` now takes `skip_hooks` so `--no-hooks` is a flag rather than post-hoc step filtering. `build_cli_state` / `read_cli_defaults` are shared by all three CLI entry points. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- grove rm --dry-run now previews dirty and main-worktree cases instead of exiting 1; the blocking checks only fire on real runs - confirmation prompt names the branch and the worktree path so it's unambiguous which one you're about to delete - plan output surfaces force: yes when -f is set - cmd_rm streams git output via StderrLogWriter so stdout stays empty for future --json structured output - resolve_rm_target gets unit tests for branch match / cwd inference / unknown branch cases Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- run_steps helper replaces five copies of \`for step in steps { step.run(sink)?; }\`
across run_hooks_cli, create_worktree_cli, remove_worktree_cli,
run_session_execution, and execute
- persist_recent_repo wraps the lock + push_recent + persist pattern
that the two CLI action paths shared
- create_worktree_cli / remove_worktree_cli now accept &SharedState
from the caller, so grove rm no longer reloads ~/.grove/store.json
after scanning worktrees
- cmd_rm collects is_main / dirty blockers into a single list and
applies them in one place, replacing the three-level nested
dry-run/error conditionals
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
补齐 P0 的 CLI 入口:
grove new <branch> [flags]— 创建 worktree。flag:-b/--base、-p/--path、-r/--remote、--existing、--no-hooks、-q/--quietgrove rm [branch] [flags]— 删除 worktree。无参时默认删 cwd 所在 worktree;TTY 下交互确认([[feedback_dangerous_ops_confirm]]兜底),非 TTY 必须-y。flag:-f/--force、-y/--yes、--dry-run、--prune、--no-hooksgrove new -q让脚本可以cd "\$(grove new feat/foo -q -b origin/main)",stdout 只输出路径,所有日志走 stderr。实现
actions.rs仿run_hooks_cli的模式:plan_create_worktree→create_worktree_cliplan_remove_worktree_execution加skip_hooks参数 →remove_worktree_clibuild_cli_state/read_cli_defaults三个 CLI 入口共用CLI 示例
```bash
grove new feat/login # 默认 base + 默认路径 + hooks
grove new feat/login -b develop -p ../scratch
grove new feat/login -r origin/feat/login # 跟踪远程
grove new feat/login --existing # 把已有分支放进 worktree
grove new feat/login --no-hooks -q # 脚本模式
grove rm feat/login # TTY 下问 [y/N]
grove rm feat/login -y --prune # 跳过确认 + 顺手 prune
grove rm # 删 cwd 所在 worktree
grove rm feat/login --dry-run # 仅打印计划
```
Test plan
-qquiet 模式 → stdout 只有路径-y真删 /--prune触发 prune备注
-o/--open/--launch、grove rm --pick(交互选择)、模糊分支匹配——属于 P1 范围git worktree remove默认不删本地分支,本 PR 保持现状(GUI 行为一致)🤖 Generated with Claude Code