Repository navigation
Conversation
With `[switch] cd = false` or `wt switch --no-cd`, opening the interactive picker (`wt switch` with no branch argument) and selecting a worktree printed the branch name and exited: no switch, no hooks, and `Alt-c` created nothing. The picker now runs the same plan_switch/execute_switch pipeline as `wt switch <branch>`, suppressing only the cd directive. Pre- and post-switch hooks fire, `Alt-c` creates the worktree, and `--format=json` is honored in the picker too — `requires = "branch"` and the `--branches`/`--remotes` conflict are dropped from the flag. JSON emission is extracted into a shared `emit_switch_json` so the argument path and the picker produce identical output. Scripts that relied on the old print-only output should use `wt switch --format=json`, which both switches and prints a structured result. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # docs/content/tips-patterns.md # skills/worktrunk/reference/tips-patterns.md
worktrunk-bot
approved these changes
May 21, 2026
`wt select` (deprecated) routes through `handle_select_command` to `handle_picker`, but no test exercised it, so `codecov/patch` flagged the `handle_picker` call as an uncovered diff line. A non-TTY smoke test runs `wt select` and snapshots the deprecation warning plus the interactive-terminal bail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
May 21, 2026
…#2858) ## Summary `wt switch <branch>` and the interactive picker (`wt switch` with no argument) each ran the same switch sequence as separate, parallel code. [#2845](#2845) made the two paths *behave* identically; this makes the *code* identical too — a single `SwitchPipeline` that both entry points build and `.run()`. `SwitchPipeline::run` (in `src/commands/worktree/switch.rs`) owns the whole sequence: the bare-repo worktree-path fix-up, pre-switch hooks, source-identity capture, `plan_switch` → `approve_switch_hooks` → `validate_switch_templates` → `execute_switch`, output, background hooks, and `--execute`. Each caller now only resolves a branch identifier and loads config. The picker-vs-argument differences (`--execute`, the shell-integration offer, source-identity capture) are struct field values, not divergent branches. ## Bug fixed The duplication hid a real bug: the picker passed `yes = true` to `run_pre_switch_hooks`, **auto-approving project `pre-switch` hooks without a prompt** — unapproved code from a freshly cloned `.config/wt.toml` running silently. Every other hook the picker runs (`post-switch`, `pre-create`, `post-create`) already went through the approval prompt. With one shared `run_pre_switch_hooks` call gated by the pipeline's single `verify`/`yes` pair, the picker (which has no `--yes`) now prompts for project `pre-switch` hooks like `wt switch <branch>` does — and the two paths can't drift on hook approval again. ## Reviewer notes - One intentional reorder on the argument path: `offer_bare_repo_worktree_path_fix` now runs before `run_pre_switch_hooks` (the picker already used this order). The fix only mutates `worktree-path` config, which pre-switch hooks never read — behavior-neutral. - `capture_switch_source` runs inside `run()` after pre-switch hooks — the same relative position as the old `run_switch`. - Eight now-internal helpers were narrowed from `pub`/`pub(crate)` to private; `worktree/mod.rs` re-exports trimmed accordingly. ## Testing Pure refactor — the existing `test_switch_*`, `test_switch_format_json_*`, and `test_switch_picker_*` suites cover behavior preservation. `test_switch_picker_pre_switch_hook_requires_approval` is a new regression test for the bug fix (verified to fail under the bug). --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
May 23, 2026
…#2858) ## Summary `wt switch <branch>` and the interactive picker (`wt switch` with no argument) each ran the same switch sequence as separate, parallel code. [#2845](#2845) made the two paths *behave* identically; this makes the *code* identical too — a single `SwitchPipeline` that both entry points build and `.run()`. `SwitchPipeline::run` (in `src/commands/worktree/switch.rs`) owns the whole sequence: the bare-repo worktree-path fix-up, pre-switch hooks, source-identity capture, `plan_switch` → `approve_switch_hooks` → `validate_switch_templates` → `execute_switch`, output, background hooks, and `--execute`. Each caller now only resolves a branch identifier and loads config. The picker-vs-argument differences (`--execute`, the shell-integration offer, source-identity capture) are struct field values, not divergent branches. ## Bug fixed The duplication hid a real bug: the picker passed `yes = true` to `run_pre_switch_hooks`, **auto-approving project `pre-switch` hooks without a prompt** — unapproved code from a freshly cloned `.config/wt.toml` running silently. Every other hook the picker runs (`post-switch`, `pre-create`, `post-create`) already went through the approval prompt. With one shared `run_pre_switch_hooks` call gated by the pipeline's single `verify`/`yes` pair, the picker (which has no `--yes`) now prompts for project `pre-switch` hooks like `wt switch <branch>` does — and the two paths can't drift on hook approval again. ## Reviewer notes - One intentional reorder on the argument path: `offer_bare_repo_worktree_path_fix` now runs before `run_pre_switch_hooks` (the picker already used this order). The fix only mutates `worktree-path` config, which pre-switch hooks never read — behavior-neutral. - `capture_switch_source` runs inside `run()` after pre-switch hooks — the same relative position as the old `run_switch`. - Eight now-internal helpers were narrowed from `pub`/`pub(crate)` to private; `worktree/mod.rs` re-exports trimmed accordingly. ## Testing Pure refactor — the existing `test_switch_*`, `test_switch_format_json_*`, and `test_switch_picker_*` suites cover behavior preservation. `test_switch_picker_pre_switch_hook_requires_approval` is a new regression test for the bug fix (verified to fail under the bug). --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
May 24, 2026
…le (#2870) Five data-safety / correctness fixes in the worktree-lifecycle paths, plus one rebase-integration follow-up. Each closes a real TOCTOU or scoping gap and carries integration tests; together they form a dependency chain through `output/handlers.rs` and `step/prune.rs`. - **`merge` / `remove` — revalidate cleanliness after `pre-remove` hooks.** `wt merge` / `wt remove` snapshotted the clean check and branch-integration decision during planning, then ran `pre-remove` hooks before cleanup. A hook (or concurrent process) could dirty the worktree or advance the branch in between; the stale decision then trashed the directory or ran `git branch -D`. Cleanliness and integration are now recomputed from a fresh ref snapshot after hooks run. - **`remove` — recompute branch safety in the background path.** The background removal path also acted on pre-hook planning state, and synthesized `git worktree remove --force` whenever `.gitmodules` existed. It now re-runs `ensure_clean`, recomputes integration via `delete_branch_if_safe`, and fails closed for submodule worktrees on the fallback path instead of forcing. - **`prune` — serialize the rename-failure fallback.** When the fast-path rename failed, prune spawned a detached `git branch -d` that ran after the lock guard dropped, racing a live integration-check reader on `.git/config` (#2801's residual gap). It now runs synchronously under the write guard for non-current worktrees. - **`prune` — scope hook approval to the removal set.** Approval was built from every linked worktree (including ones prune would skip) plus an always-on primary `post-switch`, so a non-interactive prune could abort on an unrelated unapproved hook. Approval is now built only for the worktrees prune will actually remove. - **`prune` — prune stale *detached* worktree metadata.** A detached worktree whose directory was deleted outside Worktrunk (`branch == None`) was silently skipped and lingered in `git worktree list` forever; it is now pruned via an idempotent `git worktree prune`. The final commit drops a struct field — removed by the first commit — from a test constructor that landed in `picker/mod.rs` after this chain's base (#2845), which the cherry-pick's auto-merge did not catch. > _This was written by Claude Code on behalf of Maximilian Roos_ --------- Co-authored-by: Claude <[email protected]>
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.
With
[switch] cd = falseorwt switch --no-cd, opening the interactive picker (wt switchwith no branch argument) and selecting a worktree printed the branch name and exited — no switch, no hooks, andAlt-ccreated nothing. #1445 introduced this as an explicit print-only mode, but it surprises anyone who setscd = falseas a standing navigation preference (driving worktree switches through tmux or cmux): the picker silently stops doing anything.The picker now runs the same
plan_switch→execute_switchpipeline aswt switch <branch>, suppressing only the cd directive. Pre- and post-switch hooks fire,Alt-ccreates the worktree, and--format=jsonworks in the picker too (requires = "branch"and the--branches/--remotesconflict are dropped from the flag). JSON emission is extracted into a sharedemit_switch_jsonso the argument path and the picker produce identical output.This is a behavior change: the print-only picker mode is gone. Scripts that captured its bare-branch-name output should switch to
wt switch --format=json, which both performs the switch and prints a structuredaction/branch/pathresult — now shown as apickalias example in tips-patterns. The cmux recipe drops itspickalias workaround, since the picker firespre-switchhooks directly.Closes #2837. Thanks to @endigma for the discussion that pinned down the intended behavior: the picker should be identical to passing the branch as an argument.