Repository navigation
fix: pass directive file through wt step aliases - #2077
Merged
Merged
Conversation
Inside a `wt step <alias>` body, an inner `wt switch --create` would print the "shell integration not installed" hint and drop its `cd` directive, so workflows like "move staged changes into a new worktree" couldn't actually leave the user in the new worktree from a single alias. Aliases are explicit, named, user-authorised commands — user-config aliases are trusted and project-config aliases already require approval — so let the alias subprocess inherit `WORKTRUNK_DIRECTIVE_FILE` from the parent shell wrapper. Inner `wt` invocations then write `cd '/path'` into the parent's directive file, which the shell wrapper sources after `wt` exits. `wt step for-each` keeps scrubbing the env var: it's not the same trust model as a named alias (it can run across every worktree) and the issue explicitly scoped this to aliases. Closes #2075 Co-Authored-By: Claude <[email protected]>
The Windows CI path (e.g. `D:\a\worktrunk\...\wt.exe`) contains `\a` and `\w`, which are invalid escape sequences inside a TOML basic string. Double the backslashes so they parse as literal characters. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
|
also add a short note to the alias docs that also add a Todo re unifying hook and alias execution so they both pass through |
Adds a one-line note to the `wt step` aliases docs explaining that an inner `wt switch` inside an alias body lands the parent shell in the new worktree, and a TODO in `step_alias` flagging that hook execution still scrubs the directive file env var so the same passthrough should eventually be unified across hooks and aliases. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Collaborator
Author
|
Done in fe4f494:
Required CI is green and |
This was referenced Apr 11, 2026
This was referenced Apr 11, 2026
max-sixty
pushed a commit
that referenced
this pull request
Apr 11, 2026
…2083) ## Summary Adds a tested recipe to the Aliases section of `docs/content/extending.md` showing three `[aliases]` entries that compose `wt switch --create` with git's stash/diff plumbing to carry in-progress changes into a new worktree: - `move-changes` — stashes staged + unstaged + untracked, creates the new worktree, and pops the stash with `--execute`. Source becomes clean. - `copy-changes` — same push, plus `git stash apply --index --quiet` to restore the source before the new worktree pops. Both sides end up with identical state. - `copy-staged` — writes `git diff --cached` to a tempfile and applies it with `git apply --index` in the new worktree, so the source is untouched and staged/unstaged overlap is handled. Each alias takes the target branch via `--var to=feature-xyz`. Because an inner `wt switch --create` inside an alias body propagates its `cd` to the parent shell (#2077), they drop you in the new worktree directly. The content was worked out and tested end-to-end in the issue thread (`git status --porcelain` verified on both sides for clean / staged+unstaged+untracked / untracked-only / empty-staged scenarios). Closes #938. ## Test plan - [ ] `cargo test --test integration test_command_pages_and_skill_files_are_in_sync` — keep `skills/worktrunk/reference/extending.md` in sync - [ ] `pre-commit run --all-files` — lints - [ ] Visual check of the rendered Aliases section on the docs dev server Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
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.
Problem
Inside a
wt step <alias>body, an innerwt switch --createprints the "shell integration not installed" warning and drops itscddirective — so alias-driven workflows like "move staged changes into a new worktree" can't actually leave the user in the new worktree. Users have to chainwt step <alias> && wt switch <branch>so the trailingwt switchruns in the parent shell withWORKTRUNK_DIRECTIVE_FILEstill intact.Root cause:
run_command_streaminginsrc/commands/for_each.rsunconditionally scrubsWORKTRUNK_DIRECTIVE_FILEfrom child env, which is right forwt step for-each(arbitrary script across every worktree) but wrong forwt step <alias>(explicit, named, user-authorised command).Solution
Give
run_command_streaminganOption<&Path>directive-file parameter:Nonekeeps the current scrub;Some(path)setsWORKTRUNK_DIRECTIVE_FILE=pathon the child.step_aliasreads the parent shell'sWORKTRUNK_DIRECTIVE_FILEonce viastd::env::var_osand passes it through to each alias command.step_for_eachpassesNoneto keep its old behaviour.Safety: aliases are user-authorised (user-config trusted; project-config requires approval), and an alias body is already arbitrary shell that can
cd/rm/execanything locally — letting it ask the parent shell tocdis strictly less powerful than what the body can already do. Inline comment atsrc/commands/alias.rsrecords this reasoning.Testing
test_alias_passes_directive_file_to_subprocessintests/integration_tests/step_alias.rs— writes a user-config alias that invokes the testwtbinary aswt switch --create alias-created, runs the outerwt stepwithWORKTRUNK_DIRECTIVE_FILEset, and asserts the directive file ends up containingcd '…alias-created…'and no "shell integration" warning on stderr.step_aliastests, all 19directivestests, and all 11for_eachtests pass locally.Closes #2075