feat(cd): wt ~ takes you to the repo root - #9
Merged
Merged
Conversation
Also accepts `wt root`, since a bare `~` is quote-fragile. The shell tilde-expands a bare `~` before wt sees it (bash and zsh both), so `$HOME` is accepted as a synonym - otherwise `wt ~` could never work. Those two short-circuit before `_wt_resolve`, which is safe: a branch would have to resolve to an absolute path with a `//` in it to collide. `root` is different - it's a plausible branch name, so it only falls through to the repo root when no worktree resolves it. Outside a repo, all three error rather than silently dropping you in your home directory. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
There are correctness/robustness issues to address in the new logic/tests (notably $HOME used as a case pattern and a leaked mktemp -d directory), plus a completion behavior mismatch that should be resolved or explicitly accepted.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a repo root navigation target to wt so you can jump to the main worktree root from any linked worktree via wt ~ (shell-expanded to $HOME) or wt root, while preserving the existing “worktree named root wins” behavior.
Changes:
- Updated
_wt_cdto support~/$HOME/rootfallback-to-repo-root semantics. - Updated help text and shell completions to surface
root. - Added Bats tests covering
~,$HOMEform,root,rootcollision, and outside-repo behavior; updated README example.
File summaries
| File | Description |
|---|---|
| wt.sh | Adds repo-root navigation handling in _wt_cd, updates help text, and updates bash/zsh completion candidates. |
| test/cd.bats | Adds tests validating repo-root navigation and edge cases. |
| README.md | Documents wt ~ / wt root usage. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
stilliard
added a commit
that referenced
this pull request
Aug 24, 2026
From Copilot's review on #9. The completion listed `root` as a top-level token but not as a `wt cd` argument, though `wt cd root` works. The third comment (glob metacharacters in the `case` pattern) doesn't apply - the expansion is double-quoted, which makes it literal in both bash and zsh. Co-Authored-By: Claude Opus 5 (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.
wt ~(andwt root) now cd to the repo root, from any worktree.Notes
~is expanded to$HOMEbeforewtruns, in both bash and zsh, so$HOMEis accepted as a synonym — otherwisewt ~could never work.wt '~'works too.rootis an alias, since~is quote-fragile. A real worktree wins: with a branch namedroot,wt rootstill goes there — the fallback only fires when nothing resolves.-was considered and deliberately left free — it conventionally means "previous directory", which is a plausible futurewtfeature.Help text, README and shell completions updated (
rootonly;~is expanded before completion matters).Testing
Five new tests in
test/cd.batscovering~, the$HOMEform,root, the branch-named-rootcollision, and the outside-a-repo failure — all starting from inside a linked worktree. Full suite: 84 passing.🤖 Generated with Claude Code