Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Align Windows and Unix behavior for --execute and hints (#168)
Maximilian Roos43fd5e3b93cb
diff --git a/src/main.rs b/src/main.rsindex fc620c776..5a0847c21 100644--- a/src/main.rs+++ b/src/main.rs@@ -474,7 +474,11 @@ fn enhance_and_exit_error(err: clap::Error) -> ! {// Enhance `wt switch` missing argument error with shortcut hints.// Safe in directive mode: hints go to stderr, only stdout is eval'd.- if err.kind() == ErrorKind::MissingRequiredArgument && format!("{err}").contains("wt switch") {+ // Check for both "wt switch" and "wt.exe switch" (Windows)+ let err_str = format!("{err}");+ let is_switch_missing_arg = err.kind() == ErrorKind::MissingRequiredArgument+ && (err_str.contains("wt switch") || err_str.contains("wt.exe switch"));+ if is_switch_missing_arg {eprint!("{}", err.render().ansi());ceprintln!("<green,bold>Quick switches:</>");ceprintln!(" <cyan,bold>wt switch ^</> default branch's worktree");diff --git a/src/output/interactive.rs b/src/output/interactive.rsindex fe352aa79..1b9d91119 100644--- a/src/output/interactive.rs+++ b/src/output/interactive.rs@@ -89,10 +89,22 @@ impl OutputHandler for InteractiveOutput {#[cfg(not(unix))]fn execute(&mut self, command: String) -> anyhow::Result<()> {- // On non-Unix platforms, fall back to spawn-and-wait- // This uses the shell abstraction (Git Bash if available)+ use worktrunk::git::WorktrunkError;++ // On non-Unix platforms, fall back to spawn-and-wait.+ // This uses the shell abstraction (Git Bash if available).let exec_dir = self.target_dir.as_deref().unwrap_or_else(|| Path::new("."));- execute_streaming(&command, exec_dir, false, None)?;+ if let Err(err) = execute_streaming(&command, exec_dir, false, None) {+ // If the command failed with an exit code, just exit with that code.+ // This matches Unix behavior where exec() replaces the process and+ // the shell's exit code becomes the process exit code (no error message).+ if let Some(WorktrunkError::ChildProcessExited { code, .. }) =+ err.downcast_ref::<WorktrunkError>()+ {+ std::process::exit(*code);+ }+ return Err(err);+ }Ok(())}diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 3e1746136..3a3e68b10 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -243,8 +243,6 @@ fn test_switch_execute_creates_file(repo: TestRepo) {);}-/// Skipped on Windows: error message format differs (`exit status: 1` shown explicitly).-#[cfg_attr(windows, ignore)]#[rstest]fn test_switch_execute_failure(repo: TestRepo) {snapshot_switch(@@ -584,10 +582,7 @@ fn test_switch_ping_pong_realistic(repo: TestRepo) {}/// Test that `wt switch` without arguments shows helpful hints about shortcuts.-///-/// Skipped on Windows: Hints display differently on Windows.#[rstest]-#[cfg_attr(windows, ignore)]fn test_switch_missing_argument_shows_hints(repo: TestRepo) {// Run switch with no arguments - should show clap error plus hintssnapshot_switch("switch_missing_argument_hints", &repo, &[]);