use anyhow::{bail, Result};
use std::process::{Command, Stdio};
fn main() -> Result<()> {
let commit = Command::new("git")
.args(["log", "-1", "--format=%B"])
.stdout(Stdio::piped())
.output()?
.stdout;
let commit = String::from_utf8(commit)?;
let commit = gccrs_tools::Commit::new(commit);
let prefixed_commit = commit.maybe_prefix();
let status = Command::new("git")
.args(["commit", "--amend", "-m", &prefixed_commit])
.status()?;
if status.success() {
Ok(())
} else {
bail!("error when amending commit with new message:\n{prefixed_commit}")
}
}