worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Rationalizing hooks

Open max-sixty opened this issue 8 months ago • 2 comments

From #1571 — creating a new issue to track

Updated analysis using start instead of create to avoid the post-create collision. Hooks ordered by lifecycle stage, with post-commit added.

Current hooks mapped to the new scheme

Current name Current behavior Proposed name Proposed behavior Impact
post-create blocking pre-start blocking Rename only — same semantics
post-start background post-start background No change
pre-switch blocking pre-switch blocking No change
post-switch background post-switch background No change
pre-commit blocking pre-commit blocking No change
(none) — post-commit background New hook
pre-merge blocking pre-merge blocking No change
post-merge blocking (Warn) post-merge background Behavior change
pre-remove blocking pre-remove blocking No change
post-remove background post-remove background No change

The pattern

Every lifecycle event gets a symmetric pre- (blocking) / post- (background) pair:

Event pre- (blocking) post- (background)
start pre-start (was post-create) post-start
switch pre-switch post-switch
commit pre-commit post-commit (new)
merge pre-merge post-merge (was blocking)
remove pre-remove post-remove

Summary

  • 7 unchanged: post-start, pre-switch, post-switch, pre-commit, pre-merge, pre-remove, post-remove
  • 1 easy rename: post-create → pre-start (still blocking, same semantics)
  • 1 new hook: post-commit — runs in the background after wt commit completes. Useful for things like triggering CI, notifications, or background linting
  • 1 behavior change: post-merge — currently blocks (with Warn failure strategy), would become background under the post- = background rule

Migration

Only one hook needs migration: post-create → pre-start. Accept both names for one release cycle with a deprecation warning.

The post-merge behavior change remains the main design decision:

  1. Accept the change — post-merge becomes background. Users who need blocking can move logic to a script that runs before removal
  2. Add an exception — keep post-merge blocking, breaking the clean pre=blocking, post=background rule
  3. Drop post-merge — less common hook; users can use external git hooks instead

Originally posted by @worktrunk-bot in #1571

max-sixty avatar Mar 23 '26 03:03 max-sixty

Thanks for extracting this from #1571 — the proposal is well-structured.

I searched the codebase and confirmed none of the proposed changes are implemented yet. Current state:

  • HookType enum (src/git/mod.rs:318-340) defines all 9 hooks
  • HooksConfig (src/config/hooks.rs) maps them to TOML config with kebab-case serialization
  • Execution strategy is FailFast for all pre- hooks and post-create, Warn for post-merge, and background for post-start/post-switch/post-remove
Related issues
  • #1571 — Original discussion on hook naming clarity
  • #1617 — Requests a blocking post-switch hook (for copying gitignored files on switch). This conflicts with the proposed post- = background rule. Worth considering whether this use case needs a different mechanism or an exception.

I'll leave it for a maintainer to evaluate the design decisions, particularly the post-merge behavior change and how #1617's use case fits into the pattern.

worktrunk-bot avatar Mar 23 '26 03:03 worktrunk-bot

Thanks for this @max-sixty - it looks nice, and much easier to reason about

ortonomy avatar Mar 23 '26 09:03 ortonomy