Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ mod test {
RemoteConfig,
TextProcessor,
};
use crate::BLAME_IGNORE_FILE;
use pretty_assertions::assert_eq;
use regex::Regex;
use std::str;
Expand Down Expand Up @@ -719,19 +720,22 @@ mod test {
output: None,
},
git: GitConfig {
conventional_commits: Some(true),
require_conventional: Some(false),
filter_unconventional: Some(false),
split_commits: Some(false),
commit_preprocessors: Some(vec![TextProcessor {
conventional_commits: Some(true),
require_conventional: Some(false),
filter_unconventional: Some(false),
blame_ignore_revs_file: Some(BLAME_IGNORE_FILE.to_string()),
filter_blame_ignored_revs: Some(false),
filter_mono_commits_to_blame_ignore: Some(true),
split_commits: Some(false),
commit_preprocessors: Some(vec![TextProcessor {
pattern: Regex::new("<preprocess>")
.expect("failed to compile regex"),
replace: Some(String::from(
"this commit is preprocessed",
)),
replace_command: None,
}]),
commit_parsers: Some(vec![
commit_parsers: Some(vec![
CommitParser {
sha: Some(String::from("tea")),
message: None,
Expand Down Expand Up @@ -866,16 +870,16 @@ mod test {
},
]),
protect_breaking_commits: None,
filter_commits: Some(false),
tag_pattern: None,
skip_tags: Regex::new("v3.*").ok(),
ignore_tags: None,
count_tags: None,
use_branch_tags: Some(false),
topo_order: Some(false),
sort_commits: Some(String::from("oldest")),
link_parsers: None,
limit_commits: None,
filter_commits: Some(false),
tag_pattern: None,
skip_tags: Regex::new("v3.*").ok(),
ignore_tags: None,
count_tags: None,
use_branch_tags: Some(false),
topo_order: Some(false),
sort_commits: Some(String::from("oldest")),
link_parsers: None,
limit_commits: None,
},
remote: RemoteConfig {
github: Remote {
Expand Down
11 changes: 10 additions & 1 deletion git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ pub struct GitConfig {
/// Exclude commits that do not match the conventional commits specification
/// from the changelog.
pub filter_unconventional: Option<bool>,

/// Path to a file containing revision hashes to ignore when blaming
/// This is typically configured with `git config blame.ignoreRevsFile`
pub blame_ignore_revs_file: Option<String>,
/// Exclude commits with refs in the `blame_ignore_revs_file`
pub filter_blame_ignored_revs: Option<bool>,
/// Exclude commits that only modify the `blame_ignore_revs_file`
pub filter_mono_commits_to_blame_ignore: Option<bool>,

/// Split commits on newlines, treating each line as an individual commit.
pub split_commits: Option<bool>,
pub split_commits: Option<bool>,

/// An array of regex based parsers to modify commit messages prior to
/// further processing.
Expand Down
2 changes: 2 additions & 0 deletions git-cliff-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ pub const DEFAULT_CONFIG: &str = "cliff.toml";
pub const DEFAULT_OUTPUT: &str = "CHANGELOG.md";
/// Default ignore file.
pub const IGNORE_FILE: &str = ".cliffignore";
/// Default blame ignore file.
pub const BLAME_IGNORE_FILE: &str = ".git-blame-ignore-revs";
36 changes: 20 additions & 16 deletions git-cliff-core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use git_cliff_core::config::{
use git_cliff_core::error::Result;
use git_cliff_core::release::*;
use git_cliff_core::template::Template;
use git_cliff_core::BLAME_IGNORE_FILE;
use pretty_assertions::assert_eq;
use regex::Regex;
use std::collections::HashMap;
Expand Down Expand Up @@ -45,16 +46,19 @@ fn generate_changelog() -> Result<()> {
output: None,
};
let git_config = GitConfig {
conventional_commits: Some(true),
require_conventional: Some(false),
filter_unconventional: Some(true),
split_commits: Some(false),
commit_preprocessors: Some(vec![TextProcessor {
conventional_commits: Some(true),
require_conventional: Some(false),
filter_unconventional: Some(true),
blame_ignore_revs_file: Some(String::from(BLAME_IGNORE_FILE)),
filter_blame_ignored_revs: Some(false),
filter_mono_commits_to_blame_ignore: Some(true),
split_commits: Some(false),
commit_preprocessors: Some(vec![TextProcessor {
pattern: Regex::new(r"\(fixes (#[1-9]+)\)").unwrap(),
replace: Some(String::from("[closes Issue${1}]")),
replace_command: None,
}]),
commit_parsers: Some(vec![
commit_parsers: Some(vec![
CommitParser {
sha: Some(String::from("coffee")),
message: None,
Expand Down Expand Up @@ -117,15 +121,15 @@ fn generate_changelog() -> Result<()> {
},
]),
protect_breaking_commits: None,
filter_commits: Some(true),
tag_pattern: None,
skip_tags: None,
ignore_tags: None,
count_tags: None,
use_branch_tags: None,
topo_order: None,
sort_commits: None,
link_parsers: Some(vec![
filter_commits: Some(true),
tag_pattern: None,
skip_tags: None,
ignore_tags: None,
count_tags: None,
use_branch_tags: None,
topo_order: None,
sort_commits: None,
link_parsers: Some(vec![
LinkParser {
pattern: Regex::new("#(\\d+)").unwrap(),
href: String::from("https://github.com/$1"),
Expand All @@ -137,7 +141,7 @@ fn generate_changelog() -> Result<()> {
text: Some(String::from("$1")),
},
]),
limit_commits: None,
limit_commits: None,
};

let mut commit_with_author = Commit::new(
Expand Down
11 changes: 11 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use git_cliff_core::error::{
use git_cliff_core::release::Release;
use git_cliff_core::repo::Repository;
use git_cliff_core::{
BLAME_IGNORE_FILE,
DEFAULT_CONFIG,
IGNORE_FILE,
};
Expand Down Expand Up @@ -661,6 +662,16 @@ pub fn run_with_changelog_modifier(
.collect::<Vec<String>>();
skip_list.extend(commits);
}
let blame_ignore_file = repository.join(BLAME_IGNORE_FILE);
if blame_ignore_file.exists() {
let contents = fs::read_to_string(blame_ignore_file)?;
let commits = contents
.lines()
.filter(|v| !(v.starts_with('#') || v.trim().is_empty()))
.map(|v| String::from(v.trim()))
.collect::<Vec<String>>();
skip_list.extend(commits);
}
if let Some(ref skip_commit) = args.skip_commit {
skip_list.extend(skip_commit.clone());
}
Expand Down
34 changes: 34 additions & 0 deletions website/docs/configuration/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This section contains the parsing and git related configuration options.
conventional_commits = true
filter_unconventional = true
require_conventional = false
blame_ignore_revs_file = ".git-blame-ignore-revs"
filter_blame_ignored_revs = false
filter_mono_commits_to_blame_ignore = true
split_commits = false
commit_parsers = [
{ message = "^feat", group = "Features"},
Expand Down Expand Up @@ -96,6 +99,37 @@ If set to `true`, this option takes precedence over `filter_unconventional`.

Checking takes place after `commit_parsers`. Thus commits can be skipped by matching parsers.

### blame_ignore_revs_file

Path to a file containing a list of commit refs to ignore when generating blame information (configured with `git config blame.ignoreRevsFile`). The file should contain one commit ref per line. By convention, this file is named `.git-blame-ignore-revs` and is located in the root of the repository.

When used with `filter_blame_ignored_revs` set to `true`, commits that are listed in the file will be excluded from the changelog.

```toml
[git]
blame_ignore_revs_file = ".git-blame-ignore-revs"
```

### filter_blame_ignored_revs

If set to `true`, commits that are listed in the `blame_ignore_revs_file` will be excluded from the changelog.

```toml
[git]
blame_ignore_revs_file = ".git-blame-ignore-revs"
filter_blame_ignored_revs = false
```

### filter_mono_commits_to_blame_ignore

If set to `true`, commits that only modify the `blame_ignore_revs_file` will be excluded from the changelog.

```toml
[git]
blame_ignore_revs_file = ".git-blame-ignore-revs"
filter_mono_commits_to_blame_ignore = true
```

### split_commits

> This flag violates "conventional commits". It should remain off by default if conventional commits is to be respected.
Expand Down