Skip to content

Commit 8ede538

Browse files
authored
gitcl: log output of failed git commands. (#409)
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 <aznashwan@icloud.com>
1 parent 50bebaf commit 8ede538

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

vergen-gitcl/src/gitcl/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,15 @@ impl Gitcl {
517517
_ = cmd.arg(command);
518518
_ = cmd.stdout(Stdio::piped());
519519
_ = cmd.stderr(Stdio::piped());
520-
Ok(cmd.output()?)
520+
521+
let output = cmd.output()?;
522+
if !output.status.success() {
523+
eprintln!("Command failed: `{command}`");
524+
eprintln!("--- stdout:\n{}\n", String::from_utf8_lossy(&output.stdout));
525+
eprintln!("--- stderr:\n{}\n", String::from_utf8_lossy(&output.stderr));
526+
}
527+
528+
Ok(output)
521529
}
522530

523531
#[cfg(target_env = "msvc")]
@@ -530,7 +538,15 @@ impl Gitcl {
530538
_ = cmd.arg(command);
531539
_ = cmd.stdout(Stdio::piped());
532540
_ = cmd.stderr(Stdio::piped());
533-
Ok(cmd.output()?)
541+
542+
let output = cmd.output()?;
543+
if !output.status.success() {
544+
eprintln!("Command failed: `{command}`");
545+
eprintln!("--- stdout:\n{}\n", String::from_utf8_lossy(&output.stdout));
546+
eprintln!("--- stderr:\n{}\n", String::from_utf8_lossy(&output.stderr));
547+
}
548+
549+
Ok(output)
534550
}
535551

536552
#[allow(clippy::too_many_lines)]

0 commit comments

Comments
 (0)