From 19d92d78e88485c0b4cea1fc11cd43c74892d171 Mon Sep 17 00:00:00 2001 From: Nashwan Azhari Date: Mon, 31 Mar 2025 17:17:30 +0300 Subject: [PATCH] gitcl: log output of failed `git` commands. This patch makes any `git` commands in the `vergen-gitcl` subcrate log their stdout/stderr on failure to provide more background. Signed-off-by: Nashwan Azhari --- vergen-gitcl/src/gitcl/mod.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/vergen-gitcl/src/gitcl/mod.rs b/vergen-gitcl/src/gitcl/mod.rs index 27cfc7d4..2af83778 100644 --- a/vergen-gitcl/src/gitcl/mod.rs +++ b/vergen-gitcl/src/gitcl/mod.rs @@ -517,7 +517,15 @@ impl Gitcl { _ = cmd.arg(command); _ = cmd.stdout(Stdio::piped()); _ = cmd.stderr(Stdio::piped()); - Ok(cmd.output()?) + + let output = cmd.output()?; + if !output.status.success() { + eprintln!("Command failed: `{command}`"); + eprintln!("--- stdout:\n{}\n", String::from_utf8_lossy(&output.stdout)); + eprintln!("--- stderr:\n{}\n", String::from_utf8_lossy(&output.stderr)); + } + + Ok(output) } #[cfg(target_env = "msvc")] @@ -530,7 +538,15 @@ impl Gitcl { _ = cmd.arg(command); _ = cmd.stdout(Stdio::piped()); _ = cmd.stderr(Stdio::piped()); - Ok(cmd.output()?) + + let output = cmd.output()?; + if !output.status.success() { + eprintln!("Command failed: `{command}`"); + eprintln!("--- stdout:\n{}\n", String::from_utf8_lossy(&output.stdout)); + eprintln!("--- stderr:\n{}\n", String::from_utf8_lossy(&output.stderr)); + } + + Ok(output) } #[allow(clippy::too_many_lines)]