Skip to content

Commit

Permalink
fix(changelog): return the last version if there is nothing to bump
Browse files Browse the repository at this point in the history
fixes #533
  • Loading branch information
orhun committed Mar 8, 2024
1 parent d0c9d3b commit 45c87f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 21 additions & 9 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 45c87f2

Please sign in to comment.