Skip to content

Commit e74080c

Browse files
authored
fix(changelog): allow using --bumped-version without conventional commits (#806)
1 parent 6f8ea19 commit e74080c

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

git-cliff-core/src/config.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use std::fs;
1414
use std::path::Path;
1515
use std::path::PathBuf;
1616

17+
/// Default initial tag.
18+
const DEFAULT_INITIAL_TAG: &str = "0.1.0";
19+
1720
/// Manifest file information and regex for matching contents.
1821
#[derive(Debug)]
1922
struct ManifestInfo {
@@ -246,6 +249,30 @@ pub struct Bump {
246249
pub bump_type: Option<BumpType>,
247250
}
248251

252+
impl Bump {
253+
/// Returns the initial tag.
254+
///
255+
/// This function also logs the returned value.
256+
pub fn get_initial_tag(&self) -> String {
257+
match self.initial_tag.clone() {
258+
Some(tag) => {
259+
warn!(
260+
"No releases found, using initial tag '{tag}' as the next \
261+
version."
262+
);
263+
tag
264+
}
265+
None => {
266+
warn!(
267+
"No releases found, using {DEFAULT_INITIAL_TAG} as the next \
268+
version."
269+
);
270+
DEFAULT_INITIAL_TAG.into()
271+
}
272+
}
273+
}
274+
}
275+
249276
/// Parser for grouping commits.
250277
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
251278
pub struct CommitParser {

git-cliff-core/src/release.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,7 @@ impl<'a> Release<'a> {
154154
Ok(next_version)
155155
}
156156
}
157-
None => match config.initial_tag.clone() {
158-
Some(tag) => {
159-
warn!(
160-
"No releases found, using initial tag '{tag}' as the next \
161-
version."
162-
);
163-
Ok(tag)
164-
}
165-
None => {
166-
warn!("No releases found, using 0.1.0 as the next version.");
167-
Ok(String::from("0.1.0"))
168-
}
169-
},
157+
None => Ok(config.get_initial_tag()),
170158
}
171159
}
172160
}

git-cliff/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ pub fn run(mut args: Opt) -> Result<()> {
583583
{
584584
warn!("There is nothing to bump.");
585585
last_version
586+
} else if changelog.releases.is_empty() {
587+
config.bump.get_initial_tag()
586588
} else {
587589
return Ok(());
588590
};

0 commit comments

Comments
 (0)