Repository navigation
refactor(hooks): drop primary-worktree config fallback; surface parse errors - #2714
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]>
worktrunk-bot
approved these changes
May 11, 2026
Collaborator
|
|
# 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
worktrunk-bot
approved these changes
May 11, 2026
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
…oo (#2717) ## Summary Follow-up to #2714: the fallback removal in the shared `collect_remove_hook_commands` helper 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 a `pre-remove` from the primary that the executor will then silently skip. This patch carries the original change forward to the helper. Each removed worktree's `pre-remove` reads its own `.config/wt.toml`; if it has none, no project `pre-remove` runs and the primary's config is not consulted. ## Why this matters Post-#2714, `wt remove` / `wt merge` / `wt step prune` all delegate `pre-remove` approval 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. Local `cargo test --test integration` runs 1704 tests, all pass. --------- Co-authored-by: Claude <[email protected]>
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 was referenced May 19, 2026
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
Each worktree's
.config/wt.tomlnow stands alone. When the worktree a 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.Why
The fallback (#2690, extended to
wt switchin #2703) was an internal detail meant to keep worktrees branched off before a hook was added still firing the hook. But it made which file each hook actually reads ambiguous — Codex flagged this in review of #2703 (P3): a destination worktree with a malformed.config/wt.tomlsilently ran the primary's hooks instead of surfacing the parse error.Removing the fallback gives a cleaner model: each worktree owns its config. Users who want a hook to apply project-wide commit it on the default branch — new worktrees branched off that branch inherit it. Worktrees branched off before the commit no longer fire the hook silently, which was the leaky part.
Behavior change
A
pre-removehook added onmainno longer fires when removing a feature worktree that predates the commit adding it. To restore that behavior, branch the feature offmainagain (or commit the hook on the feature branch itself).What changed
Repository::project_config_at_refnow returnsanyhow::Result<Option<ProjectConfig>>—Ok(None)for refs with no.config/wt.toml,Errfor present-but-malformed.commands::project_config::collect_remove_hook_commands(the shared helper introduced in refactor(approval): share the remove-hook approval helper across remove/merge/prune #2709) and fromoutput::handlers::execute_pre_remove_hooks_if_needed,worktree::switch::{switch_hook_project_config, hook_repo_for_worktree, spawn_switch_background_hooks}, andworktree::finish::finish_after_merge.commands::hooksspec docstring — table rows lose the fallback sub-clauses; trailing paragraph drops the fallback handling.Tests
project_config_at_ref_reads_committed_confignow assertsErron malformed committed config (wasNone).test_switch_existing_aborts_on_malformed_destination_configandtest_remove_aborts_on_malformed_worktree_configfor the end-to-end abort path.test_switch_pr_hooks_see_pr_vars(commits onpr-source),test_merge_teardown_hooks_read_destination_worktree_config→..._read_acting_worktree_config(feature carries pre-remove),test_approval_prompt_remove_decline(commits before creating the worktree to remove). Snapshot regenerated for the last.