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.rsindex 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.snapindex 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: warnSOURCE_DATE_EPOCH: "1735776000"+ TERM: alacrittyUSERPROFILE: "[TEST_HOME]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"@@ -42,6 +43,4 @@ exit_code: 1[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m[36m◎[39m [36mRunning post-merge project hook @ [1m_REPO_[22m:[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1-[0m[33m▲[39m [33mCommand failed: exit status: 1[39m-[31m✗[39m [31mpost-merge command failed: exit status: 1[39m-[2m↳[22m [2mTo skip post-merge hooks, re-run with [90m--no-verify[39m[22m+[0m[31m✗[39m [31mCommand failed: exit status: 1[39mdiff --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.snapindex 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 -----[36m◎[39m [36mRunning post-create project hook @ [1m_REPO_.feature[22m:[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1-[0m[33m▲[39m [33mCommand failed: exit status: 1[39m+[0m[31m✗[39m [31mCommand failed: exit status: 1[39m[32m✓[39m [32mCreated branch [1mfeature[22m and worktree from [1mmain[22m @ [1m_REPO_.feature[22m[39m[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39mdiff --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.snapindex 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 -----[36m◎[39m [36mRunning post-create [1muser:failing[22m @ [1m_REPO_.feature[22m:[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1-[0m[33m▲[39m [33mCommand [1mfailing[22m failed: exit status: 1[39m+[0m[31m✗[39m [31mCommand [1mfailing[22m failed: exit status: 1[39m[32m✓[39m [32mCreated branch [1mfeature[22m and worktree from [1mmain[22m @ [1m_REPO_.feature[22m[39m[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m