Skip to content

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

Refactor switch output for shell integration states

Maximilian Roos65a7f19501a0
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index f70b11aa8..fe2c05f65 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -352,17 +352,20 @@ pub fn handle_switch_output(
)))?;
}
SwitchResult::Existing(path) => {
- // Check if we can cd or if shell integration is at least configured
- let is_configured = Shell::is_integration_configured().ok().flatten().is_some();
+ let path_display = format_path_for_display(path);
- if is_directive_mode || has_execute_command || is_configured {
- // Shell integration active, --execute provided, or configured - show success
+ if is_directive_mode || has_execute_command {
+ // Shell integration active or --execute provided - show success
super::print(success_message(format_switch_success_message(
branch, path, false, None, None,
)))?;
+ } else if Shell::is_integration_configured().ok().flatten().is_some() {
+ // Shell configured but not active (ran binary directly, e.g. `command wt`)
+ super::print(warning_message(cformat!(
+ "Worktree for <bold>{branch}</> at <bold>{path_display}</>; cannot cd (binary invoked directly)"
+ )))?;
} else {
// Shell integration not configured - show warning and setup hint
- let path_display = format_path_for_display(path);
super::print(warning_message(cformat!(
"Worktree for <bold>{branch}</> at <bold>{path_display}</>; cannot cd (no shell integration)"
)))?;
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 3a3e68b10..43886e022 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -103,8 +103,9 @@ fn test_switch_existing_branch(mut repo: TestRepo) {
/// Test switching to existing worktree when shell integration is configured but not active.
///
/// When shell integration is configured in user's rc files (e.g., .zshrc) but the user
-/// runs `wt switch` directly (not through the shell wrapper), we should show success
-/// with a hint to use `wt switch` for cd, not a warning about missing shell integration.
+/// runs `wt` binary directly (not through the shell wrapper), show a warning that explains
+/// the actual situation: shell IS configured, but cd can't happen because we're not
+/// running through the shell function.
#[rstest]
fn test_switch_existing_with_shell_integration_configured(mut repo: TestRepo) {
use std::fs;
@@ -121,8 +122,8 @@ fn test_switch_existing_with_shell_integration_configured(mut repo: TestRepo) {
)
.unwrap();
- // Switch to existing worktree - should show success + "cd with: wt switch" hint
- // NOT the warning about "cannot cd (no shell integration)"
+ // Switch to existing worktree - should show warning about binary invoked directly
+ // (different from "no shell integration" warning when shell is not configured at all)
snapshot_switch(
"switch_existing_with_shell_configured",
&repo,
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 97f68f4e5..5a1ff7e6c 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
@@ -6,6 +6,7 @@ info:
- switch
- shell-configured
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -16,12 +17,15 @@ info:
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
----- stdout -----
----- stderr -----
-✅ Switched to worktree for shell-configured at [REPO].shell-configured
+🟡 Worktree for shell-configured at [REPO].shell-configured; cannot cd (binary invoked directly)