Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(alias): let a template's own `dry_run` binding take `--dry-run <value>` (#4058)

Worktrunk Botd0fbe2c4aa96
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d7af8a45..e62976c2a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
### Fixed
+- **An alias that binds `dry_run` can take `--dry-run <value>`**: `wt <alias> --dry-run <value>` answered the retired-flag error even when the alias's own template referenced `{{ dry_run }}`, while `--dry-run=<value>` bound normally — so one flag behaved two ways. Both value-taking spellings now bind for an alias that references the name, matching how `--help` and `--yes` already yield to a template that binds them. A bare `--dry-run` with no value still errors, since forwarding it into `{{ args }}` would leave `dry_run` unset and run the live command; the message names `--dry-run=1`. ([#4058](https://github.com/max-sixty/worktrunk/pull/4058))
+
- **`wt merge` no longer runs `post-commit` in a worktree the user never chose**: the merge removes the worktree that hook is anchored on before the hook starts, so the pipeline was spawned into an emptied path. Where the worktree sat inside the repository, git discovery walked up from there and the hook's commands ran in the primary worktree; anywhere else they didn't run at all, and the only record was a log file nothing reads. The merge now prints `▲ Skipped post-commit: …` naming that worktree, and points at `pre-remove` for work that must finish there. `--no-remove`, merging on the target branch, `wt step commit`, and `wt step squash` still run it. ([#4049](https://github.com/max-sixty/worktrunk/pull/4049))
- **`wt config plugins claude uninstall` / `codex uninstall` no longer report success over a marketplace that is still there**: to tell an already-removed marketplace from a removal that failed, uninstall used to read the harness's own config file. A file or key the harness renamed reads as an absence there, so every failed removal would have printed `Plugin & marketplace removed` and exited 0. It now asks `claude` / `codex plugin marketplace list --json`, and an answer it cannot read leaves the harness's error standing. ([#4048](https://github.com/max-sixty/worktrunk/pull/4048))
diff --git a/src/commands/alias.rs b/src/commands/alias.rs
index ca3098b2b..02021b11b 100644
--- a/src/commands/alias.rs
+++ b/src/commands/alias.rs
@@ -173,7 +173,20 @@ impl AliasOptions {
/// instead. The parser raises an actionable error pointing at the new
/// subcommand rather than silently forwarding the flag into `{{ args }}`.
/// The bail fires only outside `literal_mode`, so `wt alias -- --dry-run`
- /// still forwards `--dry-run` as a positional.
+ /// still forwards `--dry-run` as a positional. A template that references
+ /// `dry_run` owns the flag's value-taking spellings — the same deference
+ /// `--help` gets in `try_intercept_alias_help` and `--yes` gets from the
+ /// `--KEY` rule above — so `--dry-run <value>` and `--dry-run=<value>`
+ /// bind there rather than erroring. Only the `=` form used to bind, since
+ /// the bail matches the whole token, so one flag behaved two ways.
+ ///
+ /// A bare `--dry-run` at end of args bails either way. The general `--KEY`
+ /// rule would forward it into `{{ args }}` with `dry_run` left unset, so a
+ /// `{% if dry_run %}` template would run the live command with nothing on
+ /// stderr — the silent forward this bail exists to prevent, on the one flag
+ /// whose purpose is not doing the thing. The referenced case gets its own
+ /// message naming `--dry-run=1`, because `wt config alias dry-run <name>`
+ /// previews the alias instead of passing the value the user is after.
///
/// Hyphens in variable names are canonicalized to underscores before
/// lookup and storage (minijinja parses `{{ my-var }}` as subtraction),
@@ -212,9 +225,16 @@ impl AliasOptions {
continue;
}
if arg == "--dry-run" {
- bail!(
- "--dry-run is no longer supported; use `wt config alias dry-run {name}` instead"
- );
+ if !referenced_vars.contains("dry_run") {
+ bail!(
+ "--dry-run is no longer supported; use `wt config alias dry-run {name}` instead"
+ );
+ }
+ if i + 1 == args.len() {
+ bail!(
+ "--dry-run at the end of the command binds nothing, leaving `dry_run` unset in {name}; pass `--dry-run=1` instead"
+ );
+ }
}
if let Some(rest) = arg.strip_prefix("--") {
if let Some((key, value)) = rest.split_once('=') {
@@ -1409,6 +1429,63 @@ cmd = [
assert_snapshot!(parse(&["deploy", "--dry-run"]).unwrap_err(), @"--dry-run is no longer supported; use `wt config alias dry-run deploy` instead");
}
+ /// A template that references `{{ dry_run }}` owns the flag's value-taking
+ /// spellings: the retired-flag bail steps aside and both bind, matching
+ /// `--help`'s deference to a `help` binding and `--yes`'s to a `yes` one.
+ /// A bare `--dry-run` at end of args still errors — see
+ /// `test_parse_dry_run_bare_errors_when_referenced`.
+ #[test]
+ fn test_parse_dry_run_binds_when_referenced() {
+ use insta::assert_debug_snapshot;
+ assert_debug_snapshot!(parse_with(&["deploy", "--dry-run", "1"], &["dry_run"]).unwrap(), @r#"
+ AliasOptions {
+ name: "deploy",
+ vars: [
+ (
+ "dry_run",
+ "1",
+ ),
+ ],
+ positional_args: [],
+ }
+ "#);
+ // The `=` form already bound before this — the bail matches the whole
+ // token — so the two spellings agree either way.
+ assert_debug_snapshot!(parse_with(&["deploy", "--dry-run=1"], &["dry_run"]).unwrap(), @r#"
+ AliasOptions {
+ name: "deploy",
+ vars: [
+ (
+ "dry_run",
+ "1",
+ ),
+ ],
+ positional_args: [],
+ }
+ "#);
+ }
+
+ /// The general `--KEY` end-of-args rule would forward a bare `--dry-run`
+ /// into `{{ args }}` with `dry_run` unset, so `{% if dry_run %}` would run
+ /// the live command silently. The bail holds there for a referenced
+ /// template too, with a message naming the spelling that does bind.
+ #[test]
+ fn test_parse_dry_run_bare_errors_when_referenced() {
+ use insta::{assert_debug_snapshot, assert_snapshot};
+ assert_snapshot!(parse_with(&["deploy", "--dry-run"], &["dry_run"]).unwrap_err(), @"--dry-run at the end of the command binds nothing, leaving `dry_run` unset in deploy; pass `--dry-run=1` instead");
+ // A value-taking spelling is unaffected, and `--` still forwards the
+ // token verbatim rather than erroring.
+ assert_debug_snapshot!(parse_with(&["deploy", "--", "--dry-run"], &["dry_run"]).unwrap(), @r#"
+ AliasOptions {
+ name: "deploy",
+ vars: [],
+ positional_args: [
+ "--dry-run",
+ ],
+ }
+ "#);
+ }
+
/// `referenced_vars_for_config` unions across pipeline steps so a var
/// referenced in any one command is a binding candidate for the whole
/// alias.