diff --git a/.github/fixtures/test-cli-arg-ignore-tags/cliff.toml b/.github/fixtures/test-cli-arg-ignore-tags/cliff.toml new file mode 100644 index 0000000000..63a1308e48 --- /dev/null +++ b/.github/fixtures/test-cli-arg-ignore-tags/cliff.toml @@ -0,0 +1,33 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing whitespace from the templates +trim = true + +[git] +# regex for skipping tags +skip_tags = "" +# regex for ignoring tags +ignore_tags = "" diff --git a/.github/fixtures/test-cli-arg-ignore-tags/commit.sh b/.github/fixtures/test-cli-arg-ignore-tags/commit.sh new file mode 100755 index 0000000000..4cc91676ac --- /dev/null +++ b/.github/fixtures/test-cli-arg-ignore-tags/commit.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add first beta feature" +git tag v1.0.0-beta.1 + +GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add second beta feature" +git tag v1.0.0-beta.2 + +# WARNING: If we won't create this commit, 1.0.0 won't be created! +GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "chore: why do i need a commit here?" +git tag v1.0.0 + +GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "fix: simple fix" +git tag v1.0.1 diff --git a/.github/fixtures/test-cli-arg-ignore-tags/expected.md b/.github/fixtures/test-cli-arg-ignore-tags/expected.md new file mode 100644 index 0000000000..c847179e2b --- /dev/null +++ b/.github/fixtures/test-cli-arg-ignore-tags/expected.md @@ -0,0 +1,22 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [1.0.1] - 2021-01-23 + +### Fix + +- Simple fix + +## [1.0.0] - 2021-01-23 + +### Chore + +- Why do i need a commit here? + +### Feat + +- Add first beta feature +- Add second beta feature + + diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index 59fe955ec9..0afbefd0d9 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -77,6 +77,9 @@ jobs: command: --bump - fixtures-name: test-bump-initial-tag-cli-arg command: --bump --tag=2.1.1 + - fixtures-name: test-cli-arg-ignore-tags + command: --ignore-tags ".*beta" + steps: - name: Checkout uses: actions/checkout@v4 diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 3d52a7b697..1fcd1c3b3c 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -142,6 +142,9 @@ pub struct Opt { num_args(1..) )] pub with_commit: Option>, + /// Sets the tags to ignore in the changelog. + #[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")] + pub ignore_tags: Option, /// Sets commits that will be skipped in the changelog. #[arg( long, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 61a835f6a5..a58c5d5695 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -489,7 +489,9 @@ pub fn run(mut args: Opt) -> Result<()> { if args.tag.is_some() { config.bump.initial_tag.clone_from(&args.tag); } - + if args.ignore_tags.is_some() { + config.git.ignore_tags.clone_from(&args.ignore_tags); + } // Process the repositories. let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]); let mut releases = Vec::::new(); diff --git a/website/docs/configuration/git.md b/website/docs/configuration/git.md index b7d7145919..7d3a92fc45 100644 --- a/website/docs/configuration/git.md +++ b/website/docs/configuration/git.md @@ -193,6 +193,8 @@ A regex for skip processing the matched tags. A regex for ignore processing the matched tags. +This value can be also overridden with using the `--ignore-tags` argument. + While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag. ### topo_order diff --git a/website/docs/usage/args.md b/website/docs/usage/args.md index f131874a78..5219301042 100644 --- a/website/docs/usage/args.md +++ b/website/docs/usage/args.md @@ -35,6 +35,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE] --exclude-path ... Sets the path to exclude related commits [env: GIT_CLIFF_EXCLUDE_PATH=] --tag-pattern Sets the regex for matching git tags [env: GIT_CLIFF_TAG_PATTERN=] --with-commit ... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=] + --ignore-tags Sets the tags to ignore in the changelog [env: GIT_CLIFF_IGNORE_TAGS=] --skip-commit ... Sets commits that will be skipped in the changelog [env: GIT_CLIFF_SKIP_COMMIT=] -p, --prepend Prepends entries to the given changelog file [env: GIT_CLIFF_PREPEND=] -o, --output [] Writes output to the given file [env: GIT_CLIFF_OUTPUT=]