Skip to content

refactor(hooks): drop primary-worktree config fallback; surface parse errors - #2714

Merged
max-sixty merged 3 commits into
mainfrom
hook-config-no-fallback
May 11, 2026
Merged

max-sixty merged 3 commits into
mainfrom
hook-config-no-fallback

Conversation

@max-sixty

@max-sixty max-sixty commented May 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

Each worktree's .config/wt.toml now 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 switch in #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.toml silently 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-remove hook added on main no longer fires when removing a feature worktree that predates the commit adding it. To restore that behavior, branch the feature off main again (or commit the hook on the feature branch itself).

What changed

  • 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.
  • Dropped the fallback from 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 from output::handlers::execute_pre_remove_hooks_if_needed, worktree::switch::{switch_hook_project_config, hook_repo_for_worktree, spawn_switch_background_hooks}, and worktree::finish::finish_after_merge.
  • Updated the commands::hooks spec docstring — table rows lose the fallback sub-clauses; trailing paragraph drops the fallback handling.

Tests

  • Unit test project_config_at_ref_reads_committed_config now asserts Err on malformed committed config (was None).
  • Added test_switch_existing_aborts_on_malformed_destination_config and test_remove_aborts_on_malformed_worktree_config for the end-to-end abort path.
  • Updated three tests that relied on the fallback to commit configs on the relevant branches instead: test_switch_pr_hooks_see_pr_vars (commits on pr-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.

… 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

Copy link
Copy Markdown
Collaborator

test (windows) failed in the 📊 Upload test timing step (the actions/upload-artifact@v7 post-test step), not the test suite itself — all 3233 tests passed and the codecov upload that followed succeeded. The artifact step took ~1s and produced no error output before the failure, consistent with a transient backend glitch unrelated to this PR. Leaving the approval in place; the job can be rerun if the test-timing artifact is needed.

max-sixty added 2 commits May 11, 2026 11:37
# 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
@max-sixty
max-sixty merged commit 1dbbe84 into main May 11, 2026
33 checks passed
@max-sixty
max-sixty deleted the hook-config-no-fallback branch May 11, 2026 19:09
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]>
@max-sixty max-sixty mentioned this pull request May 13, 2026
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.
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