diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 4014c95b47..110fe9ff2f 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -485,6 +485,7 @@ mod test { tag_pattern: None, skip_tags: Regex::new("v3.*").ok(), ignore_tags: None, + count_tags: None, topo_order: Some(false), sort_commits: Some(String::from("oldest")), link_parsers: None, diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index ad778637d2..4e8da72b94 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -109,6 +109,9 @@ pub struct GitConfig { /// Regex to ignore matched tags. #[serde(with = "serde_regex", default)] pub ignore_tags: Option, + /// Regex to count matched tags. + #[serde(with = "serde_regex", default)] + pub count_tags: Option, /// Whether to sort tags topologically. pub topo_order: Option, /// Sorting of the commits inside sections. diff --git a/git-cliff-core/tests/integration_test.rs b/git-cliff-core/tests/integration_test.rs index 27b2142668..9d01f24b88 100644 --- a/git-cliff-core/tests/integration_test.rs +++ b/git-cliff-core/tests/integration_test.rs @@ -113,6 +113,7 @@ fn generate_changelog() -> Result<()> { tag_pattern: None, skip_tags: None, ignore_tags: None, + count_tags: None, topo_order: None, sort_commits: None, link_parsers: Some(vec![ diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 51c63a7564..4276ed79de 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -87,12 +87,23 @@ fn process_repository<'a>( let mut tags = repository.tags(&config.git.tag_pattern, args.topo_order)?; let skip_regex = config.git.skip_tags.as_ref(); let ignore_regex = config.git.ignore_tags.as_ref(); + let count_tags = config.git.count_tags.as_ref(); tags = tags .into_iter() .filter(|(_, name)| { // Keep skip tags to drop commits in the later stage. let skip = skip_regex.map(|r| r.is_match(name)).unwrap_or_default(); + let count = count_tags + .map(|r| { + let count_tag = r.is_match(name); + if count_tag { + trace!("Counting release: {}", name) + } + count_tag + }) + .unwrap_or(true); + let ignore = ignore_regex .map(|r| { if r.as_str().trim().is_empty() { @@ -107,7 +118,7 @@ fn process_repository<'a>( }) .unwrap_or_default(); - skip || !ignore + skip || (count && !ignore) }) .collect();