From 6701e86c3878956a5f8859a80695eb4fc1b7f007 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 28 Jan 2024 01:33:43 +0100 Subject: [PATCH] changelog until last tag --- src/changelog/mod.rs | 23 ++++++++++++++++++++++- src/error.rs | 4 +++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/changelog/mod.rs b/src/changelog/mod.rs index 6a06e77..c9ef833 100644 --- a/src/changelog/mod.rs +++ b/src/changelog/mod.rs @@ -22,15 +22,36 @@ impl Changelog { return Ok(None); } let mut cmd = Command::new("git"); - cmd.arg("log").arg("--oneline").arg("--decorate"); + cmd.arg("log").arg(format!("{}..HEAD", Self::get_last_tag()?,)).arg("--oneline"); let out = cmd.output()?; // FIXME: this does not catch fancy colors let buf = String::from_utf8(out.stdout).map_err(|err|{ ChangelogError::GitUTF8Error(err) })?; + if !out.status.success() { + return Err( + ChangelogError::GitBadStatus(out.status, buf).into() + ) + } Ok(Some(buf)) } + + fn get_last_tag() -> Result { + let mut cmd = Command::new("git"); + cmd.arg("describe").arg("--tags").arg("--abbrev=0"); + let out = cmd.output()?; + let buf = String::from_utf8(out.stdout).map_err(|err|{ + ChangelogError::GitUTF8Error(err) + })?; + if !out.status.success() { + return Err( + ChangelogError::GitBadStatus(out.status, buf).into() + ) + } + let buf = buf.replace("\n", ""); + return Ok(buf) + } } impl Display for Changelog { diff --git a/src/error.rs b/src/error.rs index 32e5d7b..deb1e8a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, string::FromUtf8Error}; +use std::{path::PathBuf, process::ExitStatus, string::FromUtf8Error}; use anyhow; use thiserror::Error; @@ -30,6 +30,8 @@ pub enum ChangelogError { GitCommandError, #[error("error while using `git log`, could not format stdout with utf8")] GitUTF8Error(#[from] FromUtf8Error), + #[error("git exited with status {0}: {1}")] + GitBadStatus(ExitStatus, String), } #[derive(Error, Debug)] pub enum ConfigError {