Repository navigation
Add a retry-setup hint when pre-start fails during wt switch --create - #4705
Conversation
When pre-start fails, wt switch --create leaves the new worktree behind, and switching to it again only runs post-switch, so nothing re-runs setup. The failure now adds a hint naming the command that does: ↳ To retry setup, run wt -C <path> hook pre-start Closes #4143
worktrunk-bot
left a comment
There was a problem hiding this comment.
The suggested wt hook pre-start doesn't re-run setup with the variables the failed run had. build_manual_hook_template_vars (in src/commands/hook_commands.rs) binds base to the current worktree's branch and base_worktree_path to the current worktree. Run via -C <new worktree>, both point at the new worktree. The switch passed the real base branch and the source worktree through with_base_strs, plus pr_number/pr_url from with_pr, and none of those reach the manual run. So a pre-start hook like cp {{ base_worktree_path }}/.env . copies the new worktree onto itself, and one that branches on {{ pr_number }} takes a different path. For those configs, "To retry setup" points at a command that runs different setup.
Hooks that don't reference those variables, including the documented wt step copy-ignored pattern, are unaffected. So this is a judgment call on how exact the hint should be. One option is to append --base=…/--base_worktree_path=… shorthand (and the PR vars) when the plan's templates reference them. That makes the hint longer, and it depends on shorthand bindings taking precedence over the manual defaults, which I haven't checked. The other is to word the hint so it doesn't promise an identical retry. I'm leaving that choice to a maintainer rather than pushing either one.
|
don't we generally dissuade having multiple lines of hints? |
Hints with several suggestions share one line joined by a semicolon, with the more commonly needed command last for easy copying: ↳ To skip pre-start hooks, re-run with --no-hooks; to retry setup, run wt -C <path> hook pre-start
|
Yes — the output guidelines combine multiple suggestions into one hint with a semicolon, with the more commonly needed command last. Pushed 20b6157, which folds it into a single line: The line is fairly long. If that's too much, the other option is to drop the |
…ing hint (#4725) `writing-user-outputs` explained how to join two suggestions into one hint, but never said to join them instead of stacking a second hint line. This edit states that rule. Without it, a session that loaded the skill still wrote a second `hint_message` line on #4705, and only maintainer review caught it, since no test or lint checks how many hint lines a message has. With the rule, a second suggestion goes into the existing hint with a semicolon, most commonly needed command last. The rule covers suggestions only. Context hints already sit beside a suggestion hint in `GitError::WorktreeRemovalFailed` ("Remaining in directory") and `GitError::WorktreeCreationFailed` ("Failed command"), and those stay as they are. <details><summary>Evidence</summary> - The session that wrote #4705's two-line hint was mention run 41976059785. It loaded `writing-user-outputs` before writing the change. - A maintainer then asked on #4705 whether multiple hint lines are generally dissuaded. The bot folded the hint into one line in 20b6157. - Observation logged in the review-runs tracker #4657. </details> --------- Co-authored-by: worktrunk-bot <[email protected]>
…4841) When `wt switch --create` failed after `git worktree add -b` had already written the branch, the leftover-branch hint suggested a bare `wt switch <branch>`. Following it created the worktree at the `worktree-path` template location instead of the `--path` given, and skipped the `--execute` command. `WorktreeCreationFailed` is raised in `execute_switch`, whose errors weren't wrapped in `WithSwitchSuggestion` the way `plan_switch`'s are, so the hint had no flags to draw on. `SwitchPipeline::run` now wraps that variant with the switch context, and the hint applies it. The hint becomes e.g. `wt switch stranded --path=blocked/stranded --execute='echo hi' -- extra`. `--create` is not in the context, so it stays out of the suggestion, which is correct now that the branch exists. Other `execute_switch` errors pass through unchanged, so their context chains and downcasts are untouched. `test_switch_create_leftover_branch_hint_keeps_flags` fails on `main` (the hint ends at `wt switch stranded`) and passes with this change. The existing leftover-branch test still covers the no-flags form. #4705 adds a hint for pre-start failures on the same `execute_switch` path. If it suggests a `wt switch` command, it can reuse this wrapping. Closes #4839 — automated triage --------- Co-authored-by: worktrunk-bot <[email protected]>
|
@worktrunk-bot two changes to the hint:
|
When pre-start fails during `wt switch --create`, the branch and worktree
are kept, so re-running the switch with --no-hooks stops at "Branch already
exists". The hint now names only the retry command.
A manual `wt hook pre-start` binds base and base_worktree_path to the
worktree it runs in and has no PR, so the retry passes the switch's own
base, base_worktree_path, pr_number and pr_url as --KEY=VALUE — only those
the frozen pre-start templates reference, since an unreferenced key would
forward into {{ args }}.
|
I made both changes in ed7b7b7:
A new integration test sets up a hook that copies from |
When
pre-startfails duringwt switch --create, the error now names the command that retries setup, with the same variables the switch used:The failed switch leaves the new branch and worktree in place, and a later
wt switch <branch>only runspost-switchbecause the worktree already exists, so nothing re-runs setup unless the user knows to. This failure is the one point where wt knows setup didn't finish, so the hint goes here instead of on the laterBranch already existscollision (#4172 put it there, so it showed on every ordinary branch conflict).At this site the hint replaces the
--no-hookssuggestion. Re-runningwt switch --create --no-hookswould stop atBranch … already exists, which is the trap #4143 reported. Every other hook failure still shows the--no-hookshint as before.A manual
wt hook pre-startbindsbaseandbase_worktree_pathto the worktree it runs in and knows no PR. So the retry passes the switch's own--base,--base-worktree-path,--pr-number, and--pr-url, but only those the frozen pre-start templates reference, becausewt hookforwards an unreferenced--KEY=VALUEinto{{ args }}. With that, a hook likecp {{ base_worktree_path }}/.env .reruns the same setup. A hook that references none of them gets a barewt -C <path> hook pre-start.Verified by:
test_user_pre_start_failure_retry_reruns_same_setup: a hook copies a file from{{ base_worktree_path }}and fails; running the hinted command afterwards copies from the original worktree. Without the flag, the manual run would read from the new worktree.pre-startfailure integration snapshots.Closes #4143