Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Merge stderr to stdout for consistent output
Maximilian Roos692dbe02651e
diff --git a/templates/fish.fish b/templates/fish.fishindex d1ad5c208..c9e737c4e 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -34,6 +34,8 @@ if type -q {{ cmd_prefix }}# Use psub (process substitution) to preserve NUL bytes# Command substitution $(...) strips NUL bytes, but psub preserves them+ # Redirect stderr to stdout (2>&1) to capture child process output+ # (child output goes to stderr per output system architecture)# Redirect directly from psub output, and save exit code to temp fileset -l chunk_count 0while read -z chunk@@ -65,7 +67,7 @@ if type -q {{ cmd_prefix }}endprintf '%s\n' $chunkend- end < (begin; command $_WORKTRUNK_CMD $argv; echo $status > $exit_code_file; end | psub)+ end < (begin; command $_WORKTRUNK_CMD $argv 2>&1; echo $status > $exit_code_file; end | psub)if test $debug_mode -eq 1echo "[DEBUG] Finished reading, total chunks: $chunk_count" >&2diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 7d1ec9971..45450db5a 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -130,7 +130,22 @@ fn build_shell_script(shell: &str, repo: &TestRepo, subcommand: &str, args: &[&s}script.push('\n');- script+ // Merge stderr to stdout to simulate real terminal behavior+ // In a real terminal, both streams interleave naturally by the OS.+ // The .output() method captures them separately, so we merge them here+ // to preserve temporal locality (output appears when operations complete, not batched at the end)+ match shell {+ "fish" => {+ // Fish uses begin...end for grouping+ // Note: This exposes a Fish wrapper buffering bug where child output appears out of order+ // (see templates/fish.fish - psub causes buffering). Tests document current behavior.+ format!("begin\n{}\nend 2>&1", script)+ }+ _ => {+ // bash/zsh use parentheses for subshell grouping+ format!("( {} ) 2>&1", script)+ }+ }}/// Execute a command through a shell wrapper@@ -170,11 +185,9 @@ fn exec_through_wrapper_from(.output().unwrap_or_else(|_| panic!("Failed to execute {} wrapper", shell));- // Combine stdout and stderr as users would see in a terminal- let mut combined = String::from_utf8_lossy(&output.stdout).to_string();- if !output.stderr.is_empty() {- combined.push_str(&String::from_utf8_lossy(&output.stderr));- }+ // With 2>&1 in the script, both streams are merged to stdout+ // This preserves temporal locality (output appears when operations complete)+ let combined = String::from_utf8_lossy(&output.stdout).to_string();ShellOutput {combined,diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_bash.snapnew file mode 100644index 000000000..a40888224--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_bash.snap@@ -0,0 +1,6 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+β [32mAlready on [1m[32mmain[0m, nothing to merge[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_fish.snapnew file mode 100644index 000000000..a40888224--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_already_on_target_fish.snap@@ -0,0 +1,6 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+β [32mAlready on [1m[32mmain[0m, nothing to merge[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_bash.snapnew file mode 100644index 000000000..d8b334233--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_bash.snap@@ -0,0 +1,17 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mPushing 1 commit to [1m[36mmain[0m @ 986886a[0m++* [33m986886a[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-nohooks[m[33m)[m Add feature++ feature.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mCleaning up worktree...[0m++β [32mReturned to primary at [TMPDIR]/test-repo[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_fish.snapnew file mode 100644index 000000000..2409f6dc9--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_no_hooks_fish.snap@@ -0,0 +1,16 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mPushing 1 commit to [1m[36mmain[0m @ 986886a[0m++* [33m986886a[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-nohooks[m[33m)[m Add feature++ feature.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mCleaning up worktree...[0m+β [32mReturned to primary at [TMPDIR]/test-repo[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_bash.snapnew file mode 100644index 000000000..15d90f29e--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_bash.snap@@ -0,0 +1,32 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mPushing 1 commit to [1m[36mmain[0m @ c6eae6a[0m++* [33mc6eae6a[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-post[m[33m)[m Add feature++ feature.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mRunning post-merge command [1m[36mcleanup[0m:[0m+[40m [0m echo 'β Cleaning up temporary files'++β Cleaning up temporary files++π [36mRunning post-merge command [1m[36mdeploy[0m:[0m+[40m [0m echo 'β Triggering deployment pipeline'++β Triggering deployment pipeline++π [36mRunning post-merge command [1m[36mnotify[0m:[0m+[40m [0m echo 'β Merge successful - notifying team'++β Merge successful - notifying team++π [36mCleaning up worktree...[0m++β [32mReturned to primary at [TMPDIR]/test-repo[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_fish.snapnew file mode 100644index 000000000..f72e369d3--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_post_merge_hooks_fish.snap@@ -0,0 +1,28 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mValidating merge...[0m+π [36mRebasing onto [1m[36mmain[0m...[0m+π [36mPushing 1 commit to [1m[36mmain[0m @ c6eae6a[0m++* [33mc6eae6a[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature-post[m[33m)[m Add feature++ feature.txt | 1 [32m+[m+ 1 file changed, 1 insertion(+)++β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0m+π [36mRunning post-merge command [1m[36mcleanup[0m:[0m+[40m [0m echo 'β Cleaning up temporary files'++π [36mRunning post-merge command [1m[36mdeploy[0m:[0m+[40m [0m echo 'β Triggering deployment pipeline'++π [36mRunning post-merge command [1m[36mnotify[0m:[0m+[40m [0m echo 'β Merge successful - notifying team'++π [36mCleaning up worktree...[0m+β [32mReturned to primary at [TMPDIR]/test-repo[0m+β Cleaning up temporary files+β Triggering deployment pipeline+β Merge successful - notifying teamdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snapindex 96d8b4f3b..d438c6728 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_bash.snap@@ -6,11 +6,11 @@ expression: output.normalized().as_ref()π [36mRunning pre-merge command [1m[36mformat[0m:[0m[40m [0m echo 'β Code formatting check passed'+β Code formatting check passedπ [36mRunning pre-merge command [1m[36mtest[0m:[0m[40m [0m echo 'β Test suite failed: 3 tests failing' && exit 1-β Code formatting check passedβ Test suite failed: 3 tests failingβ [31mPre-merge command failed: [1m[31mtest[0m[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_fish.snapindex 8e873bebb..d438c6728 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_fish.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_fish.snap@@ -6,10 +6,11 @@ expression: output.normalized().as_ref()π [36mRunning pre-merge command [1m[36mformat[0m:[0m[40m [0m echo 'β Code formatting check passed'+β Code formatting check passed+π [36mRunning pre-merge command [1m[36mtest[0m:[0m[40m [0m echo 'β Test suite failed: 3 tests failing' && exit 1-β Code formatting check passedβ Test suite failed: 3 tests failingβ [31mPre-merge command failed: [1m[31mtest[0m[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snapindex f985b23ec..8ffd4517b 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap@@ -6,14 +6,17 @@ expression: output.normalized().as_ref()π [36mRunning pre-merge command [1m[36mformat[0m:[0m[40m [0m echo 'β Code formatting check passed'+β Code formatting check passedπ [36mRunning pre-merge command [1m[36mlint[0m:[0m[40m [0m echo 'β Linting passed - no warnings'+β Linting passed - no warningsπ [36mRunning pre-merge command [1m[36mtest[0m:[0m[40m [0m echo 'β All 47 tests passed in 2.3s'+β All 47 tests passed in 2.3sπ [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 1 commit to [1m[36mmain[0m @ d067f01[0m@@ -27,6 +30,3 @@ expression: output.normalized().as_ref()π [36mCleaning up worktree...[0mβ [32mReturned to primary at [TMPDIR]/test-repo[0m-β Code formatting check passed-β Linting passed - no warnings-β All 47 tests passed in 2.3sdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_fish.snapindex 16c6bf991..95365dfc9 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_fish.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_fish.snap@@ -6,12 +6,18 @@ expression: output.normalized().as_ref()π [36mRunning pre-merge command [1m[36mformat[0m:[0m[40m [0m echo 'β Code formatting check passed'+β Code formatting check passed+π [36mRunning pre-merge command [1m[36mlint[0m:[0m[40m [0m echo 'β Linting passed - no warnings'+β Linting passed - no warnings+π [36mRunning pre-merge command [1m[36mtest[0m:[0m[40m [0m echo 'β All 47 tests passed in 2.3s'+β All 47 tests passed in 2.3s+π [36mRebasing onto [1m[36mmain[0m...[0mπ [36mPushing 1 commit to [1m[36mmain[0m @ d067f01[0m@@ -23,6 +29,3 @@ expression: output.normalized().as_ref()β [32mPushed to [1m[32mmain[0m (1 commit, 1 file, [32m+1[0m) [0mπ [36mCleaning up worktree...[0mβ [32mReturned to primary at [TMPDIR]/test-repo[0m-β Code formatting check passed-β Linting passed - no warnings-β All 47 tests passed in 2.3sdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snapindex 1ede37f78..98117f88b 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap@@ -5,10 +5,12 @@ expression: output.normalized().as_ref()π [36mExecuting (post-create):[0m[40m [0m echo 'Installing dependencies...'+Installing dependencies...π [36mExecuting (post-create):[0m[40m [0m echo 'Building project...'+Building project...π [36mStarting (background):[0m[40m [0m echo 'Starting dev server on port 3000'@@ -17,5 +19,3 @@ expression: output.normalized().as_ref()[40m [0m echo 'Watching for file changes'β [32mCreated new worktree for [1m[32mfeature-hooks[0m at [TMPDIR]/test-repo.feature-hooks[0m-Installing dependencies...-Building project...diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snapindex a83a945fa..98117f88b 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap@@ -5,9 +5,13 @@ expression: output.normalized().as_ref()π [36mExecuting (post-create):[0m[40m [0m echo 'Installing dependencies...'+Installing dependencies...+π [36mExecuting (post-create):[0m[40m [0m echo 'Building project...'+Building project...+π [36mStarting (background):[0m[40m [0m echo 'Starting dev server on port 3000'@@ -15,5 +19,3 @@ expression: output.normalized().as_ref()[40m [0m echo 'Watching for file changes'β [32mCreated new worktree for [1m[32mfeature-hooks[0m at [TMPDIR]/test-repo.feature-hooks[0m-Installing dependencies...-Building project...diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_bash.snapnew file mode 100644index 000000000..6c313484f--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_bash.snap@@ -0,0 +1,11 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mStarting (background):[0m+[40m [0m sleep 0.1 && echo 'Server output'++π [36mStarting (background):[0m+[40m [0m sleep 0.1 && echo 'Watcher output'++β [32mCreated new worktree for [1m[32mfeature-logs[0m at [TMPDIR]/test-repo.feature-logs[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_fish.snapnew file mode 100644index 000000000..6c313484f--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_log_paths_fish.snap@@ -0,0 +1,11 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+π [36mStarting (background):[0m+[40m [0m sleep 0.1 && echo 'Server output'++π [36mStarting (background):[0m+[40m [0m sleep 0.1 && echo 'Watcher output'++β [32mCreated new worktree for [1m[32mfeature-logs[0m at [TMPDIR]/test-repo.feature-logs[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_bash.snapnew file mode 100644index 000000000..6d6577aca--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_bash.snap@@ -0,0 +1,5 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+β [32mCreated new worktree for [1m[32mfeature[0m at [TMPDIR]/test-repo.feature[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_fish.snapnew file mode 100644index 000000000..6d6577aca--- /dev/null+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_uncommitted_changes_fish.snap@@ -0,0 +1,5 @@+---+source: tests/integration_tests/shell_wrapper.rs+expression: output.normalized().as_ref()+---+β [32mCreated new worktree for [1m[32mfeature[0m at [TMPDIR]/test-repo.feature[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 562f99bd0..cd61879ed 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -15,7 +15,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpuVpY4n/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp6EmXqA/test-config.toml---success: trueexit_code: 0@@ -56,6 +56,8 @@ if type -q wt# Use psub (process substitution) to preserve NUL bytes# Command substitution $(...) strips NUL bytes, but psub preserves them+ # Redirect stderr to stdout (2>&1) to capture child process output+ # (child output goes to stderr per output system architecture)# Redirect directly from psub output, and save exit code to temp fileset -l chunk_count 0while read -z chunk@@ -87,7 +89,7 @@ if type -q wtendprintf '%s\n' $chunkend- end < (begin; command $_WORKTRUNK_CMD $argv; echo $status > $exit_code_file; end | psub)+ end < (begin; command $_WORKTRUNK_CMD $argv 2>&1; echo $status > $exit_code_file; end | psub)if test $debug_mode -eq 1echo "[DEBUG] Finished reading, total chunks: $chunk_count" >&2