Skip to content

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

fix: improve shell integration warning for Windows path expansion (#447)

Maximilian Roos73d532744a02
diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rs
index 07810c526..70ace7f25 100644
--- a/src/output/shell_integration.rs
+++ b/src/output/shell_integration.rs
@@ -117,8 +117,28 @@ fn compute_shell_warning_reason_inner(
) -> String {
if is_configured {
if explicit_path {
- // Invoked with explicit path - shell wrapper won't intercept this binary
- cformat!("ran <bold>{invoked}</>; shell integration wraps <bold>{wraps}</>")
+ // Invoked with explicit path - shell wrapper won't intercept this binary.
+ let invoked_name = std::path::Path::new(invoked)
+ .file_name()
+ .and_then(|s| s.to_str())
+ .unwrap_or(invoked);
+
+ // Check if the only difference is .exe suffix (case-insensitive for Windows)
+ let invoked_lower = invoked_name.to_lowercase();
+ let wraps_lower = wraps.to_lowercase();
+ if invoked_lower == format!("{wraps_lower}.exe") {
+ // Windows .exe mismatch - give targeted advice
+ cformat!(
+ "ran <bold>{invoked_name}</>; use <bold>{wraps}</> (without .exe) for auto-cd"
+ )
+ } else if invoked_name == wraps {
+ // Filename matches but full path differs - show full path for clarity
+ // (e.g., "./target/debug/wt" vs "wt" - the path IS the useful info)
+ cformat!("ran <bold>{invoked}</>; shell integration wraps <bold>{wraps}</>")
+ } else {
+ // Different binary name - show just the filename
+ cformat!("ran <bold>{invoked_name}</>; shell integration wraps <bold>{wraps}</>")
+ }
} else {
"shell requires restart".to_string()
}
@@ -400,11 +420,44 @@ mod tests {
}
#[test]
- fn test_compute_shell_warning_reason_explicit_path() {
- // Shell integration configured + explicit path -> "ran X; wraps Y"
+ fn test_compute_shell_warning_reason_explicit_path_same_name() {
+ // When filename matches wraps, show full path (the path IS the useful info)
let reason = compute_shell_warning_reason_inner(true, true, "./target/debug/wt", "wt");
assert!(reason.contains("./target/debug/wt"));
+ assert!(reason.contains("wraps"));
+ }
+
+ #[test]
+ fn test_compute_shell_warning_reason_explicit_path_different_binary() {
+ // When invoked binary differs from wrapped binary, show both
+ let reason = compute_shell_warning_reason_inner(true, true, "/usr/local/bin/git-wt", "wt");
+ assert!(reason.contains("git-wt"));
assert!(reason.contains("wt"));
+ assert!(reason.contains("wraps"));
+ }
+
+ #[test]
+ #[cfg(windows)]
+ fn test_compute_shell_warning_reason_windows_exe_suffix() {
+ // Windows: invoked as git-wt.exe, wraps git-wt -> targeted .exe message
+ let reason = compute_shell_warning_reason_inner(
+ true,
+ true,
+ r"C:\Users\user\AppData\Local\Microsoft\WinGet\Packages\git-wt.exe",
+ "git-wt",
+ );
+ // Should extract filename and give targeted advice
+ assert!(reason.contains("git-wt.exe"));
+ assert!(reason.contains("without .exe"));
+ assert!(!reason.contains(r"C:\Users")); // No full path
+ }
+
+ #[test]
+ #[cfg(windows)]
+ fn test_compute_shell_warning_reason_windows_exe_case_insensitive() {
+ // Windows paths are case-insensitive
+ let reason = compute_shell_warning_reason_inner(true, true, r"C:\path\to\WT.EXE", "wt");
+ assert!(reason.contains("without .exe"));
}
#[test]
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index da0d02bb6..8b0f56963 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -22,6 +22,7 @@ fn snapshot_switch_from_dir(test_name: &str, repo: &TestRepo, args: &[&str], cwd
snapshot_switch_impl(test_name, repo, args, false, Some(cwd), None);
}
+#[cfg(not(windows))]
fn snapshot_switch_with_shell(test_name: &str, repo: &TestRepo, args: &[&str], shell: &str) {
snapshot_switch_impl(test_name, repo, args, false, None, Some(shell));
}
@@ -108,7 +109,11 @@ fn test_switch_existing_branch(mut repo: TestRepo) {
/// Since tests run via `cargo test`, argv[0] contains a path (`target/debug/wt`), which
/// triggers the "explicit path" code path. The warning explains that shell integration
/// won't intercept explicit paths.
+///
+/// Skipped on Windows: the binary is `wt.exe` so a different (more targeted) warning is
+/// shown ("use wt without .exe"). Windows-specific behavior is tested in unit tests.
#[rstest]
+#[cfg(not(windows))]
fn test_switch_existing_with_shell_integration_configured(mut repo: TestRepo) {
use std::fs;
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_existing_with_shell_configured.snap b/tests/snapshots/integration__integration_tests__switch__switch_existing_with_shell_configured.snap
index 4eb609cb8..e069e5496 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_existing_with_shell_configured.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_existing_with_shell_configured.snap
@@ -1,5 +1,6 @@
---
source: tests/integration_tests/switch.rs
+assertion_line: 53
info:
program: wt
args:
@@ -14,6 +15,7 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ GIT_FETCH_ARGS: ""
GIT_TERMINAL_PROMPT: "0"
HOME: "[TEST_HOME]"
LANG: C
@@ -22,6 +24,7 @@ info:
RUST_LOG: warn
SHELL: /bin/zsh
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"