Repository navigation
fix(hooks): drop primary fallback from collect_remove_hook_commands too - #2717
Merged
Merged
Conversation
… errors Each worktree's `.config/wt.toml` now stands alone. When the worktree the hook acts on has no `.config/wt.toml`, no project hooks run — the primary worktree's config is no longer consulted as a fallback. A present-but- malformed config aborts the operation with the parse error instead of silently using a different one. The fallback (added in #2690, extended to `wt switch` in #2703) was internal — users with project-wide hooks committed on the default branch already inherit them when creating new worktrees off that branch. The fallback only helped worktrees branched off *before* the hook was added, at the cost of making it ambiguous which file each hook actually read. `Repository::project_config_at_ref` now returns `anyhow::Result<Option<ProjectConfig>>` — `Ok(None)` for refs with no `.config/wt.toml`, `Err` for present-but-malformed. Co-authored-by: Claude <[email protected]>
# Conflicts: # src/commands/step/prune.rs # src/git/repository/config.rs # src/main.rs # src/output/handlers.rs
# Conflicts: # src/commands/hooks.rs # src/commands/merge.rs # src/commands/step/prune.rs # src/main.rs
… too PR #2714 dropped the primary-worktree config fallback from the `pre-remove` executor (`output::handlers::execute_pre_remove_hooks_if_needed`), and from each individual approval call site (`main.rs::approve_remove`, `merge::collect_merge_commands`, `step::prune::approve_prune_hooks`). But during the merge-conflict resolution against the shared helper that landed in #2709 (`collect_remove_hook_commands`), the fallback removal in the helper itself was working-tree-only at commit time — it got dropped from the squash merge. Result on main: the executor and the approval path disagree. The approval helper still falls back to the primary worktree's config when the removed worktree has none, so the prompt can list a `pre-remove` from the primary; the executor then silently skips it. Same kind of leaky abstraction #2714 was meant to remove. This patch carries the original fix forward to the helper, restoring the "each worktree's `.config/wt.toml` stands alone" invariant across both sides of approval/execution. Co-authored-by: Claude <[email protected]>
worktrunk-bot
approved these changes
May 11, 2026
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
…config approval path (#2727) Two small consolidations on top of #2717 (which dropped the residual fallback in the shared `collect_remove_hook_commands` approval helper, finishing what #2714 started): **Spec tightening.** The `commands::hooks` "Which `.config/wt.toml` a hook reads" table row for `post-merge` / `post-remove` / `post-switch` after a removal previously read "the destination — for `wt merge`, the target branch's worktree (else the primary)". Once the fallback rule was gone, "(else the primary)" could be misread as a config fallback. Re-phrased it as the path choice for the destination — the merge target's worktree if one exists, otherwise the primary — explicitly noted "not a config fallback". **Regression test.** Added `test_remove_no_fallback_to_primary_pre_remove`: a worktree with no `.config/wt.toml` plus a `pre-remove` in the primary. Before #2717, `wt remove` without `--yes` aborted with "needs approval" because the helper surfaced the primary's hook and tests have no TTY; after #2717 the prompt is empty and removal succeeds. #2717's commit message argued the malformed-config tests covered the helper end-to-end, but no test covered the no-config (empty-prompt) path specifically — this fills that gap, so a future re-introduction of the fallback would surface immediately. Verified twice: stashed `project_config.rs` to its pre-#2717 state → test fails with exactly the symptom (`pre-remove: echo ran > ...` shown in the prompt, `Cannot prompt for approval in non-interactive environment`). Restored → test passes. `cargo run -- hook pre-merge --yes` is green. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Merged
max-sixty
added a commit
that referenced
this pull request
May 13, 2026
Release v0.50.0. Highlights: - Experimental Azure DevOps support (#1256, thanks @mikeyroush; fixes #1144 from @dlecan) — `wt switch pr:<N>`, `wt list --full`, and `wt config show --full` recognize Azure DevOps via the `az` CLI. - Experimental Gitea CI-status detection (#2702) on top of the Gitea `pr:` shortcut (#1320, thanks @SjB). - Hooks now resolve `.config/wt.toml` from the worktree they act on — the primary-worktree fallback is gone, and `post-remove` reads the removed worktree's config (snapshotted before removal). Approval prompts collect hook commands from the same worktree. Breaking change for setups that relied on the primary-worktree fallback; the changelog entry has the recovery action. (#2690, #2703, #2714, #2717, #2701, #2708, #2727, #2736, #2748) - The `wt switch` picker's `alt-r` removal no longer runs unapproved project hooks (#2746) — the picker's removal path is now routed through `handle_remove_output` and consults the existing approval state read-only. - `wt config alias show` with no name lists every alias's full definition (#2684, #2691); `wt --help` switches to a compact aliases pointer (#2688). - `wt list --branches` warm-run perf: SHA-keyed cache for `main↕` and `Remote⇅` ahead/behind counts; shared push-remote URL and local-branch scan (#2704, #2718, #2673). - Claude Code plugin ships the `wt-switch-create` skill (#2737, thanks @onetom for #2631). See `CHANGELOG.md` for the full list (8 Improved, 5 Fixed, 5 Internal). semver-checks reports breaking library-API changes (new enum variants without `#[non_exhaustive]`, removed `Branch::github_push_url`, new trait method on `RemoteRefProvider`), which mandates at minimum a minor bump pre-1.0.
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
Follow-up to #2714: the fallback removal in the shared
collect_remove_hook_commandshelper was lost in the merge-conflict resolution against #2709 (which introduced the helper) and didn't land in the squash merge. The executor (output::handlers::execute_pre_remove_hooks_if_needed) has no fallback, but the approval helper still falls back to the primary worktree's config — so an approval prompt can list apre-removefrom the primary that the executor will then silently skip.This patch carries the original change forward to the helper. Each removed worktree's
pre-removereads its own.config/wt.toml; if it has none, no projectpre-removeruns and the primary's config is not consulted.Why this matters
Post-#2714,
wt remove/wt merge/wt step pruneall delegatepre-removeapproval to this helper. Without the fix the worktrunk-on-main has an executor/approval mismatch — exactly the kind of leaky abstraction #2714 set out to eliminate.Tests
The integration tests added in #2714 (
test_remove_aborts_on_malformed_worktree_config,test_switch_existing_aborts_on_malformed_destination_config) and the fallback-test fixups (commit on the relevant branch instead of relying on inheritance) already cover the helper's behavior end-to-end. Localcargo test --test integrationruns 1704 tests, all pass.