Skip to content

fix(hooks): announce background hooks per directory - #4781

Merged
max-sixty merged 1 commit into
mainfrom
nightly/clean-43566069546
Nov 14, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/clean-43566069546

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

wt merge --no-remove with both a post-commit and a post-merge hook printed one combined line, Running post-commit: mark (user); post-merge: sync (user) @ ~/repo. That reads as if post-commit ran in the target, but it runs in the feature worktree. This PR gives hooks that run in different directories separate Running lines:

◎ Running post-commit: mark (user)
◎ Running post-merge: sync (user) @ ~/repo

run_hooks_background puts the display path of the first pipeline that has one at the end of the line, on the assumption (written in its docstring) that every hook in a batch shares a path. That stopped being true for post-commit once the post-commit pipeline started being dropped when its worktree is removed. Now post-commit reaches the flush only when the feature worktree is kept, which is exactly when its directory differs from post-merge's. Hooks that share a path, such as post-remove, post-switch and post-merge after a removal, still combine onto one line, so existing snapshots are unchanged.

The new snapshot test test_merge_announces_post_commit_and_post_merge_by_directory produced the misleading single line before this change. The module spec in hook_announcement.rs is updated to match. Its four-type wt merge example, which included post-commit alongside post-remove, described output that can no longer happen.

Found by the nightly code survey of src/commands/hooks.rs.

`wt merge --no-remove` registers post-commit (in the feature worktree, no
display path) and post-merge (in the target, with a display path) on one
announcer. The flush took the first display path it found and put it on a
single combined line, so the output read
`Running post-commit: mark (user); post-merge: sync (user) @ ~/repo`,
implying post-commit ran in the target.

Group pipelines by display path and print one `Running` line per group.
Pipelines sharing a path (post-remove, post-switch, post-merge after a
removal) still combine onto one line.
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Nov 14, 2026
@max-sixty
max-sixty merged commit 0df6533 into main Nov 14, 2026
36 of 45 checks passed
@max-sixty
max-sixty deleted the nightly/clean-43566069546 branch November 14, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants