diff --git a/README.md b/README.md index 2957a0f277..5233d9b5df 100644 --- a/README.md +++ b/README.md @@ -778,6 +778,8 @@ BREAKING CHANGE: this is a breaking change If the `BREAKING CHANGE:` footer is present, the footer will also be included in `commit.footers`. +Breaking changes will never be skipped, even when matched by a skipping [commit_parser](#commit_parsers). + ##### Committer vs Author From [Git docs](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History): diff --git a/git-cliff-core/src/commit.rs b/git-cliff-core/src/commit.rs index 0df2914b47..d1f14e33c8 100644 --- a/git-cliff-core/src/commit.rs +++ b/git-cliff-core/src/commit.rs @@ -233,6 +233,15 @@ impl Commit<'_> { Ok(self) } + /// States if the commit is skipped in the provided `CommitParser`. + /// + /// Returns `true` if the parser's `skip` field is `true` and the commit is + /// not breaking, `false` otherwise. + fn skip_commit(&self, parser: &CommitParser) -> bool { + parser.skip.unwrap_or(false) && + self.conv.as_ref().map(|c| !c.breaking()).unwrap_or(false) + } + /// Parses the commit using [`CommitParser`]s. /// /// Sets the [`group`] and [`scope`] of the commit. @@ -253,15 +262,15 @@ impl Commit<'_> { } for (regex, text) in regex_checks { if regex.is_match(&text) { - if parser.skip != Some(true) { + if self.skip_commit(parser) { + return Err(AppError::GroupError(String::from( + "Skipping commit", + ))); + } else { self.group = parser.group.as_ref().cloned(); self.scope = parser.scope.as_ref().cloned(); self.default_scope = parser.default_scope.as_ref().cloned(); return Ok(self); - } else { - return Err(AppError::GroupError(String::from( - "Skipping commit", - ))); } } } diff --git a/git-cliff/src/changelog.rs b/git-cliff/src/changelog.rs index f56b2faf23..67d79a0025 100644 --- a/git-cliff/src/changelog.rs +++ b/git-cliff/src/changelog.rs @@ -301,6 +301,10 @@ mod test { String::from("qwerty"), String::from("chore: "), ), + Commit::new( + String::from("qwertz"), + String::from("feat!: support breaking commits"), + ), ], commit_id: Some(String::from("0bc123")), timestamp: 50000000, @@ -328,6 +332,10 @@ mod test { String::from("docs(app): document zyx"), ), Commit::new(String::from("def789"), String::from("merge #4")), + Commit::new( + String::from("dev063"), + String::from("feat!: merge #5"), + ), Commit::new( String::from("qwerty"), String::from("fix(app): fix abc"), @@ -364,6 +372,9 @@ mod test { #### app - add xyz + #### other + - merge #5 + ### Other #### app - document zyx @@ -388,6 +399,7 @@ mod test { #### other - support unscoped commits + - support breaking commits ### Other #### app @@ -455,6 +467,9 @@ chore(deps): fix broken deps #### app - add xyz + #### other + - merge #5 + ### Other #### app - document zyx @@ -490,6 +505,7 @@ chore(deps): fix broken deps #### other - support unscoped commits + - support breaking commits - add awesome stuff ### Other