Repository navigation
feat(hooks): rename worktree-creation hooks to pre-create/post-create - #2840
Conversation
Phase 1 of a staged deprecation (#2838): the worktree-creation hooks pre-start and post-start are renamed to pre-create and post-create. Old configs keep working with no warning yet. migrate_content() rewrites the old keys silently on load, wt config update rewrites them on disk, and wt hook pre-start/post-start still run. The dead pre-0.32.0 post-create machinery (fatal load error, vestigial field) is removed, and post-create is reclaimed as the canonical background hook. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Blocker — CI is failing on every OS because of the .config/wt.toml change.
.github/workflows/ci.yaml installs [email protected] from crates.io and runs wt hook pre-merge --yes insta doctest doc with that binary. v0.50.0 still treats [post-create] as the pre-0.32.0 alias and rejects it as a fatal load error before any tests run:
✗ Failed to load project config
Project config:post-createhook was renamed topre-startin v0.32.0 and the silent rewrite has been removed. Renamepost-createtopre-startin your config.
That message comes from the POST_CREATE_REMOVED_MSG machinery this PR removes — but the bootstrap binary in CI is the older version that still has it. Net effect: linux / macos / windows all fail in <2 minutes with zero tests actually executed, so the new migration paths aren't exercised on CI either.
Simplest fix is to keep .config/wt.toml using [post-start] until a new worktrunk release ships and the CI pin can move. The new binary will silently migrate it to pre-create in memory (the whole point of Phase 1), and v0.50.0 keeps treating it as canonical. Inline suggestion below.
Once CI is unblocked, one smaller observation worth flagging: wt hook show pre-start now errors at clap parse time (HOOK_TYPE_NAMES in src/cli/hook.rs:54 only lists canonical names, and Show.hook_type uses PossibleValuesParser::new(HOOK_TYPE_NAMES)), even though parse_hook_type accepts the deprecated alias for wt hook pre-start itself. The PR description says "old names keep working … on the command line"; this one CLI surface is a small inconsistency with that claim. Probably fine to leave (the in-memory migration means the hook still shows up under pre-create in wt hook show), but worth a sentence in the PR description if it's intentional.
Otherwise the structure of the change is clean: detection (find_renamed_hook_key), migration (rename_hook_key), the DEPRECATED_SECTION_KEYS entries that route warn_unknown_fields away, the empty-warnings guard in check_and_migrate, and the symmetric parse_hook_type aliasing. Good docstrings on the silent-migration / table-form ordering invariant.
CI runs `wt hook pre-merge` with a pinned older `wt` installed from crates.io, which predates the pre-create rename and rejects a `post-create` hook section as the removed pre-0.32.0 alias. Keep the repo's own config on `post-start` (the new code migrates it silently) until a release ships the rename and the CI pin moves. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… show` Two gaps in the pre-create/post-create rename (#2838), found in review: - ProjectConfig::load discarded check_and_migrate's migrated_content and deserialized the raw file, so a current-worktree .config/wt.toml using [pre-start]/[post-start] silently dropped those hooks from `wt hook show`, standalone `wt hook` runs, and completion. Deserialize the migrated content, matching the user-config loader. - `wt hook show <type>` rejected pre-start/post-start at clap parse, before parse_hook_type could map the aliases. Accept them as hidden PossibleValue aliases (help and completion still list canonical names only) and route the parsed value through parse_hook_type. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # src/config/expansion.rs
The merge of main pulled in a new `HookType::PostStart` reference (a test added by #2841); this branch renamed that variant to `PostCreate`. Textual auto-merge took main's line verbatim, breaking the build. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # src/commands/hook_commands.rs
The merge of #2844 ("merge per-project user hooks into display") brought in a new test whose config uses `[post-start]` — canonical on main, a deprecated alias on this branch. Switch it to `post-create` (the test exercises the per-project merge, not deprecation) and regenerate the snapshot, which now shows both hooks under `post-create`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…2857) Per @max-sixty's [direction in #2838](#2838 (comment)): revert the docs portion of #2840 and keep the code. Docs continue to recommend `pre-start`/`post-start`; both names work in code so anyone who already followed the briefly-changed docs (e.g. @EcksDy) isn't stranded once a release ships these aliases. ## User-visible — back to `pre-start`/`post-start` - README, docs site, skill mirrors, `dev/*.example.toml`, `plugins/worktrunk/README.md`, `flake.nix`, `.config/wt.toml` - `src/cli/mod.rs` / `src/cli/config.rs` / `src/cli/step.rs` / `src/help.rs` after_long_help and example snippets — and the auto-synced `docs/content/` and `skills/worktrunk/reference/` mirrors - `wt hook --help` canonical subcommand names; completion advertises `-start` only - `HookType` Display via strum, serde `rename`, and clap `ValueEnum` name — all `pre-start`/`post-start`. The Rust variant identifiers stay `PreCreate`/`PostCreate` (internal; we already paid for that rename in #2840, and now the eventual flip is a Display-only change) - `HooksConfig` serde canonical fields ## `*-create` still works (kept code) - `wt hook pre-create` / `post-create` — CLI alias on the canonical subcommand - `pre-create` / `post-create` in config: top-level, `[hooks.*]`, and per-project, in string, `[table]`, and `[[array-of-tables]]` form. Mechanism: serde `alias = ...` on the field, plus a silent in-memory rename in `migrate_content()` so the round-trip in `unknown_tree` doesn't flag table forms as schema-unknown. - The pre-0.32.0 `post-create` fatal-load-error machinery stays removed — the name is reclaimed, and both forms load without error. ## Smaller bits - `valid_user_config_keys()` / `valid_project_config_keys()` append `pre-create` / `post-create` so the unknown-field round-trip skips them. `test_valid_*_keys_all_deserialize` skips both aliases (they can't sit alongside the canonical without a duplicate-field error). - `DEPRECATED_SECTION_KEYS` drops the `pre-start`/`post-start` entries #2840 added — `pre-start`/`post-start` are canonical again. - `find_pre_start_from_doc` / `find_post_start_from_doc` / `find_renamed_hook_key` / `is_non_empty_item` / `migrate_start_hooks_doc` and their tests are removed; the migration direction flips via a new `migrate_create_hooks_doc` (silent, mirrors the prior shape). - Test files `e2e_shell_post_create.rs` and `post_create_commands.rs` rename back to `_post_start_` (via `git mv`, so the rename shows as a rename). ## Testing `cargo run -- hook pre-merge --yes` — 3806 tests pass; the 10 failures are all `case_4` of `shell_wrapper::unix_tests::*` (nu-shell case; `nu` isn't installed in this runner; same failures occur on `main`). Also manually verified that a fresh `wt switch --create` against a project config with `[post-create]` loads cleanly with no unknown-field warning and the hook fires as `post-start`. ## Follow-up Per @max-sixty: in a couple of weeks, once a release with both-names-work is out and users have had a chance to upgrade, the docs flip is straightforward (most of it is in `src/cli/mod.rs`'s `after_long_help` and the doc-sync test propagates). Re #2838. Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.7 <[email protected]>
Two small follow-ups noticed while fixing the test comments in #2877. **`pre_create` docstring was wrong.** It read "Commands to execute before worktree creation (blocking)", but `pre-start` actually runs *after* the worktree is created (`switch.rs:1142` executes it against "the new worktree (created just above)", and the renamed test below asserts the worktree exists after a failing pre-start). The wrong wording entered in #2840 as part of the mechanical `pre-start` → `pre-create` rename — someone "corrected" the docstring to match the new name. #2857 reverted the name but left the docstring. Restoring "after worktree creation (blocking, fail-fast)" matches the actual behavior, `docs/content/hook.md` ("Runs once when a new worktree is created, blocking…"), and the parallel `post_create` docstring. Because `HooksConfig` derives `JsonSchema`, this docstring is user-visible in generated schema descriptions. **`test_user_post_start_hook_failure` was misnamed.** The fixture is `[pre-start]`, the comment and assertion describe a failing pre-start, and only the function name said post-start. Renamed to `test_user_pre_start_hook_failure` along with its snapshot name and file (`git mv`, so the rename shows as a rename). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…2857) Per @max-sixty's [direction in #2838](#2838 (comment)): revert the docs portion of #2840 and keep the code. Docs continue to recommend `pre-start`/`post-start`; both names work in code so anyone who already followed the briefly-changed docs (e.g. @EcksDy) isn't stranded once a release ships these aliases. ## User-visible — back to `pre-start`/`post-start` - README, docs site, skill mirrors, `dev/*.example.toml`, `plugins/worktrunk/README.md`, `flake.nix`, `.config/wt.toml` - `src/cli/mod.rs` / `src/cli/config.rs` / `src/cli/step.rs` / `src/help.rs` after_long_help and example snippets — and the auto-synced `docs/content/` and `skills/worktrunk/reference/` mirrors - `wt hook --help` canonical subcommand names; completion advertises `-start` only - `HookType` Display via strum, serde `rename`, and clap `ValueEnum` name — all `pre-start`/`post-start`. The Rust variant identifiers stay `PreCreate`/`PostCreate` (internal; we already paid for that rename in #2840, and now the eventual flip is a Display-only change) - `HooksConfig` serde canonical fields ## `*-create` still works (kept code) - `wt hook pre-create` / `post-create` — CLI alias on the canonical subcommand - `pre-create` / `post-create` in config: top-level, `[hooks.*]`, and per-project, in string, `[table]`, and `[[array-of-tables]]` form. Mechanism: serde `alias = ...` on the field, plus a silent in-memory rename in `migrate_content()` so the round-trip in `unknown_tree` doesn't flag table forms as schema-unknown. - The pre-0.32.0 `post-create` fatal-load-error machinery stays removed — the name is reclaimed, and both forms load without error. ## Smaller bits - `valid_user_config_keys()` / `valid_project_config_keys()` append `pre-create` / `post-create` so the unknown-field round-trip skips them. `test_valid_*_keys_all_deserialize` skips both aliases (they can't sit alongside the canonical without a duplicate-field error). - `DEPRECATED_SECTION_KEYS` drops the `pre-start`/`post-start` entries #2840 added — `pre-start`/`post-start` are canonical again. - `find_pre_start_from_doc` / `find_post_start_from_doc` / `find_renamed_hook_key` / `is_non_empty_item` / `migrate_start_hooks_doc` and their tests are removed; the migration direction flips via a new `migrate_create_hooks_doc` (silent, mirrors the prior shape). - Test files `e2e_shell_post_create.rs` and `post_create_commands.rs` rename back to `_post_start_` (via `git mv`, so the rename shows as a rename). ## Testing `cargo run -- hook pre-merge --yes` — 3806 tests pass; the 10 failures are all `case_4` of `shell_wrapper::unix_tests::*` (nu-shell case; `nu` isn't installed in this runner; same failures occur on `main`). Also manually verified that a fresh `wt switch --create` against a project config with `[post-create]` loads cleanly with no unknown-field warning and the hook fires as `post-start`. ## Follow-up Per @max-sixty: in a couple of weeks, once a release with both-names-work is out and users have had a chance to upgrade, the docs flip is straightforward (most of it is in `src/cli/mod.rs`'s `after_long_help` and the doc-sync test propagates). Re #2838. Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.7 <[email protected]>
Two small follow-ups noticed while fixing the test comments in #2877. **`pre_create` docstring was wrong.** It read "Commands to execute before worktree creation (blocking)", but `pre-start` actually runs *after* the worktree is created (`switch.rs:1142` executes it against "the new worktree (created just above)", and the renamed test below asserts the worktree exists after a failing pre-start). The wrong wording entered in #2840 as part of the mechanical `pre-start` → `pre-create` rename — someone "corrected" the docstring to match the new name. #2857 reverted the name but left the docstring. Restoring "after worktree creation (blocking, fail-fast)" matches the actual behavior, `docs/content/hook.md` ("Runs once when a new worktree is created, blocking…"), and the parallel `post_create` docstring. Because `HooksConfig` derives `JsonSchema`, this docstring is user-visible in generated schema descriptions. **`test_user_post_start_hook_failure` was misnamed.** The fixture is `[pre-start]`, the comment and assertion describe a failing pre-start, and only the function name said post-start. Renamed to `test_user_pre_start_hook_failure` along with its snapshot name and file (`git mv`, so the rename shows as a rename). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Phase 1 of the staged hook rename tracked in #2838: the worktree-creation hooks
pre-start/post-startbecomepre-create/post-create. The old names keep working with no deprecation warning yet (Phase 2, months out, adds the warning).What changes
pre-create/post-createare canonical everywhere: theHookTypeenum, theHooksConfigserde fields, thewt hookCLI, completion, and all docs.migrate_content()rewritespre-start/post-startconfig keys to-createbefore serde, andparse_hook_typeaccepts the old CLI names as silent aliases.wt config updaterewrites them on disk;wt config showshows the migration diff.wt hook <type>execution andwt hook showboth accept the old names; completion and--helpadvertise only the canonical names.detect_deprecations()flags the old keys soupdate/showact on them, butformat_deprecation_warnings()stays silent (Phase 2 adds the warning). A new empty-warnings guard incheck_and_migratekeeps a-start-only config from emitting a stray hint.post-createmachinery is removed: the fatalPOST_CREATE_REMOVED_MSGload error, the vestigialHooksConfig.post_createmerge-fold, andfind_post_create_from_doc.post-createis reclaimed as the canonical background creation hook.Semantic flip
Before v0.32.0, the key
post-createnamed a blocking hook. It now names the background one.Since v0.44.0, a pre-0.32.0
post-createconfig is a fatal load error on thecheck_and_migratepaths:ProjectConfig::loadand user/system config loading, which fire on essentially everywtcommand. A repo carrying one has been unusable ever since. The one path that skips that check isproject_config_at_ref(the base-ref read behindwt switch --create), which applies only structural migration. A pre-0.32.0post-createsurviving solely on a base ref, never checked out into a worktree, would now load as a background hook rather than folding into the blockingpre-start. That edge case is accepted: oncepost-createis valid again, reclaiming the name and detecting the dead key are mutually exclusive.Reviewing this diff
205 files, but the substance is ~36 files under
src/. The rest is regenerated snapshots and auto-synced doc mirrors. Start with:src/config/deprecation.rs— detection (find_renamed_hook_key), migration (rename_hook_key), removal of the fatal block, the empty-warnings guard, and theDEPRECATED_SECTION_KEYSentries that stop unknown-field detection from flagging the migrated keys.src/config/hooks.rs,src/git/mod.rs— the serde field and enum renames.src/config/project.rs—ProjectConfig::loaddeserializescheck_and_migrate's migrated content, so a current-worktree config using the old keys loads into the canonical fields.src/cli/hook.rs,src/commands/hook_commands.rs,src/completion.rs,src/main.rs— the CLI alias layer;wt hook showaccepts the old type names as hidden value-parser aliases.src/cli/mod.rs— thewt hookdocs, including the soft-deprecation note linking Tracking: rename creation hooks pre-start/post-start → pre-create/post-create #2838.The ~93 modified snapshots also pick up deterministic env-block lines (
GIT_*: "",LLVM_PROFILE_FILE) that pre-existing snapshots already carry. That is stale-snapshot drift surfaced by the regeneration, not a behavior change.Testing
Full suite green (3799 tests). New coverage:
snapshot_migrate_start_to_create(migration preserves value shape and position),test_deprecated_start_hook_key_runs_silentlyandtest_standalone_hook_start_alias_runs_silently(old config and CLI names run with no warning),test_config_show_displays_start_hook_migration(config showreveals the diff without an "unknown field" warning), andtest_hook_show_accepts_deprecated_start_hooks(a current-worktree config using the old keys loads, andwt hook showtakes both the canonical and the deprecated type arguments).Part of #2838.
🤖 Generated with Claude Code