feat: grove cd and grove shell-init#25
Merged
Merged
Conversation
\`grove cd [branch]\` prints the path of a matching worktree on stdout. With no argument it picks the main worktree; with one it tries exact branch match first, then falls back to substring containment. Multiple matches surface a candidate list on stderr and exit 1. \`grove shell-init <zsh|bash|fish>\` emits a shell function that wraps \`grove cd\` so users can actually \`cd\` after \`eval "\$(grove shell-init zsh)"\` in their rc. Other subcommands fall through to the binary. Adds \`git::main_worktree_root\` (using \`git rev-parse --git-common-dir\`) and routes \`current_repo_root\` through it. Previously CLI commands run from inside a linked worktree resolved to that worktree's path, which made \`scan_worktrees\` mis-flag \`is_main\` and store keys diverged from the main repo path. The new helper fixes that latent bug for every CLI entry point. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`grove cd` runs on every shell directory change via the shell-init wrapper, but was calling scan_worktrees — which shells out to gh and runs ~5 git subprocesses per worktree for status/PR data it never uses. - Add git::list_worktrees, a porcelain-only helper for branch→path lookup - Switch cmd_cd to list_worktrees; drop the unneeded store::load_store - Fold main_worktree_root onto the existing run_git_text helper - Tighten the multi-match error and drop the manual Debug for MatchOutcome 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
补齐 git worktree 最大的痛点:没法 cd 到 worktree。
```bash
eval "$(grove shell-init zsh)" # 写到 .zshrc
grove cd feat/login # 真的 cd 过去
```
匹配规则:
顺手修了一个 latent bug
CLI 路径里 `current_repo_root` 用的是 `git rev-parse --show-toplevel`,在 linked worktree 内调用会返回当前 worktree 而不是主仓。这导致:
新增 `git::main_worktree_root`(基于 `git rev-parse --git-common-dir`),`current_repo_root` 切到它。所有 CLI 入口现在不管 cwd 在哪都解析到主仓。
测试
CLI 示例
```bash
$ grove cd # 主仓路径
/Users/you/code/grove
$ grove cd login # 子串命中 feat/login
/Users/you/code/grove/.worktrees/login
$ grove cd feat/ # 多候选
error: 'feat/' matches multiple worktrees:
feat/login
feat/oauth
hint: pass the full branch name
```
Test plan
🤖 Generated with Claude Code