Skip to content

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

feat: Display --execute command in switch output

Maximilian Roosc417ee6b7f67
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 2f99fbd35..dcff26f77 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -75,6 +75,8 @@ pub fn handle_switch_output(
branch: &str,
execute: Option<&str>,
) -> Result<(), GitError> {
+ use worktrunk::styling::{CYAN, format_with_gutter};
+
// Set target directory for command execution
super::change_directory(result.path())?;
@@ -83,6 +85,10 @@ pub fn handle_switch_output(
// Execute command if provided
if let Some(cmd) = execute {
+ // Show what command is being executed (matches post-create/post-start format)
+ super::progress(format!("πŸ”„ {CYAN}Executing (--execute):{CYAN:#}"))?;
+ super::progress(format_with_gutter(cmd, "", None))?;
+
super::execute(cmd)?;
} else {
// No execute command: show shell integration hint
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap
index 3e9e7dc98..4dcf5d5dd 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap
@@ -1,8 +1,11 @@
---
source: tests/integration_tests/shell_wrapper.rs
-expression: normalized.as_ref()
+expression: output.normalized().as_ref()
---
βœ… Created new worktree for fish-multiline at [TMPDIR]/test-repo.fish-multiline
+πŸ”„ Executing (--execute):
+  echo 'line 1'; echo 'line 2'; echo 'line 3'
+
line 1
line 2
line 3
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_bash.snap
index 9bb4c47c2..8bef55bb1 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_bash.snap
@@ -3,4 +3,7 @@ source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized().as_ref()
---
βœ… Created new worktree for test-exec at [TMPDIR]/test-repo.test-exec
+πŸ”„ Executing (--execute):
+  echo executed
+
executed
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_fish.snap
index 9bb4c47c2..8bef55bb1 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_fish.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_fish.snap
@@ -3,4 +3,7 @@ source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized().as_ref()
---
βœ… Created new worktree for test-exec at [TMPDIR]/test-repo.test-exec
+πŸ”„ Executing (--execute):
+  echo executed
+
executed
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap
index 301be4a41..8bef55bb1 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap
@@ -1,6 +1,9 @@
---
source: tests/integration_tests/shell_wrapper.rs
-expression: normalized.as_ref()
+expression: output.normalized().as_ref()
---
βœ… Created new worktree for test-exec at [TMPDIR]/test-repo.test-exec
+πŸ”„ Executing (--execute):
+  echo executed
+
executed
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap b/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
index febba510e..135e87bad 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__execute_with_post_start.snap
@@ -18,7 +18,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp78KaQw/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpE0F9E8/test-config.toml
---
success: true
exit_code: 0
@@ -27,5 +27,8 @@ exit_code: 0
  echo 'Background task' > background.txt
βœ… Created new worktree for feature at [REPO].feature
+πŸ”„ Executing (--execute):
+  echo 'Execute flag' > execute.txt
+
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap
index a69027df0..2c4d8159d 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_creates_file.snap
@@ -18,11 +18,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfuR0Av/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpnFxFGm/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Created new worktree for file-test at [REPO].file-test
+πŸ”„ Executing (--execute):
+  echo 'test content' > test.txt
+
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_existing.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_existing.snap
index 4aee16c41..0c97242a1 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_existing.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_existing.snap
@@ -17,11 +17,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpG1OQqC/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpB10CRl/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Switched to worktree for existing-exec at [WORKTREE_EXISTING_EXEC]
+πŸ”„ Executing (--execute):
+  echo 'existing worktree' > existing.txt
+
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_failure.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_failure.snap
index 8670c160a..08c8a0674 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_failure.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_failure.snap
@@ -18,12 +18,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpnsD0ds/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpw4Og5c/test-config.toml
---
success: false
exit_code: 1
----- stdout -----
βœ… Created new worktree for fail-test at [REPO].fail-test
+πŸ”„ Executing (--execute):
+  exit 1
+
----- stderr -----
Command failed with exit code: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_multiline.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_multiline.snap
index 9023da248..d47966871 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_multiline.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_multiline.snap
@@ -18,12 +18,17 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpcj4xNM/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp2CpQIq/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Created new worktree for multiline-test at [REPO].multiline-test
+πŸ”„ Executing (--execute):
+  echo 'line1'
+  echo 'line2'
+  echo 'line3'
+
----- stderr -----
line1
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap
index 61ea6b78d..6c21c03e3 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_success.snap
@@ -18,12 +18,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmprttGVs/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpC1eteo/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Created new worktree for exec-test at [REPO].exec-test
+πŸ”„ Executing (--execute):
+  echo 'test output'
+
----- stderr -----
test output
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap
index 1754e8c85..5724099b4 100644
Binary files a/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap and b/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap differ
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
index b4bfca301..90fc5fd90 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_execute_still_runs.snap
@@ -19,12 +19,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpd89MIY/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpzDqH7z/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Created new worktree for no-hooks-test at [REPO].no-hooks-test
+πŸ”„ Executing (--execute):
+  echo 'execute command runs'
+
----- stderr -----
execute command runs
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
index 723622449..25e0c3985 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_hooks_existing.snap
@@ -18,12 +18,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpjCYNYD/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpblVMRT/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
βœ… Switched to worktree for existing-no-hooks at [WORKTREE_EXISTING_NO_HOOKS]
+πŸ”„ Executing (--execute):
+  echo 'execute still runs'
+
----- stderr -----
execute still runs