Skip to content

feat(cd): wt ~ takes you to the repo root - #9

Merged
stilliard merged 1 commit into
mainfrom
feat/cd-repo-root
Aug 24, 2026
Merged

feat(cd): wt ~ takes you to the repo root#9
stilliard merged 1 commit into
mainfrom
feat/cd-repo-root

Conversation

@stilliard

Copy link
Copy Markdown
Owner

wt ~ (and wt root) now cd to the repo root, from any worktree.

Notes

  • The shell eats the tilde. A bare ~ is expanded to $HOME before wt runs, in both bash and zsh, so $HOME is accepted as a synonym — otherwise wt ~ could never work. wt '~' works too.
  • root is an alias, since ~ is quote-fragile. A real worktree wins: with a branch named root, wt root still goes there — the fallback only fires when nothing resolves.
  • Outside a repo it errors rather than silently dropping you in your home directory.
  • - was considered and deliberately left free — it conventionally means "previous directory", which is a plausible future wt feature.

Help text, README and shell completions updated (root only; ~ is expanded before completion matters).

Testing

Five new tests in test/cd.bats covering ~, the $HOME form, root, the branch-named-root collision, and the outside-a-repo failure — all starting from inside a linked worktree. Full suite: 84 passing.

🤖 Generated with Claude Code

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>
Copilot AI lite review requested due to automatic review settings August 24, 2026 12:03

@stilliard stilliard left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@stilliard
stilliard merged commit 3ffbe87 into main Aug 24, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_cd to support ~ / $HOME / root fallback-to-repo-root semantics.
  • Updated help text and shell completions to surface root.
  • Added Bats tests covering ~, $HOME form, root, root collision, 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.

Comment thread wt.sh
Comment thread test/cd.bats
Comment thread wt.sh
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants