Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(switch): enrich error hints with --execute context (#1064)
Maximilian Roos51b5f6ef5fe8
diff --git a/src/commands/handle_switch.rs b/src/commands/handle_switch.rsindex 0abadc0bc..d3a43fdfc 100644--- a/src/commands/handle_switch.rs+++ b/src/commands/handle_switch.rs@@ -6,7 +6,7 @@ use std::path::Path;use anyhow::Context;use worktrunk::HookType;use worktrunk::config::{UserConfig, expand_template};-use worktrunk::git::Repository;+use worktrunk::git::{GitError, Repository, SwitchSuggestionCtx};use worktrunk::styling::{eprintln, info_message};use super::command_approval::approve_hooks;@@ -147,8 +147,31 @@ pub fn handle_switch(let repo = Repository::current().context("Failed to switch worktree")?;+ // Build switch suggestion context for enriching error hints with --execute/trailing args.+ // Without this, errors like "branch already exists" would suggest `wt switch <branch>`+ // instead of the full `wt switch <branch> --execute=<cmd> -- <args>`.+ let suggestion_ctx = execute.map(|exec| {+ let escaped = shlex::try_quote(exec).unwrap_or(exec.into());+ SwitchSuggestionCtx {+ extra_flags: vec![format!("--execute={escaped}")],+ trailing_args: execute_args.to_vec(),+ }+ });+// Validate FIRST (before approval) - fails fast if branch doesn't exist, etc.- let plan = plan_switch(&repo, branch, create, base, clobber, config)?;+ let plan = plan_switch(&repo, branch, create, base, clobber, config).map_err(|err| {+ match suggestion_ctx {+ Some(ref ctx) => match err.downcast::<GitError>() {+ Ok(git_err) => GitError::WithSwitchSuggestion {+ source: Box::new(git_err),+ ctx: ctx.clone(),+ }+ .into(),+ Err(err) => err,+ },+ None => err,+ }+ })?;// "Approve at the Gate": collect and approve hooks upfront// This ensures approval happens once at the command entry pointdiff --git a/src/git/error.rs b/src/git/error.rsindex 1a336bf10..a44faaf22 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -105,6 +105,43 @@ pub struct FailedCommand {pub exit_info: String,}+/// Extra CLI context for enriching `wt switch` suggestions in error hints.+///+/// When a switch error is raised deep in the planning layer, the error only knows+/// the branch name. The command handler wraps the error with this context so the+/// Display impl can produce a fully copy-pasteable suggestion including flags like+/// `--execute` and trailing args.+#[derive(Debug, Clone)]+pub struct SwitchSuggestionCtx {+ pub extra_flags: Vec<String>,+ pub trailing_args: Vec<String>,+}++impl SwitchSuggestionCtx {+ /// Append extra flags and trailing args to a suggested command string.+ ///+ /// Clap's `#[arg(last = true)]` on `execute_args` means `--` always routes+ /// to execute_args, so a dash-prefixed branch can't coexist with `--execute`+ /// via the CLI. The suggested command therefore never has a pre-existing `--`+ /// separator when this context is applied.+ fn apply(&self, cmd: String) -> String {+ let mut result = cmd;+ // Flags are pre-escaped at construction (handle_switch.rs uses shlex::try_quote)+ for flag in &self.extra_flags {+ result.push(' ');+ result.push_str(flag);+ }+ if !self.trailing_args.is_empty() {+ result.push_str(" --");+ for arg in &self.trailing_args {+ result.push(' ');+ result.push_str(&escape(Cow::Borrowed(arg.as_str())));+ }+ }+ result+ }+}+/// Domain errors for git and worktree operations.////// This enum provides structured error data that can be pattern-matched and tested.@@ -272,13 +309,33 @@ pub enum GitError {Other {message: String,},++ /// Wrapper that enriches an inner error's switch suggestions with CLI context.+ ///+ /// The inner error renders normally, but any `wt switch` suggestion includes+ /// the extra flags and trailing args from the context.+ WithSwitchSuggestion {+ source: Box<GitError>,+ ctx: SwitchSuggestionCtx,+ },}impl std::error::Error for GitError {}-impl std::fmt::Display for GitError {- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+impl GitError {+ /// Format with optional switch suggestion context.+ ///+ /// Most variants ignore `ctx`. The three that render `wt switch` suggestions+ /// (`BranchAlreadyExists`, `BranchNotFound`, `WorktreePathExists`) use it+ /// to append extra flags and trailing args for a copy-pasteable command.+ fn fmt_with_ctx(+ &self,+ f: &mut std::fmt::Formatter<'_>,+ ctx: Option<&SwitchSuggestionCtx>,+ ) -> std::fmt::Result {match self {+ GitError::WithSwitchSuggestion { source, ctx } => source.fmt_with_ctx(f, Some(ctx)),+GitError::DetachedHead { action } => {let message = match action {Some(action) => format!("Cannot {action}: not on a branch (detached HEAD)"),@@ -325,7 +382,10 @@ impl std::fmt::Display for GitError {}GitError::BranchAlreadyExists { branch } => {- let switch_cmd = suggest_command("switch", &[branch], &[]);+ let mut switch_cmd = suggest_command("switch", &[branch], &[]);+ if let Some(ctx) = ctx {+ switch_cmd = ctx.apply(switch_cmd);+ }write!(f,"{}\n{}",@@ -342,7 +402,10 @@ impl std::fmt::Display for GitError {} => {let list_cmd = suggest_command("list", &[], &["--branches", "--remotes"]);let hint = if *show_create_hint {- let create_cmd = suggest_command("switch", &[branch], &["--create"]);+ let mut create_cmd = suggest_command("switch", &[branch], &["--create"]);+ if let Some(ctx) = ctx {+ create_cmd = ctx.apply(create_cmd);+ }cformat!("To create a new branch, run <bright-black>{create_cmd}</>; to list branches, run <bright-black>{list_cmd}</>")@@ -438,7 +501,10 @@ impl std::fmt::Display for GitError {} else {&["--clobber"]};- let switch_cmd = suggest_command("switch", &[branch], flags);+ let mut switch_cmd = suggest_command("switch", &[branch], flags);+ if let Some(ctx) = ctx {+ switch_cmd = ctx.apply(switch_cmd);+ }write!(f,"{}\n{}",@@ -805,6 +871,12 @@ impl std::fmt::Display for GitError {}}+impl std::fmt::Display for GitError {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ self.fmt_with_ctx(f, None)+ }+}+/// Semantic errors that require special handling in main.rs////// Most errors use anyhow::bail! with formatted messages. This enum is only@@ -997,7 +1069,7 @@ mod tests {};assert_snapshot!(err.to_string(), @"[31m✗[39m [31mDirectory already exists: [1m/some/path[22m[39m- [2m↳[22m [2mTo remove manually, run [90mrm -rf /some/path[39m; to overwrite (with backup), run [90mwt switch feature --create --clobber[39m[22m+ [2m↳[22m [2mTo remove manually, run [90mrm -rf /some/path[39m; to overwrite (with backup), run [90mwt switch --create --clobber feature[39m[22m");}@@ -1337,7 +1409,7 @@ mod tests {};let display = err.to_string();assert!(display.contains("Cannot remove worktree"));- assert!(display.contains("wt remove feature --force"));+ assert!(display.contains("wt remove --force feature"));assert!(display.contains("to lose uncommitted changes, run"));}@@ -1487,4 +1559,92 @@ mod tests {assert!(display.contains("main"));// Empty output shouldn't cause issues}++ #[test]+ fn snapshot_with_switch_suggestion_branch_already_exists() {+ let err = GitError::WithSwitchSuggestion {+ source: Box::new(GitError::BranchAlreadyExists {+ branch: "emails".into(),+ }),+ ctx: SwitchSuggestionCtx {+ extra_flags: vec!["--execute=claude".into()],+ trailing_args: vec!["Check my emails".into()],+ },+ };+ assert_snapshot!(err.to_string(), @"+ [31m✗[39m [31mBranch [1memails[22m already exists[39m+ [2m↳[22m [2mTo switch to the existing branch, run without [90m--create[39m: [90mwt switch emails --execute=claude -- 'Check my emails'[39m[22m+ ");+ }++ #[test]+ fn snapshot_with_switch_suggestion_worktree_path_exists() {+ let err = GitError::WithSwitchSuggestion {+ source: Box::new(GitError::WorktreePathExists {+ branch: "emails".into(),+ path: PathBuf::from("/tmp/repo.emails"),+ create: true,+ }),+ ctx: SwitchSuggestionCtx {+ extra_flags: vec!["--execute=claude".into()],+ trailing_args: vec!["Check my emails".into()],+ },+ };+ assert_snapshot!(err.to_string(), @"+ [31m✗[39m [31mDirectory already exists: [1m/tmp/repo.emails[22m[39m+ [2m↳[22m [2mTo remove manually, run [90mrm -rf /tmp/repo.emails[39m; to overwrite (with backup), run [90mwt switch --create --clobber emails --execute=claude -- 'Check my emails'[39m[22m+ ");+ }++ #[test]+ fn snapshot_with_switch_suggestion_no_trailing_args() {+ let err = GitError::WithSwitchSuggestion {+ source: Box::new(GitError::BranchAlreadyExists {+ branch: "emails".into(),+ }),+ ctx: SwitchSuggestionCtx {+ extra_flags: vec!["--execute=claude".into()],+ trailing_args: vec![],+ },+ };+ assert_snapshot!(err.to_string(), @"+ [31m✗[39m [31mBranch [1memails[22m already exists[39m+ [2m↳[22m [2mTo switch to the existing branch, run without [90m--create[39m: [90mwt switch emails --execute=claude[39m[22m+ ");+ }++ #[test]+ fn snapshot_with_switch_suggestion_branch_not_found() {+ let err = GitError::WithSwitchSuggestion {+ source: Box::new(GitError::BranchNotFound {+ branch: "emails".into(),+ show_create_hint: true,+ }),+ ctx: SwitchSuggestionCtx {+ extra_flags: vec!["--execute=claude".into()],+ trailing_args: vec!["Check my emails".into()],+ },+ };+ assert_snapshot!(err.to_string(), @"+ [31m✗[39m [31mNo branch named [1memails[22m[39m+ [2m↳[22m [2mTo create a new branch, run [90mwt switch --create emails --execute=claude -- 'Check my emails'[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+ ");+ }++ #[test]+ fn test_with_switch_suggestion_unwrapped_errors_unaffected() {+ // Non-switch-suggestion errors should be completely unaffected by the wrapper+ let inner = GitError::DetachedHead {+ action: Some("merge".into()),+ };+ let wrapped = GitError::WithSwitchSuggestion {+ source: Box::new(inner.clone()),+ ctx: SwitchSuggestionCtx {+ extra_flags: vec!["--execute=claude".into()],+ trailing_args: vec!["Check my emails".into()],+ },+ };+ // Errors without switch suggestions should render identically+ assert_eq!(inner.to_string(), wrapped.to_string());+ }}diff --git a/src/git/mod.rs b/src/git/mod.rsindex a78751587..3d9c0ea35 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -45,6 +45,8 @@ pub use error::{// Platform-specific reference type (PR vs MR)RefContext,RefType,+ // CLI context for enriching switch suggestions in error hints+ SwitchSuggestionCtx,WorktrunkError,// Error inspection functionsadd_hook_skip_hint,diff --git a/src/styling/suggest.rs b/src/styling/suggest.rsindex 3a43c221e..2d1edfb1c 100644--- a/src/styling/suggest.rs+++ b/src/styling/suggest.rs@@ -9,7 +9,7 @@//! let branch = "feature";//! let cmd = suggest_command("remove", &[branch], &["--force"]);//! println!("{}", hint_message(cformat!("To force delete, run <bright-black>{cmd}</>")));-//! // → ↳ To force delete, run wt remove feature --force+//! // → ↳ To force delete, run wt remove --force feature//! ```//!//! Handles shell escaping and `--` separator for args starting with `-`:@@ -17,9 +17,9 @@//! ```//! use worktrunk::styling::suggest_command;//!-//! // Branch starting with dash gets -- separator+//! // Branch starting with dash gets -- separator; flags stay before --//! let cmd = suggest_command("remove", &["-bugfix"], &["--force"]);-//! assert_eq!(cmd, "wt remove -- -bugfix --force");+//! assert_eq!(cmd, "wt remove --force -- -bugfix");//!//! // Spaces are quoted//! let cmd = suggest_command("remove", &["my feature"], &[]);@@ -31,7 +31,7 @@ use std::borrow::Cow;/// Build a suggested command string for hints.///-/// Returns a copy-pasteable command like `wt remove feature --force`.+/// Returns a copy-pasteable command like `wt remove --force feature`.////// # Arguments///@@ -60,6 +60,10 @@ use std::borrow::Cow;pub fn suggest_command(subcommand: &str, args: &[&str], flags: &[&str]) -> String {let mut parts = vec!["wt".to_string(), subcommand.to_string()];+ // Flags go before positional args (and before any -- separator)+ // so they're always parsed as flags, not positional arguments.+ parts.extend(flags.iter().map(|s| s.to_string()));+// Check if any arg starts with dash (needs -- separator)let needs_separator = args.iter().any(|arg| arg.starts_with('-'));let mut separator_inserted = false;@@ -73,7 +77,6 @@ pub fn suggest_command(subcommand: &str, args: &[&str], flags: &[&str]) -> Strinparts.push(escape(Cow::Borrowed(*arg)).into_owned());}- parts.extend(flags.iter().map(|s| s.to_string()));parts.join(" ")}@@ -93,7 +96,7 @@ mod tests {fn test_command_with_flag() {assert_eq!(suggest_command("remove", &["feature"], &["--force"]),- "wt remove feature --force"+ "wt remove --force feature");}@@ -101,7 +104,7 @@ mod tests {fn test_command_with_multiple_flags() {assert_eq!(suggest_command("remove", &["feature"], &["--force", "--no-delete-branch"]),- "wt remove feature --force --no-delete-branch"+ "wt remove --force --no-delete-branch feature");}@@ -133,7 +136,7 @@ mod tests {fn test_branch_starting_with_dash_and_flag() {assert_eq!(suggest_command("remove", &["-bugfix"], &["--force"]),- "wt remove -- -bugfix --force"+ "wt remove --force -- -bugfix");}diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snapindex 9987ec725..ab9d8f2ed 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__branch_not_found.snap@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rsexpression: err.to_string()---[31m✗[39m [31mNo branch named [1mnonexistent[22m[39m-[2m↳[22m [2mTo create a new branch, run [90mwt switch nonexistent --create[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create nonexistent[39m; to list branches, run [90mwt list --branches --remotes[39m[22mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snapindex 6232f1d7e..c61aa418f 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__uncommitted_changes_with_force_hint.snap@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rsexpression: err.to_string()---[31m✗[39m [31mCannot remove worktree: [1mfeature-branch[22m has uncommitted changes[39m-[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [90mwt remove feature-branch --force[39m[22m+[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [90mwt remove --force feature-branch[39m[22mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snapindex bfdc909e6..b5206b5f8 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_exists.snap@@ -3,4 +3,4 @@ source: tests/integration_tests/git_error_display.rsexpression: err.to_string()---[31m✗[39m [31mDirectory already exists: [1m/tmp/repo.feature[22m[39m-[2m↳[22m [2mTo remove manually, run [90mrm -rf /tmp/repo.feature[39m; to overwrite (with backup), run [90mwt switch feature --clobber[39m[22m+[2m↳[22m [2mTo remove manually, run [90mrm -rf /tmp/repo.feature[39m; to overwrite (with backup), run [90mwt switch --clobber feature[39m[22mdiff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex e3b413c9d..b0eac95fd 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -87,6 +87,36 @@ fn test_switch_create_existing_branch_error(mut repo: TestRepo) {);}+/// When --execute is passed and the branch already exists, the error hint should+/// include --execute and trailing args in the suggested command.+#[rstest]+fn test_switch_create_existing_with_execute(mut repo: TestRepo) {+ repo.add_worktree("emails");++ snapshot_switch(+ "switch_create_existing_with_execute",+ &repo,+ &[+ "--create",+ "--execute=claude",+ "emails",+ "--",+ "Check my emails",+ ],+ );+}++/// When --execute is passed and the branch doesn't exist (without --create),+/// the "create" suggestion should include --execute and trailing args.+#[rstest]+fn test_switch_nonexistent_with_execute(repo: TestRepo) {+ snapshot_switch(+ "switch_nonexistent_with_execute",+ &repo,+ &["--execute=claude", "nonexistent", "--", "Check my emails"],+ );+}+#[rstest]fn test_switch_create_with_remote_branch_only(#[from(repo_with_remote)] repo: TestRepo) {// Create a branch on the remote only (no local branch)diff --git a/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap b/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snapindex 4b29446cf..55be49252 100644--- a/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap+++ b/tests/snapshots/integration__integration_tests__directives__switch_without_directive_file.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mNo branch named [1mmy-feature[22m[39m-[2m↳[22m [2mTo create a new branch, run [90mwt switch my-feature --create[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create my-feature[39m; to list branches, run [90mwt list --branches --remotes[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap b/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snapindex 26514c104..fe9a5b27d 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_invalid_target.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mNo branch named [1mnonexistent-branch[22m[39m-[2m↳[22m [2mTo create a new branch, run [90mwt switch nonexistent-branch --create[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create nonexistent-branch[39m; to list branches, run [90mwt list --branches --remotes[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snapindex 6e17a1083..b3c8ede9d 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_branch_not_fully_merged.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-unmerged[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-unmerged -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-unmerged[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap b/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snapindex 67680c992..5ec3bc4fd 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_branch_only_unmerged.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -40,4 +41,4 @@ exit_code: 0----- stderr -----[2m○[22m No worktree found for branch [1mfeature-unmerged[22m[2m○[22m Branch [1mfeature-unmerged[22m retained; has unmerged changes-[2m↳[22m [2mTo delete the unmerged branch, run [90mwt remove feature-unmerged -D[39m[22m+[2m↳[22m [2mTo delete the unmerged branch, run [90mwt remove -D feature-unmerged[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snapindex 7a6811830..a4a4b3323 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_dirty_target.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove worktree: [1mfeature-dirty[22m has uncommitted changes[39m-[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [90mwt remove feature-dirty --force[39m[22m+[2m↳[22m [2mCommit or stash changes first, or to lose uncommitted changes, run [90mwt remove --force feature-dirty[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snapindex 94a797732..cff2722bc 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_main.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-a[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-a -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-a[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snapindex 0e9216e58..1be5ec583 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_by_name_from_other_worktree.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-b[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-b -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-b[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snapindex f19e47dd8..c3755fa02 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_detached_worktree_in_multi.snap@@ -30,6 +30,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -40,7 +41,7 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-a[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-a -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-a[39m[22m[2m○[22m No worktree found for branch [1mfeature-b[22m[2m○[22m Branch [1mfeature-b[22m retained; has unmerged changes-[2m↳[22m [2mTo delete the unmerged branch, run [90mwt remove feature-b -D[39m[22m+[2m↳[22m [2mTo delete the unmerged branch, run [90mwt remove -D feature-b[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snapindex 58f859a68..ef4cf5cfc 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_force_with_modified_files.snap@@ -30,6 +30,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -40,4 +41,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-modified[22m worktree (--force) in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-modified -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-modified[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap b/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snapindex 681d78a37..8750cbcc9 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_foreground_unmerged.snap@@ -30,6 +30,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -41,4 +42,4 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving [1mfeature-unmerged-fg[22m worktree...[39m[32m✓ Removed [1mfeature-unmerged-fg[22m worktree[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-unmerged-fg -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-unmerged-fg[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snapindex d7d198df0..29afc987e 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_including_current.snap@@ -31,6 +31,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -41,10 +42,10 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-b[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-b -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-b[39m[22m[36m◎ Removing [1mfeature-c[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-c -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-c[39m[22m[36m◎ Removing [1mfeature-a[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-a -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-a[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snapindex 3d50cbfac..959af3ab0 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_multiple_worktrees.snap@@ -31,6 +31,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -41,8 +42,8 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mfeature-a[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-a -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-a[39m[22m[36m◎ Removing [1mfeature-b[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-b -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-b[39m[22m[36m◎ Removing [1mfeature-c[22m worktree in background[39m-[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove feature-c -D[39m[22m+[2m↳[22m [2mBranch unmerged; to delete, run [90mwt remove -D feature-c[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap b/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snapindex 97455caf7..fa26d624f 100644--- a/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap+++ b/tests/snapshots/integration__integration_tests__security__error_message_with_directive_not_executed.snap@@ -30,6 +30,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -40,4 +41,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mNo branch named [1m__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6[22m[39m-[2m↳[22m [2mTo create a new branch, run [90mwt switch '__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6' --create[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create '__WORKTRUNK_EXEC__echo PWNED > /tmp/hacked6'[39m; to list branches, run [90mwt list --branches --remotes[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snapnew file mode 100644index 000000000..b07cc8ed6--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_existing_with_execute.snap@@ -0,0 +1,47 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - "--execute=claude"+ - emails+ - "--"+ - Check my emails+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[31m✗[39m [31mBranch [1memails[22m already exists[39m+[2m↳[22m [2mTo switch to the existing branch, run without [90m--create[39m: [90mwt switch emails --execute=claude -- 'Check my emails'[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snapindex 3a7c1b947..0360cd767 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied.snap@@ -30,6 +30,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -40,4 +41,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mDirectory already exists: [1m_REPO_.occupied-branch[22m[39m-[2m↳[22m [2mTo remove manually, run [90mrm -rf _REPO_.occupied-branch[39m; to overwrite (with backup), run [90mwt switch occupied-branch --create --clobber[39m[22m+[2m↳[22m [2mTo remove manually, run [90mrm -rf _REPO_.occupied-branch[39m; to overwrite (with backup), run [90mwt switch --create --clobber occupied-branch[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snapindex 79aa91363..093c651e4 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap@@ -29,6 +29,7 @@ info:WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -39,4 +40,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mNo branch named [1mnonexistent-branch[22m[39m-[2m↳[22m [2mTo create a new branch, run [90mwt switch nonexistent-branch --create[39m; to list branches, run [90mwt list --branches --remotes[39m[22m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create nonexistent-branch[39m; to list branches, run [90mwt list --branches --remotes[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snapnew file mode 100644index 000000000..835a0d21b--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_with_execute.snap@@ -0,0 +1,46 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--execute=claude"+ - nonexistent+ - "--"+ - Check my emails+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[31m✗[39m [31mNo branch named [1mnonexistent[22m[39m+[2m↳[22m [2mTo create a new branch, run [90mwt switch --create nonexistent --execute=claude -- 'Check my emails'[39m; to list branches, run [90mwt list --branches --remotes[39m[22m