Skip to content

Commit

Permalink
fix(changelog): allow using --bumped-version without conventional c…
Browse files Browse the repository at this point in the history
…ommits (#806)
  • Loading branch information
orhun authored Aug 22, 2024
1 parent 6f8ea19 commit e74080c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
27 changes: 27 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use std::fs;
use std::path::Path;
use std::path::PathBuf;

/// Default initial tag.
const DEFAULT_INITIAL_TAG: &str = "0.1.0";

/// Manifest file information and regex for matching contents.
#[derive(Debug)]
struct ManifestInfo {
Expand Down Expand Up @@ -246,6 +249,30 @@ pub struct Bump {
pub bump_type: Option<BumpType>,
}

impl Bump {
/// Returns the initial tag.
///
/// This function also logs the returned value.
pub fn get_initial_tag(&self) -> String {
match self.initial_tag.clone() {
Some(tag) => {
warn!(
"No releases found, using initial tag '{tag}' as the next \
version."
);
tag
}
None => {
warn!(
"No releases found, using {DEFAULT_INITIAL_TAG} as the next \
version."
);
DEFAULT_INITIAL_TAG.into()
}
}
}
}

/// Parser for grouping commits.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct CommitParser {
Expand Down
14 changes: 1 addition & 13 deletions git-cliff-core/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,7 @@ impl<'a> Release<'a> {
Ok(next_version)
}
}
None => match config.initial_tag.clone() {
Some(tag) => {
warn!(
"No releases found, using initial tag '{tag}' as the next \
version."
);
Ok(tag)
}
None => {
warn!("No releases found, using 0.1.0 as the next version.");
Ok(String::from("0.1.0"))
}
},
None => Ok(config.get_initial_tag()),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ pub fn run(mut args: Opt) -> Result<()> {
{
warn!("There is nothing to bump.");
last_version
} else if changelog.releases.is_empty() {
config.bump.get_initial_tag()
} else {
return Ok(());
};
Expand Down

0 comments on commit e74080c

Please sign in to comment.