Skip to content

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

fix: simplify post-merge hook failure output (#553)

Maximilian Roos519fb0f130f1
diff --git a/src/commands/hooks.rs b/src/commands/hooks.rs
index 8ce34da13..8faa3f1b9 100644
--- a/src/commands/hooks.rs
+++ b/src/commands/hooks.rs
@@ -5,7 +5,9 @@ use worktrunk::HookType;
use worktrunk::config::CommandConfig;
use worktrunk::git::WorktrunkError;
use worktrunk::path::format_path_for_display;
-use worktrunk::styling::{format_bash_with_gutter, progress_message, warning_message};
+use worktrunk::styling::{
+ error_message, format_bash_with_gutter, progress_message, warning_message,
+};
use super::command_executor::{CommandContext, PreparedCommand, prepare_commands};
use crate::commands::process::spawn_detached;
@@ -263,8 +265,8 @@ pub fn run_hook_with_filter(
return Ok(());
}
- // Track first failure for Warn strategy (to propagate exit code after all commands run)
- let mut first_failure: Option<(String, Option<String>, i32)> = None;
+ // Track first failure's exit code for Warn strategy (to propagate after all commands run)
+ let mut first_failure_exit_code: Option<i32> = None;
for cmd in commands {
cmd.announce()?;
@@ -302,12 +304,11 @@ pub fn run_hook_with_filter(
Some(name) => cformat!("Command <bold>{name}</> failed: {err_msg}"),
None => format!("Command failed: {err_msg}"),
};
- crate::output::print(warning_message(message))?;
+ crate::output::print(error_message(message))?;
// Track first failure to propagate exit code later (only for PostMerge)
- if first_failure.is_none() && hook_type == HookType::PostMerge {
- first_failure =
- Some((err_msg, cmd.prepared.name.clone(), exit_code.unwrap_or(1)));
+ if first_failure_exit_code.is_none() && hook_type == HookType::PostMerge {
+ first_failure_exit_code = Some(exit_code.unwrap_or(1));
}
}
}
@@ -318,14 +319,9 @@ pub fn run_hook_with_filter(
// For Warn strategy with PostMerge: if any command failed, propagate the exit code
// This matches git's behavior: post-hooks can't stop the operation but affect exit status
- if let Some((error, command_name, exit_code)) = first_failure {
- return Err(WorktrunkError::HookCommandFailed {
- hook_type,
- command_name,
- error,
- exit_code: Some(exit_code),
- }
- .into());
+ // Don't show another error message — warnings were already printed inline
+ if let Some(exit_code) = first_failure_exit_code {
+ return Err(WorktrunkError::AlreadyDisplayed { exit_code }.into());
}
Ok(())
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 0d1db492f..cb17b87f7 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
@@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -22,6 +22,7 @@ info:
PATH: "[PATH]"
RUST_LOG: warn
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
@@ -42,6 +43,4 @@ exit_code: 1
↳ To enable automatic cd, run wt config shell install
◎ Running post-merge project hook @ _REPO_:
  exit 1
-▲ Command failed: exit status: 1
-✗ post-merge command failed: exit status: 1
-↳ To skip post-merge hooks, re-run with --no-verify
+✗ Command failed: exit status: 1
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
index de824df61..2d1d22d6c 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap
@@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -35,7 +35,7 @@ exit_code: 0
----- stderr -----
◎ Running post-create project hook @ _REPO_.feature:
  exit 1
-▲ Command failed: exit status: 1
+✗ Command failed: exit status: 1
✓ Created branch feature and worktree from main @ _REPO_.feature
↳ Customize worktree locations: wt config create
▲ Cannot change directory — shell integration not installed
diff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap
index 00f40b83e..0061737e9 100644
--- a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap
+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap
@@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -35,7 +35,7 @@ exit_code: 0
----- stderr -----
◎ Running post-create user:failing @ _REPO_.feature:
  exit 1
-▲ Command failing failed: exit status: 1
+✗ Command failing failed: exit status: 1
✓ Created branch feature and worktree from main @ _REPO_.feature
↳ Customize worktree locations: wt config create
▲ Cannot change directory — shell integration not installed