Skip to content

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

fix: Improve merge command output visibility

Maximilian Roosaaa9979e68d3
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index cf39128b0..477bd131f 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -237,6 +237,10 @@ fn handle_commit_changes(
let formatted_message = format_commit_message_for_display(&commit_message);
print!("{}", format_with_gutter(&formatted_message, "", None));
+ // Flush stdout to ensure message appears immediately (before any subsequent stderr output)
+ use std::io::Write;
+ let _ = std::io::stdout().flush();
+
// Commit
repo.run_command(&["commit", "-m", &commit_message])
.map_err(|e| GitError::CommandFailed(format!("Failed to commit: {}", e)))?;
@@ -313,6 +317,10 @@ fn handle_squash(target_branch: &str) -> Result<Option<usize>, GitError> {
let formatted_message = format_commit_message_for_display(&commit_message);
print!("{}", format_with_gutter(&formatted_message, "", None));
+ // Flush stdout to ensure message appears immediately (before any subsequent stderr output)
+ use std::io::Write;
+ let _ = std::io::stdout().flush();
+
// Reset to merge base (soft reset stages all changes)
repo.run_command(&["reset", "--soft", &merge_base])
.map_err(|e| GitError::CommandFailed(format!("Failed to reset to merge base: {}", e)))?;
@@ -360,7 +368,7 @@ fn run_pre_merge_checks(
use worktrunk::styling;
eprintln!(
- "πŸ”„ {CYAN}Running pre-merge check '{name}':{CYAN:#}",
+ "πŸ”„ {CYAN}Running pre-merge check {CYAN_BOLD}{name}{CYAN_BOLD:#}:{CYAN:#}",
name = prepared.name
);
eprint!("{}", format_with_gutter(&prepared.expanded, "", None)); // Gutter at column 0
@@ -427,7 +435,10 @@ fn execute_post_merge_commands(
// Execute each command sequentially in the main worktree
for prepared in commands {
use std::io::Write;
- eprintln!("πŸ”„ {CYAN}Executing (post-merge):{CYAN:#}");
+ eprintln!(
+ "πŸ”„ {CYAN}Running post-merge command {CYAN_BOLD}{name}{CYAN_BOLD:#}:{CYAN:#}",
+ name = prepared.name
+ );
eprint!("{}", format_with_gutter(&prepared.expanded, "", None));
let _ = std::io::stderr().flush();
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
index 12a952d97..bc41103af 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_failure.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmptfDC49/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQHujNe/test-config.toml
---
success: true
exit_code: 0
@@ -36,6 +36,6 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Executing (post-merge):
+πŸ”„ Running post-merge command cmd:
  exit 1
🟑 Command cmd failed: Command failed with exit code: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
index 59abe40e0..8c2870d4e 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_named.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpAoqM3d/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqxip1K/test-config.toml
---
success: true
exit_code: 0
@@ -36,7 +36,7 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Executing (post-merge):
+πŸ”„ Running post-merge command deploy:
  echo 'Deploying branch feature' > deploy.txt
-πŸ”„ Executing (post-merge):
+πŸ”„ Running post-merge command notify:
  echo 'Merge to main complete' > notify.txt
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
index 737be50a3..9250b7b35 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_success.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp1YR6XY/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpMcVP4R/test-config.toml
---
success: true
exit_code: 0
@@ -36,5 +36,5 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Executing (post-merge):
+πŸ”„ Running post-merge command cmd:
  echo 'merged feature to main' > post-merge-ran.txt
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_combined_output.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_combined_output.snap
index f127bf59d..d6e3aabfe 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_combined_output.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_combined_output.snap
@@ -4,11 +4,11 @@ expression: output
---
Exit code: 0
πŸ”„ Validating merge...
-πŸ”„ Running pre-merge check 'first':
+πŸ”„ Running pre-merge check first:
  echo 'STDOUT-FROM-FIRST' && echo 'STDERR-FROM-FIRST' >&2
STDOUT-FROM-FIRST
STDERR-FROM-FIRST
-πŸ”„ Running pre-merge check 'second':
+πŸ”„ Running pre-merge check second:
  echo 'STDOUT-FROM-SECOND' && echo 'STDERR-FROM-SECOND' >&2
STDOUT-FROM-SECOND
STDERR-FROM-SECOND
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_failure.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_failure.snap
index 10385603c..44baf77a1 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_failure.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_failure.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmplG3FdQ/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp1qPE9E/test-config.toml
---
success: false
exit_code: 1
@@ -24,7 +24,7 @@ exit_code: 1
πŸ”„ Validating merge...
----- stderr -----
-πŸ”„ Running pre-merge check 'cmd':
+πŸ”„ Running pre-merge check cmd:
  exit 1
❌ Pre-merge check failed: cmd
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_named.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_named.snap
index be5ad9382..c262e6ad5 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_named.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_named.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp26Snm7/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpR9oYCy/test-config.toml
---
success: true
exit_code: 0
@@ -36,9 +36,9 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Running pre-merge check 'format':
+πŸ”„ Running pre-merge check format:
  exit 0
-πŸ”„ Running pre-merge check 'lint':
+πŸ”„ Running pre-merge check lint:
  exit 0
-πŸ”„ Running pre-merge check 'test':
+πŸ”„ Running pre-merge check test:
  exit 0
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap
index 222a00089..d125b2d24 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_stdout_stderr_ordering.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpHb5hJx/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWfdvac/test-config.toml
---
success: true
exit_code: 0
@@ -36,7 +36,7 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Running pre-merge check 'check1':
+πŸ”„ Running pre-merge check check1:
  [PROJECT_ROOT]/tests/fixtures/mixed-output.sh
  check1 3
[check1] stdout line 1
@@ -47,7 +47,7 @@ exit_code: 0
[check1] stderr line 3
[check1] stdout complete
[check1] stderr complete
-πŸ”„ Running pre-merge check 'check2':
+πŸ”„ Running pre-merge check check2:
  [PROJECT_ROOT]/tests/fixtures/mixed-output.sh
  check2 3
[check2] stdout line 1
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_success.snap b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_success.snap
index 0a7b1fd69..3ba61ed2b 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_success.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_pre_merge_check_success.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5SfvkD/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpFUYa5N/test-config.toml
---
success: true
exit_code: 0
@@ -36,5 +36,5 @@ exit_code: 0
βœ… Returned to primary at [REPO]
----- stderr -----
-πŸ”„ Running pre-merge check 'cmd':
+πŸ”„ Running pre-merge check cmd:
  exit 0