1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-12-01 21:23:20 +03:00

fix(changelog): return the last version if there is nothing to bump

fixes #533
This commit is contained in:
Orhun Parmaksız 2024-03-09 00:33:37 +01:00
parent d0c9d3b97f
commit 45c87f2f30
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
2 changed files with 23 additions and 10 deletions

View File

@ -24,7 +24,8 @@ use std::time::{
/// Changelog generator.
#[derive(Debug)]
pub struct Changelog<'a> {
releases: Vec<Release<'a>>,
/// Releases that the changelog will contain.
pub releases: Vec<Release<'a>>,
body_template: Template,
footer_template: Option<Template>,
config: &'a Config,

View File

@ -464,16 +464,28 @@ pub fn run(mut args: Opt) -> Result<()> {
// Print the result.
if args.bump || args.bumped_version {
if let Some(next_version) = changelog.bump_version()? {
if args.bumped_version {
if let Some(path) = args.output {
let mut output = File::create(path)?;
output.write_all(next_version.as_bytes())?;
} else {
println!("{next_version}");
}
return Ok(());
let next_version = if let Some(next_version) = changelog.bump_version()? {
next_version
} else if let Some(last_version) = changelog
.releases
.iter()
.next()
.cloned()
.and_then(|v| v.version)
{
warn!("There is nothing to bump.");
last_version
} else {
return Ok(());
};
if args.bumped_version {
if let Some(path) = args.output {
let mut output = File::create(path)?;
output.write_all(next_version.as_bytes())?;
} else {
println!("{next_version}");
}
return Ok(());
}
}
if args.context {