Repository navigation
fix(templates): don't suggest a different variable for an unset Worktrunk variable - #4440
Merged
Merged
Conversation
…runk variable
A post-switch hook that reads {{ target }} fails when switching to a
detached worktree, because the operation leaves target unset. The
undefined-variable error then suggested target_worktree_path, steering
the user to a different value instead of a {% if target %} guard. Skip
the suggestion when the missing name is one Worktrunk defines in some
scope; the Did-you-mean hint stays for genuine typos.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a template reads a Worktrunk variable that the current operation left unset, the undefined-variable error no longer offers a "Did you mean" suggestion. Before this change it suggested a similarly named variable, which points the user at a different value.
The reachable case is a
post-switchhook containingecho {{ target }}, run when switching to a detached worktree.TemplateVars::for_post_switchleavestargetunset there but setstarget_worktree_path. Rendering fails withundefined variable target, and #4350's suggestion logic matchedtarget_worktree_path(Jaro–Winkler ≈ 0.86, above the 0.7 cutoff). The right fix for the user is a{% if target %}guard, not a rename.base/base_worktree_pathhave the same shape.build_undefined_vars_errornow skips the suggestion when the missing name is invars_available_infor some hook scope. Typos of real names (brnch→branch) still get the hint, and the "Available variables" list is unchanged.test_unset_worktrunk_variable_gets_no_suggestionfailed before the fix (Some("target_worktree_path")) and passes now. The existing suggestion tests inconfig::expansionand the template-related integration tests also pass.